//serialization constructor /*protected Object2PropertiesMapping(SerializationInfo info,StreamingContext context) { * savedStates = (OrderedDictionary<int,SavedState>)info.GetValue("savedStates",typeof(OrderedDictionary<int,SavedState>)); * isParentObj = info.GetBoolean("isParentObj"); * parentMapping = (Object2PropertiesMapping)info.GetValue("parentMapping",typeof(Object2PropertiesMapping)); * childNo = info.GetInt32("childNo"); * prefabLoadPath = info.GetString("prefabLoadPath"); * lastChangedFrame = info.GetInt32("lastChangedFrame"); * firstChangedFrame = info.GetInt32("firstChangedFrame"); * try { * childIdentificationMode = (ChildIdentificationMode)info.GetValue("childIdentificationMode",typeof(ChildIdentificationMode)); * } catch (SerializationException) { * //file was recorded using old version of this plugin * childIdentificationMode = ChildIdentificationMode.IDENTIFY_BY_ORDER; * } * try { * gameObjectName = info.GetString("gameObjectName"); * } catch (SerializationException) { * //file was recorded using old version of this plugin * childIdentificationMode = ChildIdentificationMode.IDENTIFY_BY_ORDER; * gameObjectName = "name_untraceable"; * } * }*/ public Object2PropertiesMapping(GameObject go, bool isParent, Object2PropertiesMapping parentMapping, int childNo, string prefabLoadPath, ChildIdentificationMode childIdentificationMode) : this(go, isParent, parentMapping, childNo, prefabLoadPath) { this.childIdentificationMode = childIdentificationMode; if (isParentObj) // if gameObject is a parent.. //..instantiate mappings for all children too { Transform[] allChildren = gameObject.GetComponentsInChildren <Transform>(); for (int i = 0; i < allChildren.Length; i++) { GameObject child = allChildren[i].gameObject; if (!EZReplayManager.get.gOs2propMappings.ContainsKey(child)) { if (child != gameObject) { EZReplayManager.get.gOs2propMappings.Add(child, new Object2PropertiesMapping(child, false, this, i, "", childIdentificationMode)); } } else if (EZReplayManager.showHints) { Debug.Log("EZReplayManager HINT: GameObject '" + child + "' is already being recorded. Will not be marked for recording again."); } } } }
//called to synchronize gameObjectClone of Object2PropertiesMapping back to this saved state public void synchronizeProperties(GameObject go, Object2PropertiesMapping o2m) { //HINT: lerping is still highly experimental //EZReplayManager.singleton.StartCoroutine_Auto(EZReplayManager.singleton.MoveTo (go.transform,serVec3ToVec3(this.localPosition),0.08f)); if (o2m.isParentObj && o2m.getGameObject() != null && o2m.getGameObject().transform.parent != null) { go.transform.position = this.position; go.transform.rotation = this.rotation; } else { go.transform.localPosition = this.localPosition; go.transform.localRotation = this.localRotation; } go.SetActive(this.isActive); if (emittingParticles) { go.GetComponent <ParticleEmitter> ().emit = true; } else if (go.GetComponent <ParticleEmitter> ()) { go.GetComponent <ParticleEmitter> ().emit = false; } }
//as this is not derived from MonoBehaviour, we have a constructor protected Object2PropertiesMapping(GameObject go, bool isParent, Object2PropertiesMapping parentMapping, int childNo) { //setting instance variables this.gameObject = go; this.isParentObj = isParent; this.parentMapping = parentMapping; this.childNo = childNo; this.gameObjectInstanceID = go.GetInstanceID(); this.gameObjectName = go.name; }
//execute one cycle of the current action on the current recorder position protected void execRecorderAction() { if (gOs2propMappings != null) { foreach (KeyValuePair <GameObject, Object2PropertiesMapping> entry in gOs2propMappings) { GameObject go = entry.Key; Object2PropertiesMapping propMapping = entry.Value; if (currentAction == ActionMode.RECORD && currentMode == ViewMode.LIVE) //if recording { #if IS_UNLICENSED if (recorderPosition <= (100 * (int)ActionMode.STOPPED) / (int)ActionMode.PAUSED) { #endif maxPositions = recorderPosition; propMapping.insertStateAtPos(recorderPosition); #if IS_UNLICENSED } else { showingStoppedRecordingMsg = true; StartCoroutine(exitStoppedRecordingMsg(5f)); stop(); } #endif } else if (currentMode == ViewMode.REPLAY) //if replaying //if in between start and finish position { if ((recorderPosition <= maxPositions && orgRecorderPositionStep > 0) || (recorderPosition > 0 && orgRecorderPositionStep < 0)) { //lerping not integrated yet //float updateSyncTime = Time.realtimeSinceStartup; //float lerpInterval = interval - ((updateSyncTime - updateStartingTime) % interval) ; if (propMapping.getGameObjectClone() != null) { propMapping.synchronizeProperties(recorderPosition); } } else //else if reached the finishing position { stop(); if (exitOnFinished) { switchModeTo(ViewMode.LIVE); } } } } } }
public void CalcParentMapingRef() { for (int i = 0; i < object2PropertiesMappings.Count; i++) { Object2PropertiesMapping mapping = object2PropertiesMappings [i]; mapping.currentMappingIdx = i; if (mapping.parentMappingIdx != -1) { mapping.parentMapping = object2PropertiesMappings [mapping.parentMappingIdx]; } else { mapping.parentMapping = null; } } }
//this starts the recording of objects, which have been marked for recoring previously or while recording in progress public void record() { //markPredefinedObjects4Recording(); //mark the game objects from the public gui list for recording if (currentMode == ViewMode.LIVE) { if (currentAction == ActionMode.STOPPED) { //remove a previous recording foreach (KeyValuePair <GameObject, Object2PropertiesMapping> entry in gOs2propMappings) { //GameObject go = entry.Key; Object2PropertiesMapping propMapping = entry.Value; propMapping.clearStates(); } //reset everything to standard values recorderPosition = 0; recorderPositionStep = 1; orgRecorderPositionStep = 1; //set new action currentAction = ActionMode.RECORD; continueCallingUpdate = true; runStateUpdate(recordingInterval); sendCallback2All("__EZR_record", null); } else { if (showWarnings) { Debug.LogWarning("EZReplayManager WARNING: Ordered to record when recorder was not in stopped-state. Will not start recording."); } } } else { if (showWarnings) { Debug.LogWarning("EZReplayManager WARNING: Ordered to record when recorder was in replay mode. Will not start recording."); } } }
// public void GetObjectData (SerializationInfo info, StreamingContext ctxt) // { // info.AddValue ("object2PropertiesMappings", this.object2PropertiesMappings); // info.AddValue ("EZR_VERSION", EZR_VERSION); // info.AddValue ("recordingInterval", this.recordingInterval); // //base.GetObjectData(info, context); // } public void CalcParentMapingIdx() { for (int i = 0; i < object2PropertiesMappings.Count; i++) { Object2PropertiesMapping mapping = object2PropertiesMappings [i]; mapping.currentMappingIdx = i; } for (int i = 0; i < object2PropertiesMappings.Count; i++) { Object2PropertiesMapping mapping = object2PropertiesMappings [i]; if (mapping.parentMapping != null) { mapping.parentMappingIdx = mapping.parentMapping.currentMappingIdx; } else { mapping.parentMappingIdx = -1; } } }
// public Vector3 serVec3ToVec3 (SerVector3 serVec3) // { // return new Vector3 (serVec3.x, serVec3.y, serVec3.z); // } // // public Quaternion serQuatToQuat (SerQuaternion serQuat) // { // return new Quaternion (serQuat.x, serQuat.y, serQuat.z, serQuat.w); // } public bool isDifferentTo(SavedState otherState, Object2PropertiesMapping o2m) { bool changed = false; if (!changed && isActive != otherState.isActive) { changed = true; } if (o2m.isParentObj && o2m.getGameObject().transform.parent != null) { if (!changed && position.isDifferentTo(otherState.position)) { changed = true; } if (!changed && rotation.isDifferentTo(otherState.rotation)) { changed = true; } } if (!changed && localPosition.isDifferentTo(otherState.localPosition)) { changed = true; } if (!changed && localRotation.isDifferentTo(otherState.localRotation)) { changed = true; } if (!changed && emittingParticles != otherState.emittingParticles) { changed = true; } return(changed); }
public Object2PropertiesMapping(GameObject go,bool isParent, Object2PropertiesMapping parentMapping, int childNo, string prefabLoadPath, ChildIdentificationMode childIdentificationMode) : this(go,isParent,parentMapping, childNo, prefabLoadPath) { this.childIdentificationMode = childIdentificationMode; if (isParentObj) { // if gameObject is a parent.. //..instantiate mappings for all children too Transform[] allChildren = gameObject.GetComponentsInChildren<Transform>() ; for(int i=0;i<allChildren.Length;i++) { GameObject child = allChildren[i].gameObject; if (!EZReplayManager.get.gOs2propMappings.ContainsKey(child)) { if (child!=gameObject) EZReplayManager.get.gOs2propMappings.Add(child, new Object2PropertiesMapping(child,false,this,i,"",childIdentificationMode)); } else if (EZReplayManager.showHints) MonoBehaviour.print("EZReplayManager HINT: GameObject '"+child+"' is already being recorded. Will not be marked for recording again."); } } }
//serialization constructor protected Object2PropertiesMapping(SerializationInfo info, StreamingContext context) { savedStates = (SerializableDictionary <int, SavedState>)info.GetValue("savedStates", typeof(SerializableDictionary <int, SavedState>)); isParentObj = info.GetBoolean("isParentObj"); parentMapping = (Object2PropertiesMapping)info.GetValue("parentMapping", typeof(Object2PropertiesMapping)); childNo = info.GetInt32("childNo"); prefabLoadPath = info.GetString("prefabLoadPath"); lastChangedFrame = info.GetInt32("lastChangedFrame"); firstChangedFrame = info.GetInt32("firstChangedFrame"); try { childIdentificationMode = (ChildIdentificationMode)info.GetValue("childIdentificationMode", typeof(ChildIdentificationMode)); } catch (SerializationException e) { //file was recorded using old version of this plugin childIdentificationMode = ChildIdentificationMode.IDENTIFY_BY_ORDER; } try { gameObjectName = info.GetString("gameObjectName"); } catch (SerializationException e) { //file was recorded using old version of this plugin childIdentificationMode = ChildIdentificationMode.IDENTIFY_BY_ORDER; gameObjectName = "name_untraceable"; } }
//as this is not derived from MonoBehaviour, we have a constructor public SavedState(GameObject go, Object2PropertiesMapping o2m) { if (o2m.isParent()) { isParent = true; } else { isParent = false; } if (go != null) { if (o2m.isParent()) { this.pos = new SerVector3(go.transform.position); this.scale = new SerVector3(go.transform.lossyScale); this.rot = new SerQuaternion(go.transform.rotation); isParent = true; } else { this.pos = new SerVector3(go.transform.localPosition); this.scale = new SerVector3(go.transform.localScale); this.rot = new SerQuaternion(go.transform.localRotation); } this.isActive = go.activeInHierarchy; } else { this.pos = new SerVector3(Vector3.zero); this.scale = new SerVector3(Vector3.one); this.rot = new SerQuaternion(Quaternion.identity); this.isActive = false; } }
//as this is not derived from MonoBehaviour, we have a constructor public Object2PropertiesMapping(GameObject go,bool isParent, Object2PropertiesMapping parentMapping, int childNo) { //setting instance variables this.gameObject = go; this.isParentObj = isParent; this.parentMapping = parentMapping; this.childNo = childNo; this.gameObjectInstanceID=go.GetInstanceID(); this.gameObjectName = go.name; }
//called to synchronize gameObjectClone of Object2PropertiesMapping back to this saved state public void synchronizeProperties(GameObject go, Object2PropertiesMapping o2m) { //HINT: lerping is still highly experimental //EZReplayManager.singleton.StartCoroutine_Auto(EZReplayManager.singleton.MoveTo (go.transform,serVec3ToVec3(this.localPosition),0.08f)); if (o2m.isParentObj && o2m.getGameObject() != null && o2m.getGameObject().transform.parent != null) { go.transform.position = serVec3ToVec3(this.position); go.transform.rotation = serQuatToQuat(this.rotation); } else { go.transform.localPosition = serVec3ToVec3(this.localPosition); go.transform.localRotation = serQuatToQuat(this.localRotation); } go.SetActive( this.isActive ); if (emittingParticles) go.GetComponent<ParticleEmitter>().emit = true; else if ( go.GetComponent<ParticleEmitter>() ) go.GetComponent<ParticleEmitter>().emit = false; }
public bool isDifferentTo(SavedState otherState, Object2PropertiesMapping o2m) { bool changed = false; if (!changed && isActive != otherState.isActive) changed = true; if (o2m.isParentObj && o2m.getGameObject().transform.parent != null) { if (!changed && position.isDifferentTo(otherState.position) ) changed = true; if (!changed && rotation.isDifferentTo(otherState.rotation) ) changed = true; } if (!changed && localPosition.isDifferentTo( otherState.localPosition) ) changed = true; if (!changed && localRotation.isDifferentTo( otherState.localRotation) ) changed = true; if (!changed && emittingParticles != otherState.emittingParticles) changed = true; return changed; }
//execute one cycle of the current action on the current recorder position protected void execRecorderAction() { if (gOs2propMappings != null) { foreach (KeyValuePair <GameObject, Object2PropertiesMapping> entry in gOs2propMappings) { GameObject go = entry.Key; Object2PropertiesMapping propMapping = entry.Value; if (currentAction == ActionMode.RECORD && currentMode == ViewMode.LIVE) //if recording { #if IS_UNLICENSED if (recorderPosition <= (100 * (int)ActionMode.STOPPED) / (int)ActionMode.PAUSED) { #endif maxPositions = recorderPosition; propMapping.insertStateAtPos(recorderPosition); int deleted = 0; if (recordingBufferSeconds > 0) { deleted = propMapping.removeFramesOutOfBufferRange(); } /*if (deleted > 0) { * if (propMapping.getGameObject().name.Contains("Shaftbase")) * print(propMapping.getGameObject() + " deleted: " + deleted + ", remaining: " + propMapping.savedStates.Count); * }*/ #if IS_UNLICENSED } else { showingStoppedRecordingMsg = true; StartCoroutine(exitStoppedRecordingMsg(5f)); stop(); } #endif } else if (currentMode == ViewMode.REPLAY) //if replaying //if in between start and finish position { int lowestFrame = getLowestFrame(); if (recorderPosition <= maxPositions && orgRecorderPositionStep > 0) { propMapping.synchronizeProperties(recorderPosition, recorderPosition == lowestFrame); } else if (recorderPosition >= getLowestFrame() && orgRecorderPositionStep < 0) { //print("recorderPosition: " + recorderPosition); //if (propMapping.getGameObjectClone() != null) { propMapping.synchronizeProperties(recorderPosition, recorderPosition == maxPositions); //} } else //else if reached the finishing position { stop(); if (exitOnFinished) { switchModeTo(ViewMode.LIVE); } } } } } }
//serialization constructor protected Object2PropertiesMapping(SerializationInfo info,StreamingContext context) { savedStates = (SerializableDictionary<int,SavedState>)info.GetValue("savedStates",typeof(SerializableDictionary<int,SavedState>)); isParentObj = info.GetBoolean("isParentObj"); parentMapping = (Object2PropertiesMapping)info.GetValue("parentMapping",typeof(Object2PropertiesMapping)); childNo = info.GetInt32("childNo"); prefabLoadPath = info.GetString("prefabLoadPath"); lastChangedFrame = info.GetInt32("lastChangedFrame"); firstChangedFrame = info.GetInt32("firstChangedFrame"); try { childIdentificationMode = (ChildIdentificationMode)info.GetValue("childIdentificationMode",typeof(ChildIdentificationMode)); } catch (SerializationException e) { //file was recorded using old version of this plugin childIdentificationMode = ChildIdentificationMode.IDENTIFY_BY_ORDER; } try { gameObjectName = info.GetString("gameObjectName"); } catch (SerializationException e) { //file was recorded using old version of this plugin childIdentificationMode = ChildIdentificationMode.IDENTIFY_BY_ORDER; gameObjectName = "name_untraceable"; } }
protected Object2PropertiesMapping(GameObject go, bool isParent, Object2PropertiesMapping parentMapping, int childNo, string prefabLoadPath) : this(go, isParent, parentMapping, childNo) { this.prefabLoadPath = prefabLoadPath; }
public Object2PropertiesMapping(GameObject go,bool isParent, Object2PropertiesMapping parentMapping, int childNo, string prefabLoadPath) : this(go,isParent,parentMapping, childNo) { this.prefabLoadPath = prefabLoadPath; }
public int getMaxFrames(Object2PropertiesMapping o2pm) { return o2pm.getMaxFrames(); }
public void addMapping(Object2PropertiesMapping mapping) { object2PropertiesMappings.Add(mapping); }
public int getMaxFrames(Object2PropertiesMapping o2pm) { return(o2pm.getMaxFrames()); }
//switch to different mode.. so far there are MODE_LIVE for viewing a normal game action and MODE_REPLAY for viewing a replay of a recording public void switchModeTo(ViewMode newMode) { if (newMode == ViewMode.LIVE) { sendCallback2All("__EZR_live_prepare", null); //reset game object (i.e. rigidbody state) foreach (KeyValuePair <GameObject, Object2PropertiesMapping> entry in gOs2propMappings) { //GameObject go = entry.Key; Object2PropertiesMapping propMapping = entry.Value; if (propMapping.getGameObject() != null) { propMapping.resetObject(); } } bool tmpWasLoading = false; if (isLoadingSlotInUse()) { tmpWasLoading = true; } useRecordingSlot(); if (tmpWasLoading) //repeat to avoid a bug { switchModeTo(ViewMode.LIVE); } //COUNTFRAMES maxPositions = getMaxFrames(gOs2propMappings); sendCallback2All("__EZR_live_ready", null); } else { sendCallback2All("__EZR_replay_prepare", null); if (maxPositions > 0) { //prepare parents first foreach (KeyValuePair <GameObject, Object2PropertiesMapping> entry in gOs2propMappings) { //GameObject go = entry.Key; Object2PropertiesMapping propMapping = entry.Value; if (propMapping.isParent()) { //if (propMapping.getGameObject() != null) propMapping.prepareObjectForReplay(); } } //..then childs foreach (KeyValuePair <GameObject, Object2PropertiesMapping> entry in gOs2propMappings) { //GameObject go = entry.Key; Object2PropertiesMapping propMapping = entry.Value; if (!propMapping.isParent()) { //if (propMapping.getGameObject() != null) propMapping.prepareObjectForReplay(); } } sendCallback2All("__EZR_replay_ready", null); } else { newMode = ViewMode.LIVE; if (showWarnings) { print("EZReplayManager WARNING: You have not recorded anything yet. Will not replay."); } } } currentMode = newMode; stop(); }