Beispiel #1
0
        /// <summary>
        /// Loads a new robot and manipulator from given directorys
        /// </summary>
        /// <param name="directory">robot directory</param>
        /// <returns>whether the process was successful</returns>
        public bool LoadRobotWithManipulator(string baseDirectory, string manipulatorDirectory)
        {
            if (SpawnedRobots.Count >= MAX_ROBOTS)
            {
                return(false);
            }

            robotPath = baseDirectory;

            GameObject robotObject = new GameObject("Robot");
            MaMRobot   robot       = robotObject.AddComponent <MaMRobot>();

            robot.FilePath = robotPath;

            //Initialiezs the physical robot based off of robot directory. Returns false if not sucessful
            if (!robot.InitializeRobot(baseDirectory))
            {
                return(false);
            }

            //If this is the first robot spawned, then set it to be the active robot and initialize the robot camera on it
            if (ActiveRobot == null)
            {
                ActiveRobot = robot;
            }

            robot.ControlIndex = SpawnedRobots.Count;
            SpawnedRobots.Add(robot);

            DPMDataHandler.Load(robotPath);
            return(robot.InitializeManipulator(manipulatorDirectory));
        }
Beispiel #2
0
 /// <summary>
 /// Changes the active robot to a different robot based on a given index
 /// </summary>
 public void SwitchActiveRobot(int index)
 {
     if (index < SpawnedRobots.Count)
     {
         ActiveRobot = SpawnedRobots[index];
         DPMDataHandler.Load(ActiveRobot.FilePath);
     }
 }
Beispiel #3
0
 /// <summary>
 /// Changes the active robot to a different robot based on a given index
 /// </summary>
 public void SwitchActiveRobot(int index)
 {
     if (SpawnedRobots.Count() > 0)
     {
         ActiveRobot = SpawnedRobots[index];
         DPMDataHandler.Load(ActiveRobot.FilePath); //reload robot data to allow for driver practice for multiplayer
     }
 }
Beispiel #4
0
        /// <summary>
        /// Loads a new robot from a given directory
        /// </summary>
        /// <param name="directory">robot directory</param>
        /// <returns>whether the process was successful</returns>
        public bool LoadRobot(string directory, bool isMixAndMatch)
        {
            if (SpawnedRobots.Count < MAX_ROBOTS)
            {
                GameObject     robotObject = new GameObject("Robot");
                SimulatorRobot robot;

                if (isMixAndMatch)
                {
                    robotPath = RobotTypeManager.RobotPath;
                    MaMRobot mamRobot = robotObject.AddComponent <MaMRobot>();
                    mamRobot.RobotHasManipulator = false; // Defaults to false
                    robot = mamRobot;
                }
                else
                {
                    robotPath = directory;
                    robot     = robotObject.AddComponent <SimulatorRobot>();
                }

                robot.FilePath = robotPath;

                //Initialiezs the physical robot based off of robot directory. Returns false if not sucessful
                if (!robot.InitializeRobot(robotPath))
                {
                    return(false);
                }

                //If this is the first robot spawned, then set it to be the active robot and initialize the robot camera on it
                if (ActiveRobot == null)
                {
                    ActiveRobot = robot;
                }

                robot.ControlIndex = SpawnedRobots.Count;
                SpawnedRobots.Add(robot);

                DPMDataHandler.Load(robotPath);

                if (!isMixAndMatch && !PlayerPrefs.HasKey(robot.RootNode.GUID.ToString()) && !SampleRobotGUIDs.Contains(robot.RootNode.GUID.ToString()))
                {
                    if (PlayerPrefs.GetInt("analytics") == 1)
                    {
                        PlayerPrefs.SetString(robot.RootNode.GUID.ToString(), "analyzed");
                        Analytics.CustomEvent(robot.RootNode.exportedWith.ToString(), new Dictionary <string, object> {
                        });
                    }
                }

                return(true);
            }
            return(false);
        }
Beispiel #5
0
        // Update is called once per frame
        public override void Update()
        {
            Ray ray = UnityEngine.Camera.main.ScreenPointToRay(UnityEngine.Input.mousePosition);

            BulletSharp.Math.Vector3 start = ray.origin.ToBullet();
            BulletSharp.Math.Vector3 end   = ray.GetPoint(200).ToBullet();

            //Creates a callback result that will be updated if we do a ray test with it
            ClosestRayResultCallback rayResult = new ClosestRayResultCallback(ref start, ref end);

            //Retrieves the bullet physics world and does a ray test with the given coordinates and updates the callback object
            BPhysicsWorld world = BPhysicsWorld.Get();

            world.world.RayTest(start, end, rayResult);

            //If there is a collision object and it is dynamic and not a robot part, change the gamepiece to that
            if (rayResult.CollisionObject != null)
            {
                GameObject collisionObject = (rayResult.CollisionObject.UserObject as BRigidBody).gameObject;
                if (rayResult.CollisionObject.CollisionFlags == BulletSharp.CollisionFlags.StaticObject)
                {
                    RevertNodeColors(hoveredNode, hoveredColors);
                }
                else if (collisionObject == null)
                {
                    RevertNodeColors(hoveredNode, hoveredColors);
                }
                else if (collisionObject.transform.parent == t)
                {
                    if (hoveredNode != collisionObject)
                    {
                        RevertNodeColors(hoveredNode, hoveredColors);
                    }

                    hoveredNode = collisionObject;

                    ChangeNodeColors(hoveredNode, hoverColor, hoveredColors);
                    if (UnityEngine.Input.GetMouseButtonUp(0))
                    {
                        if (intake)
                        {
                            DPMDataHandler.dpmodes.Find(d => d.Equals(dp)).intakeNode = hoveredNode.name;
                        }
                        else
                        {
                            DPMDataHandler.dpmodes.Find(d => d.Equals(dp)).releaseNode = hoveredNode.name;
                        }
                        DPMDataHandler.WriteRobot();
                        dpr.SetAllInteractors();
                        ReturnToMainState();
                    }
                }
                else
                {
                    RevertNodeColors(hoveredNode, hoveredColors);
                }
            }
            if (UnityEngine.Input.GetKeyDown(KeyCode.Escape))
            {
                ReturnToMainState();
            }
            if (EventSystem.current.currentSelectedGameObject == highlightButton.gameObject && UnityEngine.Input.GetMouseButton(0))
            {
                HighlightNode();
            }
            else
            {
                RevertHighlight();
            }

            //if (highlightTimer > 0) highlightTimer--;
            //else if (highlightTimer == 0) RevertHighlight();
        }
Beispiel #6
0
        /// <summary>
        /// Loads a new robot from a given directory
        /// </summary>
        /// <param name="directory">robot directory</param>
        /// <returns>whether the process was successful</returns>
        public bool LoadRobot(string directory, bool isMixAndMatch, int replacementIndex)
        {
            bool b = true;

            if (!Directory.Exists(directory))
            {
                return(false);
            }
            else
            {
                string[] files = Directory.GetFiles(directory);
                foreach (string a in files)
                {
                    string name = Path.GetFileName(a);
                    if (name.ToLower().Contains("skeleton"))
                    {
                        b = false;
                    }
                }
            }

            if (b)
            {
                return(false);
            }

            if (SpawnedRobots.Count < MAX_ROBOTS)
            {
                GameObject     robotObject = new GameObject("Robot");
                SimulatorRobot robot;

                if (isMixAndMatch)
                {
                    robotPath = RobotTypeManager.RobotPath;
                    MaMRobot mamRobot = robotObject.AddComponent <MaMRobot>();
                    mamRobot.RobotHasManipulator = false; // Defaults to false
                    robot = mamRobot;

                    if (AnalyticsManager.GlobalInstance != null)
                    {
                        AnalyticsManager.GlobalInstance.LogEventAsync(AnalyticsLedger.EventCatagory.LoadRobot,
                                                                      AnalyticsLedger.EventAction.Load,
                                                                      "Robot - Mix and Match",
                                                                      AnalyticsLedger.getMilliseconds().ToString());
                    }
                }
                else
                {
                    robotPath = directory;
                    robot     = robotObject.AddComponent <SimulatorRobot>();

                    if (AnalyticsManager.GlobalInstance != null)
                    {
                        AnalyticsManager.GlobalInstance.LogEventAsync(AnalyticsLedger.EventCatagory.LoadRobot,
                                                                      AnalyticsLedger.EventAction.Load,
                                                                      "Robot - Exported",
                                                                      AnalyticsLedger.getMilliseconds().ToString());
                    }
                }

                robot.FilePath = robotPath;

                //Initialiezs the physical robot based off of robot directory. Returns false if not sucessful
                if (!robot.InitializeRobot(robotPath))
                {
                    return(false);
                }

                //If this is the first robot spawned, then set it to be the active robot and initialize the robot camera on it
                if (ActiveRobot == null)
                {
                    ActiveRobot = robot;
                }

                robot.ControlIndex = SpawnedRobots.Count;
                if (replacementIndex != -1)
                {
                    SpawnedRobots[replacementIndex] = robot;
                }
                else
                {
                    SpawnedRobots.Add(robot);
                }

                DPMDataHandler.Load(robotPath);

                if (!isMixAndMatch && !PlayerPrefs.HasKey(robot.RootNode.GUID.ToString()) && !SampleRobotGUIDs.Contains(robot.RootNode.GUID.ToString()))
                {
                    AnalyticsManager.GlobalInstance.LogEventAsync(AnalyticsLedger.EventCatagory.LoadRobot,
                                                                  AnalyticsLedger.EventAction.Load,
                                                                  robot.RootNode.GUID.ToString(),
                                                                  AnalyticsLedger.getMilliseconds().ToString());
                }

                return(true);
            }
            return(false);
        }