Ejemplo n.º 1
0
        /// <summary>
        ///     Pick up selected object
        /// </summary>
        public void PickUp()
        {
            GameObject obj;

            try
            {
                //Get selected object
                obj = selectObject.GetObject();
            }
            catch (NullReferenceException)
            {
                SSTools.ShowMessage("No object selected", SSTools.Position.bottom, SSTools.Time.twoSecond);
                return;
            }

            //If move target is selected, switch to parent
            if (MoveTargetChecker.IsMoveTarget(obj))
            {
                obj = obj.transform.parent.gameObject;
            }

            if (!HandChecker.HasHands(obj))
            {
                SSTools.ShowMessage("No hands placed", SSTools.Position.bottom, SSTools.Time.twoSecond);
                return;
            }

            List <MInstruction> list = new List <MInstruction>();

            //Get IDs of object
            String objID = obj.GetComponent <MMISceneObject>().MSceneObject.ID;

            //Instructions if both hands are present on object
            if (HandChecker.HasBothHands(obj))
            {
                _carryIDManager.CurrentCarryIdBoth = MInstructionFactory.GenerateID();
                MInstruction carryInstruction =
                    new MInstruction(_carryIDManager.CurrentCarryIdBoth, "carry object", "Object/Carry")
                {
                    Properties = PropertiesCreator.Create("TargetID", objID, "Hand",
                                                          "Both")
                };
                list.Add(carryInstruction);
            }

            //Instructions if only right hand is present on object
            else if (HandChecker.HasRightHand(obj))
            {
                _carryIDManager.CurrentCarryIdRight = MInstructionFactory.GenerateID();
                MInstruction carryInstruction =
                    new MInstruction(_carryIDManager.CurrentCarryIdRight, "carry object", "Object/Carry")
                {
                    Properties = PropertiesCreator.Create("TargetID", objID, "Hand",
                                                          "Right"),
                };
                list.Add(carryInstruction);
            }

            //Instructions if only left hand is present on object
            else if (HandChecker.HasLeftHand(obj))
            {
                _carryIDManager.CurrentCarryIdLeft = MInstructionFactory.GenerateID();
                MInstruction carryInstruction =
                    new MInstruction(_carryIDManager.CurrentCarryIdLeft, "carry object", "Object/Carry")
                {
                    Properties = PropertiesCreator.Create("TargetID", objID, "Hand",
                                                          "Left"),
                };
                list.Add(carryInstruction);
            }
            //Indicates that an object has been picked up, so it cannot be released
            pickedUp = true;

            //Add instructions to queue
            queueController.AddItem(list, "Pick up " + obj.name);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Place selected object
        /// </summary>
        public void MoveObject()
        {
            GameObject obj;

            try
            {
                //Get selected object
                obj = selectObject.GetObject();
            }
            catch (NullReferenceException)
            {
                SSTools.ShowMessage("No object selected", SSTools.Position.bottom, SSTools.Time.twoSecond);
                return;
            }

            //If move target is selected, switch to parent
            if (MoveTargetChecker.IsMoveTarget(obj))
            {
                obj = obj.transform.parent.gameObject;
            }

            if (!HandChecker.HasHands(obj))
            {
                SSTools.ShowMessage("No hands placed", SSTools.Position.bottom, SSTools.Time.twoSecond);
                return;
            }

            GameObject positionTarget;

            try
            {
                //Get move target
                positionTarget = obj.transform.Find("moveTarget").gameObject;
            }
            catch (NullReferenceException)
            {
                SSTools.ShowMessage("No move target defined", SSTools.Position.bottom, SSTools.Time.twoSecond);
                return;
            }

            //List for instructions
            List <MInstruction> list = new List <MInstruction>();

            //Get IDs of objects
            String objectID         = obj.GetComponent <MMISceneObject>().MSceneObject.ID;
            String targetPositionID = positionTarget.GetComponent <MMISceneObject>().MSceneObject.ID;

            //Instruction if both hands are present on object
            if (HandChecker.HasBothHands(obj))
            {
                MInstruction moveObject = new MInstruction(MInstructionFactory.GenerateID(), "move object", "Object/Move")
                {
                    Properties = PropertiesCreator.Create("SubjectID", objectID, "Hand",
                                                          "Both", "TargetID", targetPositionID, CoSimTopic.OnStart,
                                                          _carryIDManager.CurrentCarryIdBoth + ":" + CoSimAction.EndInstruction)
                };
                list.Add(moveObject);
            }

            //Instruction if only right hand is present on object
            else if (HandChecker.HasRightHand(obj))
            {
                MInstruction moveObject = new MInstruction(MInstructionFactory.GenerateID(), "move object", "Object/Move")
                {
                    Properties = PropertiesCreator.Create("SubjectID", objectID, "Hand",
                                                          "Right", "TargetID", targetPositionID, CoSimTopic.OnStart,
                                                          _carryIDManager.CurrentCarryIdRight + ":" + CoSimAction.EndInstruction)
                };
                list.Add(moveObject);
            }

            //Instruction if only left hand is present on object
            else if (HandChecker.HasLeftHand(obj))
            {
                MInstruction moveObject = new MInstruction(MInstructionFactory.GenerateID(), "move object", "Object/Move")
                {
                    Properties = PropertiesCreator.Create("SubjectID", objectID, "Hand",
                                                          "Left", "TargetID", targetPositionID, CoSimTopic.OnStart,
                                                          _carryIDManager.CurrentCarryIdLeft + ":" + CoSimAction.EndInstruction)
                };
                list.Add(moveObject);
            }
            //Indicates that an object has been moved and thus the Carry Instruction is finished
            pickedUp = false;

            //Add instructions to queue
            queueController.AddItem(list, "Place " + obj.name);
        }