SteamModule.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using KairoEngine.Core;
  6. using KairoEngine.Core.ModuleSystem;
  7. using Sirenix.OdinInspector;
  8. namespace KairoEngine.SteamIntegration
  9. {
  10. public class SteamModule : GameModuleBase
  11. {
  12. public override string name => "Steam Module";
  13. [LabelText("Steamworks App ID")] public uint appId = 0000000;
  14. public bool showDebug = false;
  15. public bool useSteamStats = true;
  16. public bool useSteamAchievements = true;
  17. [NonSerialized, ShowInInspector, InlineEditor(InlineEditorObjectFieldModes.Boxed), PropertySpace(4,0), ShowIf("@useSteamStats")]
  18. public SteamworksStatLibrary steamStats;
  19. public SteamModule(GameConfig config) : base(config)
  20. {
  21. this.gameConfig = config;
  22. this.className = this.GetType().AssemblyQualifiedName;
  23. this.typeName = "SteamModule";
  24. }
  25. public override void Load(Transform parent)
  26. {
  27. GameObject obj = GameObject.Instantiate(new GameObject(), parent);
  28. obj.name = "SteamIntegration";
  29. SteamworksManager steamworksManager = obj.AddComponent<SteamworksManager>();
  30. steamworksManager.appId = appId;
  31. steamworksManager.ShowDebug(showDebug);
  32. steamworksManager.useStats = useSteamStats;
  33. if(useSteamStats && steamStats != null) steamworksManager.steamStatsLibray = steamStats;
  34. steamworksManager.useAchievements = useSteamAchievements;
  35. }
  36. public override void Start() { }
  37. public override void Reset() { }
  38. public override void Destroy() { }
  39. public static SteamModule JSONToSteamModule(string data)
  40. {
  41. try
  42. {
  43. return JsonUtility.FromJson<SteamModule>(data);
  44. }
  45. catch (System.Exception e)
  46. {
  47. Debug.LogError($"Could not deserialize SteamModule: \n{e}");
  48. return new SteamModule(null);
  49. }
  50. }
  51. public override void OnBeforeSerialize(ObjectSerializer serializer)
  52. {
  53. if(steamStats != null) serializer.AddScriptableObject("SteamIntegration_statsLibrary", steamStats);
  54. }
  55. public override void OnBeforeDeserialize(ObjectSerializer serializer)
  56. {
  57. steamStats = (SteamworksStatLibrary)serializer.GetScriptableObject("SteamIntegration_statsLibrary");
  58. }
  59. }
  60. }