/// <summary> /// Gets the state for the object with the given guid. This is not a copy! /// </summary> /// <param name="guid">GUID.</param> /// <param name="defaultStateIsDisabled">If true the object starts disabled.</param> public PersistableObjectData GetState(string guid, bool defaultStateIsDisabled) { if (objectData.ContainsKey(guid)) { return(objectData [guid]); } else { PersistableObjectData data = new PersistableObjectData(); data.guid = guid; data.state = !defaultStateIsDisabled; objectData.Add(guid, data); return(data); } }
/// <summary> /// Sets the state for the object with the given guid. /// </summary> /// <param name="guid">GUID.</param> /// <param name="state">State to set.</param> /// <param name="extraInfo">Extra info.</param> public void SetState(string guid, bool state, string extraInfo) { if (objectData.ContainsKey(guid)) { objectData [guid].state = state; objectData [guid].extraStateInfo = extraInfo; } else { PersistableObjectData data = new PersistableObjectData(); data.guid = guid; data.state = state; data.extraStateInfo = extraInfo; objectData.Add(guid, data); } if (saveOnChange) { Save(); } }
/// <summary> /// Processes the persisted state. /// </summary> virtual protected void ProcessState() { PersistableObjectData data = PersistableObjectManager.Instance.GetState(guid, defaultStateIsDisabled); if (data.state) { switch (implementation) { case PersistableObjectType.ACTIVATE_DEACTIVATE: target.SetActive(true); break; // Skip destroy there is no corresponding 'undestroy' case PersistableObjectType.SEND_MESSAGE: target.SendMessage("SetPersistenceState", true, SendMessageOptions.RequireReceiver); break; case PersistableObjectType.PLATFORM: Platform platform = target.GetComponent <Platform> (); if (platform == null) { Debug.LogWarning("Persistence type set to PLATFORM but no Platform component was found"); } else { platform.Activate(null); } break; case PersistableObjectType.DOOR: Door door = target.GetComponent <Door> (); if (door == null) { Debug.LogWarning("Persistence type set to DOOR but no Door component was found"); } else { door.ForceOpen(); } break; } } else { switch (implementation) { case PersistableObjectType.ACTIVATE_DEACTIVATE: target.SetActive(false); break; case PersistableObjectType.DESTROY: Destroy(target); break; case PersistableObjectType.SEND_MESSAGE: target.SendMessage("SetPersistenceState", false, SendMessageOptions.RequireReceiver); break; case PersistableObjectType.PLATFORM: Platform platform = target.GetComponent <Platform> (); if (platform == null) { Debug.LogWarning("Persistence type set to PLATFORM but no Platform component was found"); } else { platform.Deactivate(null); } break; case PersistableObjectType.DOOR: Door door = target.GetComponent <Door> (); if (door == null) { Debug.LogWarning("Persistence type set to DOOR but no Door component was found"); } else { door.ForceClosed(); } break; } } }