// ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ public override void OnInspectorGUI() { DrawDefaultInspector(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Edit...", GUILayout.Width(50), GUILayout.Height(20))) { exAtlasEditor editor = exAtlasEditor.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); } } }
// ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ public override void OnInspectorGUI() { // ======================================================== // Base GUI // ======================================================== base.OnInspectorGUI(); GUILayout.Space(20); // ======================================================== // init values // ======================================================== // bool needRebuild = false; editSprite.spanim = editSprite.GetComponent <exSpriteAnimation>(); // get ElementInfo first Texture2D editTexture = exEditorHelper.LoadAssetFromGUID <Texture2D>(editSprite.textureGUID); // ======================================================== // Texture preview (input) // ======================================================== bool textureChanged = false; GUI.enabled = !inAnimMode; GUILayout.BeginHorizontal(); GUILayout.Space(20); EditorGUIUtility.LookLikeControls(); Texture2D newTexture = (Texture2D)EditorGUILayout.ObjectField(editTexture , typeof(Texture2D) , false , GUILayout.Width(100) , GUILayout.Height(100) ); EditorGUIUtility.LookLikeInspector(); if (newTexture != editTexture) { editTexture = newTexture; editSprite.textureGUID = exEditorHelper.AssetToGUID(editTexture); textureChanged = true; GUI.changed = true; } GUILayout.Space(10); GUILayout.BeginVertical(); GUILayout.Space(90); GUILayout.Label(editTexture ? editTexture.name : "None"); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUI.enabled = true; // ======================================================== // get atlas element info from atlas database // ======================================================== exAtlas editAtlas = null; int editIndex = -1; exAtlasDB.ElementInfo elInfo = exAtlasDB.GetElementInfo(editSprite.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 don't use atlas and current edit target use atlas, clear it. if (editSprite.useAtlas != useAtlas) { editSprite.Clear(); } // if we use atlas, check if the atlas,index changes if (useAtlas) { if (editAtlas != editSprite.atlas || editIndex != editSprite.index) { editSprite.SetSprite(editAtlas, editIndex); GUI.changed = true; } } // check if we are first time assignment if (useAtlas || editTexture != null) { if (isPrefab == false && editSprite.meshFilter.sharedMesh == null) { needRebuild = true; } } } // ======================================================== // get trimTexture // ======================================================== GUI.enabled = !inAnimMode && !useAtlas; bool newTrimTexture = EditorGUILayout.Toggle("Trim Texture", editSprite.trimTexture); if (!useAtlas && (textureChanged || newTrimTexture != editSprite.trimTexture)) { editSprite.GetComponent <Renderer>().sharedMaterial = exEditorHelper.GetDefaultMaterial(editTexture, editTexture.name); editSprite.trimTexture = newTrimTexture; // get trimUV Rect trimUV = new Rect(0, 0, 1, 1); if (editTexture != null) { if (editSprite.trimTexture) { if (exTextureHelper.IsValidForAtlas(editTexture) == false) { exTextureHelper.ImportTextureForAtlas(editTexture); } trimUV = exTextureHelper.GetTrimTextureRect(editTexture); trimUV = new Rect(trimUV.x / editTexture.width, (editTexture.height - trimUV.height - trimUV.y) / editTexture.height, trimUV.width / editTexture.width, trimUV.height / editTexture.height); } if (editSprite.customSize == false) { editSprite.width = trimUV.width * editTexture.width; editSprite.height = trimUV.height * editTexture.height; } } editSprite.trimUV = trimUV; editSprite.updateFlags |= exPlane.UpdateFlags.UV; editSprite.updateFlags |= exPlane.UpdateFlags.Vertex; } GUI.enabled = true; // ======================================================== // color // ======================================================== editSprite.color = EditorGUILayout.ColorField("Color", editSprite.color); // ======================================================== // atlas & index // ======================================================== GUILayout.BeginHorizontal(); GUI.enabled = false; EditorGUILayout.ObjectField("Atlas" , editSprite.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(editSprite.atlas); } GUI.enabled = true; GUILayout.EndHorizontal(); GUI.enabled = false; EditorGUILayout.IntField("Index", editSprite.index); GUI.enabled = true; // ======================================================== // custom size // ======================================================== GUI.enabled = !inAnimMode; editSprite.customSize = EditorGUILayout.Toggle("Custom Size", editSprite.customSize); GUI.enabled = true; // ======================================================== // width & height // ======================================================== ++EditorGUI.indentLevel; GUI.enabled = !inAnimMode && editSprite.customSize; // width float newWidth = EditorGUILayout.FloatField("Width", editSprite.width); if (newWidth != editSprite.width) { if (newWidth < 1.0f) { newWidth = 1.0f; } editSprite.width = newWidth; } // height float newHeight = EditorGUILayout.FloatField("Height", editSprite.height); if (newHeight != editSprite.height) { if (newHeight < 1.0f) { newHeight = 1.0f; } editSprite.height = newHeight; } --EditorGUI.indentLevel; // ======================================================== // Reset to original // ======================================================== GUILayout.BeginHorizontal(); GUILayout.Space(30); if (GUILayout.Button("Reset", GUILayout.Width(50))) { if (useAtlas) { exAtlas.Element el = editAtlas.elements[editIndex]; editSprite.width = el.trimRect.width; editSprite.height = el.trimRect.height; } else if (editTexture) { editSprite.width = editSprite.trimUV.width * editTexture.width; editSprite.height = editSprite.trimUV.height * editTexture.height; } GUI.changed = true; } GUILayout.EndHorizontal(); 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(); editSprite.Build(editTexture); } else if (GUI.changed) { if (editSprite.meshFilter.sharedMesh != null) { editSprite.UpdateMesh(editSprite.meshFilter.sharedMesh); } EditorUtility.SetDirty(editSprite); } } }
// ------------------------------------------------------------------ // Desc: // ------------------------------------------------------------------ public override void OnInspectorGUI() { // get old trim value serializedObject.Update(); SerializedProperty propTrim = serializedObject.FindProperty("trim"); bool oldTrim = propTrim.boolValue; DrawDefaultInspector(); // process trim property if (propTrim.boolValue != oldTrim) { foreach (Object obj in serializedObject.targetObjects) { exTextureInfo textureInfo = obj as exTextureInfo; if (textureInfo == null) { continue; } Texture2D rawTexture = exEditorUtility.LoadAssetFromGUID <Texture2D> (textureInfo.rawTextureGUID); if (rawTexture == null) { continue; } if (propTrim.boolValue) { Rect trimRect = exTextureUtility.GetTrimTextureRect(rawTexture, textureInfo.trimThreshold, new Rect(0, 0, rawTexture.width, rawTexture.height)); if (trimRect.width <= 0 || trimRect.height <= 0) { Debug.LogWarning("Can't not trim texture " + obj.name + ", empty pixel in it"); trimRect = new Rect(0, 0, rawTexture.width, rawTexture.height); textureInfo.trim = false; } textureInfo.trim_x = (int)trimRect.x; textureInfo.trim_y = (int)trimRect.y; textureInfo.width = (int)trimRect.width; textureInfo.height = (int)trimRect.height; } else { textureInfo.trim_x = 0; textureInfo.trim_y = 0; textureInfo.width = rawTexture.width; textureInfo.height = rawTexture.height; } EditorUtility.SetDirty(textureInfo); } } // if (serializedObject.isEditingMultipleObjects == false) { GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); // Select if (GUILayout.Button("Select...", GUILayout.Width(60), GUILayout.Height(20))) { exTextureInfo textureInfo = target as exTextureInfo; Texture texture = exEditorUtility.LoadAssetFromGUID <Texture>(textureInfo.rawTextureGUID); EditorGUIUtility.PingObject(texture); } // Atlas if (GUILayout.Button("Atlas...", GUILayout.Width(60), GUILayout.Height(20))) { exAtlasEditor editor = EditorWindow.GetWindow <exAtlasEditor>(); exTextureInfo textureInfo = target as exTextureInfo; exAtlas atlas = exEditorUtility.LoadAssetFromGUID <exAtlas>(textureInfo.rawAtlasGUID); editor.Edit(atlas); } // Edit if (GUILayout.Button("Edit...", GUILayout.Width(60), GUILayout.Height(20))) { exTextureInfoEditor editor = EditorWindow.GetWindow <exTextureInfoEditor>(); exTextureInfo textureInfo = target as exTextureInfo; editor.Edit(textureInfo); } GUILayout.Space(5); GUILayout.EndHorizontal(); } }