protected override void DrawCustomIconsUI() { EditorGUILayout.LabelField("Atlas Settings", EditorStyles.boldLabel); m.atlas = (NJGAtlas)EditorGUILayout.ObjectField("Atlas", m.atlas, typeof(NJGAtlas), false); mFolderObject = EditorGUILayout.ObjectField("Sprites Folder", AssetDatabase.LoadAssetAtPath(m.iconFolder, typeof(UnityEngine.Object)), typeof(UnityEngine.Object), false); if (mFolderObject != null) { mFolder = AssetDatabase.GetAssetPath(mFolderObject); bool valid = !mFolder.Contains("."); string folderName = mFolder.Substring(mFolder.LastIndexOf('/')).Replace('/', ' ').Trim(); GUI.backgroundColor = valid ? Color.cyan : Color.red; if (valid) { if (m.iconFolder != mFolder) { m.iconFolder = mFolder; Save(true); } GUI.backgroundColor = m.atlas != null ? Color.green : Color.cyan; if (GUILayout.Button(m.atlas != null ? "Update Atlas" : "Create Atlas")) { if (m.atlas != null) { NJGEditorTools.UpdateAtlas(m.atlas, m.iconFolder + "/"); } else { m.atlas = NJGEditorTools.CreateAtlas(m.iconFolder + "/", folderName); Save(true); } } GUI.backgroundColor = Color.white; EditorGUILayout.HelpBox(m.iconFolder, MessageType.Info); } else { EditorGUILayout.HelpBox("INVALID! You must select a folder", MessageType.Error); } GUI.backgroundColor = Color.white; } else { GUI.backgroundColor = Color.yellow; EditorGUILayout.HelpBox("Drag your icon folder here", MessageType.Warning); GUI.backgroundColor = Color.white; } //GUILayout.EndHorizontal(); NJGEditorTools.DrawSeparator(); }
/// <summary> /// Draw the custom wizard. /// </summary> void OnGUI() { #if UNITY_4_3 EditorGUIUtility.LookLikeControls(80f); #else EditorGUIUtility.labelWidth = 80f; #endif bool close = false; GUILayout.Label("Icons", "LODLevelNotifyText"); NJGEditorTools.DrawSeparator(); GUILayout.BeginHorizontal(); GUILayout.Space(84f); string before = mSearch; string after = EditorGUILayout.TextField("", before, "SearchTextField"); mSearch = after; if (GUILayout.Button("", "SearchCancelButton", GUILayout.Width(18f))) { mSearch = ""; GUIUtility.keyboardControl = 0; } GUILayout.Space(84f); GUILayout.EndHorizontal(); Texture2D tex = mAtlas.texture as Texture2D; if (tex == null) { GUILayout.Label("The atlas doesn't have a texture to work with"); return; } List <string> sprites = mAtlas.GetListOfSprites(mSearch); float size = 80f; float padded = size + 10f; int columns = Mathf.FloorToInt(Screen.width / padded); if (columns < 1) { columns = 1; } int offset = 0; Rect rect = new Rect(10f, 0, size, size); GUILayout.Space(10f); mPos = GUILayout.BeginScrollView(mPos); while (offset < sprites.Count) { GUILayout.BeginHorizontal(); { int col = 0; rect.x = 10f; for (; offset < sprites.Count; ++offset) { NJGAtlas.Sprite sprite = mAtlas.GetSprite(sprites[offset]); if (sprite == null) { continue; } // Button comes first if (GUI.Button(rect, "")) { float delta = Time.realtimeSinceStartup - mClickTime; mClickTime = Time.realtimeSinceStartup; if (mSprite != sprite.name) { mSprite = sprite.name; if (mCallback != null) { mCallback(mSprite); } } else if (delta < 0.5f) { close = true; } } if (Event.current.type == EventType.Repaint) { // On top of the button we have a checkboard grid NJGEditorTools.DrawTiledTexture(rect, NJGEditorTools.backdropTexture); // Calculate the texture's scale that's needed to display the sprite in the clipped area float scaleX = rect.width / sprite.width; float scaleY = rect.height / sprite.height; // Stretch the sprite so that it will appear proper float aspect = (scaleY / scaleX) / ((float)sprite.height / sprite.width); Rect clipRect = rect; if (aspect != 1f) { if (aspect < 1f) { // The sprite is taller than it is wider float padding = size * (1f - aspect) * 0.5f; clipRect.xMin += padding; clipRect.xMax -= padding; } else { // The sprite is wider than it is taller float padding = size * (1f - 1f / aspect) * 0.5f; clipRect.yMin += padding; clipRect.yMax -= padding; } } GUI.DrawTextureWithTexCoords(clipRect, tex, sprite.uvs); // Draw the selection if (mSprite == sprite.name) { NJGEditorTools.DrawOutline(rect, new Color(0.4f, 1f, 0f, 1f)); } } if (++col >= columns) { ++offset; break; } rect.x += padded; } } GUILayout.EndHorizontal(); GUILayout.Space(padded); rect.y += padded; } GUILayout.EndScrollView(); if (close) { Close(); } }
//float extraSpace = 0; /// <summary> /// Draw the Map Marker inspector. /// </summary> public override void OnInspectorGUI() { #if UNITY_4_3 EditorGUIUtility.LookLikeControls(120f); #else EditorGUIUtility.labelWidth = 120f; #endif m = target as NJGMapItem; NJGEditorTools.DrawEditMap(); if (UIMiniMapBase.inst != null) { string info = "Map Position: " + UIMiniMapBase.inst.WorldToMap(m.cachedTransform.position).ToString(); GUI.color = Color.cyan; EditorGUILayout.LabelField(info, EditorStyles.boldLabel); GUI.color = Color.white; } NJGEditorTools.DrawSeparator(); int type = 0; if (NJG.NJGMapBase.instance != null) { type = NJGEditorTools.DrawList("Marker Type", NJG.NJGMapBase.instance.mapItemTypes, m.type); } string tooltip = "You can use to display name + anything else you want.\nFor example: Ore [FF0000]+100 Mineral[-]"; string content = ""; if (type != 0) { EditorGUILayout.LabelField(new GUIContent("Tooltip Content", tooltip)); content = EditorGUILayout.TextArea(m.content); GUI.backgroundColor = Color.gray; EditorGUILayout.HelpBox(tooltip, MessageType.Info); GUI.backgroundColor = Color.white; } //m.drawDirection = EditorGUILayout.Toggle("Draw Direction Line", m.drawDirection); bool revealFOW = EditorGUILayout.Toggle("Reveal FOW", m.revealFOW); GUI.enabled = m.revealFOW; int revealDistance = (int)EditorGUILayout.Slider("Reveal Distance", m.revealDistance, 0, 100); GUI.enabled = true; GUI.backgroundColor = Color.gray; EditorGUILayout.HelpBox("Overrides Global Reveal Distance, if value = 0 it will use the global reveal distance.", MessageType.Info); GUI.backgroundColor = Color.white; /*if (NJG.NJGMapBase.instance != null) * { * if (NJG.NJGMapBase.instance.atlas != null) * { * GUILayout.BeginHorizontal(); * EditorGUILayout.LabelField("Icon Sprite", GUILayout.Width(100.0f)); * * // Draw sprite preview. * Material mat = NJG.NJGMapBase.instance.atlas.spriteMaterial; * * if (mat != null) * { * Texture2D tex = mat.mainTexture as Texture2D; * * if (tex != null) * { * UIAtlas.Sprite sprite = m.sprite; * Rect rect = sprite.outer; * if (NJG.NJGMapBase.instance.atlas.coordinates == UIAtlas.Coordinates.Pixels) * { * rect = NGUIMath.ConvertToTexCoords(rect, tex.width, tex.height); * } * * GUILayout.Space(4f); * GUILayout.Label("", GUILayout.Height(NJGMapBase.instance.iconSize)); * GUI.color = m.color; * DrawSprite(tex, rect, null, false, NJGMapBase.instance.iconSize); * GUI.color = Color.white; * * extraSpace = NJGMapBase.instance.iconSize * (float)sprite.outer.height / sprite.outer.width; * } * * } * GUILayout.EndHorizontal(); * * extraSpace = Mathf.Max(0f, extraSpace - 30f); * //GUILayout.Space(extraSpace); * } * EditorGUILayout.Separator(); * }*/ EditorGUILayout.Separator(); if (m.type != type || m.content != content || m.revealFOW != revealFOW || m.revealDistance != revealDistance) { m.type = type; m.content = content; m.revealFOW = revealFOW; m.revealDistance = revealDistance; NJGEditorTools.RegisterUndo("Map Item Properties", m); } }
/// <summary> /// Draw the custom wizard. /// </summary> void OnGUI() { #if UNITY_4_3 EditorGUIUtility.LookLikeControls(80f); #else EditorGUIUtility.labelWidth = 80f; #endif bool close = false; GUILayout.Label(string.IsNullOrEmpty(mTitle) ? "Choose a Key" : mTitle, "LODLevelNotifyText"); NJGEditorTools.DrawSeparator(); GUILayout.BeginHorizontal(); GUILayout.Space(84f); string before = mSearch; string after = EditorGUILayout.TextField("", before, "SearchTextField"); mSearch = after; if (GUILayout.Button("", "SearchCancelButton", GUILayout.Width(18f))) { mSearch = ""; GUIUtility.keyboardControl = 0; } GUILayout.Space(84f); GUILayout.EndHorizontal(); GUIStyle centered = GUI.skin.GetStyle("Label"); centered.alignment = TextAnchor.UpperCenter; GUILayout.Label("Keys in use are disabled and marked as red", centered); centered.alignment = TextAnchor.UpperLeft; float w = 120f; float wPad = w + 5f; float h = 30f; float hPad = h + 5f; int columns = Mathf.FloorToInt(Screen.width / wPad); if (columns < 1) { columns = 1; } int offset = 0; Rect rect = new Rect(10f, 0, w, h); GUILayout.Space(10f); mPos = GUILayout.BeginScrollView(mPos); if (keyCodeMods != null) { KeyCode[] keyCodes = GetKeyCodes(mSearch); while (offset < keyCodes.Length) { GUILayout.BeginHorizontal(); { int col = 0; rect.x = 10f; for (; offset < keyCodes.Length; ++offset) { KeyCode key = keyCodes[offset]; bool isInUse = IsInUse(key); // Button comes first GUI.enabled = !isInUse; // && key != KeyCode.None if (key == mKeyCode) { GUI.enabled = true; } if (GUI.Button(rect, key.ToString())) { float delta = Time.realtimeSinceStartup - mClickTime; mClickTime = Time.realtimeSinceStartup; if (mKeyCode != key) { mKeyCode = key; if (mCallbackKeyCode != null) { mCallbackKeyCode(mKeyCode); } } else if (delta < 0.5f) { close = true; } } if (Event.current.type == EventType.Repaint) { // Draw the selection if (key == mKeyCode) { NJGEditorTools.DrawOutline(rect, new Color(0.4f, 1f, 0f, 1f)); } else if (isInUse) // && key != KeyCode.None { NJGEditorTools.DrawOutline(rect, Color.red); } } GUI.enabled = true; if (++col >= columns) { ++offset; break; } rect.x += wPad; } } GUILayout.EndHorizontal(); GUILayout.Space(hPad); rect.y += hPad; } } else { string[] keys = GetKeys(mSearch); while (offset < keys.Length) { GUILayout.BeginHorizontal(); { int col = 0; rect.x = 10f; for (; offset < keys.Length; ++offset) { string key = keys[offset]; bool isInUse = IsInUse(key); // Button comes first GUI.enabled = !isInUse; //&& key != "None" if (GUI.Button(rect, key)) { float delta = Time.realtimeSinceStartup - mClickTime; mClickTime = Time.realtimeSinceStartup; if (mKey != key) { mKey = key; if (mCallback != null) { mCallback(mKey); } } else if (delta < 0.5f) { close = true; } } if (Event.current.type == EventType.Repaint) { // Draw the selection if (key == mKey) { NJGEditorTools.DrawOutline(rect, new Color(0.4f, 1f, 0f, 1f)); } if (isInUse) // && key != "None" { NJGEditorTools.DrawOutline(rect, Color.red); } } GUI.enabled = true; if (++col >= columns) { ++offset; break; } rect.x += wPad; } } GUILayout.EndHorizontal(); GUILayout.Space(hPad); rect.y += hPad; } } GUILayout.EndScrollView(); if (close) { Close(); } }
/// <summary> /// Draw the inspector. /// </summary> public override void OnInspectorGUI() { #if UNITY_4_3 EditorGUIUtility.LookLikeControls(130f); #else EditorGUIUtility.labelWidth = 130f; #endif m = target as NJGMapZone; NJGEditorTools.DrawEditMap(); GUILayout.BeginHorizontal("AppToolbar"); EditorGUILayout.LabelField(new GUIContent("Zone Name Preview", ""), GUILayout.Width(130f)); GUI.contentColor = m.color; EditorGUILayout.LabelField(new GUIContent(m.zone, ""), EditorStyles.boldLabel); GUI.contentColor = Color.white; GUILayout.EndHorizontal(); string level = NJGEditorTools.DrawList("Level", NJGMapBase.instance.GetLevels(), m.level); string zone = NJGEditorTools.DrawList("Zone", NJGMapBase.instance.GetZones(m.level), m.zone); string triggerTag = EditorGUILayout.TagField("Trigger Tag", m.triggerTag); int colliderRadius = (int)EditorGUILayout.Slider("Collider Radius", m.colliderRadius, 1, 1000); bool generateOnTrigger = EditorGUILayout.Toggle("Generate On Trigger", m.generateOnTrigger); string name = "Zone - [" + NJGMapZone.list.IndexOf(m) + "] " + m.zone; if (m.name != name || m.level != level || m.zone != zone || m.triggerTag != triggerTag || m.colliderRadius != colliderRadius || m.generateOnTrigger != generateOnTrigger) { m.name = name; m.level = level; m.zone = zone; m.triggerTag = triggerTag; m.colliderRadius = colliderRadius; m.zoneCollider.radius = colliderRadius; m.generateOnTrigger = generateOnTrigger; NJGEditorTools.RegisterUndo("NJG Zone Update", m); } /*if (NJGMapBase.instance != null) * { * if (NJGMapBase.instance.atlas != null) * { * extraSpace = Mathf.Max(0f, extraSpace - 30f); * } * }*/ NJGEditorTools.DrawSeparator(); GUILayout.BeginHorizontal(); GUI.backgroundColor = Color.green; if (GUILayout.Button("Add New Zone")) { NJGMenu.AddMapZone(); } GUI.backgroundColor = Color.white; GUI.backgroundColor = Color.red; if (GUILayout.Button("Delete Zone")) { Delete(); } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); EditorGUILayout.Separator(); }