public void DrawInspector_Slider(MenuActions.MenuAction action) { //Parameter action.parameter = DrawParameterDropDown(action.parameter, "Parameter"); //Animations EditorGUI.BeginDisabledGroup(true); //Disable for now action.actionLayerAnimations.enter = DrawAnimationReference("Action Layer", action.actionLayerAnimations.enter, $"{action.name}_Action_Slider"); EditorGUI.EndDisabledGroup(); action.fxLayerAnimations.enter = DrawAnimationReference("FX Layer", action.fxLayerAnimations.enter, $"{action.name}_FX_Slider"); }
public override void Build(MenuActions.MenuAction parentAction) { //Layer name var layerName = this.name; if (parentAction != null) { layerName = $"{parentAction.name}_{layerName}_SubActions"; } //Build BuildNormal(AnimationLayer.FX, layerName, this.actions, parentAction); }
public void DrawInspector_SubMenu(MenuActions.MenuAction action) { EditorGUILayout.BeginHorizontal(); action.subMenu = (MenuActions)EditorGUILayout.ObjectField("Sub Menu", action.subMenu, typeof(MenuActions), false); EditorGUI.BeginDisabledGroup(action.subMenu != null); if (GUILayout.Button("New", GUILayout.Width(64f))) { //Create var subMenu = ScriptableObject.CreateInstance<MenuActions>(); subMenu.name = $"Menu {action.name}"; BaseActions.SaveAsset(subMenu, script, null, true); //Set action.subMenu = subMenu; } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); }
public void Inspector_Control(MenuActions.MenuAction action) { //Parameter action.parameter = DrawParameterDropDown(action.parameter, "Parameter"); if(action.menuType == MenuActions.MenuAction.MenuType.Toggle) { string tooltip = "This action will be used when no other toggle with the same parameter is turned on.\n\nOnly one action can be marked as the off state for a parameter name."; action.isOffState = EditorGUILayout.Toggle(new GUIContent("Is Off State", tooltip), action.isOffState); } //Default base.Inspector_Action_Body(action); //Sub Actions EditorGUILayout.BeginVertical(GUI.skin.box); EditorGUI.indentLevel += 1; action.foldoutSubActions = EditorGUILayout.Foldout(action.foldoutSubActions, Title("Sub Actions", action.subActions.Count > 0)); if (action.foldoutSubActions) { //Add if (GUILayout.Button("Add")) { action.subActions.Add(null); } //Sub-Actions for (int i = 0; i < action.subActions.Count; i++) { EditorGUILayout.BeginHorizontal(); action.subActions[i] = (NonMenuActions)EditorGUILayout.ObjectField(action.subActions[i], typeof(NonMenuActions), false); if (GUILayout.Button("X", GUILayout.Width(32))) { action.subActions.RemoveAt(i); i--; } EditorGUILayout.EndHorizontal(); } } EditorGUI.indentLevel -= 1; EditorGUILayout.EndVertical(); }
public abstract void Build(MenuActions.MenuAction parentAction);
void BuildLayer(AnimationLayer layerType, string layerName, List <VisemeAction> actions, MenuActions.MenuAction parentAction) { var controller = GetController(layerType); var VisemeValues = System.Enum.GetValues(typeof(VisemeEnum)).Cast <VisemeEnum>(); //Add parameter AddParameter(controller, "Viseme", AnimatorControllerParameterType.Int, 0); //Prepare layer var layer = GetControllerLayer(controller, layerName); layer.stateMachine.entryTransitions = null; layer.stateMachine.anyStateTransitions = null; layer.stateMachine.states = null; layer.stateMachine.entryPosition = StatePosition(-1, 0); layer.stateMachine.anyStatePosition = StatePosition(-1, 1); layer.stateMachine.exitPosition = StatePosition(-1, 2); //Default AnimatorState defaultState = null; VisemeAction defaultAction = null; var unusedValues = new List <VisemeEnum>(); foreach (var value in VisemeValues) { unusedValues.Add(value); } //Build states int actionIter = 0; foreach (var action in this.actions) { //Check if valid if (!action.visimeTable.IsModified()) { EditorUtility.DisplayDialog("Build Warning", $"Visemes {action.name} has no selected conditions.", "Okay"); continue; } //Build var state = layer.stateMachine.AddState(action.name, StatePosition(0, actionIter + 1)); state.motion = action.GetAnimation(layerType, true); actionIter += 1; //Conditions foreach (var value in VisemeValues) { AddCondition(value); } void AddCondition(BaseActions.VisemeEnum visime) { if (action.visimeTable.GetValue(visime)) { //Transition var transition = layer.stateMachine.AddAnyStateTransition(state); transition.hasExitTime = false; transition.exitTime = 0; transition.duration = action.fadeIn; transition.canTransitionToSelf = false; transition.AddCondition(AnimatorConditionMode.Equals, (int)visime, "Viseme"); //Parent if (parentAction != null) { parentAction.AddCondition(transition, true); } //Cleanup unusedValues.Remove(visime); } } //Store default if (action.visimeTable.sil) { defaultState = state; defaultAction = action; } } //Default state if (defaultState == null) { defaultState = layer.stateMachine.AddState("Default", StatePosition(0, 0)); } layer.stateMachine.defaultState = defaultState; //Animation Layer Weight var layerWeight = defaultState.AddStateMachineBehaviour <VRC.SDK3.Avatars.Components.VRCAnimatorLayerControl>(); layerWeight.goalWeight = 1; layerWeight.layer = GetLayerIndex(controller, layer); layerWeight.blendDuration = 0; layerWeight.playable = VRC.SDKBase.VRC_AnimatorLayerControl.BlendableLayer.FX; //Default transitions foreach (var visime in unusedValues) { //Transition var transition = layer.stateMachine.AddAnyStateTransition(defaultState); transition.hasExitTime = false; transition.exitTime = 0; transition.duration = defaultAction != null ? defaultAction.fadeIn : 0f; transition.canTransitionToSelf = false; transition.AddCondition(AnimatorConditionMode.Equals, (int)visime, "Viseme"); } //Parent if (parentAction != null) { var transition = layer.stateMachine.AddAnyStateTransition(defaultState); transition.hasExitTime = false; transition.exitTime = 0; transition.duration = defaultAction != null ? defaultAction.fadeIn : 0f; transition.canTransitionToSelf = false; parentAction.AddCondition(transition, false); } }
void BuildNormal(AnimationLayer layerType, string layerName, List <VisemeAction> sourceActions, MenuActions.MenuAction parentAction) { //Find all that affect this layer var layerActions = new List <VisemeAction>(); foreach (var action in sourceActions) { if (!action.ShouldBuild()) { continue; } if (!action.AffectsLayer(layerType)) { continue; } layerActions.Add(action); } if (layerActions.Count == 0) { return; } //Build BuildLayer(layerType, layerName, layerActions, parentAction); }
void BuildLayers(IEnumerable <GenericAction> sourceActions, AnimationLayer layerType, MenuActions.MenuAction parentAction) { //Build normal BuildGroupedLayers(sourceActions, layerType, parentAction, delegate(Action action) { if (!action.AffectsLayer(layerType)) { return(false); } return(true); }, delegate(AnimatorController controller, string layerName, List <Action> actions) { //Name if (parentAction != null) { layerName = $"{parentAction.name}_{layerName}_SubActions"; } //Build layer if (layerType == AnimationLayer.Action) { BuildActionLayer(controller, actions, layerName, parentAction); } else { BuildNormalLayer(controller, actions, layerName, layerType, parentAction); } }); }
public override void Build(MenuActions.MenuAction parentAction) { BuildLayers(actions, AnimationLayer.Action, parentAction); BuildLayers(actions, AnimationLayer.FX, parentAction); }
void BuildLayer(AnimationLayer layerType, string layerName, List <GestureAction> actions, MenuActions.MenuAction parentAction) { var controller = GetController(layerType); //Add parameter if (side == GestureSide.Left || side == GestureSide.Both) { AddParameter(controller, "GestureLeft", AnimatorControllerParameterType.Int, 0); } if (side == GestureSide.Right || side == GestureSide.Both) { AddParameter(controller, "GestureRight", AnimatorControllerParameterType.Int, 0); } //Prepare layer var layer = GetControllerLayer(controller, layerName); layer.stateMachine.entryTransitions = null; layer.stateMachine.anyStateTransitions = null; layer.stateMachine.states = null; layer.stateMachine.entryPosition = StatePosition(-1, 0); layer.stateMachine.anyStatePosition = StatePosition(-1, 1); layer.stateMachine.exitPosition = StatePosition(-1, 2); //Default state AnimatorState defaultState = null; GestureAction defaultAction = null; var unusedGestures = new List <GestureEnum>(); unusedGestures.Add(GestureEnum.Neutral); unusedGestures.Add(GestureEnum.Fist); unusedGestures.Add(GestureEnum.OpenHand); unusedGestures.Add(GestureEnum.FingerPoint); unusedGestures.Add(GestureEnum.Victory); unusedGestures.Add(GestureEnum.RockNRoll); unusedGestures.Add(GestureEnum.HandGun); unusedGestures.Add(GestureEnum.ThumbsUp); //Build states int actionIter = 0; foreach (var action in this.actions) { //Check if valid if (!action.gestureTable.IsModified()) { EditorUtility.DisplayDialog("Build Warning", $"Simple Gesture {action.name} has no selected conditions.", "Okay"); continue; } //Build var state = layer.stateMachine.AddState(action.name, StatePosition(0, actionIter + 1)); state.motion = action.GetAnimation(layerType, true); actionIter += 1; //Conditions AddGestureCondition(GestureEnum.Neutral); AddGestureCondition(GestureEnum.Fist); AddGestureCondition(GestureEnum.OpenHand); AddGestureCondition(GestureEnum.FingerPoint); AddGestureCondition(GestureEnum.Victory); AddGestureCondition(GestureEnum.RockNRoll); AddGestureCondition(GestureEnum.HandGun); AddGestureCondition(GestureEnum.ThumbsUp); void AddGestureCondition(BaseActions.GestureEnum gesture) { if (!action.gestureTable.GetValue(gesture)) { return; } //Transition var transition = layer.stateMachine.AddAnyStateTransition(state); transition.hasExitTime = false; transition.exitTime = 0; transition.duration = action.fadeIn; if (side == GestureSide.Left || side == GestureSide.Both) { transition.AddCondition(AnimatorConditionMode.Equals, (int)gesture, "GestureLeft"); } if (side == GestureSide.Right || side == GestureSide.Both) { transition.AddCondition(AnimatorConditionMode.Equals, (int)gesture, "GestureRight"); } //Parent if (parentAction != null && gesture != GestureEnum.Neutral) { parentAction.AddCondition(transition, true); } //Cleanup unusedGestures.Remove(gesture); } //Default if (action.gestureTable.neutral) { defaultState = state; defaultAction = action; } } //Default state if (defaultState == null) { defaultState = layer.stateMachine.AddState("Neutral", StatePosition(0, 0)); } layer.stateMachine.defaultState = defaultState; //Animation Layer Weight var layerWeight = defaultState.AddStateMachineBehaviour <VRC.SDK3.Avatars.Components.VRCAnimatorLayerControl>(); layerWeight.goalWeight = 1; layerWeight.layer = GetLayerIndex(controller, layer); layerWeight.blendDuration = 0; layerWeight.playable = VRC.SDKBase.VRC_AnimatorLayerControl.BlendableLayer.FX; //Default transitions foreach (var gesture in unusedGestures) { //Transition var transition = layer.stateMachine.AddAnyStateTransition(defaultState); transition.hasExitTime = false; transition.exitTime = 0; transition.duration = defaultAction != null ? defaultAction.fadeIn : 0f; if (side == GestureSide.Left || side == GestureSide.Both) { transition.AddCondition(AnimatorConditionMode.Equals, (int)gesture, "GestureLeft"); } if (side == GestureSide.Right || side == GestureSide.Both) { transition.AddCondition(AnimatorConditionMode.Equals, (int)gesture, "GestureRight"); } } //Parent if (parentAction != null) { var transition = layer.stateMachine.AddAnyStateTransition(defaultState); transition.hasExitTime = false; transition.exitTime = 0; transition.duration = defaultAction != null ? defaultAction.fadeIn : 0f; parentAction.AddCondition(transition, false); } }