Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEditor;
- using System.Collections;
- [CustomEditor(typeof(MessageManager))]
- public class MessageManagerInspector : Editor {
- public int size = 0;
- public bool expanded = true;
- public bool[] displaysExpanded = new bool[0];
- public MessageManager thisTarget;
- // The developer can rename any of the field titles here:
- public string thisDisplayTitle = "Name: ";
- public string messageDisplayTitle = "Message Display: ";
- public string defaultColorTitle = "Default Color: ";
- public string displayTypeTitle = "Display Type: ";
- public string dropShadowTitle = "Drop Shadow: ";
- public string dropShadowOffsetTitle = "Drop Shadow Offset: ";
- // public string isConstant = false;
- public string buildDirection = "Build Direction: ";
- public string fadeDelayTitle = "Fade Delay: ";
- public string fadeSpeedTitle = "Fade Speed: ";
- // public string clip = false;
- public string clippingRectTitle = "Clipping Rect: ";
- // public string useScrollContainer = false;
- // public string pool;
- public string poolSizeTitle = "Pool Size: ";
- void OnEnable () {
- thisTarget = target as MessageManager;
- size = thisTarget.messageDisplays.Length;
- displaysExpanded = new bool[thisTarget.messageDisplays.Length];
- for (int i = 0; i < displaysExpanded.Length; i++) {
- displaysExpanded[i] = EditorPrefs.GetBool ("FoldFlag"+i);
- }
- }
- void OnDisable () {
- for (int i = 0; i < displaysExpanded.Length; i++) {
- EditorPrefs.SetBool ("FoldFlag"+i, displaysExpanded[i]);
- }
- }
- public override void OnInspectorGUI () {
- // MessageManager thisTarget = target as MessageManager;
- EditorGUILayout.BeginHorizontal();
- GUILayout.FlexibleSpace();
- if (GUILayout.Button ("Expand All")) {
- ToggleAllFoldFlags (true);
- }
- GUILayout.FlexibleSpace();
- if (GUILayout.Button ("Collapse All")) {
- ToggleAllFoldFlags (false);
- }
- GUILayout.FlexibleSpace();
- EditorGUILayout.EndHorizontal();
- expanded = EditorGUILayout.Foldout(expanded, "Message Displays");
- EditorGUI.indentLevel = 0;
- if (expanded) {
- EditorGUIUtility.LookLikeInspector();
- // EditorGUIUtility.LookLikeControls();
- EditorGUI.indentLevel = 1;
- size = EditorGUILayout.IntField("Size", size);
- if (size != thisTarget.messageDisplays.Length) {
- ResizeDisplays (thisTarget.messageDisplays.Length, size);
- }
- for (int i = 0; i < thisTarget.messageDisplays.Length; i++) {
- EditorGUI.indentLevel = 2;
- string elementName = (!(thisTarget.messageDisplays[i] == null || thisTarget.messageDisplays[i].thisDisplay == "")) ? thisTarget.messageDisplays[i].thisDisplay : "Element " + i;
- displaysExpanded[i] = EditorGUILayout.Foldout(displaysExpanded[i], elementName);
- if (displaysExpanded[i]) {
- EditorGUI.indentLevel = 3;
- thisTarget.messageDisplays[i].thisDisplay = EditorGUILayout.TextField (thisDisplayTitle, thisTarget.messageDisplays[i].thisDisplay);
- thisTarget.messageDisplays[i].messageDisplay = (SpriteText)EditorGUILayout.ObjectField (messageDisplayTitle, thisTarget.messageDisplays[i].messageDisplay, typeof(SpriteText), true);
- thisTarget.messageDisplays[i].defaultColor = EditorGUILayout.ColorField (defaultColorTitle, thisTarget.messageDisplays[i].defaultColor);
- thisTarget.messageDisplays[i].displayType = (DisplayType)EditorGUILayout.EnumPopup (displayTypeTitle, thisTarget.messageDisplays[i].displayType);
- switch (thisTarget.messageDisplays[i].displayType) {
- case DisplayType.Standard:
- case DisplayType.Scrolling:
- thisTarget.messageDisplays[i].fadeDelay = EditorGUILayout.FloatField (fadeDelayTitle, thisTarget.messageDisplays[i].fadeDelay);
- thisTarget.messageDisplays[i].fadeSpeed = EditorGUILayout.FloatField (fadeSpeedTitle, thisTarget.messageDisplays[i].fadeSpeed);
- thisTarget.messageDisplays[i].dropShadow = EditorGUILayout.Toggle (dropShadowTitle, thisTarget.messageDisplays[i].dropShadow);
- if (thisTarget.messageDisplays[i].dropShadow) {
- EditorGUI.indentLevel = 5;
- EditorGUIUtility.LookLikeControls();
- thisTarget.messageDisplays[i].dropShadowOffset = EditorGUILayout.Vector3Field (dropShadowOffsetTitle, thisTarget.messageDisplays[i].dropShadowOffset);
- EditorGUIUtility.LookLikeInspector();
- }
- break;
- case DisplayType.Clipped:
- thisTarget.messageDisplays[i].fadeDelay = EditorGUILayout.FloatField (fadeDelayTitle, thisTarget.messageDisplays[i].fadeDelay);
- thisTarget.messageDisplays[i].fadeSpeed = EditorGUILayout.FloatField (fadeSpeedTitle, thisTarget.messageDisplays[i].fadeSpeed);
- thisTarget.messageDisplays[i].dropShadow = EditorGUILayout.Toggle (dropShadowTitle, thisTarget.messageDisplays[i].dropShadow);
- if (thisTarget.messageDisplays[i].dropShadow) {
- EditorGUI.indentLevel = 5;
- EditorGUIUtility.LookLikeControls();
- thisTarget.messageDisplays[i].dropShadowOffset = EditorGUILayout.Vector3Field (dropShadowOffsetTitle, thisTarget.messageDisplays[i].dropShadowOffset);
- EditorGUIUtility.LookLikeInspector();
- }
- EditorGUI.indentLevel = 5;
- EditorGUIUtility.LookLikeControls();
- thisTarget.messageDisplays[i].clippingRect = EditorGUILayout.RectField (clippingRectTitle, thisTarget.messageDisplays[i].clippingRect);
- EditorGUIUtility.LookLikeInspector();
- break;
- case DisplayType.Pooling:
- thisTarget.messageDisplays[i].fadeDelay = EditorGUILayout.FloatField (fadeDelayTitle, thisTarget.messageDisplays[i].fadeDelay);
- thisTarget.messageDisplays[i].fadeSpeed = EditorGUILayout.FloatField (fadeSpeedTitle, thisTarget.messageDisplays[i].fadeSpeed);
- thisTarget.messageDisplays[i].poolSize = EditorGUILayout.IntField (poolSizeTitle, thisTarget.messageDisplays[i].poolSize);
- break;
- case DisplayType.Constant:
- thisTarget.messageDisplays[i].dropShadow = EditorGUILayout.Toggle (dropShadowTitle, thisTarget.messageDisplays[i].dropShadow);
- if (thisTarget.messageDisplays[i].dropShadow) {
- EditorGUI.indentLevel = 5;
- EditorGUIUtility.LookLikeControls();
- thisTarget.messageDisplays[i].dropShadowOffset = EditorGUILayout.Vector3Field (dropShadowOffsetTitle, thisTarget.messageDisplays[i].dropShadowOffset);
- EditorGUIUtility.LookLikeInspector();
- }
- break;
- }
- }
- }
- }
- }
- void ToggleAllFoldFlags (bool flag) {
- for (int i = 0; i < displaysExpanded.Length; i++) {
- displaysExpanded[i] = flag;
- }
- }
- void ResizeDisplays (int oldSize, int newSize) {
- Debug.Log ("RESIZING");
- // MessageManager thisTarget = target as MessageManager;
- // MessageDisplay[] newDisplays = new MessageDisplay[newSize];
- // for (int i = 0; i < newSize; i++) {
- // if (i < oldSize)
- // newDisplays[i] = thisTarget.messageDisplays[i];
- // else
- // newDisplays[i] = new MessageDisplay();
- // }
- // thisTarget.messageDisplays = newDisplays;
- }
- // public string thisDisplay = "New Display";
- // public SpriteText messageDisplay;
- // public Color defaultColor = Color.white;
- // public DisplayType displayType = DisplayType.Standard;
- // public bool dropShadow = true;
- // public Vector3 dropShadowOffset = new Vector3 (1.0f, -1.0f, 2.0f);
- // public bool isConstant = false;
- // public BuildDirection buildDirection;
- // public float fadeDelay;
- // public float fadeSpeed;
- // public bool clip = false;
- // public Rect clippingRect;
- // public bool useScrollContainer = false;
- // public bool pool;
- // public int poolSize;
- }
- /*
- asdf a
- // MyObject.js
- public var ElementsExpand : boolean = true;
- public var ElementsSize : int = 1;
- public var Elements : Transform[] = new Transform[ElementsSize];
- // MyObjectEditor.js -
- OnInspectorGUI()
- target.ElementsExpand = EditorGUILayout.Foldout(target.ElementsExpand, "Transforms");
- if (target.ElementsExpand) {
- var x : int = 0;
- target.ElementsSize = EditorGUILayout.IntField("Size", target.ElementsSize);
- if (target.Elements.length != target.ElementsSize) {
- var newArray : Transform[] = new Transform[target.ElementsSize];
- for (x = 0; x < target.ElementsSize; x++) {
- if (target.Elements.length > x) {
- newArray[x] = target.Elements[x];
- }
- }
- target.Elements = newArray;
- }
- for (x = 0; x < target.Elements.length; x++) {
- target.Elements[x] = EditorGUILayout.ObjectField("Element " + x, target.Elements[x], typeof(Transform));
- }
- }
- }
- -
- -
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement