/// <summary>
        /// Determines whether the grab point can be created for the given action.
        /// </summary>
        /// <param name="action">The action to check whether a grab point can be created for.</param>
        /// <returns>Whether the grab point can be created.</returns>
        protected virtual bool CanCreateGrabPoint(GrabInteractableAction action)
        {
            if (action == null || action.GetType() != typeof(GrabInteractableFollowAction))
            {
                return(false);
            }

            GrabInteractableFollowAction followAction = (GrabInteractableFollowAction)action;

            return(followAction != null && followAction.GrabOffset == GrabInteractableFollowAction.OffsetType.PrecisionPoint);
        }
        /// <summary>
        /// Snaps the follow on the primary and secondary action if they are <see cref="GrabInteractableFollowAction"/> type.
        /// </summary>
        public virtual void SnapFollowOrientation()
        {
            if (PrimaryAction != null && PrimaryAction.GetType() == typeof(GrabInteractableFollowAction))
            {
                GrabInteractableFollowAction action = (GrabInteractableFollowAction)PrimaryAction;
                action.ForceSnapOrientation();
            }

            if (SecondaryAction != null && SecondaryAction.GetType() == typeof(GrabInteractableFollowAction))
            {
                GrabInteractableFollowAction action = (GrabInteractableFollowAction)SecondaryAction;
                action.ForceSnapOrientation();
            }
        }
        protected virtual void DrawFollowActionSettings(InteractableFacade facade, GrabInteractableAction actionProperty, string undoRedoWarningPropertyPath)
        {
            if (actionProperty == null || !typeof(GrabInteractableFollowAction).IsAssignableFrom(actionProperty.GetType()))
            {
                return;
            }

            GrabInteractableFollowAction followAction = (GrabInteractableFollowAction)actionProperty;
            SerializedObject             actionObject = new SerializedObject(followAction);

            SerializedProperty followTracking = DrawPropertyFieldWithChangeHandlers(actionObject, "followTracking", undoRedoWarningPropertyPath);

            if (followTracking.intValue == 4)
            {
                RotateAroundAngularVelocity rotationModifier = (RotateAroundAngularVelocity)followAction.FollowRotateAroundAngularVelocityModifier.RotationModifier;
                DrawPropertyFieldWithChangeHandlers(new SerializedObject(rotationModifier), "applyToAxis", undoRedoWarningPropertyPath);
            }

            SerializedProperty grabOffset = DrawPropertyFieldWithChangeHandlers(actionObject, "grabOffset", undoRedoWarningPropertyPath);

            if (grabOffset.intValue == 1)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel(" ");
                if (GUILayout.Button("Show Orientation Container"))
                {
                    EditorGUIUtility.PingObject(followAction.OrientationLogicContainer);
                }
                EditorGUILayout.EndHorizontal();
            }

            showFollowAdvancedFeatures = EditorGUILayout.Foldout(showFollowAdvancedFeatures, "Advanced Follow Settings");
            if (showFollowAdvancedFeatures)
            {
                EditorGUI.indentLevel++;
                DrawPropertyFieldWithChangeHandlers(actionObject, "isKinematicWhenActive", undoRedoWarningPropertyPath);
                DrawPropertyFieldWithChangeHandlers(actionObject, "isKinematicWhenInactive", undoRedoWarningPropertyPath);
                DrawPropertyFieldWithChangeHandlers(actionObject, "willInheritIsKinematicWhenInactiveFromConsumerRigidbody", undoRedoWarningPropertyPath);
                EditorGUI.indentLevel--;
            }
        }
示例#4
0
        private static void ConfigInteractableGrabAction(GameObject interactable)
        {
            InteractableFacade facade = interactable.GetComponent<InteractableFacade>();

            // Set "Primary Action" to "Follow"
            int primaryActionIndex = 1; // Follow
            GameObject primaryActionPrefab = (GameObject)PrefabUtility.InstantiatePrefab(facade.Configuration.GrabConfiguration.ActionTypes.NonSubscribableElements[primaryActionIndex], facade.Configuration.GrabConfiguration.ActionTypes.transform);
            GrabInteractableAction primaryAction = primaryActionPrefab.GetComponent<GrabInteractableAction>();
            facade.Configuration.GrabConfiguration.PrimaryAction = primaryAction;

            // Set "Grab Offset" to "Precision Point"
            GrabInteractableFollowAction followAction = (GrabInteractableFollowAction)primaryAction;
            SerializedObject actionObject = new SerializedObject(followAction);
            SerializedProperty foundProperty = actionObject.FindProperty("grabOffset");
            foundProperty.intValue = 2; // Precision Point
            foundProperty.serializedObject.ApplyModifiedProperties();

            // Set "Secondary Action" to "Scale"
            // int secondaryActionIndex = 4; // Scale disabled until scaling bug is fixed in Tilia: shorturl.at/ayFP3
            int secondaryActionIndex = 2; // Swap
            GameObject secondaryActionPrefab = (GameObject)PrefabUtility.InstantiatePrefab(facade.Configuration.GrabConfiguration.ActionTypes.NonSubscribableElements[secondaryActionIndex], facade.Configuration.GrabConfiguration.ActionTypes.transform);
            GrabInteractableAction secondaryAction = secondaryActionPrefab.GetComponent<GrabInteractableAction>();
            facade.Configuration.GrabConfiguration.SecondaryAction = secondaryAction;
        }