Ejemplo n.º 1
0
        void Start()
        {
            if (dummyGrabbable == null)
            {
                var go = new GameObject("Dummy Grabbable");
                dummyGrabbable = go.AddComponent <Grabbable>();
                dummyGrabbable.transform.parent        = transform;
                dummyGrabbable.transform.localPosition = Vector3.zero;
                dummyGrabbable.transform.localRotation = Quaternion.identity;



                // Copy over grab points
                List <Transform> grabs = new List <Transform>();
                for (int x = 0; x < GrabPoints.Count; x++)
                {
                    GrabPoint g = GrabPoints[x];
                    grabs.Add(g.transform);
                }
                dummyGrabbable.GrabPoints      = grabs;
                dummyGrabbable.GrabMechanic    = GrabType.Snap;
                dummyGrabbable.ParentHandModel = false;
                dummyGrabbable.CanBeDropped    = false;

                // Copy settings over from reference object if available
                if (GrabObject != null)
                {
                    dummyGrabbable.GrabButton = GrabObject.GrabButton;
                    dummyGrabbable.Grabtype   = GrabObject.Grabtype;
                }
            }
        }
Ejemplo n.º 2
0
        void OnTriggerEnter(Collider other)
        {
            // Object isn't being held, ignore this
            if (OtherGrabbableMustBeHeld != null && !OtherGrabbableMustBeHeld.BeingHeld)
            {
                return;
            }

            // Already have something in the trigger
            if (grabberInTrigger != null)
            {
                return;
            }

            // Our component has been disabled
            if (!this.isActiveAndEnabled || dummyGrabbable == null)
            {
                return;
            }

            Grabber grab = other.GetComponent <Grabber>();

            if (grab != null && !grab.HoldingItem && currentGrabber == null)
            {
                // Check if any Grab Points have been found
                Transform closestGrab = dummyGrabbable.GetClosestGrabPoint(grab);

                if (closestGrab != null)
                {
                    closestPoint = closestGrab.GetComponent <GrabPoint>();
                }
                else
                {
                    closestPoint = null;
                }

                grabberInTrigger = grab;

                // Update Grabber
                if (closestPoint != null)
                {
                    dummyGrabbable.ActiveGrabPoint = closestPoint;
                    setGrabber(grab);
                }
            }
        }
Ejemplo n.º 3
0
        public virtual void UpdateGrabPoint(GrabPoint newPoint)
        {
            closestPoint = newPoint;

            // Update hand animation
            dummyGrabbable.CustomHandPose = newPoint.HandPose;

            // Move Hand Graphics if they are available
            if (currentGrabber != null && currentGrabber.HandsGraphics != null)
            {
                if (MoveInStyle != HandMovement.None)
                {
                    currentGrabber.HandsGraphics.parent = closestPoint.transform;
                }

                // Move hands in place
                if (MoveInStyle == HandMovement.Instant)
                {
                    currentGrabber.HandsGraphics.localPosition    = currentGrabber.handsGraphicsGrabberOffset;
                    currentGrabber.HandsGraphics.localEulerAngles = Vector3.zero;
                }
            }
        }
Ejemplo n.º 4
0
        public Transform GetClosestGrabPoint(Grabber grabber)
        {
            Transform grabPoint    = null;
            float     lastDistance = 9999;

            if (GrabPoints != null)
            {
                foreach (var g in GrabPoints)
                {
                    // Transform may have been destroyed
                    if (g == null)
                    {
                        continue;
                    }

                    // Check for GrabPoint component that may override some values
                    GrabPoint gp = g.GetComponent <GrabPoint>();
                    if (gp)
                    {
                        float currentAngle = Quaternion.Angle(grabber.transform.rotation, g.transform.rotation);
                        if (currentAngle > gp.MaxDegreeDifferenceAllowed)
                        {
                            continue;
                        }
                    }

                    float thisDist = Vector3.Distance(g.transform.position, grabber.transform.position);
                    if (thisDist < lastDistance)
                    {
                        grabPoint    = g;
                        lastDistance = thisDist;
                    }
                }
            }

            return(grabPoint);
        }
Ejemplo n.º 5
0
        public override void OnInspectorGUI()
        {
            grabPoint = (GrabPoint)target;
            bool inPrefabMode = false;

#if UNITY_EDITOR
            inPrefabMode = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage() != null;
#endif

            // Double check that there wasn't an object left in the scene
            checkForExistingPreview();

            // Load the texture resource
            if (buttonLeftTexture == null)
            {
                buttonLeftTexture          = (Texture)Resources.Load("handIcon", typeof(Texture));
                buttonLeftTextureSelected  = (Texture)Resources.Load("handIconSelected", typeof(Texture));
                buttonRightTexture         = (Texture)Resources.Load("handIconRight", typeof(Texture));
                buttonRightTextureSelected = (Texture)Resources.Load("handIconSelectedRight", typeof(Texture));
            }


            GUILayout.Label("Toggle Hand Preview : ", EditorStyles.boldLabel);

            if (inPrefabMode)
            {
                GUILayout.Label("(Some preview features disabled in prefab mode)", EditorStyles.largeLabel);
            }

            GUILayout.BeginHorizontal();

            // Show / Hide Left Hand
            if (showingLeftHand)
            {
                // Define a GUIContent which uses the texture
                buttonLeftContent = new GUIContent(buttonLeftTextureSelected);

                if (!grabPoint.LeftHandIsValid || GUILayout.Button(buttonLeftContent))
                {
                    GameObject.DestroyImmediate(LeftHandPreview);
                    showingLeftHand = false;
                }
            }
            else
            {
                buttonLeftContent = new GUIContent(buttonLeftTexture);

                if (grabPoint.LeftHandIsValid && GUILayout.Button(buttonLeftContent))
                {
                    // Create and add the Editor preview
                    LeftHandPreview = Instantiate(Resources.Load("LeftHandModelsEditorPreview", typeof(GameObject))) as GameObject;
                    LeftHandPreview.transform.name             = "LeftHandModelsEditorPreview";
                    LeftHandPreview.transform.parent           = grabPoint.transform;
                    LeftHandPreview.transform.localPosition    = Vector3.zero;
                    LeftHandPreview.transform.localEulerAngles = Vector3.zero;
                    LeftHandPreview.gameObject.hideFlags       = HideFlags.HideAndDontSave;

                    showingLeftHand = true;
                }
            }

            // Show / Hide Right Hand
            if (showingRightHand)
            {
                // Define a GUIContent which uses the texture
                buttonRightContent = new GUIContent(buttonRightTextureSelected);

                if (!grabPoint.RightHandIsValid || GUILayout.Button(buttonRightContent))
                {
                    GameObject.DestroyImmediate(RightHandPreview);
                    showingRightHand = false;
                }
            }
            else
            {
                buttonRightContent = new GUIContent(buttonRightTexture);

                if (grabPoint.RightHandIsValid && GUILayout.Button(buttonRightContent))
                {
                    // Create and add the Editor preview
                    RightHandPreview = Instantiate(Resources.Load("RightHandModelsEditorPreview", typeof(GameObject))) as GameObject;
                    RightHandPreview.transform.name             = "RightHandModelsEditorPreview";
                    RightHandPreview.transform.parent           = grabPoint.transform;
                    RightHandPreview.transform.localPosition    = Vector3.zero;
                    RightHandPreview.transform.localEulerAngles = Vector3.zero;
                    RightHandPreview.gameObject.hideFlags       = HideFlags.HideAndDontSave;

                    showingRightHand = true;
                }
            }

            GUILayout.EndHorizontal();

            updateEditorAnimation();

            base.OnInspectorGUI();
        }
Ejemplo n.º 6
0
        public override void OnInspectorGUI()
        {
            grabPoint = (GrabPoint)target;
            bool inPrefabMode = false;

#if UNITY_EDITOR
            inPrefabMode = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage() != null;
#endif

            // Double check that there wasn't an object left in the scene
            checkForExistingPreview();

            // Check for change in handpose type
            if (grabPoint.handPoseType != previousType)
            {
                OnHandPoseTypeChange();
            }

            // Load the texture resource
            if (buttonLeftTexture == null)
            {
                buttonLeftTexture          = (Texture)Resources.Load("handIcon", typeof(Texture));
                buttonLeftTextureSelected  = (Texture)Resources.Load("handIconSelected", typeof(Texture));
                buttonRightTexture         = (Texture)Resources.Load("handIconRight", typeof(Texture));
                buttonRightTextureSelected = (Texture)Resources.Load("handIconSelectedRight", typeof(Texture));
            }


            GUILayout.Label("Toggle Hand Preview : ", EditorStyles.boldLabel);

            if (inPrefabMode)
            {
                GUILayout.Label("(Some preview features disabled in prefab mode)", EditorStyles.largeLabel);
            }

            GUILayout.BeginHorizontal();

            // Show / Hide Left Hand
            if (showingLeftHand)
            {
                // Define a GUIContent which uses the texture
                buttonLeftContent = new GUIContent(buttonLeftTextureSelected);

                if (!grabPoint.LeftHandIsValid || GUILayout.Button(buttonLeftContent))
                {
                    GameObject.DestroyImmediate(LeftHandPreview);
                    showingLeftHand = false;
                }
            }
            else
            {
                buttonLeftContent = new GUIContent(buttonLeftTexture);

                if (grabPoint.LeftHandIsValid && GUILayout.Button(buttonLeftContent))
                {
                    // Create and add the Editor preview
                    CreateLeftHandPreview();
                }
            }

            // Show / Hide Right Hand
            if (showingRightHand)
            {
                // Define a GUIContent which uses the texture
                buttonRightContent = new GUIContent(buttonRightTextureSelected);

                if (!grabPoint.RightHandIsValid || GUILayout.Button(buttonRightContent))
                {
                    GameObject.DestroyImmediate(RightHandPreview);
                    showingRightHand = false;
                }
            }
            else
            {
                buttonRightContent = new GUIContent(buttonRightTexture);

                if (grabPoint.RightHandIsValid && GUILayout.Button(buttonRightContent))
                {
                    CreateRightHandPreview();
                }
            }

            GUILayout.EndHorizontal();

            updateEditorAnimation();

            EditorGUILayout.PropertyField(LeftHandIsValid);
            EditorGUILayout.PropertyField(RightHandIsValid);

            EditorGUILayout.PropertyField(handPoseType);

            if (grabPoint.handPoseType == HandPoseType.HandPose)
            {
                EditorGUILayout.PropertyField(SelectedHandPose);

                GUILayout.BeginHorizontal();

                EditorGUILayout.LabelField("");
                EditorGUILayout.Space(0, true);

                if (GUILayout.Button("Edit Pose..."))
                {
                    EditHandPose();
                }
                GUILayout.EndHorizontal();
            }
            else if (grabPoint.handPoseType == HandPoseType.AnimatorID)
            {
                EditorGUILayout.PropertyField(HandPose);
            }

            //EditorGUILayout.PropertyField(HandPosition);
            EditorGUILayout.PropertyField(MaxDegreeDifferenceAllowed);
            EditorGUILayout.PropertyField(IndexBlendMin);
            EditorGUILayout.PropertyField(IndexBlendMax);
            EditorGUILayout.PropertyField(ThumbBlendMin);
            EditorGUILayout.PropertyField(ThumbBlendMax);
            EditorGUILayout.PropertyField(ShowAngleGizmo);

            serializedObject.ApplyModifiedProperties();
            // base.OnInspectorGUI();
        }