using Nullframes.Intrigues.SaveSystem; using UnityEngine; namespace Nullframes.Intrigues { public class RuntimeActor : Actor { protected override void OnAwake() { Init(); LoadData(); RegisterEvents(); } protected override void OnStart() { } protected override void OnActorDeath() { base.OnActorDeath(); } #region RUNTIME /// /// Creates a new RuntimeActor and its corresponding GameObject to represent a new actor in the game. /// /// The name of the new actor. /// The initial state of the new actor. /// The age of the new actor. /// The cultural background of the new actor. /// The gender of the new actor. /// The sprite used for the new actor's portrait. /// Out parameter that returns the created RuntimeActor instance. /// Out parameter that returns the GameObject associated with the new actor. /// /// This method is used to create new characters within the game, such as when a child is born or a new character is introduced. /// It initializes a RuntimeActor with the provided details and also creates a corresponding GameObject. /// public static void CreateActor(string name, IState state, int age, Culture culture, IGender gender, Sprite portrait, out RuntimeActor runtimeActor, out GameObject gameObj) { var actor = CreateActor(name, state, age, culture, gender, portrait); runtimeActor = actor; gameObj = runtimeActor.gameObject; } /// /// Creates a new RuntimeActor and its corresponding GameObject to represent a new actor in the game. /// /// The name of the new actor. /// The initial state of the new actor. /// The age of the new actor. /// The cultural background of the new actor. /// The gender of the new actor. /// The sprite used for the new actor's portrait. /// /// This method is used to create new characters within the game, such as when a child is born or a new character is introduced. /// It initializes a RuntimeActor with the provided details and also creates a corresponding GameObject. /// public static RuntimeActor CreateActor(string name, IState state, int age, Culture culture, IGender gender, Sprite portrait) { var gameObj = new GameObject($"{name}(Runtime)"); var runtimeActor = gameObj.AddComponent(); runtimeActor.ID = NullUtils.GenerateID(); runtimeActor.Name = name; runtimeActor.State = state; runtimeActor.Age = age; runtimeActor.Culture = culture; runtimeActor.Gender = gender; runtimeActor.Portrait = portrait; IM.AddActor(runtimeActor); runtimeActor.UpdateVariables(); runtimeActor.UpdateActor(); IM.onRuntimeActorCreated?.Invoke(runtimeActor, gameObj); return runtimeActor; } public static void LoadRuntimeActor(ActorData data) { if (IM.ActorDictionary.ContainsKey(data.id)) return; var gameObject = new GameObject($"{data.name}(Runtime)"); var actor = gameObject.AddComponent(); actor.ID = data.id; actor.Data = data; actor.UpdateVariables(); actor.UpdateActor(); IM.AddActor(actor); IntrigueSaveSystem.onRuntimeActorsLoaded += Load; void Load() { actor.UpdateFamily(); actor.UpdateClan(); actor.SpawnFamilyMember(); IM.onRuntimeActorCreated?.Invoke(actor, gameObject); IntrigueSaveSystem.onRuntimeActorsLoaded -= Load; } } #endregion } }