Пример #1
0
        override public void refresh()
        {
            //Debug.Log("MFigure refresh");
            base.refresh();
            if (needsRefresh)
            {
                return;
            }
            //boundingBox.GetComponent<Renderer>().material.color = new Color(_Color.x, _Color.y, _Color.z);
            var localSize = USize;

            localSize[2] = 1;
            //boundingBox.transform.localScale = localSize;
            //boundingBox.transform.localPosition = localSize/2;
            //boundingBox.GetComponent<Renderer>().enabled = false;

            var bounds   = Misc.CalculateLocalBounds(transform.gameObject);
            var collider = transform.gameObject.AddComponent <BoxCollider>();

            collider.center = bounds.center;
            collider.size   = bounds.size;

            var rb = transform.gameObject.AddComponent <Rigidbody>();

            rb.isKinematic = false;
            rb.useGravity  = false;
            rb.drag        = 2f;
            rb.angularDrag = 2f;

            var io = transform.gameObject.AddComponent <VRTK.VRTK_InteractableObject>();

            io.isGrabbable            = true;
            io.holdButtonToGrab       = true;
            io.allowedGrabControllers = VRTK.VRTK_InteractableObject.AllowedController.Both;

            var gam = transform.gameObject.AddComponent <VRTK.GrabAttachMechanics.VRTK_ChildOfControllerGrabAttach>();

            gam.precisionGrab = true;

            var ga = transform.gameObject.AddComponent <VRTK.SecondaryControllerGrabActions.VRTK_AxisScaleGrabAction>();

            ga.uniformScaling = true;

            var ih = transform.gameObject.AddComponent <VRTK.VRTK_InteractHaptics>();

            ih.strengthOnGrab = 0.5f;
            ih.intervalOnGrab = 0.05f;
            ih.durationOnGrab = 0.1f;

            // allow figures to collide/intersect with each other
            var figureLayer = LayerMask.NameToLayer("Figures");

            transform.gameObject.layer = figureLayer;
            Physics.IgnoreLayerCollision(figureLayer, figureLayer);

            // move this figure so that it is not intersecting with any others
            var figManager = GameObject.FindObjectOfType <FigureManager>();

            Debug.Assert(figManager != null);
            figManager.needsRearrange = true;
        }