// Returns the info for the specified state/element. public virtual ASCSEInfo GetStateElementInfo(int stateNum) { ASCSEInfo info = new ASCSEInfo(); info.transitions = GetTransitions(stateNum); info.stateLabel = GetStateLabel(stateNum); return(info); }
static void SetTexture(int StateNum, string TexPath) { Texture2D TempTex = (Texture2D)Resources.Load(TexPath, typeof(Texture2D)); StateInfo = Button.GetStateElementInfo(StateNum); StateInfo.tex = TempTex; StateInfo.stateObj.frameGUIDs = new string[1] { "" }; StateInfo.stateObj.frameGUIDs[0] = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(StateInfo.tex)); if (StateNum == 0) { BaseTexture = TempTex; } }
void ShowSpriteSettings() { IPackableControl cont = (IPackableControl)control; // Get the info for this state/element: stateInfo = cont.GetStateElementInfo(curState); // Put up a texture drop box: // Load the texture: if (stateInfo.stateObj.frameGUIDs.Length < 1) { stateInfo.tex = null; } else { stateInfo.tex = (Texture2D)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(stateInfo.stateObj.frameGUIDs[0]), typeof(Texture2D)); } BeginMonitorChanges(); // Select the texture for the state: #if UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9 stateInfo.tex = (Texture2D)EditorGUILayout.ObjectField(stateNames[curState], stateInfo.tex, typeof(Texture2D), false); #else stateInfo.tex = (Texture2D)EditorGUILayout.ObjectField(stateNames[curState], stateInfo.tex, typeof(Texture2D)); #endif EndMonitorChanges(); // Re-assign the state info to the control: // If we have an available frame, assign the new GUID if (stateInfo.stateObj.frameGUIDs.Length > 0) { stateInfo.stateObj.frameGUIDs[0] = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(stateInfo.tex)); } // Else only create a new GUID element if the selection is non-null: else if (stateInfo.tex != null) { stateInfo.stateObj.frameGUIDs = new string[1]; stateInfo.stateObj.frameGUIDs[0] = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(stateInfo.tex)); } // Else, don't do anything. Period. transitions = stateInfo.transitions; }
public override void OnInspectorGUI() { base.OnInspectorGUI(); isDirty = false; control = (IControl)target; // Have the specific control class's implementation // draw any control-specific settings: DrawPrestateSettings(); GUILayout.BeginVertical(); //------------------------------- // Draw a nice separator: //------------------------------- GUILayout.Space(5.0f); GUILayout.BeginVertical("Toolbar"); GUILayout.BeginHorizontal(); GUILayout.Space(10.0f); GUILayout.Label("State/Element: "); GUILayout.FlexibleSpace(); // Start keeping track of any changed values: BeginMonitorChanges(); // Do the pre-state selection GUI, if any: control.DrawPreStateSelectGUI(curState, true); EndMonitorChanges(); // Get the control's state names: stateNames = control.EnumStateElements(); if (stateNames == null) return; // Cap our state to the number of states available: curState = Mathf.Min(curState, stateNames.Length - 1); // Choose the state we want to edit: curState = EditorGUILayout.Popup(curState, stateNames); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.EndVertical(); //------------------------------- // End separator //------------------------------- // Keep track of any changed values: BeginMonitorChanges(); // Do the post-state selection GUI, if any: control.DrawPostStateSelectGUI(curState); EndMonitorChanges(); if (control is IPackableControl) ShowSpriteSettings(); else stateInfo = control.GetStateElementInfo(curState); transitions = stateInfo.transitions; //----------------------------------------- // Draw our state label stuff: //----------------------------------------- if (stateInfo.stateLabel != null) { BeginMonitorChanges(); DoStateLabel(); EndMonitorChanges(); } //----------------------------------------- // Draw our transition stuff: //----------------------------------------- if (transitions != null) if (transitions.list != null) if (transitions.list.Length > 0) DoTransitionStuff(); GUILayout.Space(10f); GUILayout.EndVertical(); // Set dirty if anything changed: if (isDirty) EditorUtility.SetDirty((MonoBehaviour)control); }
void ShowSpriteSettings() { IPackableControl cont = (IPackableControl)control; // Get the info for this state/element: stateInfo = cont.GetStateElementInfo(curState); // Put up a texture drop box: // Load the texture: if (stateInfo.stateObj.frameGUIDs.Length < 1) { stateInfo.tex = null; } else stateInfo.tex = (Texture2D)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(stateInfo.stateObj.frameGUIDs[0]), typeof(Texture2D)); BeginMonitorChanges(); // Select the texture for the state: #if UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9 stateInfo.tex = (Texture2D)EditorGUILayout.ObjectField(stateNames[curState], stateInfo.tex, typeof(Texture2D), false); #else stateInfo.tex = (Texture2D)EditorGUILayout.ObjectField(stateNames[curState], stateInfo.tex, typeof(Texture2D)); #endif EndMonitorChanges(); // Re-assign the state info to the control: // If we have an available frame, assign the new GUID if (stateInfo.stateObj.frameGUIDs.Length > 0) { stateInfo.stateObj.frameGUIDs[0] = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(stateInfo.tex)); } // Else only create a new GUID element if the selection is non-null: else if (stateInfo.tex != null) { stateInfo.stateObj.frameGUIDs = new string[1]; stateInfo.stateObj.frameGUIDs[0] = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(stateInfo.tex)); } // Else, don't do anything. Period. transitions = stateInfo.transitions; }
// Returns the info for the specified state/element. public virtual ASCSEInfo GetStateElementInfo(int stateNum) { ASCSEInfo info = new ASCSEInfo(); info.transitions = GetTransitions(stateNum); info.stateLabel = GetStateLabel(stateNum); return info; }
void ShowSpriteSettings() { IPackableControl cont = (IPackableControl)control; // Get the info for this state/element: stateInfo = cont.GetStateElementInfo(curState); // See if the sprite timeline is available: if (ste == null) { System.Reflection.Assembly asm = System.Reflection.Assembly.GetAssembly(typeof(UICtlEditor)); System.Type steType = asm.GetType("SpriteTimeline"); if (steType != null) { ste = (ISTE)System.Activator.CreateInstance(steType); ste.Setup(position, 0); } } // NOW see if the timeline is available: if (ste != null) { ste.SetCurAnim(curState); needRepaint = ste.STEOnGUI(-(20f + height), out textureAreaBottom); } else { // Put up a texture drop box: // Load the texture: if (stateInfo.stateObj.frameGUIDs.Length < 1) { stateInfo.stateObj.frameGUIDs = new string[1] { "" }; } stateInfo.tex = (Texture2D)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(stateInfo.stateObj.frameGUIDs[0]), typeof(Texture2D)); BeginMonitorChanges(); #if UNITY_IPHONE && !(UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9) // Draw a "clear" button: if(GUI.Button(new Rect(clearRect.x, clearRect.y + height, clearRect.width, clearRect.height), "X")) stateInfo.tex = null; // Select the texture for the state: stateInfo.tex = (Texture2D)EditorGUI.ObjectField(tempRect, stateInfo.tex, typeof(Texture2D)); textureAreaBottom = tempRect.yMax + ctlVirtSpace; #else // Select the texture for the state: #if UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9 stateInfo.tex = (Texture2D)EditorGUILayout.ObjectField(stateNames[curState], stateInfo.tex, typeof(Texture2D), false); #else stateInfo.tex = (Texture2D)EditorGUILayout.ObjectField(stateNames[curState], stateInfo.tex, typeof(Texture2D)); #endif textureAreaBottom = 0; // This tells us to use Layout. #endif // Handle drag and drop from an outside source: EventType eventType = Event.current.type; if (eventType == EventType.DragUpdated || eventType == EventType.DragPerform) { // Validate what is being dropped: if (DragAndDrop.objectReferences[0] is Texture2D) { // Show a copy icon on the drag DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (eventType == EventType.DragPerform) { DragAndDrop.AcceptDrag(); stateInfo.tex = (Texture2D)DragAndDrop.objectReferences[0]; needRepaint = true; } Event.current.Use(); } } EndMonitorChanges(); // Re-assign the state info to the control: stateInfo.stateObj.frameGUIDs[0] = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(stateInfo.tex)); } }
public void OnGUI() { needRepaint = false; int oldState = curState; textureAreaBottom = 0; isDirty = false; if (restarted) { selGO = null; control = null; OnSelectionChange(); restarted = false; } // See if our window size has changed: if (wndRect != position) WindowResized(); // See if we need to update our selection: if (Selection.activeGameObject != selGO) OnSelectionChange(); //#if UNITY_IPHONE && !(UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9) if (Selection.activeGameObject != null) control = (IControl)Selection.activeGameObject.GetComponent("IControl"); //#endif // Bailout if we don't have valid values: if (null == (MonoBehaviour)control) { // See if this is a scroll list: UIScrollList list = null; if (Selection.activeGameObject != null) list = Selection.activeGameObject.GetComponent<UIScrollList>(); if (list != null) { list.DrawPreTransitionUI(0, this); return; } else { PrintNoSelectMsg(); return; } } // Start keeping track of any changed values: BeginMonitorChanges(); // Do the pre-state selection GUI, if any: height = control.DrawPreStateSelectGUI(curState, false); EndMonitorChanges(); // Get the control's state names: stateNames = control.EnumStateElements(); if (stateNames == null) return; // Cap our state to the number of states available: if (stateNames != null) curState = Mathf.Min(curState, stateNames.Length - 1); else curState = 0; // Choose the state we want to edit: curState = GUILayout.Toolbar(curState, stateNames); // Reset our selected transition element // if the state selection changed: if (curState != oldState) { curFromTrans = 0; curTransElement = 0; } // Keep track of any changed values: BeginMonitorChanges(); // Do the post-state selection GUI, if any: height += control.DrawPostStateSelectGUI(curState); EndMonitorChanges(); // Adjust our texture selection rect: tempRect = texRect; tempRect.y += height; if (control is IPackableControl) ShowSpriteSettings(); else stateInfo = control.GetStateElementInfo(curState); transitions = stateInfo.transitions; if (!Application.isPlaying) { #if UNITY_IPHONE && !(UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9) // Box off our script selection and transition fields area: GUILayout.BeginArea(new Rect(0, textureAreaBottom, position.width, position.height-textureAreaBottom)); GUILayout.FlexibleSpace(); #endif //----------------------------------------- // Draw script selection: //----------------------------------------- BeginMonitorChanges(); control.DrawPreTransitionUI(curState, this); EndMonitorChanges(); //----------------------------------------- // Draw our state label stuff: //----------------------------------------- if (stateInfo.stateLabel != null) { BeginMonitorChanges(); DoStateLabel(); EndMonitorChanges(); } //----------------------------------------- // Draw our transition stuff: //----------------------------------------- if (transitions != null) if (transitions.list != null) if (transitions.list.Length > 0) DoTransitionStuff(); #if UNITY_IPHONE && !(UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_4_8 || UNITY_4_9) // End the boxed off area for our script selection and transition fields. GUILayout.EndArea(); #endif } GUILayout.BeginVertical(); GUILayout.Space(10f); GUILayout.EndVertical(); // Set dirty if anything changed: if (isDirty) { EditorUtility.SetDirty((MonoBehaviour)control); } if (needRepaint) Repaint(); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); isDirty = false; control = (IControl)target; // Have the specific control class's implementation // draw any control-specific settings: DrawPrestateSettings(); GUILayout.BeginVertical(); //------------------------------- // Draw a nice separator: //------------------------------- GUILayout.Space(5.0f); GUILayout.BeginVertical("Toolbar"); GUILayout.BeginHorizontal(); GUILayout.Space(10.0f); GUILayout.Label("State/Element: "); GUILayout.FlexibleSpace(); // Start keeping track of any changed values: BeginMonitorChanges(); // Do the pre-state selection GUI, if any: control.DrawPreStateSelectGUI(curState, true); EndMonitorChanges(); // Get the control's state names: stateNames = control.EnumStateElements(); if (stateNames == null) { return; } // Cap our state to the number of states available: curState = Mathf.Min(curState, stateNames.Length - 1); // Choose the state we want to edit: curState = EditorGUILayout.Popup(curState, stateNames); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.EndVertical(); //------------------------------- // End separator //------------------------------- // Keep track of any changed values: BeginMonitorChanges(); // Do the post-state selection GUI, if any: control.DrawPostStateSelectGUI(curState); EndMonitorChanges(); if (control is IPackableControl) { ShowSpriteSettings(); } else { stateInfo = control.GetStateElementInfo(curState); } transitions = stateInfo.transitions; //----------------------------------------- // Draw our state label stuff: //----------------------------------------- if (stateInfo.stateLabel != null) { BeginMonitorChanges(); DoStateLabel(); EndMonitorChanges(); } //----------------------------------------- // Draw our transition stuff: //----------------------------------------- if (transitions != null) { if (transitions.list != null) { if (transitions.list.Length > 0) { DoTransitionStuff(); } } } GUILayout.Space(10f); GUILayout.EndVertical(); // Set dirty if anything changed: if (isDirty) { EditorUtility.SetDirty((MonoBehaviour)control); } }
void ShowSpriteSettings() { IPackableControl cont = (IPackableControl)control; // Get the info for this state/element: stateInfo = cont.GetStateElementInfo(curState); // See if the sprite timeline is available: if (ste == null) { System.Reflection.Assembly asm = System.Reflection.Assembly.GetAssembly(typeof(UICtlEditor)); System.Type steType = asm.GetType("SpriteTimeline"); if (steType != null) { ste = (ISTE)System.Activator.CreateInstance(steType); ste.Setup(position, 0); } } // NOW see if the timeline is available: if (ste != null) { ste.SetCurAnim(curState); needRepaint = ste.STEOnGUI(-(20f + height), out textureAreaBottom); } else { // Put up a texture drop box: // Load the texture: if (stateInfo.stateObj.frameGUIDs.Length < 1) { stateInfo.stateObj.frameGUIDs = new string[1] { "" }; } stateInfo.tex = (Texture2D)AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(stateInfo.stateObj.frameGUIDs[0]), typeof(Texture2D)); BeginMonitorChanges(); #if UNITY_IPHONE && !(UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9) // Draw a "clear" button: if (GUI.Button(new Rect(clearRect.x, clearRect.y + height, clearRect.width, clearRect.height), "X")) { stateInfo.tex = null; } // Select the texture for the state: stateInfo.tex = (Texture2D)EditorGUI.ObjectField(tempRect, stateInfo.tex, typeof(Texture2D)); textureAreaBottom = tempRect.yMax + ctlVirtSpace; #else // Select the texture for the state: #if UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9 stateInfo.tex = (Texture2D)EditorGUILayout.ObjectField(stateNames[curState], stateInfo.tex, typeof(Texture2D), false); #else stateInfo.tex = (Texture2D)EditorGUILayout.ObjectField(stateNames[curState], stateInfo.tex, typeof(Texture2D)); #endif textureAreaBottom = 0; // This tells us to use Layout. #endif // Handle drag and drop from an outside source: EventType eventType = Event.current.type; if (eventType == EventType.DragUpdated || eventType == EventType.DragPerform) { // Validate what is being dropped: if (DragAndDrop.objectReferences[0] is Texture2D) { // Show a copy icon on the drag DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (eventType == EventType.DragPerform) { DragAndDrop.AcceptDrag(); stateInfo.tex = (Texture2D)DragAndDrop.objectReferences[0]; needRepaint = true; } Event.current.Use(); } } EndMonitorChanges(); // Re-assign the state info to the control: stateInfo.stateObj.frameGUIDs[0] = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(stateInfo.tex)); } }
public void OnGUI() { needRepaint = false; int oldState = curState; textureAreaBottom = 0; isDirty = false; if (restarted) { selGO = null; control = null; OnSelectionChange(); restarted = false; } // See if our window size has changed: if (wndRect != position) { WindowResized(); } // See if we need to update our selection: if (Selection.activeGameObject != selGO) { OnSelectionChange(); } //#if UNITY_IPHONE && !(UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9) if (Selection.activeGameObject != null) { control = (IControl)Selection.activeGameObject.GetComponent("IControl"); } //#endif // Bailout if we don't have valid values: if (null == (MonoBehaviour)control) { PrintNoSelectMsg(); return; } // Start keeping track of any changed values: BeginMonitorChanges(); // Do the pre-state selection GUI, if any: height = control.DrawPreStateSelectGUI(curState, false); EndMonitorChanges(); // Get the control's state names: stateNames = control.EnumStateElements(); if (stateNames == null) { return; } // Cap our state to the number of states available: if (stateNames != null) { curState = Mathf.Min(curState, stateNames.Length - 1); } else { curState = 0; } // Choose the state we want to edit: curState = GUILayout.Toolbar(curState, stateNames); // Reset our selected transition element // if the state selection changed: if (curState != oldState) { curFromTrans = 0; curTransElement = 0; } // Keep track of any changed values: BeginMonitorChanges(); // Do the post-state selection GUI, if any: height += control.DrawPostStateSelectGUI(curState); EndMonitorChanges(); // Adjust our texture selection rect: tempRect = texRect; tempRect.y += height; if (control is IPackableControl) { ShowSpriteSettings(); } else { stateInfo = control.GetStateElementInfo(curState); } transitions = stateInfo.transitions; if (!Application.isPlaying) { #if UNITY_IPHONE && !(UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9) // Box off our script selection and transition fields area: GUILayout.BeginArea(new Rect(0, textureAreaBottom, position.width, position.height - textureAreaBottom)); GUILayout.FlexibleSpace(); #endif //----------------------------------------- // Draw script selection: //----------------------------------------- BeginMonitorChanges(); control.DrawPreTransitionUI(curState, this); EndMonitorChanges(); //----------------------------------------- // Draw our state label stuff: //----------------------------------------- if (stateInfo.stateLabel != null) { BeginMonitorChanges(); DoStateLabel(); EndMonitorChanges(); } //----------------------------------------- // Draw our transition stuff: //----------------------------------------- if (transitions != null) { if (transitions.list != null) { if (transitions.list.Length > 0) { DoTransitionStuff(); } } } #if UNITY_IPHONE && !(UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 || UNITY_3_6 || UNITY_3_7 || UNITY_3_8 || UNITY_3_9) // End the boxed off area for our script selection and transition fields. GUILayout.EndArea(); #endif } GUILayout.BeginVertical(); GUILayout.Space(10f); GUILayout.EndVertical(); // Set dirty if anything changed: if (isDirty) { EditorUtility.SetDirty((MonoBehaviour)control); } if (needRepaint) { Repaint(); } }