示例#1
0
        public void AttachTower(TowerObject tower, Vector3 positionOFfset, Vector3 rotationOffset)
        {
            // Fix the tower to the position and rotation of the node
            Vector3    newPos = transform.position + positionOFfset;
            Quaternion newRot = transform.rotation /* Quaternion.Euler(rotationOffset)*/;

            tower.transform.SetPositionAndRotation(newPos, newRot);
            tower.transform.Rotate(rotationOffset);
            print("applied rotation : " + rotationOffset);
            towerRigidWasColliding = tower.GetComponent <Rigidbody>().detectCollisions;
            towerRigidWasKinematic = tower.GetComponent <Rigidbody>().isKinematic;
            tower.GetComponent <Rigidbody>().detectCollisions = false;
            tower.GetComponent <Rigidbody>().isKinematic      = true;

            // Change the material to indicate that this position is now closed
            GetComponent <Renderer>().material = closedMat;

            // Set the HUD text
            if (hudText != null)
            {
                hudText.text = tower.towerName;
            }

            // Store a reference to the attached tower
            attachedTower = tower;

            tower.SpawnTowerComponents(this);
            tower.HideTowerObject();
        }
示例#2
0
        public bool RemoveTower()
        {
            // We can't do anything if there's nothing to remove
            if (attachedTower == null)
            {
                return(false);
            }

            // Free the position and rotation of the tower
            attachedTower.GetComponent <Rigidbody>().detectCollisions = towerRigidWasColliding;
            attachedTower.GetComponent <Rigidbody>().isKinematic      = towerRigidWasKinematic;

            // Change the material to indicate that this position is now open
            GetComponent <Renderer>().material = openHoverMat;

            // Clear the HUD text
            if (hudText != null)
            {
                hudText.text = "";
            }

            // Restore the tower object and destroy the tower dive components
            attachedTower.DestroyTowerComponents();
            attachedTower.ShowTowerObject();

            // Clear the reference to the attached tower;
            attachedTower = null;

            return(true);
        }
示例#3
0
        public bool TryAttachTower(TowerObject tower, Vector3 positionOffset, Vector3 rotationOffset, Hand hand)
        {
            TowerObject temp = attachedTower;

            if (temp != null)
            {
                if (allowsSwapping)
                {
                    RemoveTower();
                    hand.AttachObject(temp.gameObject, GrabTypes.Grip, temp.attachmentFlags, temp.attachentOffset);
                    AttachTower(tower, positionOffset, rotationOffset);

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                AttachTower(tower, positionOffset, rotationOffset);

                return(true);
            }
        }
示例#4
0
        /** STEAMVR SYSTEM ROUTINES **/
        protected virtual void HandHoverUpdate(Hand hand)
        {
            // We want to handle potentially picking up a tower that has been placed at this node
            // Capture current grab information from the hand
            GrabTypes startingGrabType = hand.GetGrabStarting();

            // If the hand is grabbing and there is a tower here to be grabbed
            if (attachedTower != null && startingGrabType != GrabTypes.None && !da.isDived())
            {
                // Remove the tower and attach it to the hand
                TowerObject temp = attachedTower;
                RemoveTower();
                hand.AttachObject(temp.gameObject, startingGrabType, temp.attachmentFlags, temp.attachentOffset);
                hand.HideGrabHint();
            }
        }