static void Initialize() { //Change Icons if (EditorGUIUtility.isProSkin) { ChangeIcons("MLPASAnimatorSFXController", "AnimatorSFXControllerProIco"); ChangeIcons("MLPASAnimatorSFX", "AnimatorSFXProIco"); ChangeIcon("MultiAudioManager", "AudioManagerIcoPro"); } else { ChangeIcons("MLPASAnimatorSFXController", "AnimatorSFXControllerLightIco"); ChangeIcons("MLPASAnimatorSFX", "AnimatorSFXLightIco"); ChangeIcon("MultiAudioManager", "AudioManagerIcoLight"); } AlmenaraGames.Tools.MLPASConfig config = Resources.Load("MLPASConfig/MLPASConfig", typeof(AlmenaraGames.Tools.MLPASConfig)) as AlmenaraGames.Tools.MLPASConfig; if (config == null || config != null && !config.updated) { DisableGizmoIcons.DisableIcons(); MLPASConfigWindow window = (MLPASConfigWindow)EditorWindow.GetWindow <MLPASConfigWindow>(false, "MLPAS Config", true); window.Show(); } EditorApplication.update -= Initialize; }
void OnEnable() { logoTex = Resources.Load("MLPASImages/logoSmall") as Texture; config = null; MonoScript ms = MonoScript.FromScriptableObject(this); string docsPath = AssetDatabase.GetAssetPath(ms).Replace("Editor/MLPASConfigWindow.cs", "Docs.asset"); if (!AssetDatabase.LoadAssetAtPath <ScriptableObject>(docsPath)) { AlmenaraGames.Tools.Documentation mlpasDocs = AlmenaraGames.Tools.Documentation.CreateInstance("Docs") as AlmenaraGames.Tools.Documentation; AssetDatabase.CreateAsset(mlpasDocs, docsPath); AssetDatabase.Refresh(); } if (config == null) { config = Resources.Load("MLPASConfig/MLPASConfig", typeof(AlmenaraGames.Tools.MLPASConfig)) as AlmenaraGames.Tools.MLPASConfig; } #if UNITY_EDITOR if (config == null) { AlmenaraGames.Tools.MLPASConfig mlpasConfig = AlmenaraGames.Tools.MLPASConfig.CreateInstance("MLPASConfig") as AlmenaraGames.Tools.MLPASConfig; string path = AssetDatabase.GetAssetPath(ms); path = path.Replace("Editor/MLPASConfigWindow.cs", "Resources/MLPASConfig/"); AssetDatabase.CreateAsset(mlpasConfig, path + "MLPASConfig.asset"); string[] guids2 = AssetDatabase.FindAssets("t: MLPASConfig"); foreach (string guid in guids2) { AlmenaraGames.Tools.MLPASConfig ao = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guid), typeof(AlmenaraGames.Tools.MLPASConfig)) as AlmenaraGames.Tools.MLPASConfig; if (ao != null) { config = ao; Debug.LogWarning("<b>Multi Listener Pooling Audio System Config</b> is missing, a <i>New One</i> has been created", ao); break; } } AssetDatabase.Refresh(); } #endif UpdateFiles(); }
public static bool UpdateValues(bool showMessage = false) { string[] guids = AssetDatabase.FindAssets("t: AnimatorController"); List <Object> revertState = new List <Object>(); double startTime = EditorApplication.timeSinceStartup; int behavioursCount = 0; int animatorsCount = 0; bool error = false; float currentIndex = -1; int behaviourIndex = -1; int behaviourCurrentCount = 0; EditorUtility.ClearProgressBar(); foreach (string guid in guids) { currentIndex += 1; if (showMessage) { EditorUtility.DisplayProgressBar("Rebuild Runtime MLPAS Animator State SFX Values", "Rebuilding... Animator: " + currentIndex.ToString() + "/" + guids.Length.ToString() + (behaviourCurrentCount > 0 ? " | Behaviours: " + (behaviourIndex).ToString() : ""), currentIndex / guids.Length); } AnimatorController anim = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guid), typeof(AnimatorController)) as AnimatorController; if (anim != null) { animatorsCount += 1; MLPASAnimatorSFX[] behaviours = anim.GetBehaviours <MLPASAnimatorSFX>(); behaviourCurrentCount = behaviours.Length; behavioursCount += behaviourCurrentCount; for (int i = 0; i < behaviours.Length; i++) { behaviourIndex += 1; if (!behaviours[i].UpdateRuntimeValues()) { error = true; break; } else { // StateMachineBehaviourContext[] context = AnimatorController.FindStateMachineBehaviourContext(behaviours[i] as StateMachineBehaviour); /*if (context != null && context.Length > 0) * { * AnimatorState state = (context[0].animatorObject as AnimatorState); * AnimatorStateMachine stateMachine = (context[0].animatorObject as AnimatorStateMachine); * * if (state != null) * { * foreach (var st in state.transitions) * { * if (st.duration == 0) * st.duration = 0.0001f; * * } * } * * if (stateMachine != null) * { * foreach (var st in stateMachine.anyStateTransitions) * { * if (st.duration == 0) * st.duration = 0.0001f; * * } * } * * revertState.Add(context[0].animatorObject); * * }*/ } } } if (error) { break; } } if (!error) { if (showMessage) { Debug.Log("Rebuild Runtime Animator State SFX Values for: <b>" + animatorsCount + " Animators</b> - <b>" + behavioursCount + " Behaviours</b>" + " | <b>Operation Completed!</b>"); } AlmenaraGames.Tools.MLPASConfig config = Resources.Load("MLPASConfig/MLPASConfig", typeof(AlmenaraGames.Tools.MLPASConfig)) as AlmenaraGames.Tools.MLPASConfig; if (config != null) { config.stateClipboardBuffer = new AlmenaraGames.MLPASAnimatorSFX.StateSFX[0]; } } else { foreach (var item in revertState) { AnimatorState state = (item as AnimatorState); AnimatorStateMachine stateMachine = (item as AnimatorStateMachine); if (state != null) { foreach (var st in state.transitions) { if (st.duration == 0) { st.duration = 0.0001f; } } } if (stateMachine != null) { foreach (var st in stateMachine.anyStateTransitions) { if (st.duration == 0) { st.duration = 0.0001f; } } } } Debug.LogError("Rebuild Runtime Animator State SFX Values | <b>Operation Failed!</b>"); } if (showMessage) { AssetDatabase.SaveAssets(); EditorUtility.ClearProgressBar(); } return(!error); }