bool DrawToggleContent(TweenPRS _tw, TweenPRS.PRSType _type) { GUI.changed = false; string name = ""; if (_type == TweenPRS.PRSType.Pos) { name = " TweenPosition"; } else if (_type == TweenPRS.PRSType.Rot) { name = " TweenRotation"; } else { name = " TweenScale"; } bool enablePRS = _tw.isEnable(_type); enablePRS = EditorGUILayout.ToggleLeft(name, enablePRS); if (GUI.changed == true) { UIEditorTools.RegisterUndo("Tween Change", _tw); _tw.setEnable(_type, enablePRS); UnityEditor.EditorUtility.SetDirty(_tw); } return(enablePRS); }
protected void DrawCommonProperties(TweenPRS _tw, TweenPRS.PRSType _type) { if (UIEditorTools.DrawHeader("Tweener", "Tweener_" + _type.ToString())) { UIEditorTools.BeginContents(); UIEditorTools.SetLabelWidth(110f); GUI.changed = false; TweenPRS.Style style = _tw.GetStyle(_type); style = (TweenPRS.Style)EditorGUILayout.EnumPopup("Play Style", style); AnimationCurve curve = _tw.GetAnimationCurve(_type); curve = EditorGUILayout.CurveField("Animation Curve", curve, GUILayout.Width(170), GUILayout.Height(62)); bool useSpeed = _tw.isSpeed(_type); if (style == TweenPRS.Style.Once && _type == TweenPRS.PRSType.Pos) { useSpeed = EditorGUILayout.ToggleLeft("Use Speed", useSpeed); } else { useSpeed = false; } GUILayout.BeginHorizontal(); float dur = _tw.GetDuration(_type); string str = style == TweenPRS.Style.Once ? (useSpeed ? "Speed" : "Duration") : "Duration"; dur = EditorGUILayout.FloatField(str, dur, GUILayout.Width(170f)); str = style == TweenPRS.Style.Once ? (useSpeed ? "unit/s" : "seconds") : "seconds"; GUILayout.Label(str); GUILayout.EndHorizontal(); if (GUI.changed == true) { UIEditorTools.RegisterUndo("Tween Change", _tw); _tw.SetAnimationCurve(_type, curve); _tw.SetDuration(_type, dur); _tw.SetStyle(_type, style); _tw.setEnableSpeed(_type, useSpeed); UnityEditor.EditorUtility.SetDirty(_tw); } UIEditorTools.EndContents(); } UIEditorTools.SetLabelWidth(80f); UIEditorTools.DrawEvents("On Finished", "On Finished_" + _type.ToString(), _tw, _tw.GetOnFinished(_type)); }
bool DrawOffsetContent(TweenPRS _tw, TweenPRS.PRSType _type) { GUI.changed = false; bool enableOffset = _tw.isEnableOffset(_type); enableOffset = EditorGUILayout.ToggleLeft(" Enable Offset", enableOffset); if (GUI.changed == true) { UIEditorTools.RegisterUndo("Tween Change", _tw); _tw.setEnableOffset(_type, enableOffset); UnityEditor.EditorUtility.SetDirty(_tw); } return(enableOffset); }
protected void DrawCommonProperties() { Tweener tw = target as Tweener; if (UIEditorTools.DrawHeader("Tweener")) { UIEditorTools.BeginContents(); UIEditorTools.SetLabelWidth(110f); GUI.changed = false; Tweener.Style style = (Tweener.Style)EditorGUILayout.EnumPopup("Play Style", tw.m_Style); AnimationCurve curve = EditorGUILayout.CurveField("Animation Curve", tw.m_AnimationCurve, GUILayout.Width(170), GUILayout.Height(62)); GUILayout.BeginHorizontal(); float dur = EditorGUILayout.FloatField("Duration", tw.Duration, GUILayout.Width(170f)); GUILayout.Label("seconds"); GUILayout.EndHorizontal(); if (GUI.changed == true) { UIEditorTools.RegisterUndo("Tween Change", tw); tw.m_AnimationCurve = curve; tw.m_Style = style; tw.Duration = dur; UnityEditor.EditorUtility.SetDirty(tw); } UIEditorTools.EndContents(); } UIEditorTools.SetLabelWidth(80f); UIEditorTools.DrawEvents("On Finished", tw, tw.onFinished); }
public override void OnInspectorGUI() { GUILayout.Space(6f); UIEditorTools.SetLabelWidth(120f); TweenColor tw = target as TweenColor; GUI.changed = false; Color from = EditorGUILayout.ColorField("From", tw.From); Color to = EditorGUILayout.ColorField("To", tw.To); if (GUI.changed) { UIEditorTools.RegisterUndo("Tween Change", tw); tw.From = from; tw.To = to; UnityEditor.EditorUtility.SetDirty(tw); } DrawCommonProperties(); }
/// <summary> /// Draw an editor field for the Unity Delegate. /// </summary> static public bool Field(Object undoObject, EventDelegate del, bool removeButton) { if (del == null) { return(false); } bool prev = GUI.changed; GUI.changed = false; bool retVal = false; MonoBehaviour target = del.target; bool remove = false; if (removeButton && (del.target != null || del.isValid)) { if (del.target == null && del.isValid) { EditorGUILayout.LabelField("Notify", del.ToString()); } else { target = EditorGUILayout.ObjectField("Notify", del.target, typeof(MonoBehaviour), true) as MonoBehaviour; } GUILayout.Space(-20f); GUILayout.BeginHorizontal(); GUILayout.Space(64f); if (GUILayout.Button("", "ToggleMixed", GUILayout.Width(20f))) { target = null; remove = true; } GUILayout.EndHorizontal(); } else { target = EditorGUILayout.ObjectField("Notify", del.target, typeof(MonoBehaviour), true) as MonoBehaviour; } if (remove) { UIEditorTools.RegisterUndo("Delegate Selection", undoObject); del.Clear(); EditorUtility.SetDirty(undoObject); } else if (del.target != target) { UIEditorTools.RegisterUndo("Delegate Selection", undoObject); del.target = target; EditorUtility.SetDirty(undoObject); } if (del.target != null && del.target.gameObject != null) { GameObject go = del.target.gameObject; List <Entry> list = GetMethods(go); int index = 0; string[] names = PropertyReferenceDrawer.GetNames(list, del.ToString(), out index); int choice = 0; GUILayout.BeginHorizontal(); choice = EditorGUILayout.Popup("Method", index, names); GUILayout.Space(18f); GUILayout.EndHorizontal(); if (choice > 0 && choice != index) { //Entry entry = list[choice - 1]; Entry entry = list[choice - 2]; UIEditorTools.RegisterUndo("Delegate Selection", undoObject); del.target = entry.target as MonoBehaviour; del.methodName = entry.name; EditorUtility.SetDirty(undoObject); retVal = true; } GUI.changed = false; EventDelegate.Parameter[] ps = del.parameters; if (ps != null) { for (int i = 0; i < ps.Length; ++i) { EventDelegate.Parameter param = ps[i]; //Object _obj = param.obj as Object; //if (_obj == null) // continue; Object obj = EditorGUILayout.ObjectField(" Arg " + i, param.obj, typeof(Object), true); if (GUI.changed) { GUI.changed = false; param.obj = obj; EditorUtility.SetDirty(undoObject); } if (obj == null) { continue; } System.Type type = obj.GetType(); GameObject selGO = null; if (type == typeof(GameObject)) { selGO = obj as GameObject; } else if (type.IsSubclassOf(typeof(Component))) { selGO = (obj as Component).gameObject; } if (selGO != null) { // Parameters must be exact -- they can't be converted like property bindings PropertyReferenceDrawer.filter = param.expectedType; PropertyReferenceDrawer.canConvert = false; List <PropertyReferenceDrawer.Entry> ents = PropertyReferenceDrawer.GetProperties(selGO, true, false); int selection; string[] props = GetNames(ents, UIEditorTools.GetFuncName(param.obj, param.field), out selection); GUILayout.BeginHorizontal(); int newSel = EditorGUILayout.Popup(" ", selection, props); GUILayout.Space(18f); GUILayout.EndHorizontal(); if (GUI.changed) { GUI.changed = false; if (newSel == 0) { param.obj = selGO; param.field = null; } else { param.obj = ents[newSel - 1].target; param.field = ents[newSel - 1].name; } EditorUtility.SetDirty(undoObject); } } else if (!string.IsNullOrEmpty(param.field)) { param.field = null; EditorUtility.SetDirty(undoObject); } PropertyReferenceDrawer.filter = typeof(void); PropertyReferenceDrawer.canConvert = true; } } } else { retVal = GUI.changed; } GUI.changed = prev; return(retVal); }
public override void OnInspectorGUI() { GUILayout.Space(6f); UIEditorTools.SetLabelWidth(120f); TweenHeight tw = target as TweenHeight; GUI.changed = false; bool enableOffset = EditorGUILayout.ToggleLeft("Enable Offset ", tw.EnableOffset); if (GUI.changed) { UIEditorTools.RegisterUndo("Tween Change", tw); tw.EnableOffset = enableOffset; UnityEditor.EditorUtility.SetDirty(tw); } GUI.changed = false; int from = 0, to = 0, offset = 0; GUILayout.BeginHorizontal(); GUILayout.Space(20f); GUILayout.BeginVertical(); GUILayout.Space(2f); if (!enableOffset) { from = EditorGUILayout.IntField("From", (int)tw.From); to = EditorGUILayout.IntField("To", (int)tw.To); } else { offset = EditorGUILayout.IntField("Offset", (int)tw.Offset); } GUILayout.EndHorizontal(); GUILayout.Space(20f); GUILayout.EndVertical(); GUILayout.Space(2f); if (from < 0) { from = 0; } if (to < 0) { to = 0; } if (offset < 0) { offset = 0; } if (GUI.changed) { UIEditorTools.RegisterUndo("Tween Change", tw); if (!enableOffset) { tw.From = from; tw.To = to; } else { tw.Offset = offset; } UnityEditor.EditorUtility.SetDirty(tw); } DrawCommonProperties(); }
bool DrawTweenInfo(TweenPRS _tw, TweenPRS.PRSType _type, bool _offset) { GUILayout.BeginHorizontal(); GUILayout.Space(20f); GUILayout.BeginVertical(); GUILayout.Space(2f); GUI.changed = false; Vector3 from = _tw.GetFrom(_type); Vector3 to = _tw.GetTo(_type); Vector3 offset = _tw.GetOffset(_type); if (!_offset) { if (_type == TweenPRS.PRSType.Pos) { Vector2 tmpFrom = new Vector2(from.x, from.y); Vector2 tmpTo = new Vector2(to.x, to.y); tmpFrom = EditorGUILayout.Vector2Field("From", tmpFrom); tmpTo = EditorGUILayout.Vector2Field("To", tmpTo); from = new Vector3(tmpFrom.x, tmpFrom.y, 0); to = new Vector3(tmpTo.x, tmpTo.y, 0); } else { from = EditorGUILayout.Vector3Field("From", from); to = EditorGUILayout.Vector3Field("To", to); } } else { if (_type == TweenPRS.PRSType.Pos) { Vector2 tmp = new Vector2(offset.x, offset.y); tmp = EditorGUILayout.Vector2Field("Offset", tmp); offset = new Vector3(tmp.x, tmp.y, 0); } else { offset = EditorGUILayout.Vector3Field("Offset", offset); } } if (GUI.changed == true) { UIEditorTools.RegisterUndo("Tween Change", _tw); if (!_offset) { _tw.SetFrom(_type, from); _tw.SetTo(_type, to); } else { _tw.SetOffset(_type, offset); } UnityEditor.EditorUtility.SetDirty(_tw); } GUILayout.EndHorizontal(); GUILayout.Space(20f); GUILayout.EndVertical(); GUILayout.Space(2f); return(true); }