Пример #1
0
    // Update is called once per frame
    void Update()
    {
        // save selected object in _go
        _go = _camera.GetComponent <SelectObject>().GetObject();

        // check if _go is a move target object
        if (MoveTargetChecker.IsMoveTarget(_go) && (Input.GetKey(KeyCode.M) || Input.GetKey(KeyCode.X) || Input.GetKey(KeyCode.Y) || Input.GetKey(KeyCode.Z)))
        {
            var trans = transform;
            // save position of move target in _pos
            _pos = trans.position;

            //save rotation of move target in _rotation
            _rotation = trans.rotation;
        }
        // if _go is not a move target object
        else
        {
            // overwrite position and rotation
            transform.SetPositionAndRotation(_pos, _rotation);
        }
    }
Пример #2
0
    //-------------------often used/helpful methods-------------------

    /// <summary>
    ///     Change the color back to its original one
    /// </summary>
    public void ResetColor()
    {
        //Look after the child if the object is a hand
        if (_child != null)
        {
            _mRendererChild.material.color = _originalColor;
            _child          = null;
            _mRendererChild = null;
        }
        //Change of the material if the object is a moveTarget
        else if (MoveTargetChecker.IsMoveTarget(_go))
        {
            _mRenderer.material = _defaultMaterial;
        }
        //Reset the color if the gameobject is not null
        if (_go != null)
        {
            _mRenderer.material.color = _originalColor;
            _go        = null;
            _mRenderer = null;
            _addObjectMenu.ObjectSelected(_go);
        }
    }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
0
        /// <summary>
        ///     Release selected object
        /// </summary>
        public void Release()
        {
            if (!pickedUp)
            {
                GameObject go;
                try
                {
                    //Get selected object
                    go = 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(go))
                {
                    go = go.transform.parent.gameObject;
                }

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

                //List for hands on object
                List <GameObject> hands = new List <GameObject>();

                if (HandChecker.HasLeftHand(go))
                {
                    MInstruction releaseLeft =
                        new MInstruction(MInstructionFactory.GenerateID(), "release object", "Object/Release")
                    {
                        Properties = PropertiesCreator.Create("Hand", "Left", CoSimTopic.OnStart,
                                                              _handPoseIdManager.CurrentHandIdLeft + ":" + CoSimAction.EndInstruction)
                                     //Properties = PropertiesCreator.Create("Hand", "Left")
                    };

                    //Add instructions to position fingers
                    list.AddRange(ReleaseHandPose("Left"));

                    //Add instruction to release left hand
                    list.Add(releaseLeft);

                    //Remove left hand game object from object
                    //hands.Add(go.transform.Find("LeftHand(Clone)").gameObject);
                    hands.Add(HandChecker.GetLeftHand(go));
                }


                if (HandChecker.HasRightHand(go))
                {
                    MInstruction releaseRight =
                        new MInstruction(MInstructionFactory.GenerateID(), "release object", "Object/Release")
                    {
                        Properties = PropertiesCreator.Create("Hand", "Right", CoSimTopic.OnStart,
                                                              _handPoseIdManager.CurrentHandIdRight + ":" + CoSimAction.EndInstruction)
                                     //Properties = PropertiesCreator.Create("Hand", "Right")
                    };

                    //Add instructions to position fingers
                    list.AddRange(ReleaseHandPose("Right"));

                    //Add instruction to release right hand
                    list.Add(releaseRight);

                    //Remove right hand game object from object
                    //hands.Add(go.transform.Find("RightHand(Clone)").gameObject);
                    hands.Add(HandChecker.GetRightHand(go));
                }

                //Destroy the hands after moving an object
                foreach (var hand in hands)
                {
                    Destroy(hand);
                }

                //Add instructions to queue
                queueController.AddItem(list, "Release " + go.name);
            }
            else
            {
                SSTools.ShowMessage("Object needs to be moved first!", SSTools.Position.bottom, SSTools.Time.twoSecond);
            }
        }
Пример #6
0
        /// <summary>
        ///     Reach selected object
        /// </summary>
        public void ReachObject()
        {
            GameObject go;

            try
            {
                //Get selected object
                go = 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(go))
            {
                go = go.transform.parent.gameObject;
            }

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

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

            if (HandChecker.HasLeftHand(go))
            {
                //Get UnitySceneAccess ID of hand
                //GameObject hand = go.transform.Find("LeftHand(Clone)").gameObject;
                GameObject hand     = HandChecker.GetLeftHand(go);
                String     objectID = hand.GetComponent <MMISceneObject>().MSceneObject.ID;

                //Now create a specific instruction to reach with the right hand
                MInstruction reachLeft = new MInstruction(MInstructionFactory.GenerateID(), "reach left", "Pose/Reach")
                {
                    Properties = PropertiesCreator.Create("TargetID", objectID,
                                                          "Hand", "Left")
                };

                //Add instructions to list
                list.Add(reachLeft);
                list.AddRange(MakeHandPose(go, "Left"));
            }

            if (HandChecker.HasRightHand(go))
            {
                //Get UnitySceneAccess ID of hand
                //GameObject hand = go.transform.Find("RightHand(Clone)").gameObject;
                GameObject hand     = HandChecker.GetRightHand(go);
                String     objectID = hand.GetComponent <MMISceneObject>().MSceneObject.ID;
                //Now create a specific instruction to reach with the right hand
                MInstruction reachRight = new MInstruction(MInstructionFactory.GenerateID(), "reach right", "Pose/Reach")
                {
                    Properties = PropertiesCreator.Create("TargetID", objectID, "Hand", "Right")
                };

                //Add instructions to list
                list.Add(reachRight);
                list.AddRange(MakeHandPose(go, "Right"));
            }

            //Add instruction to queue
            queueController.AddItem(list, "Reach " + go.name);
        }
Пример #7
0
    // Update is called once per frame
    private void Update()
    {
        if (Input.GetMouseButtonDown(0) && Input.GetKey(KeyCode.LeftControl))
        {
            if (!(Camera.main is null))
            {
                _ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            }

            if (Physics.Raycast(_ray, out _hit, 100.0f) && !_hit.transform.gameObject.name.Equals("Plane"))
            {
                if (_hit.transform)
                {
                    //If an object was already selected change it to it's original color
                    if (_go != null)
                    {
                        //Look after the child if the object is a hand
                        if (HandChecker.IsAnyHand(_go))
                        {
                            _mRendererChild.material.color = _originalColor;
                            _child = null;
                        }
                        //Change of the material if the object is a moveTarget
                        else if (MoveTargetChecker.IsMoveTarget(_go))
                        {
                            _mRenderer.material = _defaultMaterial;
                        }
                        _mRenderer.material.color = _originalColor;
                    }

                    //Get object and Hit Point
                    _hitPoint       = _hit.point;
                    _hitPointNormal = _hit.normal;
                    _go             = _hit.transform.gameObject;

                    //Mark the selected object as red
                    _mRenderer     = _go.GetComponent <MeshRenderer>();
                    _originalColor = _mRenderer.material.color;

                    _addObjectMenu.ObjectSelected(_go);

                    //Look after the child if the object is a hand
                    if (HandChecker.IsAnyHand(_go))
                    {
                        _child          = _go.transform.GetChild(0);
                        _mRendererChild = _child.GetComponent <MeshRenderer>();
                        _mRendererChild.material.color = _selectColor;
                    }
                    //Change of the material if the object is a moveTarget
                    else if (MoveTargetChecker.IsMoveTarget(_go))
                    {
                        _defaultMaterial    = _mRenderer.material;
                        _mRenderer.material = _materialTransparent;
                    }
                    //Standard procedure for normal GameObjects
                    else
                    {
                        _mRenderer.material.color = _selectColor;
                    }

                    _dragAndRotate = new DragAndRotate(_go, lockY);
                    if (HandChecker.IsHand(_go))
                    {
                        _handMovement = new HandMovement(_go);
                    }
                }
            }
            else
            {
                //If an object was already selected change it to it's original color and set the object to null
                if (_go != null)
                {
                    //Look after the child if the object is a hand
                    if (HandChecker.IsAnyHand(_go))
                    {
                        _mRendererChild.material.color = _originalColor;
                        _child          = null;
                        _mRendererChild = null;
                    }
                    //Change of the material if the object is a moveTarget
                    else if (MoveTargetChecker.IsMoveTarget(_go))
                    {
                        _mRenderer.material = _defaultMaterial;
                    }
                    _mRenderer.material.color = _originalColor;
                    _go        = null;
                    _mRenderer = null;
                    _addObjectMenu.ObjectSelected(_go);
                }
            }
        }
        try
        {
            if (HandChecker.IsHand(_go))
            {
                //Handle rotate OR Drag for a hand object
                if (Input.GetKey(KeyCode.M) || Input.GetKey(KeyCode.X))
                {
                    _moving = true;
                }
                else
                {
                    _moving = false;
                }

                if (!Input.GetKey(KeyCode.X))
                {
                    _handMovement.CastRayFromObject();
                }
                if (!Input.GetKey(KeyCode.M))
                {
                    _handMovement.HandleRotateHand();
                }
            }
            else
            {
                //handle Rotate OR Drag
                if (!Input.GetKey(KeyCode.M))
                {
                    _dragAndRotate.HandleRotate();
                }
                if (!Input.GetKey(KeyCode.X) && !Input.GetKey(KeyCode.Y) && !Input.GetKey(KeyCode.Z))
                {
                    _dragAndRotate.HandleDrag();
                }
            }
        }
        catch (Exception)
        {
            //Catch if no object is selected
        }
    }