|
@@ -1,4 +1,5 @@
|
|
|
-using System.Collections;
|
|
|
+using System;
|
|
|
+using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using UnityEngine;
|
|
|
using Sirenix.OdinInspector;
|
|
@@ -15,37 +16,44 @@ namespace KairoEngine.StorySystem
|
|
|
None
|
|
|
}
|
|
|
|
|
|
- [System.Serializable]
|
|
|
- public class StoryObject
|
|
|
+ [Serializable, HideReferenceObjectPicker]
|
|
|
+ public class StoryObject : System.Object
|
|
|
{
|
|
|
- public string name;
|
|
|
- public GameObject prefab;
|
|
|
- [HideInInspector] public GameObject instance;
|
|
|
+ [HorizontalGroup("line", 0.3f), HideLabel] public string name;
|
|
|
+ [HorizontalGroup("line", 0.7f), HideLabel, NonSerialized] public GameObject prefab;
|
|
|
+ [HideInInspector, NonSerialized] public GameObject instance;
|
|
|
}
|
|
|
|
|
|
- public class StorySystemModule : IGameModule
|
|
|
+ [Serializable, HideReferenceObjectPicker]
|
|
|
+ public class StorySystemModule : GameModuleBase
|
|
|
{
|
|
|
- private string _name = "Story Module";
|
|
|
+ public override string name => "Story Module";
|
|
|
|
|
|
- public string name { get => _name; set => _name = value; }
|
|
|
+ [FoldoutGroup("@name"), ShowInInspector, NonSerialized] public TextAsset inkJSONAsset = null;
|
|
|
+ [FoldoutGroup("@name")] public string storyName = "Storyline";
|
|
|
|
|
|
- public TextAsset inkJSONAsset = null;
|
|
|
- public string storyName = "Storyline";
|
|
|
+ [FoldoutGroup("@name")] public bool showStoryLog = false;
|
|
|
|
|
|
- public bool showStoryLog = false;
|
|
|
+ [FoldoutGroup("@name")] public int lineInverval = 250;
|
|
|
|
|
|
- public int lineInverval = 250;
|
|
|
+ [FoldoutGroup("@name"), LabelText("Start")] public StoryInitType startType;
|
|
|
|
|
|
- [LabelText("Start")] public StoryInitType startType;
|
|
|
+ [FoldoutGroup("@name"), ShowIf("@startType == StoryInitType.OnEvent")] public string eventStartName = "StartStory";
|
|
|
|
|
|
- [ShowIf("@startType == StoryInitType.OnEvent")] public string eventStartName = "StartStory";
|
|
|
-
|
|
|
- [Space] public List<StoryObject> storyObjects = new List<StoryObject>();
|
|
|
+ [FoldoutGroup("@name"), Space] public List<StoryObject> storyObjects = new List<StoryObject>();
|
|
|
+ [SerializeField, HideInInspector] private int storyObjectsCount = 0;
|
|
|
|
|
|
private StoryController storyController;
|
|
|
private Transform storyObjectsContainer = null;
|
|
|
|
|
|
- public void Load(Transform parent)
|
|
|
+ public StorySystemModule(GameConfig config) : base(config)
|
|
|
+ {
|
|
|
+ this.gameConfig = config;
|
|
|
+ this.className = this.GetType().AssemblyQualifiedName;
|
|
|
+ this.typeName = "StorySystemModule";
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void Load(Transform parent)
|
|
|
{
|
|
|
if(storyObjects.Count > 0) storyObjectsContainer = new GameObject("StoryObjects").transform;
|
|
|
if(storyObjectsContainer != null) storyObjectsContainer.transform.parent = parent;
|
|
@@ -60,17 +68,65 @@ namespace KairoEngine.StorySystem
|
|
|
if(storyController != null) storyController.Start();
|
|
|
}
|
|
|
|
|
|
- public void Reset()
|
|
|
+ public override void Reset()
|
|
|
{
|
|
|
showStoryLog = false;
|
|
|
inkJSONAsset = null;
|
|
|
storyController = null;
|
|
|
}
|
|
|
|
|
|
- public void Destroy()
|
|
|
+ public override void Destroy()
|
|
|
{
|
|
|
if(storyController != null) storyController.Stop();
|
|
|
if(startType == StoryInitType.OnEvent) GenericEvents.StopListening(eventStartName, () => LoadStory(storyObjectsContainer));
|
|
|
}
|
|
|
+
|
|
|
+ public static StorySystemModule JSONToStorySystemModule(string data)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ return JsonUtility.FromJson<StorySystemModule>(data);
|
|
|
+ }
|
|
|
+ catch (System.Exception e)
|
|
|
+ {
|
|
|
+ Debug.LogError($"Could not deserialize StorySystemModule: \n{e}");
|
|
|
+ return new StorySystemModule(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void OnBeforeSerialize(ObjectSerializer serializer)
|
|
|
+ {
|
|
|
+ if(inkJSONAsset) serializer.objects.Add("inkJSONAsset", inkJSONAsset);
|
|
|
+ if(storyObjectsContainer != null) serializer.gameObjecs.Add("storyObjectsContainer", storyObjectsContainer.gameObject);
|
|
|
+ if(storyController != null) serializer.objects.Add("storyController", storyController);
|
|
|
+ storyObjectsCount = storyObjects.Count;
|
|
|
+ for (int i = 0; i < storyObjects.Count; i++)
|
|
|
+ {
|
|
|
+ serializer.objects.Add($"storyObjects_{i}", storyObjects[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public override void OnBeforeDeserialize(ObjectSerializer serializer)
|
|
|
+ {
|
|
|
+ // inkJSONAsset
|
|
|
+ object obj = null;
|
|
|
+ serializer.objects.TryGetValue("inkJSONAsset", out obj);
|
|
|
+ if(obj != null) inkJSONAsset = (TextAsset)obj;
|
|
|
+ // storyObjectsContainer
|
|
|
+ GameObject gameObject = null;
|
|
|
+ serializer.gameObjecs.TryGetValue("storyObjectsContainer", out gameObject);
|
|
|
+ if(gameObject != null) storyObjectsContainer = gameObject.transform;
|
|
|
+ // storyController
|
|
|
+ obj = null;
|
|
|
+ serializer.objects.TryGetValue("storyController", out obj);
|
|
|
+ if(obj != null) storyController = (StoryController)obj;
|
|
|
+ // storyObjects
|
|
|
+ for (int i = 0; i < storyObjectsCount; i++)
|
|
|
+ {
|
|
|
+ obj = null;
|
|
|
+ serializer.objects.TryGetValue($"storyObjects_{i}", out obj);
|
|
|
+ if(obj != null) storyObjects.Add((StoryObject)obj);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|