public static int FindBlendSystems(BlendSystemUser component) { blendSystems = new List <Type>(); blendSystemNames = new List <string>(); blendSystems.Add(null); blendSystemNames.Add("None"); foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies()) { foreach (Type t in a.GetTypes()) { if (t.IsSubclassOf(typeof(BlendSystem))) { blendSystems.Add(t); blendSystemNames.Add(LipSyncEditorExtensions.AddSpaces(t.Name)); } } } if (component.blendSystem != null) { return(blendSystems.IndexOf(component.blendSystem.GetType())); } return(0); }
public static void ChangeBlendSystem(BlendSystemUser component, int blendSystem) { Undo.RecordObject(component, "Change Blend System"); // Unregister from existing system if one exists if (component.blendSystem != null) { // Remove existing editor if one exists if (blendSystemEditors.ContainsKey(component)) { DestroyImmediate(blendSystemEditors[component]); blendSystemEditors.Remove(component); } component.blendSystem.Unregister(component); } // Only attempt to create new system if a new system was actually chosen if (blendSystem != 0) { // Attempt to find existing instance of new system BlendSystem system = (BlendSystem)component.GetComponent(blendSystems[blendSystem]); if (system == null) { // Blend System doesn't exist - must be created first system = (BlendSystem)Undo.AddComponent(component.gameObject, blendSystems[blendSystem]); } // Register with the new system system.Register(component); } CreateBlendSystemEditor(component); }
static void CreateBlendSystemEditor(BlendSystemUser component) { if (component.blendSystem != null) { if (!blendSystemEditors.ContainsKey(component)) { blendSystemEditors.Add(component, CreateEditor(component.blendSystem)); blendSystemEditors[component].Repaint(); } } }
public static int DrawBlendSystemEditor(BlendSystemUser component, int blendSystemNumber, string notReadyMessage) { int number = blendSystemNumber; if (blendSystems == null) { number = FindBlendSystems(component); } if (blendSystems.Count == 0) { EditorGUILayout.Popup("Blend System", 0, new string[] { "No BlendSystems Found" }); } else { if (component.blendSystem == null) { EditorGUI.BeginChangeCheck(); number = EditorGUILayout.Popup("Blend System", number, blendSystemNames.ToArray(), GUIStyle.none); if (EditorGUI.EndChangeCheck()) { if (Event.current.type != EventType.Layout) { ChangeBlendSystem(component, number); } } GUI.Box(new Rect(EditorGUIUtility.labelWidth + GUILayoutUtility.GetLastRect().x, GUILayoutUtility.GetLastRect().y, GUILayoutUtility.GetLastRect().width, GUILayoutUtility.GetLastRect().height), "Select a BlendSystem", EditorStyles.popup); } else { EditorGUI.BeginChangeCheck(); number = EditorGUILayout.Popup("Blend System", number, blendSystemNames.ToArray()); if (EditorGUI.EndChangeCheck()) { if (Event.current.type != EventType.Layout) { ChangeBlendSystem(component, number); } } } } if (component.blendSystem == null) { GUILayout.Label("No BlendSystem Selected"); EditorGUILayout.HelpBox(notReadyMessage, MessageType.Info); } EditorGUILayout.Space(); if (component.blendSystem != null) { if (!blendSystemEditors.ContainsKey(component)) { CreateBlendSystemEditor(component); } // Recreate this editor if the target has been lost if (blendSystemEditors[component].target == null && Event.current.type == EventType.Repaint) { if (blendSystemEditors.ContainsKey(component)) { Editor e = blendSystemEditors[component]; blendSystemEditors.Remove(component); DestroyImmediate(e); } } else { blendSystemEditors[component].OnInspectorGUI(); } if (!component.blendSystem.isReady) { GUILayout.Space(10); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Continue", GUILayout.MaxWidth(200))) { component.blendSystem.OnVariableChanged(); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Space(10); } } return(number); }