Exemple #1
0
        private void CreateIndicatorCanvas()
        {
            var canvas = _Canvas = UnityHelper.CreateGameObjectAsChild("IKFK", FindAttachPosition("trackpad")).gameObject.AddComponent <Canvas>();


            canvas.renderMode = RenderMode.WorldSpace;

            canvas.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 100);
            canvas.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 100);

            canvas.transform.localPosition = new Vector3(0, 0, 0.00327f);
            canvas.transform.localRotation = Quaternion.Euler(0, 180, 90);
            canvas.transform.localScale    = new Vector3(0.0002294636f, 0.0002294636f, 0.0002294636f);


            var text    = UnityHelper.CreateGameObjectAsChild("Text", canvas.transform).gameObject.AddComponent <Text>();
            var outline = text.gameObject.AddComponent <Outline>();

            text.gameObject.AddComponent <IKStateReactor>();

            // Maximize
            text.GetComponent <RectTransform>().anchorMin = Vector2.zero;
            text.GetComponent <RectTransform>().anchorMax = Vector2.one;
            text.font                 = Resources.GetBuiltinResource <Font>("Arial.ttf");
            text.alignment            = TextAnchor.MiddleCenter;
            text.color                = Color.white;
            text.fontSize             = 50;
            text.resizeTextForBestFit = false;
        }
Exemple #2
0
        protected virtual HandAttachments BuildAttachmentHand(Chirality handedness)
        {
            var hand = new GameObject("AHand_" + handedness).AddComponent <HandAttachments>();

            hand._handedness = handedness;
            hand.gameObject.AddComponent <HandEnableDisable>();
            hand.gameObject.AddComponent <WarpHandler>();

            // Create transforms
            hand.GrabPoint  = UnityHelper.CreateGameObjectAsChild("GrabPoint", hand.transform, true);
            hand.Arm        = UnityHelper.CreateGameObjectAsChild("Arm", hand.transform, true);
            hand.Thumb      = UnityHelper.CreateGameObjectAsChild("Thumb", hand.transform, true);
            hand.Index      = UnityHelper.CreateGameObjectAsChild("Index", hand.transform, true);
            hand.Middle     = UnityHelper.CreateGameObjectAsChild("Middle", hand.transform, true);
            hand.Ring       = UnityHelper.CreateGameObjectAsChild("Ring", hand.transform, true);
            hand.Pinky      = UnityHelper.CreateGameObjectAsChild("Pinky", hand.transform, true);
            hand.PinchPoint = UnityHelper.CreateGameObjectAsChild("PinchPoint", hand.transform, true);
            hand.Palm       = UnityHelper.CreateGameObjectAsChild("Palm", hand.transform, true);
            hand.OnBegin   += delegate
            {
                if (!_ControllerFound)
                {
                    _ControllerFound = true;
                    ChangeModeOnControllersDetected();
                }
            };
            return(hand);
        }
        private DynamicBoneCollider CreateCollider(Transform parent, float radius)
        {
            var collider = UnityHelper.CreateGameObjectAsChild("Dynamic Collider", parent).gameObject.AddComponent <DynamicBoneCollider>();

            collider.m_Radius    = radius;
            collider.m_Bound     = DynamicBoneCollider.Bound.Outside;
            collider.m_Direction = DynamicBoneCollider.Direction.X;
            collider.m_Center.y  = 0;
            collider.m_Center.z  = 0;
            return(collider);
        }
Exemple #4
0
        protected void SetUpDetectors()
        {
            var fistDetector = UnityHelper.CreateGameObjectAsChild("fistdetector", transform)
                               .gameObject.AddComponent <ExtendedFingerDetector>();

            fistDetector.HandModel = hand;
            fistDetector.Thumb     = PointingState.Either;
            fistDetector.Index     = PointingState.NotExtended;
            fistDetector.Middle    = PointingState.NotExtended;
            fistDetector.Ring      = PointingState.NotExtended;
            fistDetector.Pinky     = PointingState.NotExtended;
            fistDetector.OnActivate.AddListener(OnFistStart);
            fistDetector.OnDeactivate.AddListener(OnFistEnd);
        }
Exemple #5
0
        private void CreateCanvas()
        {
            var canvas = _Canvas = UnityHelper.CreateGameObjectAsChild("ToolCanvas", FindAttachPosition("trackpad")).gameObject.AddComponent <Canvas>();

            canvas.renderMode = RenderMode.WorldSpace;

            canvas.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 100);
            canvas.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 100);

            canvas.transform.localPosition = new Vector3(-0.00327f, 0, 0.00327f);
            canvas.transform.localRotation = Quaternion.Euler(0, 180, 90);
            canvas.transform.localScale    = Vector3.one * 0.0002294636f;

            var cutout = UnityHelper.CreateGameObjectAsChild("Cutout", _Canvas.transform).gameObject.AddComponent <GaugeCutout>();

            cutout.GetComponent <RectTransform>().anchorMin = Vector2.zero;
            cutout.GetComponent <RectTransform>().anchorMax = Vector2.one;
        }
        void SetUpDetectors()
        {
            var detectorHolder = UnityHelper.CreateGameObjectAsChild("Warp Detector Holder", transform).gameObject;

            _OpenPalmDownwardsDetector = detectorHolder.AddComponent <DetectorLogicGate>();

            _PalmDownwardsDetector                   = detectorHolder.AddComponent <PalmDirectionDetector>();
            _PalmDownwardsDetector.HandModel         = _Hand;
            _PalmDownwardsDetector.PointingDirection = new Vector3(0, -1, 0.5f).normalized;
            _PalmDownwardsDetector.OnAngle           = 10;
            //_PalmDownwardsDetector.OffAngle = 60;


            _ExtendedFingerDetector           = UnityHelper.CreateGameObjectAsChild("_ExtendedFingerDetector", detectorHolder.transform).gameObject.AddComponent <ExtendedFingerDetector>();
            _ExtendedFingerDetector.HandModel = _Hand;
            _ExtendedFingerDetector.Thumb     = PointingState.Extended;
            _ExtendedFingerDetector.Index     = PointingState.Extended;
            _ExtendedFingerDetector.Middle    = PointingState.Extended;
            _ExtendedFingerDetector.Ring      = PointingState.Extended;
            _ExtendedFingerDetector.Pinky     = PointingState.Extended;

            _Fistdetector           = UnityHelper.CreateGameObjectAsChild("_Fistdetector", detectorHolder.transform).gameObject.AddComponent <ExtendedFingerDetector>();
            _Fistdetector.HandModel = _Hand;
            _Fistdetector.Thumb     = PointingState.Either;
            _Fistdetector.Index     = PointingState.NotExtended;
            _Fistdetector.Middle    = PointingState.NotExtended;
            _Fistdetector.Ring      = PointingState.NotExtended;
            _Fistdetector.Pinky     = PointingState.NotExtended;


            _OpenPalmDownwardsDetector.AddDetector(_PalmDownwardsDetector);
            _OpenPalmDownwardsDetector.AddDetector(_ExtendedFingerDetector);
            _OpenPalmDownwardsDetector.OnActivate.AddListener(OnOpenPalmDownwardStart);
            _OpenPalmDownwardsDetector.OnDeactivate.AddListener(OnOpenPalmDownwardEnd);

            _Fistdetector.OnActivate.AddListener(OnFist);
        }
        void SetUpDetectors()
        {
            _Left      = UnityHelper.CreateGameObjectAsChild("Pinch Detector", transform).gameObject.AddComponent <PinchDetector>();
            _Right     = UnityHelper.CreateGameObjectAsChild("Pinch Detector", transform).gameObject.AddComponent <PinchDetector>();
            _Proximity = VR.Mode.LeftHand.PinchPoint.gameObject.AddComponent <ProximityDetector>();
            _Proximity.TargetObjects = new GameObject[] { VR.Mode.RightHand.PinchPoint.gameObject };
            _Proximity.OnDistance    = 0.1f;
            _Proximity.OffDistance   = 0.11f;
            _Detector      = gameObject.AddComponent <DetectorLogicGate>();
            _StartDetector = gameObject.AddComponent <DetectorLogicGate>();

            _Left._handModel  = VR.Mode.LeftHand;
            _Right._handModel = VR.Mode.RightHand;

            _StartDetector.AddDetector(_Left);
            _StartDetector.AddDetector(_Right);
            _StartDetector.AddDetector(_Proximity);

            _Detector.AddDetector(_Left);
            _Detector.AddDetector(_Right);

            _StartDetector.OnActivate.AddListener(OnStartPinch);
            _Detector.OnDeactivate.AddListener(OnStopPinch);
        }