protected override ObjectInitData AttemptRecreateInitData() { string guessedPrefabPath = PrefabPath + gameObject.name.Split(new char[' '])[0]; ObjectInitData newinitData = new ObjectInitData(guessedPrefabPath); return(newinitData); }
GameObject SpawnInstance(GameObject prototype, ObjectInitData initData = null, string savedUniqueID = null) { // Instantiate prototype GameObject instance = Instantiate(prototype); // Get SaveLoadable component of instance SaveLoadableGameObject spawnedObject = instance.GetComponent <SaveLoadableGameObject>(); if (initData == null) { Debug.LogFormat("GameObject {0} spawning without any initialization data", prototype.name); } else { spawnedObject.Initialize(initData); } // If we are spawning an object with a saved UniqueID, set it here if (savedUniqueID != null) { instance.GetComponent <UniqueID>().SetUniqueIDFromSaveFile(savedUniqueID); } // WorldController should listen for this and add it to its dictionary cbPrefabSpawned(instance); return(instance); }
// TODO: Would be nice to track which prefabs have already been loaded // to avoid loading Poster / Postit prefabs more than once public void OnSpawnMenuButtonClicked(MenuButton menuButton, ObjectInitData objectInitdata) { GameObject prototype = CreatePrototype(objectInitdata.PrefabPath); // TODO: Add prototype to dictionary here GameObject instance = SpawnInstance(prototype, objectInitdata); // TODO: Call ManipulateController or otherwise handle the grab when spawning from menu }
public virtual void Save(WorldSaveData worldSaveData) { // This would occur if we place objects in the Editor manually. if (initData == null) { initData = AttemptRecreateInitData(); } // Record current transform in serializable format transformData = new SerializableTransform(this.transform); }
// TODO: Is it safe to keep this public? Maybe should be called by Start / OnEnable and protected? public override void Initialize(ObjectInitData initData) { // Confirm that ObjectInitData is valid PosterData if (initData == null) { Debug.LogError("Attempting to initialize Poster with null objectInitData"); return; } else if (initData.GetType() != typeof(PosterInitData)) { Debug.LogErrorFormat("Attempting to initialize a Poster with ObjectInitData of type {0}. Valid PosterInitData required."); return; } // Cast initData to PosterInitData posterInitData = (PosterInitData)initData; // Set label to PosterData.Label // Set texture to PosterData.Texture posterTexture = posterInitData.Texture; base.Initialize(initData); }
// All SaveLoadableGameObjects must be initialized from prefabs. // ObjectInitData contains everything this prefab need to build a specific instance. // ObjectInitData contains a prefab path as a string at the minimum. // Derived classes may use more specific InitData // For example, PosterInitData (with texture and label information) // TODO: Is it safe to keep this public? public virtual void Initialize(ObjectInitData initData) { this.initData = initData; }
public GameObjectSaveData(ObjectInitData initData, SerializableTransform transformData) { this.initData = initData; this.transformData = transformData; }
public SpawnMenuItem(string label, Sprite icon, ObjectInitData objectInitData = null) { this.Label = label; this.Icon = icon; this.ObjectInitData = objectInitData; }