// ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ public override void OnInspectorGUI() { DrawDefaultInspector(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Edit...", GUILayout.Width(50), GUILayout.Height(20))) { exGUIBorderEditor editor = exGUIBorderEditor.NewWindow(); editor.Edit(target); } GUILayout.Space(5); GUILayout.EndHorizontal(); }
// ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ public override void OnInspectorGUI() { // ======================================================== // Base GUI // ======================================================== base.OnInspectorGUI(); GUILayout.Space(20); // ======================================================== // init values // ======================================================== // bool needRebuild = false; // ======================================================== // exGUIBorder object filed // ======================================================== bool borderChanged = false; EditorGUI.indentLevel = 1; GUILayout.BeginHorizontal(); GUI.enabled = !inAnimMode; exGUIBorder newGUIBorder = (exGUIBorder)EditorGUILayout.ObjectField("GUI Border" , editSpriteBorder.guiBorder , typeof(exGUIBorder) , false ); if (newGUIBorder != editSpriteBorder.guiBorder) { borderChanged = true; } if (GUILayout.Button("Edit...", GUILayout.Width(40), GUILayout.Height(15))) { exGUIBorderEditor editor = exGUIBorderEditor.NewWindow(); editor.Edit(editSpriteBorder.guiBorder); } GUI.enabled = true; GUILayout.EndHorizontal(); GUILayout.Space(5); // get edit texture Texture2D editTexture = null; if (newGUIBorder) { editTexture = exEditorHelper.LoadAssetFromGUID <Texture2D>(newGUIBorder.textureGUID); // ======================================================== // border preview // ======================================================== Rect lastRect = GUILayoutUtility.GetLastRect(); GUILayout.BeginHorizontal(); GUILayout.Space(30); lastRect = GUILayoutUtility.GetLastRect(); Rect previewRect = new Rect(lastRect.xMax, lastRect.yMax, Mathf.Max(100, newGUIBorder.border.horizontal), Mathf.Max(100, newGUIBorder.border.vertical)); exGUIBorderEditor.TexturePreviewField(previewRect, newGUIBorder, editTexture); GUILayout.Space(10); lastRect = GUILayoutUtility.GetLastRect(); previewRect = new Rect(lastRect.x, lastRect.yMax, Mathf.Max(100, newGUIBorder.border.horizontal), Mathf.Max(100, newGUIBorder.border.vertical)); exGUIBorderEditor.BorderPreviewField(previewRect, newGUIBorder, editTexture); if (GUILayout.Button("Select...", GUILayout.Width(60), GUILayout.Height(15))) { EditorGUIUtility.PingObject(editTexture); } GUILayout.EndHorizontal(); GUILayout.Space(5); } // ======================================================== // get atlas element info from atlas database // ======================================================== exAtlas editAtlas = null; int editIndex = -1; exAtlasDB.ElementInfo elInfo = null; if (newGUIBorder) { elInfo = exAtlasDB.GetElementInfo(newGUIBorder.textureGUID); } if (elInfo != null) { editAtlas = exEditorHelper.LoadAssetFromGUID <exAtlas>(elInfo.guidAtlas); editIndex = elInfo.indexInAtlas; } bool useAtlas = editAtlas != null && editIndex != -1; // get atlas and index from textureGUID if (!EditorApplication.isPlaying) { // if we use atlas, check if the atlas,index changes if (useAtlas) { if (editAtlas != editSpriteBorder.atlas || editIndex != editSpriteBorder.index) { borderChanged = true; } } // if we don't use atlas and current edit target use atlas, clear it. else { if (editSpriteBorder.useAtlas) { borderChanged = true; } } // check if we are first time assignment if (useAtlas || editTexture != null) { if (isPrefab == false && editSpriteBorder.meshFilter.sharedMesh == null) { needRebuild = true; } } } // set border if (borderChanged) { // if (newGUIBorder == null) { editSpriteBorder.Clear(); } else { editSpriteBorder.SetBorder(newGUIBorder, editAtlas, editIndex); if (editSpriteBorder.useAtlas == false) { editSpriteBorder.GetComponent <Renderer>().sharedMaterial = exEditorHelper.GetDefaultMaterial(editTexture, editTexture.name); editSpriteBorder.updateFlags |= exPlane.UpdateFlags.UV; } } GUI.changed = true; } // ======================================================== // color // ======================================================== editSpriteBorder.color = EditorGUILayout.ColorField("Color", editSpriteBorder.color); // ======================================================== // atlas & index // ======================================================== GUILayout.BeginHorizontal(); GUI.enabled = false; EditorGUILayout.ObjectField("Atlas" , editSpriteBorder.atlas , typeof(exAtlas) , false ); GUI.enabled = true; GUI.enabled = !inAnimMode; if (GUILayout.Button("Edit...", GUILayout.Width(40), GUILayout.Height(15))) { exAtlasEditor editor = exAtlasEditor.NewWindow(); editor.Edit(editSpriteBorder.atlas); } GUI.enabled = true; GUILayout.EndHorizontal(); GUI.enabled = false; EditorGUILayout.IntField("Index", editSpriteBorder.index); GUI.enabled = true; // ======================================================== // width & height // ======================================================== GUI.enabled = !inAnimMode; // width float newWidth = EditorGUILayout.FloatField("Width", editSpriteBorder.width); if (newWidth != editSpriteBorder.width) { if (newWidth < 1.0f) { newWidth = 1.0f; } editSpriteBorder.width = newWidth; } // height float newHeight = EditorGUILayout.FloatField("Height", editSpriteBorder.height); if (newHeight != editSpriteBorder.height) { if (newHeight < 1.0f) { newHeight = 1.0f; } editSpriteBorder.height = newHeight; } GUI.enabled = true; // ======================================================== // Rebuild button // ======================================================== GUI.enabled = !inAnimMode; GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Rebuild...", GUILayout.Height(20))) { needRebuild = true; } GUILayout.EndHorizontal(); GUI.enabled = true; GUILayout.Space(5); // if dirty, build it. if (!EditorApplication.isPlaying && !AnimationUtility.InAnimationMode()) { if (needRebuild) { EditorUtility.ClearProgressBar(); editSpriteBorder.Build(editTexture); } else if (GUI.changed) { if (editSpriteBorder.meshFilter.sharedMesh != null) { editSpriteBorder.UpdateMesh(editSpriteBorder.meshFilter.sharedMesh); } EditorUtility.SetDirty(editSpriteBorder); } } }
public static exGUIBorderEditor NewWindow() { exGUIBorderEditor newWindow = EditorWindow.GetWindow <exGUIBorderEditor>(); return(newWindow); }