/** * Destroys the current prefab * Sets the state to the new state * Finds the proper prefab for the state and instantiates it **/ protected virtual void Update() { if (_requestedState == _state) { return; } _state = _requestedState; //TODO: Send out End() update? if (currentPrefab) { Destroy(currentPrefab); } foreach (Prefab prefab in prefabs) { if (prefab.state == _state) { currentPrefab = Instantiate(prefab.prefabObject); break; } } // Dispatch any messages intended for this guy foreach (KeyValuePair <string, object> kvp in _queuedMessages) { currentPrefab.SendMessage(kvp.Key, kvp.Value); } }
// Common save function for all the game prefabs. public void SaveFunction(object sender, EventArgs args) { PrefabState ps = new PrefabState(); ps.prefabTag = PrefabTag; ps.position = gameObject.transform.position; ps.rotation = gameObject.transform.rotation; ps.id = SaveManager.Instance.Game.GetUniqueId(); SaveManager.Instance.Game.SaveableObjects.Add(ps); // Save a spatial anchor, if possible. WorldAnchorStore store = SaveManager.Instance.Store; if (store != null) { Debug.Log("Begin saving World Anchor for " + gameObject.name); // Get an existing anchor or add a new one. WorldAnchor anchor = gameObject.GetComponent(typeof(WorldAnchor)) as WorldAnchor; if (anchor == null) { anchor = gameObject.AddComponent(typeof(WorldAnchor)) as WorldAnchor; } // Save this position to restore later. if (anchor != null && anchor.isLocated) { String storeId = SaveManager.Instance.Game.AppAnchorPrefix + ps.id; if (store.Delete(storeId)) { Debug.Log("Deleted old World Anchor for " + gameObject.name); } if (store.Save(storeId, anchor)) { Debug.Log("World Anchor Saved for " + gameObject.name); } } else { Debug.Log("Unable to save World Anchor for " + gameObject.name); } } Debug.Log(gameObject.name + " added to save game"); }
public void changeState(PrefabState state) { _requestedState = state; }