Пример #1
0
        /// <summary>
        /// Changes the drive base, destroys old manipulator and creates new manipulator, sets wheels
        /// </summary>
        public void MaMChangeRobot(string robotDirectory, string manipulatorDirectory)
        {
            MaMRobot mamRobot = State.ActiveRobot as MaMRobot;

            robotCameraManager.DetachCamerasFromRobot(State.ActiveRobot);
            sensorManager.RemoveSensorsFromRobot(State.ActiveRobot);

            //If the current robot has a manipulator, destroy the manipulator
            if (mamRobot != null && mamRobot.RobotHasManipulator)
            {
                State.DeleteManipulatorNodes();
            }

            if (!State.ChangeRobot(robotDirectory, true))
            {
                AppModel.ErrorToMenu("ROBOT_SELECT|Failed to load Mix & Match robot");
            }

            //If the new robot has a manipulator, load the manipulator
            if (RobotTypeManager.HasManipulator)
            {
                State.LoadManipulator(manipulatorDirectory);
            }
            else if (mamRobot != null)
            {
                mamRobot.RobotHasManipulator = false;
            }
        }
Пример #2
0
 /// <summary>
 /// Called at a fixed rate - updates robot packet information.
 /// </summary>
 public override void FixedUpdate()
 {
     //This line is essential for the reset to work accurately
     //robotCameraObject.transform.position = activeRobot.transform.GetChild(0).transform.position;
     if (ActiveRobot == null)
     {
         AppModel.ErrorToMenu("ROBOT_SELECT|Robot instance not valid.");
         return;
     }
 }
Пример #3
0
        /// <summary>
        /// Updates positional information of the robot.
        /// </summary>
        protected virtual void UpdateTransform()
        {
            BRigidBody rigidBody = GetComponentInChildren <BRigidBody>();

            if (rigidBody == null)
            {
                AppModel.ErrorToMenu("Could not generate robot physics data.");
            }
            else if (!rigidBody.GetCollisionObject().IsActive)
            {
                rigidBody.GetCollisionObject().Activate();
            }
        }
Пример #4
0
        /// <summary>
        /// Called every step of the program to listen to input commands for various features
        /// </summary>
        public override void Update()
        {
            if (ActiveRobot == null)
            {
                AppModel.ErrorToMenu("ROBOT_SELECT|Robot instance not valid.");
                return;
            }

            if (ActiveRobot.transform.GetChild(0).transform.position.y < -10 || ActiveRobot.transform.GetChild(0).transform.position.y > 60)
            {
                BeginRobotReset();
                EndRobotReset();
            }

            if (reset)
            {
                BeginRobotReset();
                reset = false;
            }

            //Spawn a new robot from the same path or switch active robot
            if (!ActiveRobot.IsResetting && ActiveRobot.ControlIndex == 0)
            {
                if (InputControl.GetButtonDown(Controls.Players[ActiveRobot.ControlIndex].GetButtons().duplicateRobot))
                {
                    LoadRobot(robotPath, ActiveRobot is MaMRobot);
                }
                if (InputControl.GetButtonDown(Controls.Players[ActiveRobot.ControlIndex].GetButtons().switchActiveRobot))
                {
                    SwitchActiveRobot(SpawnedRobots.IndexOf(ActiveRobot) + 1 < SpawnedRobots.Count() ? SpawnedRobots.IndexOf(ActiveRobot) + 1 : 0);
                }
            }

            // Toggles between the different camera states if the camera toggle button is pressed
            if ((InputControl.GetButtonDown(Controls.Global.GetButtons().cameraToggle)) &&
                DynamicCameraObject.activeSelf && DynamicCamera.ControlEnabled)
            {
                dynamicCamera.ToggleCameraState(dynamicCamera.ActiveState);
            }

            // Switches to replay mode
            if (!ActiveRobot.IsResetting && InputControl.GetButtonDown(Controls.Global.GetButtons().replayMode))
            {
                CollisionTracker.ContactPoints.Add(null);
                StateMachine.PushState(new ReplayState(fieldPath, CollisionTracker.ContactPoints));
            }
        }
Пример #5
0
        /// <summary>
        /// Called every step of the program to listen to input commands for various features
        /// </summary>
        public override void Update()
        {
            if (ActiveRobot == null)
            {
                AppModel.ErrorToMenu("Robot instance not valid.");
                return;
            }

            if (reset)
            {
                BeginRobotReset();
                reset = false;
            }

            //Spawn a new robot from the same path or switch active robot
            if (!ActiveRobot.IsResetting && ActiveRobot.ControlIndex == 0)
            {
                if (InputControl.GetButtonDown(Controls.buttons[ActiveRobot.ControlIndex].duplicateRobot))
                {
                    LoadRobot(robotPath, ActiveRobot is MaMRobot);
                }
                if (InputControl.GetButtonDown(Controls.buttons[ActiveRobot.ControlIndex].switchActiveRobot))
                {
                    SwitchActiveRobot();
                }
            }

            // Toggles between the different camera states if the camera toggle button is pressed
            if ((InputControl.GetButtonDown(Controls.buttons[0].cameraToggle)) &&
                DynamicCameraObject.activeSelf && DynamicCamera.ControlEnabled)
            {
                dynamicCamera.ToggleCameraState(dynamicCamera.ActiveState);
            }

            // Switches to replay mode
            if (!ActiveRobot.IsResetting && InputControl.GetButtonDown(Controls.buttons[ActiveRobot.ControlIndex].replayMode))
            {
                CollisionTracker.ContactPoints.Add(null);
                StateMachine.PushState(new ReplayState(fieldPath, CollisionTracker.ContactPoints));
            }
        }
Пример #6
0
    /// <summary>
    /// Called once per frame to ensure all rigid bodie components are activated
    /// </summary>
    void Update()
    {
        BRigidBody rigidBody = GetComponentInChildren <BRigidBody>();

        if (rigidBody == null)
        {
            AppModel.ErrorToMenu("Could not generate robot physics data.");
            return;
        }

        if (!IsResetting)
        {
            if (InputControl.GetButtonDown(Controls.buttons[ControlIndex].resetRobot) && !MixAndMatchMode.setPresetPanelOpen)
            {
                keyDownTime = Time.time;
            }

            else if (InputControl.GetButton(Controls.buttons[ControlIndex].resetRobot) && !MixAndMatchMode.setPresetPanelOpen &&
                     !mainState.DynamicCameraObject.GetComponent <DynamicCamera>().cameraState.GetType().Equals(typeof(DynamicCamera.ConfigurationState)))
            {
                if (Time.time - keyDownTime > HOLD_TIME)
                {
                    IsResetting = true;
                    BeginReset();
                }
            }

            else if (InputControl.GetButtonUp(Controls.buttons[ControlIndex].resetRobot) && !MixAndMatchMode.setPresetPanelOpen)
            {
                BeginReset();
                EndReset();
            }
        }
        else if (!rigidBody.GetCollisionObject().IsActive)
        {
            rigidBody.GetCollisionObject().Activate();
        }
    }
Пример #7
0
    /// <summary>
    /// Called every step of the program to listen to input commands for various features
    /// </summary>
    public override void Update()
    {
        if (ActiveRobot == null)
        {
            AppModel.ErrorToMenu("Robot instance not valid.");
            return;
        }

        //Spawn a new robot from the same path or switch active robot
        if (!ActiveRobot.IsResetting)
        {
            if (Input.GetKeyDown(KeyCode.U) && !MixAndMatchMode.setPresetPanelOpen)
            {
                LoadRobot(robotPath, ActiveRobot.RobotIsMixAndMatch);
            }
            if (Input.GetKeyDown(KeyCode.Y))
            {
                SwitchActiveRobot();
            }
        }

        // Toggles between the different camera states if the camera toggle button is pressed
        if ((InputControl.GetButtonDown(Controls.buttons[0].cameraToggle)) && !MixAndMatchMode.setPresetPanelOpen)
        {
            if (DynamicCameraObject.activeSelf && DynamicCamera.MovingEnabled)
            {
                dynamicCamera.ToggleCameraState(dynamicCamera.cameraState);
            }
        }

        // Switches to replay mode
        if (!ActiveRobot.IsResetting && Input.GetKeyDown(KeyCode.Tab))
        //if (!ActiveRobot.IsResetting && InputControl.GetButtonDown(Controls.buttons[controlIndex].replayMode))
        {
            CollisionTracker.ContactPoints.Add(null);
            StateMachine.Instance.PushState(new ReplayState(fieldPath, CollisionTracker.ContactPoints));
        }
    }
Пример #8
0
    /// <summary>
    /// Called every step of the program to listen to input commands for various features
    /// </summary>
    public override void Update()
    {
        if (activeRobot == null)
        {
            AppModel.ErrorToMenu("Robot instance not valid.");
            return;
        }

        //If the reset button is held down after a certain amount of time, then go into change spawnpoint mode (reset spawnpoint feature)
        //Otherwise, reset the robot normally (quick reset feature)
        if (!activeRobot.IsResetting)
        {
            if (Input.GetKeyDown(KeyCode.U))
            {
                LoadRobot(robotPath);
            }
            if (Input.GetKeyDown(KeyCode.Y))
            {
                SwitchActiveRobot();
            }
        }

        // Toggles between the different camera states if the camera toggle button is pressed
        if ((InputControl.GetButtonDown(Controls.buttons[0].cameraToggle)))
        {
            if (dynamicCameraObject.activeSelf && DynamicCamera.MovingEnabled)
            {
                dynamicCamera.ToggleCameraState(dynamicCamera.cameraState);
            }
        }

        // Switches to replay mode
        if (!activeRobot.IsResetting && Input.GetKeyDown(KeyCode.Tab))
        {
            CollisionTracker.ContactPoints.Add(null);
            StateMachine.Instance.PushState(new ReplayState(fieldPath, CollisionTracker.ContactPoints));
        }
    }
Пример #9
0
    /// <summary>
    /// Called once per frame to ensure all rigid bodie components are activated
    /// </summary>
    void Update()
    {
        BRigidBody rigidBody = GetComponentInChildren <BRigidBody>();

        if (rigidBody == null)
        {
            AppModel.ErrorToMenu("Could not generate robot physics data.");
            return;
        }

        if (!rigidBody.GetCollisionObject().IsActive)
        {
            rigidBody.GetCollisionObject().Activate();
        }
        if (!IsResetting && StateMachine.Instance.CurrentState is MainState)
        {
            if (InputControl.GetButtonDown(Controls.buttons[controlIndex].resetRobot))
            {
                keyDownTime = Time.time;
            }

            else if (InputControl.GetButton(Controls.buttons[controlIndex].resetRobot))
            {
                if (Time.time - keyDownTime > HOLD_TIME)
                {
                    IsResetting = true;
                    BeginReset();
                }
            }

            else if (InputControl.GetButtonUp(Controls.buttons[controlIndex].resetRobot))
            {
                BeginReset();
                EndReset();
            }
        }
    }
Пример #10
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);
                }
            }
        }
Пример #11
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;
            BPhysicsTickListener.Instance.OnTick += BRobotManager.Instance.UpdateRaycastRobots;

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

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

            if (string.IsNullOrEmpty(selectedReplay))
            {
                Tracking = true;

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

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

                reset = FieldDataHandler.robotSpawn == new Vector3(99999, 99999, 99999);

                if (RobotTypeManager.IsMixAndMatch && RobotTypeManager.HasManipulator)
                {
                    Debug.Log(LoadManipulator(RobotTypeManager.ManipulatorPath) ? "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.ControlEnabled = true;

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

            simUI = StateMachine.SceneGlobal.GetComponent <SimUI>();

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

            IsMetric = PlayerPrefs.GetString("Measure").Equals("Metric") ? true : false;

            StateMachine.Link <MainState>(GameObject.Find("Main Camera").transform.GetChild(0).gameObject);
            StateMachine.Link <MainState>(GameObject.Find("Main Camera").transform.GetChild(1).gameObject, false);
            StateMachine.Link <ReplayState>(Auxiliary.FindGameObject("ReplayUI"));
            StateMachine.Link <SaveReplayState>(Auxiliary.FindGameObject("SaveReplayUI"));
            StateMachine.Link <GamepieceSpawnState>(Auxiliary.FindGameObject("ResetGamepieceSpawnpointUI"));
            StateMachine.Link <DefineNodeState>(Auxiliary.FindGameObject("DefineNodeUI"));
            StateMachine.Link <GoalState>(Auxiliary.FindGameObject("GoalStateUI"));
            StateMachine.Link <SensorSpawnState>(Auxiliary.FindGameObject("ResetSensorSpawnpointUI"));
            StateMachine.Link <DefineSensorAttachmentState>(Auxiliary.FindGameObject("DefineSensorAttachmentUI"));

            string defaultDirectory = (Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"Autodesk\Synthesis\Emulator");
            string directoryPath    = "";

            if (Directory.Exists(defaultDirectory))
            {
                directoryPath         = defaultDirectory;
                isEmulationDownloaded = true;
            }
        }
Пример #12
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;
        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;

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

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

            if (RobotTypeManager.IsMixAndMatch && RobotTypeManager.HasManipulator)
            {
                Debug.Log(LoadManipulator(RobotTypeManager.ManipulatorPath) ? "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>();

        IsMetric = PlayerPrefs.GetString("Measure").Equals("Metric") ? true : false;

        StateMachine.Instance.Link <MainState>(GameObject.Find("Main Camera").transform.GetChild(0).gameObject);
        StateMachine.Instance.Link <ReplayState>(Resources.FindObjectsOfTypeAll <GameObject>().First(x => x.name.Equals("ReplayUI")));
        StateMachine.Instance.Link <SaveReplayState>(Resources.FindObjectsOfTypeAll <GameObject>().First(x => x.name.Equals("SaveReplayUI")));
    }
Пример #13
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;
            BPhysicsTickListener.Instance.OnTick += BRobotManager.Instance.UpdateRaycastRobots;

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

            if (PlayerPrefs.GetString("simSelectedRobot", "").Equals(""))
            {
                AppModel.ErrorToMenu("ROBOT_SELECT|FIRST");
                return;
            }

            if (string.IsNullOrEmpty(selectedReplay))
            {
                Tracking = true;

                if (!LoadField(PlayerPrefs.GetString("simSelectedField")))
                {
                    //AppModel.ErrorToMenu("FIELD_SELECT|FIRST");
                    AppModel.ErrorToMenu("FIELD_SELECT|Could not load field: " + PlayerPrefs.GetString("simSelectedField") + "\nHas it been moved or deleted?)");
                    return;
                }
                else
                {
                    MovePlane();
                }

                bool result = false;

                try
                {
                    result = LoadRobot(PlayerPrefs.GetString("simSelectedRobot"), false);
                }
                catch (Exception e)
                {
                    MonoBehaviour.Destroy(GameObject.Find("Robot"));
                }

                if (!result)
                {
                    AppModel.ErrorToMenu("ROBOT_SELECT|Could not find the selected robot");
                    return;
                }

                reset = FieldDataHandler.robotSpawn == new Vector3(99999, 99999, 99999);

                if (RobotTypeManager.IsMixAndMatch && RobotTypeManager.HasManipulator)
                {
                    Debug.Log(LoadManipulator(RobotTypeManager.ManipulatorPath) ? "Load manipulator success" : "Load manipulator failed");
                }
            }
            else
            {
                awaitingReplay = true;
                PlayerPrefs.SetString("simSelectedReplay", "");
                LoadReplay(selectedReplay);
            }

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

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

            simUI = StateMachine.SceneGlobal.GetComponent <SimUI>();

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

            IsMetric = PlayerPrefs.GetString("Measure").Equals("Metric");

            StateMachine.Link <MainState>(GameObject.Find("Main Camera").transform.GetChild(0).gameObject);
            StateMachine.Link <MainState>(GameObject.Find("Main Camera").transform.GetChild(1).gameObject, false);
            StateMachine.Link <ReplayState>(Auxiliary.FindGameObject("ReplayUI"));
            StateMachine.Link <SaveReplayState>(Auxiliary.FindGameObject("SaveReplayUI"));
            StateMachine.Link <GamepieceSpawnState>(Auxiliary.FindGameObject("ResetGamepieceSpawnpointUI"));
            StateMachine.Link <DefineNodeState>(Auxiliary.FindGameObject("DefineNodeUI"));
            StateMachine.Link <GoalState>(Auxiliary.FindGameObject("GoalStateUI"));
            StateMachine.Link <SensorSpawnState>(Auxiliary.FindGameObject("ResetSensorSpawnpointUI"));
            StateMachine.Link <DefineSensorAttachmentState>(Auxiliary.FindGameObject("DefineSensorAttachmentUI"));

            MediaManager.getInstance();

            Controls.Load();
            Controls.UpdateFieldControls();
            Controls.Save(true);
        }
Пример #14
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();
    }