示例#1
0
        /// <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);
             * }*/
        }
示例#2
0
        /// <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);
                    }
                }
            }
        }
示例#3
0
        /// <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");
        }