Пример #1
0
        private void Awake()
        {
            if (Instance && Instance != this)
            {
                Destroy(this);
                return;
            }
            Instance = this;

            Assert.IsNotNull(_leftHand);
            Assert.IsNotNull(_rightHand);

            LeftHand                 = _leftHand.GetComponent <OVRHand>();
            LeftHandSkeleton         = _leftHand.GetComponent <OVRSkeleton>();
            LeftHandSkeletonRenderer = _leftHand.GetComponent <OVRSkeletonRenderer>();
            LeftHandMesh             = _leftHand.GetComponent <OVRMesh>();
            LeftHandMeshRenderer     = _leftHand.GetComponent <OVRMeshRenderer>();

            RightHand                 = _rightHand.GetComponent <OVRHand>();
            RightHandSkeleton         = _rightHand.GetComponent <OVRSkeleton>();
            RightHandSkeletonRenderer = _rightHand.GetComponent <OVRSkeletonRenderer>();
            RightHandMesh             = _rightHand.GetComponent <OVRMesh>();
            RightHandMeshRenderer     = _rightHand.GetComponent <OVRMeshRenderer>();
            _leftMeshRenderer         = LeftHand.GetComponent <SkinnedMeshRenderer>();
            _rightMeshRenderer        = RightHand.GetComponent <SkinnedMeshRenderer>();
            StartCoroutine(FindSkeletonVisualGameObjects());
        }
Пример #2
0
    public static void Init()
    {
        leftHand      = GameObject.Find("LeftHand");
        RightHand     = GameObject.Find("RightHand");
        leftHandPi    = GameObject.Find("LeftHandPi");
        rightHandXian = GameObject.Find("RightHandXian");
        twoHands      = GameObject.Find("TwoHand");
        bg1           = GameObject.Find("Background2_2");
        bg2           = GameObject.Find("Background2_4");

        leftHandAlpha      = leftHand.GetComponent <Scene22AlphaControl>();
        rightHandAlpha     = RightHand.GetComponent <Scene22AlphaControl>();
        leftHandPiAlpha    = leftHandPi.GetComponent <Scene22AlphaControl>();
        rightHandXianAlpha = rightHandXian.GetComponent <Scene22AlphaControl>();
        dumplings5Alpha    = GameObject.Find("Dumplings5").GetComponent <Scene22AlphaControl>();
        dumplings6Alpha    = GameObject.Find("Dumplings6").GetComponent <Scene22AlphaControl>();

        bg1Alpha         = bg1.GetComponent <Scene22AlphaControl>();
        bg2Alpha         = bg2.GetComponent <Scene22AlphaControl>();
        twoHandsAlpha    = twoHands.GetComponent <Scene22AlphaControl>();
        leftHandPos      = leftHand.transform.position;
        rightHandPos     = RightHand.transform.position;
        leftHandPiPos    = leftHandPi.transform.position;
        rightHandXianPos = rightHandXian.transform.position;
    }
Пример #3
0
    void createTrail()
    {
        LeftHand.AddComponent <TrailRenderer>();
        trailrendLeft      = LeftHand.GetComponent <TrailRenderer>();
        trailrendLeft.time = 120.0f;

        RightHand.AddComponent <TrailRenderer>();
        trailrendRight      = RightHand.GetComponent <TrailRenderer>();
        trailrendRight.time = 120.0f;
    }
Пример #4
0
    void withinBounds()
    {
        var cursorBoundsLeft  = LeftHand.GetComponent <Renderer>().bounds;
        var cursorBoundsRight = RightHand.GetComponent <Renderer>().bounds;
        var tunnelBounds      = tunnel.GetComponent <Renderer>().bounds;

        if ((tunnelBounds.Intersects(cursorBoundsLeft) || tunnelBounds.Intersects(cursorBoundsRight)) && (isDraggingLeft || isDraggingRight))
        {
            tunnel.GetComponent <Renderer>().material.color = new Color(0f, 0f, 1f, 0.5f);
        }
        else
        {
            tunnel.GetComponent <Renderer>().material.color = new Color(0.5f, 0.5f, 0.5f, 0.5f);
        }
    }
Пример #5
0
    // Update is called once per frame
    void Update()
    {
        LeftHand.GetComponent <SphereCollider>().enabled = currFunction == Functions.Scale;

        RightHand.GetComponent <SphereCollider>().enabled = currFunction == Functions.Scale;
        RightHand.GetComponent <LineRenderer>().enabled   = currFunction == Functions.Add ||
                                                            currFunction == Functions.Colour || leftMenuShow;

        LeftHand.GetComponent <LineRenderer>().enabled = rightMenuShow;

        LeftHandCanvas.SetActive(leftMenuShow);
        RightHandCanvas.SetActive(rightMenuShow);

        // Menu
        leftRay.origin  = LeftHand.transform.position;
        rightRay.origin = RightHand.transform.position;

        leftRay.direction  = -1f * LeftHand.transform.up;
        rightRay.direction = -1f * RightHand.transform.up;

        foreach (GameObject i in buttons)
        {
            i.GetComponent <Button>().image.color = Color.white;
        }

        if (leftMenuShow)
        {
            RightHand.GetComponent <LineRenderer>().SetPositions(new[] { RightHand.transform.position, RightHand.transform.position + RightHand.transform.up * -0.2f });

            if (Physics.Raycast(rightRay, out RaycastHit rightHit, 0.2f, (1 << 5)))
            {
                if (rightHit.collider.gameObject.CompareTag("Button"))
                {
                    rightHit.collider.gameObject.GetComponent <Button>().image.color = Color.grey;

                    if (IsRightTriggerDown)
                    {
                        switch (rightHit.collider.gameObject.GetComponentInChildren <Text>().text)
                        {
                        case "Cut":
                            currFunction = Functions.Cut;
                            break;

                        case "Add":
                            currFunction = Functions.Add;
                            SphereTool.GetComponent <SphereTool>().SetMode(Mode.Add);
                            break;

                        case "Remove":
                            currFunction = Functions.Remove;
                            SphereTool.GetComponent <SphereTool>().SetMode(Mode.Remove);
                            break;

                        case "Colour":
                            currFunction = Functions.Colour;
                            SphereTool.GetComponent <SphereTool>().SetMode(Mode.Colour);
                            break;

                        case "Scale":
                            currFunction = Functions.Scale;
                            ProxyScale.transform.position = Camera.main.gameObject.transform.position + Camera.main.gameObject.transform.forward * 0.3f;

                            ogVoxelSize = Voxel.VoxelSize;

                            ProxyScale.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);

                            ScaleTool1.transform.position = ProxyScale.transform.position + ProxyScale.transform.up * -0.05f + ProxyScale.transform.right * -0.05f + ProxyScale.transform.forward * 0.05f;
                            ScaleTool2.transform.position = ProxyScale.transform.position + ProxyScale.transform.up * 0.05f + ProxyScale.transform.right * 0.05f + ProxyScale.transform.forward * -0.05f;
                            origScaleDistance             = Vector3.Distance(ScaleTool1.transform.position, ScaleTool2.transform.position);

                            break;

                        case "Translate":
                            currFunction = Functions.Translate;
                            TranslateControl.transform.position = Camera.main.gameObject.transform.position + Camera.main.gameObject.transform.forward * 0.4f;
                            break;

                        case "Rotate":
                            currFunction = Functions.Rotate;
                            break;
                        }

                        if (currFunction == Functions.Scale)
                        {
                            switch (rightHit.collider.gameObject.GetComponentInChildren <Text>().text)
                            {
                            case "Scale +":
                                Voxel.VoxelSize += 0.01f;
                                polygon.RecomputeChunks();
                                break;

                            case "Scale -":
                                Voxel.VoxelSize -= 0.01f;
                                polygon.RecomputeChunks();
                                break;
                            }
                        }

                        IsRightTriggerDown = leftMenuShow = LeftHandCanvas.GetComponent <Canvas>().enabled = false;
                    }
                }

                RightHand.GetComponent <LineRenderer>().SetPositions(new[] { RightHand.transform.position, rightHit.point });
            }
        }
        else
        {
            RightHand.GetComponent <LineRenderer>().SetPositions(new[] { Vector3.zero, Vector3.zero });
        }

        if (rightMenuShow)
        {
            LeftHand.GetComponent <LineRenderer>().SetPositions(new[] { LeftHand.transform.position, LeftHand.transform.position + LeftHand.transform.up * -0.2f });

            if (Physics.Raycast(leftRay, out RaycastHit leftHit, 0.2f, (1 << 5)))
            {
                if (leftHit.collider.gameObject.CompareTag("Button"))
                {
                    leftHit.collider.gameObject.GetComponent <Button>().image.color = Color.grey;

                    if (IsLeftTriggerDown)
                    {
                        switch (leftHit.collider.gameObject.GetComponentInChildren <Text>().text)
                        {
                        case "Cube":
                            polygon.InitCube();
                            break;

                        case "Sphere":
                            polygon.InitSphere();
                            break;

                        case "Clear":
                            polygon.ClearChunks();
                            break;
                        }
                        IsLeftTriggerDown = rightMenuShow = RightHandCanvas.GetComponent <Canvas>().enabled =
                            LeftHand.GetComponent <LineRenderer>().enabled = false;
                    }
                }

                LeftHand.GetComponent <LineRenderer>().SetPositions(new[] { LeftHand.transform.position, leftHit.point });
            }
        }
        //Menu

        // Switch tools
        switch (currFunction)
        {
        case Functions.Scale:
            if (ScalingTool.LeftCollision && IsLeftTriggerDown && ScalingTool.RightCollision && IsRightTriggerDown)
            {
                scaleMode = true;
            }

            scalingDistance = Vector3.Distance(ScaleTool1.transform.position, ScaleTool2.transform.position) - origScaleDistance;
            ProxyScale.transform.localScale = new Vector3(0.1f + scalingDistance / 10f,
                                                          0.1f + scalingDistance / 10f, 0.1f + scalingDistance / 10f);

            if (scaleMode && !IsLeftTriggerDown && !IsRightTriggerDown)
            {
                Voxel.VoxelSize = ogVoxelSize + scalingDistance / 10f;
                ogVoxelSize     = Voxel.VoxelSize;
                polygon.RecomputeChunks();
                scaleMode = false;
                ProxyScale.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);

                ScaleTool1.transform.position = ProxyScale.transform.position + ProxyScale.transform.up * -0.05f +
                                                ProxyScale.transform.right * -0.05f +
                                                ProxyScale.transform.forward * 0.05f;

                ScaleTool2.transform.position = ProxyScale.transform.position + ProxyScale.transform.up * 0.05f +
                                                ProxyScale.transform.right * 0.05f +
                                                ProxyScale.transform.forward * -0.05f;
            }
            break;

        case Functions.Translate:
            // If colliding spheres and right trigger down then move control to match tool position then move polygon by delta value
            TranslateTool.SetActive(true);
            TranslateControl.SetActive(true);
            if (TranslateTool.GetComponent <SphereTranslate>().collideWithControl)
            {
                if (IsRightTriggerDown)
                {
                    Vector3 prevPos = TranslateControl.transform.position;

                    TranslateControl.transform.position = TranslateTool.transform.position;

                    polygon.transform.position += TranslateTool.transform.position - prevPos;
                    translateMode = true;
                }
                else if (translateMode)
                {
                    TranslateControl.transform.position = Camera.main.gameObject.transform.position + Camera.main.gameObject.transform.forward * 0.4f;
                    translateMode = false;
                }
            }

            break;

        case Functions.Colour:
        case Functions.Add:
            if (Physics.Raycast(rightRay, out RaycastHit rightHit, 0.2f, (1 << 5)))
            {
                if (rightHit.collider.gameObject.CompareTag("Button"))
                {
                    rightHit.collider.gameObject.GetComponent <Button>().image.color = Color.grey;

                    if (IsRightTriggerDown)
                    {
                        switch (rightHit.collider.gameObject.GetComponentInChildren <Text>().text)
                        {
                        case "Black":
                            SphereTool.GetComponent <SphereTool>().SetColourMode(0);
                            break;

                        case "Blue":
                            SphereTool.GetComponent <SphereTool>().SetColourMode(1);
                            break;

                        case "Green":
                            SphereTool.GetComponent <SphereTool>().SetColourMode(2);
                            break;

                        case "Red":
                            SphereTool.GetComponent <SphereTool>().SetColourMode(3);
                            break;

                        case "Yellow":
                            SphereTool.GetComponent <SphereTool>().SetColourMode(4);
                            break;

                        case "Purple":
                            SphereTool.GetComponent <SphereTool>().SetColourMode(5);
                            break;

                        case "Turquoise":
                            SphereTool.GetComponent <SphereTool>().SetColourMode(6);
                            break;

                        case "White":
                            SphereTool.GetComponent <SphereTool>().SetColourMode(7);
                            break;
                        }
                    }
                }

                RightHand.GetComponent <LineRenderer>().SetPositions(new[] { RightHand.transform.position, rightHit.point });
            }
            else
            {
                RightHand.GetComponent <LineRenderer>().SetPositions(new [] { Vector3.zero, Vector3.zero });
            }

            break;
        }