/// <summary> /// Enables every recordable that is alive, and enables the simulation object /// </summary> private void EnableRecordables() { foreach (KeyValuePair <int, GameObject> pair in RecordableRefs) { int id = pair.Key; GameObject obj = pair.Value; if (obj != null) { if (obj.GetComponent <Operator.OperatorState>() != null) { if (obj.GetComponent <Operator.OperatorState>().IsAlive()) { obj.SetActive(true); } } else { obj.SetActive(true); } if (Frames.Count > 0) { RecordableState.RecordableState lastState = Frames[Frames.Count - 1][id]; lastState.InitOwner(); } } } }
/// <summary> /// Removes and destroys replay objects that don't exist in the current frame /// </summary> private void RemoveReplayObjects() { int AIid = GameController.SideAIs[GameController.Side]; List <GameObject> visibleEnemies = CurrentFrame[AIid].GetProperty <RecordableState.ExtendedAI>().VisibleEnemies; Dictionary <GameObject, Vector3> lastPosition = CurrentFrame[AIid].GetProperty <RecordableState.ExtendedAI>().LastEnemyPositions; // destroy objects that dont exist in the frame and add their id to a list List <int> replayRefsToRemove = new List <int>(); foreach (KeyValuePair <int, GameObject> pair in ReplayRefs) { int id = pair.Key; bool isVisible = visibleEnemies.Contains(GameController.RecordableRefs[id]); if (CurrentFrame.ContainsKey(id)) { RecordableState.RecordableState state = CurrentFrame[id]; Side?side = null; if (state.GetProperty <RecordableState.BaseAI>() != null) { side = state.GetProperty <RecordableState.BaseAI>().Side; } RecordableState.OperatorState operatorState = state.GetProperty <RecordableState.OperatorState>(); if ((side != null && side != GameController.Side && !isVisible) || (side == GameController.Side && !operatorState.IsAlive)) { GameObject obj = pair.Value; Destroy(obj); replayRefsToRemove.Add(id); } } else { GameObject obj = pair.Value; Destroy(obj); replayRefsToRemove.Add(id); } } // using the created list remove all elements from replayRefs that point to a null object foreach (int id in replayRefsToRemove) { ReplayRefs.Remove(id); } /*List<int> removeFromMarkers = new List<int>(); * foreach (KeyValuePair<int, GameObject> pair in Markers) { * int id = pair.Key; * if (!lastPosition.ContainsKey(GameController.RecordableRefs[id])) { * removeFromMarkers.Add(id); * } * } * * foreach (int id in removeFromMarkers) { * Destroy(Markers[id]); * Markers.Remove(id); * }*/ }
/// <summary> /// Get the current state of every recordable /// </summary> /// <returns>The current state of every recordable stored in a Id-State dictionary </returns> public Dictionary <int, RecordableState.RecordableState> GetRecordableStates() { Dictionary <int, RecordableState.RecordableState> frame = new Dictionary <int, RecordableState.RecordableState>(); // create a new frame where to store object states // goes through the all of the recordables and saves their state foreach (KeyValuePair <int, GameObject> pair in GameController.RecordableRefs) { int id = pair.Key; GameObject obj = pair.Value; // if the recordable has not been destroyed, get its state and add it to the frame if (obj != null) { RecordableState.RecordableState state = obj.GetComponent <Recordable.Recordable>().GetState(); // gets the state by calling its getRecordableState method from the Recordable script frame.Add(id, state); } } return(frame); }
/// <summary> /// Base method + adds the transform component to the param recordableState. /// </summary> /// <param name="state">RecordableState which needs Transform data added to it.</param> protected override void AddProperties(RecordableState.RecordableState state) { base.AddProperties(state); state.AddProperty <RecordableState.Transform>(); }
protected override void AddProperties(RecordableState.RecordableState state) { base.AddProperties(state); state.AddProperty <RecordableState.BombStuff>(); }
/// <summary> /// Get the recordable's current state /// </summary> /// <returns>Returns the recordable's state</returns> public RecordableState.RecordableState GetState() { RecordableState.RecordableState state = new RecordableState.RecordableState(gameObject); AddProperties(state); return(state); }
/// <summary> /// Initializes the recordable state variables /// </summary> /// <param name="state">Reference of the state we are modifying</param> protected virtual void AddProperties(RecordableState.RecordableState state) { }
protected override void AddProperties(RecordableState.RecordableState state) { base.AddProperties(state); state.AddProperty <RecordableState.BaseAI>(); state.AddProperty <RecordableState.OperatorState>(); }
/// <summary> /// Updates and creates replay objects to match the frame state. /// </summary> private void UpdateReplayObjects() { int AIid = GameController.SideAIs[GameController.Side]; List <GameObject> visibleEnemies = CurrentFrame[AIid].GetProperty <RecordableState.ExtendedAI>().VisibleEnemies; Dictionary <GameObject, Vector3> lastPosition = CurrentFrame[AIid].GetProperty <RecordableState.ExtendedAI>().LastEnemyPositions; foreach (GameObject obj in MarkersList) { Destroy(obj); } List <GameObject> newList = new List <GameObject>(); foreach (KeyValuePair <GameObject, Vector3> pair in lastPosition) { Vector3 pos = pair.Value; GameObject marker = Instantiate(GameController.Unknown, pos, Quaternion.identity); newList.Add(marker); } MarkersList = newList; foreach (KeyValuePair <int, RecordableState.RecordableState> pair in CurrentFrame) { int id = pair.Key; RecordableState.RecordableState state = CurrentFrame[id]; bool hasReplayType = GameController.RecordableReplayTypes.ContainsKey(id); if (hasReplayType) { GameObject obj = null; bool isVisible = visibleEnemies.Contains(GameController.RecordableRefs[id]); // if replay object doesn't exist: create one if (!ReplayRefs.ContainsKey(id)) { if (state.GetProperty <RecordableState.BaseAI>() != null) { Side side = state.GetProperty <RecordableState.BaseAI>().Side; RecordableState.OperatorState operatorState = state.GetProperty <RecordableState.OperatorState>(); if (side == GameController.Side && (operatorState == null || operatorState.IsAlive == true)) { obj = Instantiate(GameController.RecordableReplayTypes[id]); ReplayRefs.Add(id, obj); } else if (side != GameController.Side) { if (isVisible) { obj = Instantiate(GameController.RecordableReplayTypes[id]); // create replay type ReplayRefs.Add(id, obj); /*if (Markers.ContainsKey(id)) { * Destroy(Markers[id]); * Markers.Remove(id); * }*/ } /*else { * if (lastPosition.ContainsKey(GameController.RecordableRefs[id])) { * if (!Markers.ContainsKey(id)) { * Markers.Add(id, Instantiate(GameController.Unknown, lastPosition[GameController.RecordableRefs[id]], Quaternion.identity)); * } * else { * Markers[id].transform.position = lastPosition[GameController.RecordableRefs[id]]; * } * } else { * if (Markers.ContainsKey(id)) { * Destroy(Markers[id]); * Markers.Remove(id); * } * } * }*/ } } else { obj = Instantiate(GameController.RecordableReplayTypes[id]); ReplayRefs.Add(id, obj); } } else { obj = ReplayRefs[id]; } // update state if (obj != null) { if (state.GetProperty <RecordableState.Audio>() != null) { for (int i = LastFrameAsInt + 1; i <= CurrentFrameAsInt; i++) { RecordableState.Audio audio = GameController.Frames[i][id].GetProperty <RecordableState.Audio>(); if (audio.StartPlay == true) { AudioSource source = obj.GetComponent <AudioSource>(); source.PlayOneShot(source.clip); break; } } } state.SetToObject(obj); } } } }
/// <summary> /// Base method + adds the animations to the param recordableState. /// </summary> /// <param name="state">RecordableState which needs AnimationStates added to it.</param> protected override void AddProperties(RecordableState.RecordableState state) { base.AddProperties(state); state.AddProperty <RecordableState.Animations>(); }
protected override void AddProperties(RecordableState.RecordableState state) { base.AddProperties(state); state.AddProperty <RecordableState.ExtendedAI>(); }
/// <summary> /// Create a planning object, that is of either planningType or replayType, of every recordable in the last frame /// </summary> private void CreatePlanningObjects() { int AIid = GameController.SideAIs[GameController.Side]; List <GameObject> visibleEnemies = LastFrame[AIid].GetProperty <RecordableState.ExtendedAI>().VisibleEnemies; Dictionary <GameObject, Vector3> lastPosition = LastFrame[AIid].GetProperty <RecordableState.ExtendedAI>().LastEnemyPositions; // go through every id-state pair in the last frame foreach (KeyValuePair <int, RecordableState.RecordableState> pair in LastFrame) { int id = pair.Key; RecordableState.RecordableState state = pair.Value; bool hasPlanningType = GameController.RecordablePlanningTypes.ContainsKey(id); bool hasReplayType = GameController.RecordableReplayTypes.ContainsKey(id); // create the object if (hasPlanningType || hasReplayType) { GameObject obj = null; if (state.GetProperty <RecordableState.BaseAI>() != null) { Side side = state.GetProperty <RecordableState.BaseAI>().Side; bool isVisible = visibleEnemies.Contains(GameController.RecordableRefs[id]); RecordableState.OperatorState operatorState = state.GetProperty <RecordableState.OperatorState>(); if (side == GameController.Side && (operatorState == null || operatorState.IsAlive)) // has planning type { if (hasPlanningType) { obj = Instantiate(GameController.RecordablePlanningTypes[id]); // create planning type if (obj.GetComponent <MakePath>() != null) { AI.OperatorAI operatorAI = GameController.RecordableRefs[id].GetComponent <AI.OperatorAI>(); if (0 < operatorAI.Path.Count) { operatorAI.Path.RemoveRange(0, operatorAI.NextPointInPath); } obj.GetComponent <MakePath>().mousePositionList = operatorAI.Path; obj.GetComponent <MakePath>().DrawPath(); if (side == Side.Terrorist) { obj.GetComponent <MakePath>().willPlant = GameController.RecordableRefs[id].GetComponent <AI.TOperatorAI>().WillPlantBomb; } if (side == Side.CounterTerrorist) { obj.GetComponent <MakePath>().willDefuse = GameController.RecordableRefs[id].GetComponent <AI.CTOperatorAI>().WillDefuse; } } } else { obj = Instantiate(GameController.RecordableReplayTypes[id]); // create replay type } } else if (side != GameController.Side) { if (isVisible) { obj = Instantiate(GameController.RecordableReplayTypes[id]); // create replay type } else if (!isVisible && lastPosition.ContainsKey(GameController.RecordableRefs[id])) { PlanningRefs.Add(Instantiate(GameController.Unknown, lastPosition[GameController.RecordableRefs[id]], Quaternion.identity), id); } } } else { obj = Instantiate(GameController.RecordableReplayTypes[id]); } if (obj != null) { state.SetToObject(obj); PlanningRefs.Add(obj, id); // add a reference of the created object to the planning refs dictionary } } } Time.timeScale = 1f; StartCoroutine("AnimInit"); }