public void CopyTo(EZTransitionList target, bool copyInit) { if (target == null) { return; } if (target.list == null) { return; } int num = 0; while (num < this.list.Length && num < target.list.Length) { if (target.list[num] != null) { target.list[num].Copy(this.list[num]); if (copyInit) { target.list[num].initialized = this.list[num].initialized; } } num++; } }
static void CopyPanel(UIPanelBase panel) { transList = new EZTransitionList[1]; transList[0] = new EZTransitionList(); panel.Transitions.CopyToNew(transList[0], true); transList[0].MarkAllInitialized(); Debug.Log("Transitions Copied"); }
public void CopyToNew(EZTransitionList target, bool copyInit) { if (target == null) { return; } if (target.list == null) { return; } target.list = new EZTransition[this.list.Length]; for (int i = 0; i < target.list.Length; i++) { target.list[i] = new EZTransition(this.list[i].name); } this.CopyTo(target, copyInit); }
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; }
static void CopyControl(IControl ctl) { int num = 0; // Count how many transition lists there are: while (ctl.GetTransitions(num) != null) { ++num; } transList = new EZTransitionList[num]; for (int i = 0; i < transList.Length; ++i) { transList[i] = new EZTransitionList(); ctl.GetTransitions(i).CopyToNew(transList[i], true); transList[i].MarkAllInitialized(); } Debug.Log(num + " transition lists Copied"); }
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(); }
/// <summary> /// Copies all of the specified control's settings /// to this control, provided they are of the same /// type. One exception is that layers are not /// copied as this would require a new allocation /// and could negatively impact performance at /// runtime. /// </summary> /// <param name="s">Reference to the control whose settings are to be copied to this control.</param> public virtual void Copy(SpriteRoot s, ControlCopyFlags flags) { if ((flags & ControlCopyFlags.Appearance) == ControlCopyFlags.Appearance) { if (Application.isPlaying && s.Started) base.Copy(s); else // If we're in-editor, copy the TextureAnims too base.CopyAll(s); if (!(s is AutoSpriteControlBase)) { if (autoResize || pixelPerfect) CalcSize(); else SetSize(s.width, s.height); SetBleedCompensation(); return; } } AutoSpriteControlBase c = (AutoSpriteControlBase)s; // Copy transitions: if ((flags & ControlCopyFlags.Transitions) == ControlCopyFlags.Transitions) { if (c is UIStateToggleBtn || !Application.isPlaying) { if (c.Transitions != null) { Transitions = new EZTransitionList[c.Transitions.Length]; for (int i = 0; i < Transitions.Length; ++i) { Transitions[i] = new EZTransitionList(); c.Transitions[i].CopyToNew(Transitions[i], true); } } } else { if (Transitions != null && c.Transitions != null) for (int i = 0; i < Transitions.Length && i < c.Transitions.Length; ++i) c.Transitions[i].CopyTo(Transitions[i], true); } } if ((flags & ControlCopyFlags.Text) == ControlCopyFlags.Text) { // See if we want to clone the other // control's text mesh: if (spriteText == null && c.spriteText != null) { GameObject newText = (GameObject)Instantiate(c.spriteText.gameObject); newText.transform.parent = transform; newText.transform.localPosition = c.spriteText.transform.localPosition; newText.transform.localScale = c.spriteText.transform.localScale; newText.transform.localRotation = c.spriteText.transform.localRotation; } if (spriteText != null) spriteText.Copy(c.spriteText); text = c.text; textOffsetZ = c.textOffsetZ; includeTextInAutoCollider = c.includeTextInAutoCollider; } if ((flags & ControlCopyFlags.Data) == ControlCopyFlags.Data) { data = c.data; } if ((flags & ControlCopyFlags.Appearance) == ControlCopyFlags.Appearance) { // See if we can copy the other control's collider's settings: if (c.collider != null) { // See if we don't already have a collider, in which case, // duplicate the one of the control being copied: if (collider == null) { gameObject.AddComponent(c.collider.GetType()); customCollider = c.customCollider; } if (collider.GetType() == c.collider.GetType()) { if (c.collider is BoxCollider) { if (collider == null) gameObject.AddComponent(typeof(BoxCollider)); BoxCollider bc1 = (BoxCollider)collider; BoxCollider bc2 = (BoxCollider)c.collider; bc1.center = bc2.center; bc1.size = bc2.size; } else if (c.collider is SphereCollider) { if (collider == null) gameObject.AddComponent(typeof(SphereCollider)); SphereCollider sc1 = (SphereCollider)collider; SphereCollider sc2 = (SphereCollider)c.collider; sc1.center = sc2.center; sc1.radius = sc2.radius; } else if (c.collider is MeshCollider) { if (collider == null) gameObject.AddComponent(typeof(MeshCollider)); MeshCollider mc1 = (MeshCollider)collider; MeshCollider mc2 = (MeshCollider)c.collider; mc1.smoothSphereCollisions = mc2.smoothSphereCollisions; mc1.convex = mc2.convex; mc1.sharedMesh = mc2.sharedMesh; } else if (c.collider is CapsuleCollider) { if (collider == null) gameObject.AddComponent(typeof(CapsuleCollider)); CapsuleCollider cc1 = (CapsuleCollider)collider; CapsuleCollider cc2 = (CapsuleCollider)c.collider; cc1.center = cc2.center; cc1.radius = cc2.radius; cc1.height = cc2.height; cc1.direction = cc2.direction; } if (collider != null) collider.isTrigger = c.collider.isTrigger; } } else if (Application.isPlaying) // Don't create a collider if we're in edit mode { // Create a default box collider to fit so // long as the control isn't of 0 size: if (collider == null && width != 0 && height != 0 && !float.IsNaN(width) && !float.IsNaN(height)) { BoxCollider bc = (BoxCollider)gameObject.AddComponent(typeof(BoxCollider)); bc.size = new Vector3(c.width, c.height, 0.001f); bc.center = c.GetCenterPoint(); bc.isTrigger = true; } else { if (collider is BoxCollider) { BoxCollider bc = (BoxCollider)collider; bc.size = new Vector3(c.width, c.height, 0.001f); bc.center = c.GetCenterPoint(); } else if (collider is SphereCollider) { SphereCollider sc = (SphereCollider)collider; sc.radius = Mathf.Max(c.width, c.height); sc.center = c.GetCenterPoint(); } // Else Fuhgettaboutit } } } if ((flags & ControlCopyFlags.DragDrop) == ControlCopyFlags.DragDrop) { isDraggable = c.isDraggable; dragOffset = c.dragOffset; cancelDragEasing = c.cancelDragEasing; cancelDragDuration = c.cancelDragDuration; } if ((flags & ControlCopyFlags.Settings) == ControlCopyFlags.Settings) { detargetOnDisable = c.detargetOnDisable; } if ((flags & ControlCopyFlags.Invocation) == ControlCopyFlags.Invocation) { changeDelegate = c.changeDelegate; inputDelegate = c.inputDelegate; } if ((flags & ControlCopyFlags.State) == ControlCopyFlags.State || (flags & ControlCopyFlags.Appearance) == ControlCopyFlags.Appearance) { Container = c.Container; if (Application.isPlaying) { controlIsEnabled = c.controlIsEnabled; Hide(c.IsHidden()); } if (curAnim != null) { if (curAnim.index == -1) { if (c.curAnim != null) curAnim = c.curAnim.Clone(); PlayAnim(curAnim); } else SetState(curAnim.index); } else SetState(0); } /* if (autoResize || pixelPerfect) CalcSize(); else SetSize(s.width, s.height); */ }
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); } }
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(); } }
static void CopyPanel(UIPanelBase panel) { transList = new EZTransitionList[1]; transList[0] = new EZTransitionList(); panel.Transitions.CopyToNew(transList[0], true); transList[0].MarkAllInitialized(); PatStuff.ScreenLog.AddMessage("Transitions Copied"); }
static void CopyControl(IControl ctl) { int num = 0; // Count how many transition lists there are: while (ctl.GetTransitions(num) != null) ++num; transList = new EZTransitionList[num]; for (int i = 0; i < transList.Length; ++i) { transList[i] = new EZTransitionList(); ctl.GetTransitions(i).CopyToNew(transList[i], true); transList[i].MarkAllInitialized(); } PatStuff.ScreenLog.AddMessage(num + " transition lists Copied"); }
public void CopyTo(EZTransitionList target) { this.CopyTo(target, false); }
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; }
void ShowSpriteSettings() { AutoSpriteControlBase cont = (AutoSpriteControlBase)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: stateInfo.tex = (Texture2D)EditorGUILayout.ObjectField(stateNames[curState], stateInfo.tex, typeof(Texture2D)); 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)); } transitions = stateInfo.transitions; }
/// <summary> /// Copies all of the specified control's settings /// to this control, provided they are of the same /// type. One exception is that layers are not /// copied as this would require a new allocation /// and could negatively impact performance at /// runtime. /// </summary> /// <param name="s">Reference to the control whose settings are to be copied to this control.</param> public virtual void Copy(SpriteRoot s, ControlCopyFlags flags) { if ((flags & ControlCopyFlags.Appearance) == ControlCopyFlags.Appearance) { if (Application.isPlaying && s.Started) { base.Copy(s); } else // If we're in-editor, copy the TextureAnims too { base.CopyAll(s); } if (!(s is AutoSpriteControlBase)) { if (autoResize || pixelPerfect) { CalcSize(); } else { SetSize(s.width, s.height); } SetBleedCompensation(); return; } } AutoSpriteControlBase c = (AutoSpriteControlBase)s; // Copy transitions: if ((flags & ControlCopyFlags.Transitions) == ControlCopyFlags.Transitions) { if (c is UIStateToggleBtn || !Application.isPlaying) { if (c.Transitions != null) { Transitions = new EZTransitionList[c.Transitions.Length]; for (int i = 0; i < Transitions.Length; ++i) { Transitions[i] = new EZTransitionList(); c.Transitions[i].CopyToNew(Transitions[i], true); } } } else { if (Transitions != null && c.Transitions != null) { for (int i = 0; i < Transitions.Length && i < c.Transitions.Length; ++i) { c.Transitions[i].CopyTo(Transitions[i], true); } } } } if ((flags & ControlCopyFlags.Text) == ControlCopyFlags.Text) { // See if we want to clone the other // control's text mesh: if (spriteText == null && c.spriteText != null) { GameObject newText = (GameObject)Instantiate(c.spriteText.gameObject); newText.transform.parent = transform; newText.transform.localPosition = c.spriteText.transform.localPosition; newText.transform.localScale = c.spriteText.transform.localScale; newText.transform.localRotation = c.spriteText.transform.localRotation; } if (spriteText != null) { spriteText.Copy(c.spriteText); } } if ((flags & ControlCopyFlags.Data) == ControlCopyFlags.Data) { data = c.data; } if ((flags & ControlCopyFlags.Appearance) == ControlCopyFlags.Appearance) { // See if we can copy the other control's collider's settings: if (c.collider != null) { if (collider.GetType() == c.collider.GetType()) { if (c.collider is BoxCollider) { if (collider == null) { gameObject.AddComponent(typeof(BoxCollider)); } BoxCollider bc1 = (BoxCollider)collider; BoxCollider bc2 = (BoxCollider)c.collider; bc1.center = bc2.center; bc1.size = bc2.size; } else if (c.collider is SphereCollider) { if (collider == null) { gameObject.AddComponent(typeof(SphereCollider)); } SphereCollider sc1 = (SphereCollider)collider; SphereCollider sc2 = (SphereCollider)c.collider; sc1.center = sc2.center; sc1.radius = sc2.radius; } else if (c.collider is MeshCollider) { if (collider == null) { gameObject.AddComponent(typeof(MeshCollider)); } MeshCollider mc1 = (MeshCollider)collider; MeshCollider mc2 = (MeshCollider)c.collider; mc1.smoothSphereCollisions = mc2.smoothSphereCollisions; mc1.convex = mc2.convex; mc1.sharedMesh = mc2.sharedMesh; } else if (c.collider is CapsuleCollider) { if (collider == null) { gameObject.AddComponent(typeof(CapsuleCollider)); } CapsuleCollider cc1 = (CapsuleCollider)collider; CapsuleCollider cc2 = (CapsuleCollider)c.collider; cc1.center = cc2.center; cc1.radius = cc2.radius; cc1.height = cc2.height; cc1.direction = cc2.direction; } if (collider != null) { collider.isTrigger = c.collider.isTrigger; } } } else if (Application.isPlaying) // Don't create a collider if we're in edit mode { // Create a default box collider to fit so // long as the control isn't of 0 size: if (collider == null && width != 0 && height != 0 && !float.IsNaN(width) && !float.IsNaN(height)) { BoxCollider bc = (BoxCollider)gameObject.AddComponent(typeof(BoxCollider)); bc.size = new Vector3(c.width, c.height, 0.001f); bc.center = c.GetCenterPoint(); bc.isTrigger = true; } else { if (collider is BoxCollider) { BoxCollider bc = (BoxCollider)collider; bc.size = new Vector3(c.width, c.height, 0.001f); bc.center = c.GetCenterPoint(); } else if (collider is SphereCollider) { SphereCollider sc = (SphereCollider)collider; sc.radius = Mathf.Max(c.width, c.height); sc.center = c.GetCenterPoint(); } // Else Fuhgettaboutit } } } if ((flags & ControlCopyFlags.Invocation) == ControlCopyFlags.Invocation) { changeDelegate = c.changeDelegate; inputDelegate = c.inputDelegate; } if ((flags & ControlCopyFlags.State) == ControlCopyFlags.State || (flags & ControlCopyFlags.Appearance) == ControlCopyFlags.Appearance) { Container = c.Container; if (Application.isPlaying) { controlIsEnabled = c.controlIsEnabled; Hide(c.IsHidden()); } if (curAnim != null) { if (curAnim.index == -1) { PlayAnim(curAnim); } else { SetState(curAnim.index); } } else { SetState(0); } } /* * if (autoResize || pixelPerfect) * CalcSize(); * else * SetSize(s.width, s.height); */ }
public override void Start() { if (m_started) { return; } base.Start(); // Check for any existing empty bars or knobs and destroy them: if (emptySprite != null) { Destroy(emptySprite); emptySprite = null; } if (knob != null) { Destroy(knob); knob = null; } // Assign our aggregate layers: aggregateLayers = new SpriteRoot[2][]; aggregateLayers[0] = filledLayers; aggregateLayers[1] = emptyLayers; // The knob will handle its own layers // Runtime init stuff: if (Application.isPlaying) { // Calculate our truncation floor and range: truncFloor = stopKnobFromEdge / width; truncRange = 1f - truncFloor * 2f; filledIndices = new int[filledLayers.Length]; emptyIndices = new int[emptyLayers.Length]; // Populate our state indices based on if we // find any valid states/animations in each // sprite layer: for (int i = 0; i < filledLayers.Length; ++i) { if (filledLayers[i] == null) { Debug.LogError("A null layer sprite was encountered on control \"" + name + "\". Please fill in the layer reference, or remove the empty element."); continue; } filledIndices[i] = filledLayers[i].GetStateIndex("filled"); if (filledIndices[i] != -1) { filledLayers[i].SetState(filledIndices[i]); } } for (int i = 0; i < emptyLayers.Length; ++i) { if (emptyLayers[i] == null) { Debug.LogError("A null layer sprite was encountered on control \"" + name + "\". Please fill in the layer reference, or remove the empty element."); continue; } emptyIndices[i] = emptyLayers[i].GetStateIndex("empty"); if (emptyIndices[i] != -1) { emptyLayers[i].SetState(emptyIndices[i]); } } // Create our knob: GameObject go = new GameObject(); go.name = name + " - Knob"; go.transform.parent = transform; go.transform.localPosition = CalcKnobStartPos(); go.transform.localRotation = Quaternion.identity; go.transform.localScale = Vector3.one; go.layer = gameObject.layer; knob = (UIScrollKnob)go.AddComponent(typeof(UIScrollKnob)); knob.plane = plane; knob.SetOffset(knobOffset); knob.persistent = persistent; knob.bleedCompensation = bleedCompensation; if (!managed) { if (knob.spriteMesh != null) { ((SpriteMesh)knob.spriteMesh).material = renderer.sharedMaterial; } } else { if (manager != null) { knob.Managed = managed; manager.AddSprite(knob); knob.SetDrawLayer(drawLayer + 1); // Knob should be drawn in front of the bar // Force it to update its UVs: knob.SetControlState(UIButton.CONTROL_STATE.ACTIVE); // We have to change to active so that when we set to normal, it isn't considered a redundant change and ignored. knob.SetControlState(UIButton.CONTROL_STATE.NORMAL); } else { Debug.LogError("Sprite on object \"" + name + "\" not assigned to a SpriteManager!"); } } if (pixelPerfect) { knob.pixelPerfect = true; } else { knob.SetSize(knobSize.x, knobSize.y); } knob.ignoreClipping = ignoreClipping; knob.color = color; knob.SetColliderSizeFactor(knobColliderSizeFactor); knob.SetSlider(this); knob.SetMaxScroll(width - (stopKnobFromEdge * 2f)); knob.SetInputDelegate(inputDelegate); // Setup knob's transitions: #if !UNITY_FLASH knob.transitions[0] = transitions[2]; knob.transitions[1] = transitions[3]; knob.transitions[2] = transitions[4]; #else EZTransitionList t = transitions[2]; knob.transitions[0] = t; t = transitions[3]; knob.transitions[1] = t; t = transitions[4]; knob.transitions[2] = t; #endif // Tell the knob what it will look like: knob.layers = knobLayers; // Child the knob's layers to the knob: for (int i = 0; i < knobLayers.Length; ++i) { knobLayers[i].transform.parent = knob.transform; } knob.animations[0].SetAnim(states[2], 0); knob.animations[1].SetAnim(states[3], 1); knob.animations[2].SetAnim(states[4], 2); knob.SetupAppearance(); knob.SetCamera(renderCamera); knob.Hide(IsHidden()); knob.autoResize = autoResize; // Create our other sprite for the // empty/background portion: go = new GameObject(); go.name = name + " - Empty Bar"; go.transform.parent = transform; go.transform.localPosition = Vector3.zero; go.transform.localRotation = Quaternion.identity; go.transform.localScale = Vector3.one; go.layer = gameObject.layer; emptySprite = (AutoSprite)go.AddComponent(typeof(AutoSprite)); emptySprite.plane = plane; emptySprite.autoResize = autoResize; emptySprite.pixelPerfect = pixelPerfect; emptySprite.persistent = persistent; emptySprite.ignoreClipping = ignoreClipping; emptySprite.bleedCompensation = bleedCompensation; if (!managed) { emptySprite.renderer.sharedMaterial = renderer.sharedMaterial; } else { if (manager != null) { emptySprite.Managed = managed; manager.AddSprite(emptySprite); emptySprite.SetDrawLayer(drawLayer); // Knob should be drawn in front of the bar } else { Debug.LogError("Sprite on object \"" + name + "\" not assigned to a SpriteManager!"); } } emptySprite.color = color; emptySprite.SetAnchor(anchor); emptySprite.Setup(width, height, m_spriteMesh.material); if (states[1].spriteFrames.Length != 0) { emptySprite.animations = new UVAnimation[1]; emptySprite.animations[0] = new UVAnimation(); emptySprite.animations[0].SetAnim(states[1], 0); emptySprite.PlayAnim(0, 0); } emptySprite.renderCamera = renderCamera; emptySprite.Hide(IsHidden()); // Add our child objects as children // of our container: if (container != null) { container.AddChild(knob.gameObject); container.AddChild(emptySprite.gameObject); } SetState(0); // Force the value to update: m_value = -1f; Value = defaultValue; } // Since hiding while managed depends on // setting our mesh extents to 0, and the // foregoing code causes us to not be set // to 0, re-hide ourselves: if (managed && m_hidden) { Hide(true); } }
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() { AutoSpriteControlBase cont = (AutoSpriteControlBase)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: stateInfo.tex = (Texture2D)EditorGUILayout.ObjectField(stateNames[curState], stateInfo.tex, typeof(Texture2D)); 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)); } transitions = stateInfo.transitions; }