public static void ForceRebuild() { string definesString = PlayerSettings.GetScriptingDefineSymbolsForGroup( EditorUserBuildSettings.selectedBuildTargetGroup); if (!definesString.Contains("MLPAS")) { definesString += ";MLPAS"; PlayerSettings.SetScriptingDefineSymbolsForGroup( EditorUserBuildSettings.selectedBuildTargetGroup, definesString); } UnityEditor.Animations.AnimatorController anim = AssetDatabase.LoadAssetAtPath <UnityEditor.Animations.AnimatorController>("Assets/AlmenaraGames/Demo Scenes/MLPAS/Basic Animator Sfx/Demo_mlpasAnimatorTest.controller"); if (anim != null) { AudioObject au1 = AssetDatabase.LoadAssetAtPath <AudioObject>("Assets/AlmenaraGames/Demo Scenes/MLPAS/Basic Animator Sfx/Demo_boink_AO.asset"); AudioObject au2 = AssetDatabase.LoadAssetAtPath <AudioObject>("Assets/AlmenaraGames/Demo Scenes/MLPAS/Basic Animator Sfx/Demo_landing_AO.asset"); if (au1 != null && au2 != null) { anim.GetBehaviours <MLPASAnimatorSFX>()[0].stateSfxs[0].audioObject = au1; anim.GetBehaviours <MLPASAnimatorSFX>()[0].stateSfxs[1].audioObject = au2; EditorUtility.SetDirty(anim); EditorUtility.SetDirty(anim.GetBehaviours <MLPASAnimatorSFX>()[0]); AssetDatabase.Refresh(); } } anim = AssetDatabase.LoadAssetAtPath <UnityEditor.Animations.AnimatorController>("Assets/AlmenaraGames/Demo Scenes/MLPAS/Advanced Animator Sfx/Anims/Demo_mlpasAnimatorWalk.controller"); if (anim != null) { AudioObject au3 = AssetDatabase.LoadAssetAtPath <AudioObject>("Assets/AlmenaraGames/Demo Scenes/MLPAS/Advanced Animator Sfx/Demo_footstep_AO.asset"); if (au3 != null) { anim.GetBehaviours <MLPASAnimatorSFX>()[0].stateSfxs[0].audioObject = au3; anim.GetBehaviours <MLPASAnimatorSFX>()[0].stateSfxs[1].audioObject = au3; EditorUtility.SetDirty(anim); EditorUtility.SetDirty(anim.GetBehaviours <MLPASAnimatorSFX>()[0]); AssetDatabase.Refresh(); } } }
public override void OnInspectorGUI() { obj.Update(); animatorValidated = false; Animator animComponent = (obj.targetObject as MLPASAnimatorSFXController).GetComponent <Animator>(); if (animComponent != null) { string assetPath = AssetDatabase.GetAssetPath(animComponent.runtimeAnimatorController); UnityEditor.Animations.AnimatorController newAnim = AssetDatabase.LoadAssetAtPath <UnityEditor.Animations.AnimatorController>(assetPath); if (anim != newAnim) { anim = newAnim; } } if (anim != null) { animatorValidated = true; } if (!animatorValidated) { EditorGUILayout.HelpBox("This Component needs to be placed next to an Animator Component", MessageType.Error); return; } GUILayout.BeginVertical(EditorStyles.helpBox); List <MLPASAnimatorSFX> validatedAnimatorSfxes = new List <MLPASAnimatorSFX>(); foreach (var i in anim.GetBehaviours <MLPASAnimatorSFX>()) { if (!validatedAnimatorSfxes.Contains(i)) { validatedAnimatorSfxes.Add(i); } } Color color_default = GUI.backgroundColor; GUIStyle itemStyle = new GUIStyle(GUI.skin.box); //make a new GUIStyle itemStyle.alignment = TextAnchor.MiddleLeft; //align text to the left itemStyle.active.background = itemStyle.normal.background; //gets rid of button click background style. itemStyle.margin = new RectOffset(0, 0, 0, 0); //removes the space between items (previously there was a small gap between GUI which made it harder to select a desired item) itemStyle.font = EditorStyles.miniFont; itemStyle.fontSize = 10; itemStyle.fixedWidth = 0; itemStyle.stretchWidth = true; itemStyle.wordWrap = true; itemStyle.richText = true; itemStyle.normal.textColor = EditorGUIUtility.isProSkin ? new Color(0.8f, 0.8f, 0.8f) : Color.black; itemStyle.hover.textColor = itemStyle.normal.textColor; itemStyle.active.textColor = itemStyle.normal.textColor; itemStyle.focused.textColor = itemStyle.normal.textColor; itemStyle.normal.background = uiBack; itemStyle.hover.background = uiBack; itemStyle.active.background = uiBack; itemStyle.focused.background = uiBack; if (validatedAnimatorSfxes.Count > 0) { GUILayout.BeginVertical(EditorStyles.helpBox); for (int i = 0; i < validatedAnimatorSfxes.Count; i++) { // Color font_default = GUI.color; GUI.backgroundColor = (selectedIndexStateM == i) ? color_selected : new Color(1, 1, 1, 0.25f); if (EditorGUIUtility.isProSkin) { GUI.backgroundColor = (selectedIndexStateM == i) ? colorPro_selected : new Color(0.25f, 0.25f, 0.25f, 0.25f); } // GUI.color = (selectedIndex == i) ? font_selected : font_default; string layerName = ""; for (int iL = 0; iL < anim.layers.Length; iL++) { if (iL == validatedAnimatorSfxes[i].transitionLayer) { layerName = anim.layers[iL].name; } } string buttonName = "L: " + layerName + " | " + (validatedAnimatorSfxes[i].currentState != null ? "S: " + validatedAnimatorSfxes[i].currentState.name : "SM: " + validatedAnimatorSfxes[i].currentStateMachine.name); if (GUILayout.Button(buttonName, itemStyle)) { selectedIndexStateM = i; if (prevSelectedIndexStateM != selectedIndexStateM) { Repaint(); prevSelectedIndexStateM = selectedIndexStateM; EditorGUI.FocusTextInControl(null); } valuesModified = true; } GUI.backgroundColor = color_default; //this is to avoid affecting other GUIs outside of the list } GUILayout.EndVertical(); if (EditorApplication.isPlaying) { GUI.enabled = false; } EditorGUILayout.Space(); MLPASAnimatorSFXController.ValuesOverride newValue = null; if (!ContainsStateEditor(validatedAnimatorSfxes[selectedIndexStateM], out newValue)) { newValue = new MLPASAnimatorSFXController.ValuesOverride(); UnityEditor.Animations.StateMachineBehaviourContext[] context = UnityEditor.Animations.AnimatorController.FindStateMachineBehaviourContext(validatedAnimatorSfxes[selectedIndexStateM]); UnityEditor.Animations.AnimatorState cState = (context[0].animatorObject as UnityEditor.Animations.AnimatorState); UnityEditor.Animations.AnimatorStateMachine cStateMachine = (context[0].animatorObject as UnityEditor.Animations.AnimatorStateMachine); string stateName = cState != null ? cState.name : cStateMachine.name; int layer = context[0].layerIndex; newValue.layer = layer; newValue.stateName = stateName; (obj.targetObject as MLPASAnimatorSFXController).newValues.Add(newValue); } BoolField("Use Different Play Position", ref newValue.useDifferentPlayPosition); if (newValue.useDifferentPlayPosition) { TransformField("Play Position Transform", ref newValue.playPosition); BoolField("Follow Play Position", ref newValue.followPosition); } GUILayout.EndVertical(); if (!EditorApplication.isPlaying) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Custom Play Methods", EditorStyles.boldLabel); EditorGUILayout.BeginVertical(EditorStyles.helpBox); customPlayMethodObj = EditorGUILayout.ObjectField(new GUIContent("Target GameObject", ""), customPlayMethodObj, typeof(GameObject), true) as GameObject; if (customPlayMethodObj != null && EditorUtility.IsPersistent(customPlayMethodObj)) { customPlayMethodObj = null; } List <MLPASAnimatorSFXController.InspectorDelegate> inspectorDelegates = new List <MLPASAnimatorSFXController.InspectorDelegate>(); if (customPlayMethodObj != null) { Component[] components = customPlayMethodObj.GetComponents <Component>(); foreach (var item in components) { System.Reflection.MethodInfo[] methods = item.GetType().GetMethods(); for (int i = 0; i < methods.Length; i++) { System.Reflection.ParameterInfo[] parameters = methods[i].GetParameters(); for (int i2 = 0; i2 < parameters.Length; i2++) { if (parameters[i2].ParameterType == typeof(MLPASACustomPlayMethodParameters)) { MLPASAnimatorSFXController.InspectorDelegate del = new MLPASAnimatorSFXController.InspectorDelegate(); del.methodName = methods[i].Name; del.target = item; inspectorDelegates.Add(del); break; } } } } string[] methodNames = new string[inspectorDelegates.Count]; for (int i = 0; i < inspectorDelegates.Count; i++) { methodNames[i] = i.ToString() + " - " + inspectorDelegates[i].methodName + " (MLPASACustomPlayMethodParameters)"; } if (inspectorDelegates.Count > 0) { playMethodIndex = EditorGUILayout.Popup(playMethodIndex, methodNames); bool alreadyExists = false; foreach (var item in (obj.targetObject as MLPASAnimatorSFXController).inspectorDelegates) { if (item.methodName == inspectorDelegates[playMethodIndex].methodName) { alreadyExists = true; break; } } bool prevGuiEnabled = GUI.enabled; GUI.enabled = !alreadyExists; Color prevBackground = GUI.backgroundColor; GUI.backgroundColor = new Color(0.35f, 0.8f, 0.95f); if (GUILayout.Button(alreadyExists ? inspectorDelegates[playMethodIndex].methodName + " Already Exists" : "Add Custom Play Method", EditorStyles.miniButton)) { if ((obj.targetObject as MLPASAnimatorSFXController).inspectorDelegates == null) { (obj.targetObject as MLPASAnimatorSFXController).inspectorDelegates = new List <MLPASAnimatorSFXController.InspectorDelegate>(); } (obj.targetObject as MLPASAnimatorSFXController).inspectorDelegates.Add(inspectorDelegates[playMethodIndex]); valuesModified = true; } GUI.backgroundColor = prevBackground; GUI.enabled = prevGuiEnabled; } else { playMethodIndex = 0; EditorGUILayout.LabelField("No methods found", EditorStyles.miniLabel); bool prevGuiEnabled = GUI.enabled; GUI.enabled = false; Color prevBackground = GUI.backgroundColor; GUI.backgroundColor = new Color(0.35f, 0.8f, 0.95f); GUILayout.Button("Select Another GameObject", EditorStyles.miniButton); GUI.backgroundColor = prevBackground; GUI.enabled = prevGuiEnabled; } } else { bool prevGuiEnabled = GUI.enabled; GUI.enabled = false; Color prevBackground = GUI.backgroundColor; GUI.backgroundColor = new Color(0.35f, 0.8f, 0.95f); GUILayout.Button("Select a GameObject", EditorStyles.miniButton); GUI.backgroundColor = prevBackground; GUI.enabled = prevGuiEnabled; } EditorGUILayout.EndVertical(); for (int i = 0; i < (obj.targetObject as MLPASAnimatorSFXController).inspectorDelegates.Count; i++) { EditorGUILayout.BeginVertical(EditorStyles.helpBox); bool prevGuiEnabled = GUI.enabled; GUI.enabled = false; if ((obj.targetObject as MLPASAnimatorSFXController).inspectorDelegates[i].target == null) { EditorGUILayout.ObjectField("Target GameObject", null, typeof(GameObject), true); } else { EditorGUILayout.ObjectField("Target GameObject", (obj.targetObject as MLPASAnimatorSFXController).inspectorDelegates[i].target.gameObject, typeof(GameObject), true); } if (!(obj.targetObject as MLPASAnimatorSFXController).inspectorDelegates[i].removed) { EditorGUILayout.Popup(0, new string[] { (obj.targetObject as MLPASAnimatorSFXController).inspectorDelegates[i].methodName + " (MLPASACustomPlayMethodParameters)" }); } else { EditorGUILayout.Popup(0, new string[] { (obj.targetObject as MLPASAnimatorSFXController).inspectorDelegates[i].methodName + " | MISSING" }); } GUI.enabled = prevGuiEnabled; Color prevBackground = GUI.backgroundColor; GUI.backgroundColor = new Color(1f, 0.35f, 0.38f); if (GUILayout.Button("Remove Play Method", EditorStyles.miniButton)) { (obj.targetObject as MLPASAnimatorSFXController).inspectorDelegates.RemoveAt(i); valuesModified = true; } GUI.backgroundColor = prevBackground; EditorGUILayout.EndVertical(); } } if (valuesModified && !dirty) { dirty = true; valuesModified = false; if (!EditorApplication.isPlaying) { SetObjectDirty((obj.targetObject as MLPASAnimatorSFXController)); } } } else { EditorGUILayout.HelpBox("The 'Animator' Next to this 'MLPASAnimatorSFXController' doesn't have any 'MLPASAnimatorSFX' State Machine Behaviour", MessageType.Warning); GUILayout.EndVertical(); return; } GUI.enabled = true; if (EditorApplication.isPlaying) { EditorGUILayout.Space(); bool nullMethods = true; EditorGUILayout.LabelField("Registered Custom Play Methods", EditorStyles.boldLabel); foreach (var item in (obj.targetObject as MLPASAnimatorSFXController).customPlayMethods) { if (item.Value != null) { EditorGUILayout.BeginVertical(EditorStyles.helpBox); GUI.enabled = false; Component comp = ((item.Value.Target) as Component); if (comp != null) { nullMethods = false; } EditorGUILayout.ObjectField("Target GameObject", comp != null ? comp.gameObject : null, typeof(GameObject), true); if (comp != null) { EditorGUILayout.Popup(0, new string[] { item.Value.Method.Name + " (MLPASACustomPlayMethodParameters)" }); } else { EditorGUILayout.Popup(0, new string[] { item.Value.Method.Name + " | MISSING" }); } GUI.enabled = true; EditorGUILayout.EndVertical(); } } if (nullMethods) { EditorGUILayout.LabelField("No methods found"); } } obj.ApplyModifiedProperties(); }