示例#1
0
        /// <summary>
        /// Loads the replay from the given replay file name.
        /// </summary>
        /// <param name="name"></param>
        void LoadReplay(string name)
        {
            List <FixedQueue <StateDescriptor> > fieldStates;
            List <KeyValuePair <string, List <FixedQueue <StateDescriptor> > > > robotStates;
            Dictionary <string, List <FixedQueue <StateDescriptor> > >           gamePieceStates;
            List <List <KeyValuePair <ContactDescriptor, int> > > contacts;

            string fieldDirectory;

            ReplayImporter.Read(name, out fieldDirectory, out fieldStates, out robotStates, out gamePieceStates, out contacts);

            if (!LoadField(fieldDirectory))
            {
                AppModel.ErrorToMenu("Could not load field: " + fieldDirectory + "\nHas it been moved or deleted?");
                return;
            }

            foreach (KeyValuePair <string, List <FixedQueue <StateDescriptor> > > rs in robotStates)
            {
                if (!LoadRobot(rs.Key, false))
                {
                    AppModel.ErrorToMenu("Could not load robot: " + rs.Key + "\nHas it been moved or deleted?");
                    return;
                }

                int j = 0;

                foreach (Tracker t in SpawnedRobots.Last().GetComponentsInChildren <Tracker>())
                {
                    t.States = rs.Value[j];
                    j++;
                }
            }

            Tracker[] fieldTrackers = fieldObject.GetComponentsInChildren <Tracker>();

            int i = 0;

            foreach (Tracker t in fieldTrackers)
            {
                t.States = fieldStates[i];
                i++;
            }

            foreach (KeyValuePair <string, List <FixedQueue <StateDescriptor> > > k in gamePieceStates)
            {
                GameObject referenceObject = GameObject.Find(k.Key);

                if (referenceObject == null)
                {
                    continue;
                }

                foreach (FixedQueue <StateDescriptor> f in k.Value)
                {
                    GameObject currentPiece = UnityEngine.Object.Instantiate(referenceObject);
                    currentPiece.name = k.Key + "(Clone)";
                    currentPiece.GetComponent <Tracker>().States = f;
                }
            }

            foreach (var c in contacts)
            {
                if (c != null)
                {
                    List <ContactDescriptor> currentContacts = new List <ContactDescriptor>();

                    foreach (var d in c)
                    {
                        ContactDescriptor currentContact = d.Key;
                        currentContact.RobotBody = ActiveRobot.transform.GetChild(d.Value).GetComponent <BRigidBody>();
                        currentContacts.Add(currentContact);
                    }

                    CollisionTracker.ContactPoints.Add(currentContacts);
                }
                else
                {
                    CollisionTracker.ContactPoints.Add(null);
                }
            }
        }
示例#2
0
    void LoadReplay(string name)
    {
        List <FixedQueue <StateDescriptor> > fieldStates;
        List <FixedQueue <StateDescriptor> > robotStates;
        Dictionary <string, List <FixedQueue <StateDescriptor> > > gamePieceStates;
        List <List <KeyValuePair <ContactDescriptor, int> > >      contacts;

        string simSelectedField;
        string simSelectedRobot;

        ReplayImporter.Read(name, out simSelectedField, out simSelectedRobot, out fieldStates, out robotStates, out gamePieceStates, out contacts);

        LoadField(simSelectedField);
        LoadRobot(simSelectedRobot);

        List <Tracker> robotTrackers = Trackers.Where(x => x.transform.parent.name.Equals("Robot")).ToList();
        List <Tracker> fieldTrackers = Trackers.Except(robotTrackers).ToList();

        int i = 0;

        foreach (Tracker t in fieldTrackers)
        {
            t.States = fieldStates[i];
            i++;
        }

        i = 0;

        foreach (Tracker t in robotTrackers)
        {
            t.States = robotStates[i];
            i++;
        }

        foreach (KeyValuePair <string, List <FixedQueue <StateDescriptor> > > k in gamePieceStates)
        {
            GameObject referenceObject = GameObject.Find(k.Key);

            if (referenceObject == null)
            {
                continue;
            }

            foreach (FixedQueue <StateDescriptor> f in k.Value)
            {
                GameObject currentPiece = UnityEngine.Object.Instantiate(referenceObject);
                currentPiece.name = "clone_" + k.Key;
                currentPiece.GetComponent <Tracker>().States = f;
            }
        }

        foreach (var c in contacts)
        {
            if (c != null)
            {
                List <ContactDescriptor> currentContacts = new List <ContactDescriptor>();

                foreach (var d in c)
                {
                    ContactDescriptor currentContact = d.Key;
                    currentContact.RobotBody = robotTrackers[d.Value].GetComponent <BRigidBody>();
                    currentContacts.Add(currentContact);
                }

                contactPoints.Add(currentContacts);
            }
            else
            {
                contactPoints.Add(null);
            }
        }
    }