Example #1
0
    private bool LoadScene = true; // For debugging

    /// <summary>
    /// Called when the SimState is started.
    /// </summary>
    public override void Start()
    {
        Debug.Log("Initializing EditScoreZone state machine");
        if (LoadScene)
        {
            Debug.Log(RobotFieldLoader.LoadField() ? "Load field success!" : "Load field failed.");
        }

        mainCam = GameObject.Find("Main Camera");

        mainCam.GetComponent <DynamicCamera>().SwitchCameraState(0);
        DynamicCamera.MovingEnabled = true;

        GameObject.Find("ScoreZonePrefsPanel").GetComponent <ScoreZonePrefUIManager>().HideSplash();
    }
Example #2
0
    /// <summary>
    /// Called after Awake() when the script instance is enabled.
    /// Initializes variables then loads the field and robot as well as setting up replay features.
    /// </summary>
    public override void Start()
    {
        AppModel.ClearError();

        //getting bullet physics information
        physicsWorld = BPhysicsWorld.Get();
        ((DynamicsWorld)physicsWorld.world).SetInternalTickCallback(BPhysicsTickListener.Instance.PhysicsTick);
        lastFrameCount = physicsWorld.frameCount;

        //setting up raycast robot tick callback
        BPhysicsTickListener.Instance.OnTick += BRobotManager.Instance.UpdateRaycastRobots;

        //setting up replay
        CollisionTracker = new CollisionTracker(this);

        //starts a new instance of unity packet which receives packets from the driver station
        unityPacket = new UnityPacket();
        unityPacket.Start();

        //loads all the controls
        Controls.Load();

        //If a replay has been selected, load the replay. Otherwise, load the field and robot.
        string selectedReplay = PlayerPrefs.GetString("simSelectedReplay");

        SpawnedRobots = new List <Robot>();

        if (string.IsNullOrEmpty(selectedReplay))
        {
            Tracking  = true;
            fieldPath = PlayerPrefs.GetString("simSelectedField");
            robotPath = PlayerPrefs.GetString("simSelectedRobot");
            Debug.Log(RobotFieldLoader.LoadField(fieldPath) ? "Load field success!" : "Load field failed.");
            Debug.Log(LoadRobot(robotPath) ? "Load robot success!" : "Load robot failed.");

            if (!LoadRobot(PlayerPrefs.GetString("simSelectedRobot")))
            {
                AppModel.ErrorToMenu("Could not load robot: " + PlayerPrefs.GetString("simSelectedRobot") + "\nHas it been moved or deleted?)");
                return;
            }

            int isMixAndMatch  = PlayerPrefs.GetInt("mixAndMatch", 0); // 0 is false, 1 is true
            int hasManipulator = PlayerPrefs.GetInt("hasManipulator");
            if (isMixAndMatch == 1 && hasManipulator == 1)
            {
                Debug.Log(LoadManipulator(PlayerPrefs.GetString("simSelectedManipulator")) ? "Load manipulator success" : "Load manipulator failed");
            }
        }
        else
        {
            awaitingReplay = true;
            LoadReplay(selectedReplay);
        }

        //initializes the dynamic camera
        dynamicCameraObject         = GameObject.Find("Main Camera");
        dynamicCamera               = dynamicCameraObject.AddComponent <DynamicCamera>();
        DynamicCamera.MovingEnabled = true;

        sensorManager    = GameObject.Find("SensorManager").GetComponent <SensorManager>();
        sensorManagerGUI = GameObject.Find("StateMachine").GetComponent <SensorManagerGUI>();

        robotCameraManager = GameObject.Find("RobotCameraList").GetComponent <RobotCameraManager>();

        ScoreZoneSimSceneManager scoreZoneSimSceneManager = GameObject.Find("StateMachine").GetComponent <ScoreZoneSimSceneManager>();

        scoreZoneSimSceneManager.LoadScoreZones();
    }
Example #3
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);

        RobotFieldLoader.LoadField(PlayerPrefs.GetString("simSelectedField"));
        LoadRobot(PlayerPrefs.GetString("simSelectedRobot"));

        foreach (KeyValuePair <string, List <FixedQueue <StateDescriptor> > > rs in robotStates)
        {
            if (!LoadRobot(rs.Key))
            {
                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);
            }
        }
    }