Esempio n. 1
0
 public void UpdateBridgeIcon(Manipulatable m)
 {
     if (m.drawBridge)
     {
         m.ShowBridge();
         foreach (Transform child in ToggleBridgeButton.transform)
         {
             if (child != ToggleBridgeButton.transform && child.GetComponent <Image>())
             {
                 child.GetComponent <Image>().sprite = BridgeOffSprite;
                 break;
             }
         }
     }
     else
     {
         m.HideBridge();
         foreach (Transform child in ToggleBridgeButton.transform)
         {
             if (child != ToggleBridgeButton.transform && child.GetComponent <Image>())
             {
                 child.GetComponent <Image>().sprite = BridgeOnSprite;
                 break;
             }
         }
     }
 }
Esempio n. 2
0
    void Start()
    {
        Manipulatable m = GetComponent <Manipulatable>();

        m.CustomHoverMaterial   = HoverMaterial;
        m.CustomOutlineMaterial = OutlineMaterial;
    }
Esempio n. 3
0
    public void ToggleBridge()
    {
        Manipulatable m = editorManager.GetSelectedObject().GetComponent <Manipulatable>();

        m.drawBridge = !m.drawBridge;
        UpdateBridgeIcon(m);
    }
Esempio n. 4
0
    public void DetectObjectRaycast()
    {
        RaycastHit hit;
        Ray        ray = new Ray(raycastOrigin.position, raycastOrigin.forward);

        if (Physics.Raycast(ray, out hit, Mathf.Infinity))
        {
            GameObject         hitObject           = hit.collider.gameObject;
            Manipulatable      objectManipulatable = hitObject.GetComponent <Manipulatable>();
            InteractableObject interactableObject  = hitObject.GetComponent <InteractableObject>();
            MonitorMatter      monitorMatter       = currentUIElement.GetComponent <MonitorMatter>();
            MonitorObject      monitorObject       = currentUIElement.GetComponent <MonitorObject>();

            if (objectManipulatable != null && monitorObject != null)
            {
                selectedWorldObject = hit.collider.gameObject;

                monitorObject.currentManipulatable = objectManipulatable;
                monitorObject.UpdateStatement();

                SetUIObjectName(selectedWorldObject.name);
            }
            else if (interactableObject != null && monitorMatter != null)
            {
                interactableObject.UpdateMatter(monitorMatter.matter);
                monitorMatter.gameObject.SetActive(false);
            }
        }
    }
Esempio n. 5
0
    public void DestroyTheGlass()
    {
        if (manipulatable == null)
        {
            manipulatable = GetComponent <Manipulatable>();
        }

        if (manipulatable != null)
        {
            manipulatable.destroyed = true;
            manipulatable.UpdateValues();
        }

        mesh.enabled = false;
        if (interactableObject == null)
        {
            interactableObject = GetComponent <InteractableObject>();
        }

        interactableObject.GetComponent <Collider>().enabled = false;
        for (int i = 0; i <= objectNumber; i++)
        {
            Instantiate(glassShards, transform.position, transform.rotation);
        }



        mesh.enabled = false;
        FindObjectOfType <SoundManager>().PlaySound("Glass");
    }
    private void endGrab(Hand hand)
    {
        int controller = (int)hand;

        //TODO - change currSelectedL/RObj to an array so that we can index with (int)hand
        if (controller == 1)
        {
            //TODO - Calculate magnitude of change along controller's forward axis.  Add to magnitude.
            currSelectedRObj.gameObject.GetComponent <Rigidbody>().useGravity = true;
            Vector3 direction = controllers[1].position - rHandLastPos;
            direction.Normalize();
            float magnitude = Vector3.Distance(controllers[1].position, rHandLastPos);
            currSelectedRObj.gameObject.GetComponent <Rigidbody>().AddForce(direction * magnitude * 30000f);
            currSelectedRObj = null;
        }
        else
        {
            currSelectedLObj.gameObject.GetComponent <Rigidbody>().useGravity = true;
            Vector3 direction = controllers[0].position - lHandLastPos;
            direction.Normalize();
            float magnitude = Vector3.Distance(controllers[0].position, lHandLastPos);
            currSelectedLObj.gameObject.GetComponent <Rigidbody>().AddForce(direction * magnitude * 30000f);
            currSelectedLObj = null;
        }
    }
    private void initializeGrab(Hand hand)
    {
        int controller = (int)hand;
        // Calculate Quaternion distance between the head to the controller and the head to the object
        Vector3    actualHeadPos    = CalcActualHeadPos();
        Quaternion headToController = Quaternion.LookRotation(controllers[controller].position - actualHeadPos);

        if (controller == 1)
        {
            currSelectedRObj = currRHandObservedObj;
            // Quaternion headToObject = Quaternion.LookRotation(currSelectedRObj.transform.position - hmd.position);
            Quaternion headToObject = Quaternion.LookRotation(currSelectedRObj.transform.position - actualHeadPos);
            rHandDiffQuat = headToObject * Quaternion.Inverse(headToController);
            //Save the distances from the hand to the object and the hand from the headset.
            rHandObjDist = Vector3.Distance(controllers[controller].position, currSelectedRObj.transform.position);
            // initRHandDistFromHmd = Vector3.Distance(controllers[controller].position, hmd.position);
            initRHandDistFromHmd = Vector3.Distance(controllers[controller].position, actualHeadPos);
            currSelectedRObj.GetComponent <Rigidbody>().velocity = Vector3.zero;
        }
        else
        {
            currSelectedLObj = currLHandObservedObj;
            // Quaternion headToObject = Quaternion.LookRotation(currSelectedLObj.transform.position - hmd.position);
            Quaternion headToObject = Quaternion.LookRotation(currSelectedLObj.transform.position - actualHeadPos);
            lHandDiffQuat = headToObject * Quaternion.Inverse(headToController);
            //Save the distances from the hand to the object and the hand from the headset.
            lHandObjDist = Vector3.Distance(controllers[controller].position, currSelectedLObj.transform.position);
            // initLHandDistFromHmd = Vector3.Distance(controllers[controller].position, hmd.position);
            initLHandDistFromHmd = Vector3.Distance(controllers[controller].position, actualHeadPos);
            currSelectedLObj.GetComponent <Rigidbody>().velocity = Vector3.zero;
        }
    }
Esempio n. 8
0
 private void ShowBridge()
 {
     if (colliders.Count == 0)
     {
         Manipulatable manipulatable = objectGO.GetComponent <Manipulatable>();
         manipulatable.ShowBridge();
     }
 }
Esempio n. 9
0
    public void SelectPart(GameObject go)
    {
        Manipulatable sensor = go.GetComponent <Manipulatable>();

        if (sensor != null)
        {
            if (selectedObject != go)
            {
                SetSelectedObject(go);
            }
            else
            {
                AnimateCameraToSelection();
            }
        }
    }
Esempio n. 10
0
    public GameObject AddPart(GameObject go, string name)
    {
        GameObject sensor = Instantiate(go);

        if (sensor.GetComponent <Manipulatable>() == null)
        {
            sensor.AddComponent <Manipulatable>();
        }

        Manipulatable m = sensor.GetComponent <Manipulatable>();

        m.ClearOutline();

        sensor.name = name;
        sensor.transform.position = Vector3.zero + new Vector3(0, sensor.transform.localScale.y / 2, 0);
        sensor.transform.SetParent(PartsContainer.transform);
        return(sensor);
    }
Esempio n. 11
0
 void OnTriggerEnter(Collider col)
 {
     if (objectGO != null)
     {
         if (col.tag.Equals(TAG))
         {
             colliders.Add(col);
             Manipulatable manipulatable = objectGO.GetComponent <Manipulatable>();
             if (manipulatable.isSelected)
             {
                 manipulatable.HideBridge();
             }
         }
     }
     else
     {
         Debug.Log("Trigger entered on bridge without it's ObjectGO set");
     }
 }
Esempio n. 12
0
    public void SelectRobotBase(RobotBase robotBase)
    {
        this.robotBase = robotBase;
        switch (robotBase)
        {
        case RobotBase.Jackal:
            robotBaseObject = Instantiate <GameObject>(Resources.Load <GameObject>("Models/Robots/Jackal"));
            break;

        case RobotBase.Husky:
            robotBaseObject = Instantiate <GameObject>(Resources.Load <GameObject>("Models/Robots/Husky"));
            break;
        }
        if (robotBaseObject != null)
        {
            //Find the highest mesh in the model
            float highestY = 0;
            foreach (Transform child in robotBaseObject.transform)
            {
                if (child.position.y > highestY)
                {
                    highestY          = child.position.y;
                    robotBaseTopPlate = child.gameObject;
                }
            }
            robotBaseTopPlate.AddComponent <Manipulatable>();
            Manipulatable robotTopPlateManipulatable = robotBaseTopPlate.GetComponent <Manipulatable>();
            robotTopPlateManipulatable.XPosManipulation = false;
            robotTopPlateManipulatable.YPosManipulation = false;
            robotTopPlateManipulatable.ZPosManipulation = false;
            robotTopPlateManipulatable.RRotManipulation = false;
            robotTopPlateManipulatable.PRotManipulation = false;
            robotTopPlateManipulatable.YRotManipulation = false;
            //robotBaseTopPlate.GetComponentInChildren<MeshRenderer>().material.color = Color.red;
            //Offset the y by that amount so that the top of the bot is at (0, 0, 0)
            robotBaseObject.transform.position = Vector3.zero - new Vector3(0, highestY, 0);

            //Show the help panel on startup
            uiManager.ShowHelpPanel();
        }
    }
Esempio n. 13
0
    private void castRay(Hand hand)
    {
        int     controller    = (int)hand;
        Vector3 actualHeadPos = CalcActualHeadPos();
        // Ray ray = new Ray(controllers[controller].position, controllers[controller].position - hmd.position);
        Ray ray = new Ray(controllers[controller].position, controllers[controller].position - actualHeadPos);

        Manipulatable[] objs = (Manipulatable[])FindObjectsOfType <Manipulatable>();
        float           min  = float.MaxValue;
        int             idx  = 0;

        for (int i = 0; i < objs.Length; i++)
        {
            float dist = Vector3.Cross(ray.direction, objs[i].transform.position - ray.origin).magnitude;
            // if (dist < min && dist < (Mathf.Sin(15f * Mathf.Deg2Rad) * Vector3.Distance(objs[i].transform.position, hmd.position)))
            // if (dist < min && dist < (Mathf.Sin(15f * Mathf.Deg2Rad) * Vector3.Distance(objs[i].transform.position, actualHeadPos))
            //  && Vector3.Distance(objs[i].transform.position, controllers[controller].position) < 30f)
            if (dist < min && dist < (Mathf.Sin(15f * Mathf.Deg2Rad) * Vector3.Distance(objs[i].transform.position, actualHeadPos)) &&
                Vector3.Distance(objs[i].transform.position, controllers[controller].position) < 100f)
            {
                min = dist;
                idx = i;
            }
        }
        if (min != float.MaxValue && controller == 1)
        {
            currRHandObservedObj = objs[idx];
        }
        else if (min != float.MaxValue && controller == 0)
        {
            currLHandObservedObj = objs[idx];
        }
        else if (min == float.MaxValue && controller == 1)
        {
            currRHandObservedObj = null;
        }
        else
        {
            currLHandObservedObj = null;
        }
    }
Esempio n. 14
0
    private void UpdateHandles()
    {
        if (selectedObject == null)
        {
            XYZHandles.SetActive(false);
            RPYHandles.SetActive(false);
            return;
        }
        XYZHandles.SetActive(true);
        RPYHandles.SetActive(true);
        Manipulatable part = selectedObject.GetComponent <Manipulatable>();

        switch (mode)
        {
        case EditorManager.Mode.Translate:
            XPosHandle.SetActive(part.XPosManipulation);
            YPosHandle.SetActive(part.YPosManipulation);
            ZPosHandle.SetActive(part.ZPosManipulation);
            RRotHandle.SetActive(false);
            PRotHandle.SetActive(false);
            YRotHandle.SetActive(false);
            HandleCamera.farClipPlane = 1000;
            break;

        case EditorManager.Mode.Rotate:
            XPosHandle.SetActive(false);
            YPosHandle.SetActive(false);
            ZPosHandle.SetActive(false);
            RRotHandle.SetActive(part.RRotManipulation);
            PRotHandle.SetActive(part.PRotManipulation);
            YRotHandle.SetActive(part.YRotManipulation);
            //Only show the front side of the torus' for rotate
            HandleCamera.farClipPlane = HandleCameraDistance;
            break;
        }

        XYZHandles.transform.position = selectedObject.transform.position;
        RPYHandles.transform.position = selectedObject.transform.position;
    }
Esempio n. 15
0
    private void releasePushWithObj(Hand hand)
    {
        int controller = (int)hand;

        if (controller == 1)
        {
            if (currSelectedRObj == null)
            {
                return;
            }
            //Direction should be away from the player
            //Vector3 direction = currSelectedRObj.transform.position - hmd.position;
            Vector3 direction = controllers[controller].forward;
            direction.Normalize();
            //Magnitude should be based on how long the button was held
            float chargeTime = Time.time - startRChargeTime;
            chargeTime = Mathf.Min(chargeTime, 2f);
            currSelectedRObj.GetComponent <Rigidbody>().AddForce(direction * (1000f + (chargeTime * 1000f)));
            currSelectedRObj.gameObject.GetComponent <Rigidbody>().useGravity = true;
            currSelectedRObj = null;
        }
        else
        {
            if (currSelectedLObj == null)
            {
                return;
            }
            //Direction should be away from the player
            //Vector3 direction = currSelectedLObj.transform.position - hmd.position;
            Vector3 direction = controllers[controller].forward;
            direction.Normalize();
            //Magnitude should be based on how long the button was held
            float chargeTime = Time.time - startLChargeTime;
            chargeTime = Mathf.Min(chargeTime, 2f);
            currSelectedLObj.GetComponent <Rigidbody>().AddForce(direction * (1000f + (chargeTime * 1000f)));
            currSelectedLObj.gameObject.GetComponent <Rigidbody>().useGravity = true;
            currSelectedLObj = null;
        }
    }
Esempio n. 16
0
 private void Start()
 {
     interactableObject = GetComponent <InteractableObject>();
     manipulatable      = GetComponent <Manipulatable>();
 }