1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using KairoEngine.Core;
- using KairoEngine.Core.ModuleSystem;
- using Sirenix.OdinInspector;
- namespace KairoEngine.SteamIntegration
- {
- public class SteamModule : GameModuleBase
- {
- public override string name => "Steam Module";
- [LabelText("Steamworks App ID")] public uint appId = 0000000;
- public bool showDebug = false;
- public bool useSteamStats = true;
- public bool useSteamAchievements = true;
- [NonSerialized, ShowInInspector, InlineEditor(InlineEditorObjectFieldModes.Boxed), PropertySpace(4,0), ShowIf("@useSteamStats")]
- public SteamworksStatLibrary steamStats;
- public SteamModule(GameConfig config) : base(config)
- {
- this.gameConfig = config;
- this.className = this.GetType().AssemblyQualifiedName;
- this.typeName = "SteamModule";
- }
- public override void Load(Transform parent)
- {
- GameObject obj = GameObject.Instantiate(new GameObject(), parent);
- obj.name = "SteamIntegration";
- SteamworksManager steamworksManager = obj.AddComponent<SteamworksManager>();
- steamworksManager.appId = appId;
- steamworksManager.ShowDebug(showDebug);
- steamworksManager.useStats = useSteamStats;
- if(useSteamStats && steamStats != null) steamworksManager.steamStatsLibray = steamStats;
- steamworksManager.useAchievements = useSteamAchievements;
- }
- public override void Start() { }
- public override void Reset() { }
- public override void Destroy() { }
- public static SteamModule JSONToSteamModule(string data)
- {
- try
- {
- return JsonUtility.FromJson<SteamModule>(data);
- }
- catch (System.Exception e)
- {
- Debug.LogError($"Could not deserialize SteamModule: \n{e}");
- return new SteamModule(null);
- }
- }
- public override void OnBeforeSerialize(ObjectSerializer serializer)
- {
- if(steamStats != null) serializer.AddScriptableObject("SteamIntegration_statsLibrary", steamStats);
- }
- public override void OnBeforeDeserialize(ObjectSerializer serializer)
- {
- steamStats = (SteamworksStatLibrary)serializer.GetScriptableObject("SteamIntegration_statsLibrary");
- }
- }
- }
|