/// <summary> /// Configures the action containers. /// </summary> /// <param name="action">The action to configure.</param> protected virtual void ConfigureActionContainer(GrabInteractableAction action) { if (action == null) { return; } action.GrabSetup = this; action.RunWhenActiveAndEnabled(() => action.GrabSetup = this); }
/// <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); }
protected virtual int UpdateIndex(InteractableFacade facade, GrabInteractableAction actionProperty, int[] template, int index) { if (actionProperty == null) { return(0); } for (int actionIndex = 0; actionIndex < facade.Configuration.GrabConfiguration.ActionTypes.NonSubscribableElements.Count; actionIndex++) { GrabInteractableAction actionComponent = facade.Configuration.GrabConfiguration.ActionTypes.NonSubscribableElements[actionIndex].GetComponent <GrabInteractableAction>(); if (actionComponent != null && actionComponent.GetType() == actionProperty.GetType()) { return(Array.IndexOf(template, actionIndex) + 1); } } return(0); }
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--; } }
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; }
protected virtual void CheckFollowAndControlDirectionPair(GrabInteractableAction primaryAction, GrabInteractableAction secondaryAction) { GrabInteractableFollowAction followAction; GrabInteractableControlDirectionAction controlDirectionAction; if (secondaryAction != null && typeof(GrabInteractableControlDirectionAction).IsAssignableFrom(secondaryAction.GetType())) { controlDirectionAction = (GrabInteractableControlDirectionAction)secondaryAction; controlDirectionAction.LinkedObjects = null; } if (primaryAction == null || secondaryAction == null || !typeof(GrabInteractableFollowAction).IsAssignableFrom(primaryAction.GetType()) || !typeof(GrabInteractableControlDirectionAction).IsAssignableFrom(secondaryAction.GetType())) { return; } followAction = (GrabInteractableFollowAction)primaryAction; controlDirectionAction = (GrabInteractableControlDirectionAction)secondaryAction; controlDirectionAction.LinkedObjects = followAction.RotationModifiers; }
/// <summary> /// Configures the action containers. /// </summary> /// <param name="action">The action to configure.</param> protected virtual void ConfigureActionContainer(GrabInteractableAction action) { action.RunWhenActiveAndEnabled(() => action.GrabSetup = this); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); string undoRedoWarningPropertyPath = UndoRedoWarningPropertyPath; grabConfigurationIsDirty = false; EditorGUILayout.Space(); EditorGUILayout.LabelField("Primary Action Settings", EditorStyles.boldLabel); selectedPrimaryActionIndex = EditorGUILayout.Popup(new GUIContent("Primary Action"), currentPrimaryActionIndex, primaryActions); GrabInteractableAction updatedPrimaryAction = UpdateAction(facade, primaryActionsIndexes, currentPrimaryActionIndex, selectedPrimaryActionIndex, facade.Configuration.GrabConfiguration.PrimaryAction, 0); if (facade.Configuration.GrabConfiguration.PrimaryAction != updatedPrimaryAction) { facade.Configuration.GrabConfiguration.PrimaryAction = updatedPrimaryAction; grabConfigurationIsDirty = true; } currentPrimaryActionIndex = selectedPrimaryActionIndex; DrawFollowActionSettings(facade, facade.Configuration.GrabConfiguration.PrimaryAction, undoRedoWarningPropertyPath); EditorGUILayout.Space(); EditorGUILayout.LabelField("Secondary Action Settings", EditorStyles.boldLabel); selectedSecondaryActionIndex = EditorGUILayout.Popup(new GUIContent("Secondary Action"), currentSecondaryActionIndex, secondaryActions); GrabInteractableAction updatedSecondaryAction = UpdateAction(facade, secondaryActionsIndexes, currentSecondaryActionIndex, selectedSecondaryActionIndex, facade.Configuration.GrabConfiguration.SecondaryAction, 1); if (facade.Configuration.GrabConfiguration.SecondaryAction != updatedSecondaryAction) { facade.Configuration.GrabConfiguration.SecondaryAction = updatedSecondaryAction; grabConfigurationIsDirty = true; } currentSecondaryActionIndex = selectedSecondaryActionIndex; DrawFollowActionSettings(facade, facade.Configuration.GrabConfiguration.SecondaryAction, undoRedoWarningPropertyPath); EditorGUILayout.Space(); EditorGUILayout.LabelField("Disallowed Touch Interactor Settings", EditorStyles.boldLabel); EditorGUI.indentLevel++; DrawDisallowedInteractorsList(facade.Configuration.DisallowedTouchInteractors, undoRedoWarningPropertyPath); EditorGUI.indentLevel--; EditorGUILayout.Space(); EditorGUILayout.LabelField("Disallowed Grab Interactor Settings", EditorStyles.boldLabel); EditorGUI.indentLevel++; DrawDisallowedInteractorsList(facade.Configuration.DisallowedGrabInteractors, undoRedoWarningPropertyPath); EditorGUI.indentLevel--; EditorGUILayout.BeginHorizontal("GroupBox"); GUILayout.FlexibleSpace(); if (GUILayout.Button("Show Mesh Container")) { EditorGUIUtility.PingObject(facade.Configuration.MeshContainer); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); if (grabConfigurationIsDirty) { CheckFollowAndControlDirectionPair(updatedPrimaryAction, updatedSecondaryAction); EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); EditorUtility.SetDirty(facade.Configuration.GrabConfiguration); } }
protected virtual GrabInteractableAction UpdateAction(InteractableFacade facade, int[] template, int currentAction, int selectedAction, GrabInteractableAction actionProperty, int siblingPosition) { if (currentAction == selectedAction || selectedAction == 0) { return(actionProperty); } if (actionProperty != null) { DestroyImmediate(actionProperty.gameObject); } int actualSelectedAction = template[selectedAction - 1]; GameObject actionPrefab = (GameObject)PrefabUtility.InstantiatePrefab(facade.Configuration.GrabConfiguration.ActionTypes.NonSubscribableElements[actualSelectedAction], facade.Configuration.GrabConfiguration.ActionTypes.transform); actionPrefab.transform.SetSiblingIndex(siblingPosition); return(actionPrefab.GetComponent <GrabInteractableAction>()); }