protected override void DrawNotFound() { UIMiniMapOnGUI mp = (UIMiniMapOnGUI)m; if (mp != null) { if (mp.planeRenderer == null) { mp.planeRenderer = mp.GetComponentInChildren <MeshRenderer>(); if (mp.planeRenderer == null) { GUI.backgroundColor = Color.red; EditorGUILayout.HelpBox("No MeshRenderer found.", MessageType.Error); GUI.backgroundColor = Color.white; /*if (GUILayout.Button("Create UITexture")) * { * NJGEditorTools.CreateUIMapTexture(m); * }*/ EditorGUILayout.Separator(); return; } } else { if (mp.material == null) { mp.material = NJGEditorTools.GetMaterial(m, true); } } } }
/// <summary> /// Draw widget's depth. /// </summary> void DrawDepth(bool isPrefab) { if (isPrefab) { return; } GUILayout.Space(2f); GUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel("Depth"); if (GUILayout.Button("Back", GUILayout.Width(60f))) { m.depth = m.depth - 1; NJGEditorTools.RegisterUndo("Map depth"); } int depth = EditorGUILayout.IntField(m.depth); if (m.depth != depth) { NJGEditorTools.RegisterUndo("Map depth"); m.depth = depth; } if (GUILayout.Button("Forward", GUILayout.Width(68f))) { m.depth = m.depth + 1; NJGEditorTools.RegisterUndo("Map depth"); } } GUILayout.EndHorizontal(); }
void DrawNotFound() { Map mp = (Map)m; if (mp != null) { if (mp.mapRenderer == null) { mp.mapRenderer = mp.GetComponentInChildren <RawImage>(); if (mp.mapRenderer == null) { GUI.backgroundColor = Color.red; EditorGUILayout.HelpBox("No UITexture found.", MessageType.Error); GUI.backgroundColor = Color.white; EditorGUILayout.Separator(); return; } } else { if (mp.material == null) { mp.material = NJGEditorTools.GetMaterial(m, true); } } } }
protected override void DrawFrameUI() { UIMiniMap mp = (UIMiniMap)m; mOverlay = (UISprite)EditorGUILayout.ObjectField("Frame Overlay", mp.overlay, typeof(UISprite), true); if (mp.overlay != mOverlay) { mp.overlay = mOverlay; NJGEditorTools.RegisterUndo("UIMiniMap Frame changed", mp); mp.UpdateAlignment(); } if (mp.overlay) { mBorderOffset = EditorGUILayout.IntField("Frame Offset", mp.overlayBorderOffset); if (mp.overlayBorderOffset != mBorderOffset) { mp.overlayBorderOffset = mBorderOffset; NJGEditorTools.RegisterUndo("UIMiniMap Frame Offset", mp); mp.UpdateAlignment(); } } //if (northIcon != null) // northIconOffset = EditorGUILayout.IntField(new GUIContent("North Icon Offset", "Adjust the north icon distance from map border"), m.northIconOffset); }
//[MenuItem("NJG MiniMap/Add NJG MiniMap %&m")] static public void AddNJGMiniMap() { GameObject parent = NJGEditorTools.SelectedRoot(); GameObject go = CreateLocalGameObject(true); go.AddComponent <NJG.NJGMapBase>(); go.name = "NJG MiniMap"; go.transform.parent = parent.transform; go.transform.localPosition = Vector3.zero; }
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 inspector. /// </summary> public override void OnInspectorGUI() { #if UNITY_4_3 EditorGUIUtility.LookLikeControls(90f); #else EditorGUIUtility.labelWidth = 90f; #endif m = target as UIWorldMapBase; PrefabType type = PrefabUtility.GetPrefabType(m.gameObject); if (m.material == null && m.planeRenderer != null) { m.material = NJGEditorTools.GetMaterial(m, false); } NJGEditorTools.DrawEditMap(); DrawNotFound(); GUILayout.BeginVertical(); EditorGUILayout.Separator(); mShader = (NJGMapBase.ShaderType)EditorGUILayout.EnumPopup("Shader Type", m.shaderType); if (mShader == NJGMapBase.ShaderType.ColorMask) { EditorGUILayout.HelpBox("Use the camera background color for masking", MessageType.Info); //m.colorMask = EditorGUILayout.ColorField("Color Mask", m.colorMask); } /*if (NJGMapBase.instance.fow.enabled && mShader != NJGMapBase.ShaderType.FOW) * { * m.shaderType = mShader = NJGMapBase.ShaderType.FOW; * m.material.shader = Shader.Find("NinjutsuGames/Map FOW"); * EditorUtility.SetDirty(m); * //EditorGUILayout.HelpBox("Fog of War is enabled\nIn order to make it work the shader type should be FOW\nIgnore this warning if you don't want to use FOW for this instance.", MessageType.Warning); * } * else if (!NJGMapBase.instance.fow.enabled && mShader == NJGMapBase.ShaderType.FOW) * { * m.shaderType = mShader = NJGMapBase.ShaderType.TextureMask; * m.material.shader = Shader.Find("NinjutsuGames/Map TextureMask"); * EditorUtility.SetDirty(m); * }*/ if (m.maskTexture == null) { m.maskTexture = mTempTex; } mMask = (Texture2D)EditorGUILayout.ObjectField("Map Mask", m.maskTexture, typeof(Texture2D), false); if (m.maskTexture != mMask) { m.maskTexture = mMask; m.material.SetTexture("_Mask", m.maskTexture); EditorUtility.SetDirty(m); } if (m.shaderType != mShader) { m.shaderType = mShader; Shader s = Shader.Find("NinjutsuGames/Map TextureMask"); switch (mShader) { case NJGMapBase.ShaderType.TextureMask: s = Shader.Find("NinjutsuGames/Map TextureMask"); NJGMapBase.instance.fow.enabled = false; break; case NJGMapBase.ShaderType.ColorMask: s = Shader.Find("NinjutsuGames/Map ColorMask"); m.material.SetColor("_MaskColor", NJGMapBase.instance.cameraBackgroundColor); NJGMapBase.instance.fow.enabled = false; break; case NJGMapBase.ShaderType.FOW: s = Shader.Find("NinjutsuGames/Map FOW"); NJGMapBase.instance.fow.enabled = true; break; } m.material.shader = s; if (m.planeRenderer != null) { if (Application.isPlaying) { m.planeRenderer.material.shader = s; } else { m.planeRenderer.sharedMaterial.shader = s; } } NJGEditorTools.RegisterUndo("UIWorldMap Shader Type", m); } EditorGUILayout.Separator(); GUILayout.EndVertical(); #if UNITY_4_3 EditorGUIUtility.LookLikeControls(120f); #else EditorGUIUtility.labelWidth = 120f; #endif bool shouldBeOn = NJGEditorTools.DrawHeader("UI Settings"); if (shouldBeOn) { Color c = Color.grey; c.a = 0.5f; GUI.backgroundColor = c; NJGEditorTools.BeginContents(); GUI.backgroundColor = Color.white; DrawDepth(type == PrefabType.Prefab); m.mapColor = EditorGUILayout.ColorField("Color", m.mapColor); if (mColor != m.mapColor) { mColor = m.mapColor; if (m.material != null) { m.material.color = m.mapColor; } EditorUtility.SetDirty(m); } GUILayout.BeginHorizontal(); EditorGUILayout.LabelField(new GUIContent("Culling Radius", "If icons get farther this radius they will dissapear"), GUILayout.Width(116f)); GUI.enabled = !m.calculateBorder; #if UNITY_4_3 mapBorderRadius = EditorGUILayout.FloatField(m.mapBorderRadius); #else mapBorderRadius = EditorGUILayout.FloatField(m.mapBorderRadius, GUILayout.Width(158f)); #endif GUI.enabled = true; calculateBorder = EditorGUILayout.Toggle(new GUIContent("Automatic", "Check this option if you want this value to be autmatically calculated at start."), m.calculateBorder); #if UNITY_4_3 EditorGUIUtility.LookLikeControls(120f); #else EditorGUIUtility.labelWidth = 120f; #endif GUILayout.EndHorizontal(); /*GUILayout.BeginHorizontal(); * EditorGUILayout.LabelField("Dimensions", GUILayout.Width(116f)); * EditorGUIUtility.LookLikeControls(10f); * mMapScale.x = EditorGUILayout.IntField((int)m.mapScale.x); * EditorGUIUtility.LookLikeControls(12f); * EditorGUILayout.LabelField("x", GUILayout.Width(15f)); * mMapScale.y = EditorGUILayout.IntField((int)m.mapScale.y); * EditorGUIUtility.LookLikeControls(80f); * GUILayout.EndHorizontal(); * * if (m.mapScale != mMapScale) * { * mMapScale.x = (int)mMapScale.x; * mMapScale.y = (int)mMapScale.y; * m.mapScale = mMapScale; * EditorUtility.SetDirty(m); * }*/ NJGEditorTools.EndContents(); EditorGUILayout.Separator(); } shouldBeOn = NJGEditorTools.DrawHeader("Zoom Settings"); if (shouldBeOn) { Color c = Color.grey; c.a = 0.5f; GUI.backgroundColor = c; NJGEditorTools.BeginContents(); GUI.backgroundColor = Color.white; GUILayout.BeginHorizontal(); mouseWheel = EditorGUILayout.Toggle("Mouse Wheel", m.mouseWheelEnabled, GUILayout.Width(140f)); GUI.contentColor = mouseWheel ? Color.cyan : Color.gray; EditorGUILayout.LabelField("Enable Mouse Wheel zoom."); GUI.contentColor = Color.white; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); zoom = EditorGUILayout.Slider(new GUIContent("Zoom", "Current zoom level"), m.zoom, m.minZoom, m.maxZoom); if (m.zoom != zoom) { if (!LeanTween.isTweening(m.gameObject)) { m.zoom = Mathf.Clamp(zoom, m.minZoom, m.maxZoom); } EditorUtility.SetDirty(m); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField(new GUIContent("Range", "Min and Max level of zoom"), GUILayout.Width(116.0f)); minZoom = EditorGUILayout.FloatField(m.minZoom, GUILayout.Width(25.0f)); EditorGUILayout.MinMaxSlider(ref minZoom, ref maxZoom, 1, 30); maxZoom = EditorGUILayout.FloatField(m.maxZoom, GUILayout.Width(25.0f)); GUILayout.EndHorizontal(); mEasing = (LeanTweenType)EditorGUILayout.EnumPopup("Easing", m.zoomEasing); if (m.zoomEasing != mEasing) { m.zoomEasing = mEasing; EditorUtility.SetDirty(m); } zoomSpeed = EditorGUILayout.Slider(new GUIContent("Speed", "Zoom animation speed"), m.zoomSpeed, 0, 2); ShowSelector("Zoom In Key", m.zoomInKey, delegate(KeyCode k) { m.keysInUse[0] = k; m.zoomInKey = k; EditorUtility.SetDirty(m); }); ShowSelector("Zoom Out Key", m.zoomOutKey, delegate(KeyCode k) { m.keysInUse[1] = k; m.zoomOutKey = k; EditorUtility.SetDirty(m); }); NJGEditorTools.EndContents(); EditorGUILayout.Separator(); } shouldBeOn = NJGEditorTools.DrawHeader("Panning Settings"); if (shouldBeOn) { Color c = Color.grey; c.a = 0.5f; GUI.backgroundColor = c; NJGEditorTools.BeginContents(); GUI.backgroundColor = Color.white; m.panning = EditorGUILayout.Toggle("Enabled", m.panning, GUILayout.Width(140f)); GUI.enabled = m.panning; m.panningEasing = (LeanTweenType)EditorGUILayout.EnumPopup("Easing", m.panningEasing); m.panningSpeed = EditorGUILayout.Slider(new GUIContent("Speed", "How fast the panning should move"), m.panningSpeed, 0, 5); m.panningSensitivity = EditorGUILayout.Slider(new GUIContent("Sensitivy", "How fast the panning should respond on mouse move"), m.panningSensitivity, 0.1f, 10f); m.panningMoveBack = EditorGUILayout.Toggle(new GUIContent("Return on Release", "Moves back the panning to its original position"), m.panningMoveBack, GUILayout.Width(140f)); GUI.enabled = true; EditorGUILayout.Separator(); if (mColor != m.mapColor) { mColor = m.mapColor; if (m.material != null) { m.material.color = m.mapColor; m.material.SetColor("_Color", m.mapColor); } } if (m.minZoom != minZoom || m.maxZoom != maxZoom || m.zoomSpeed != zoomSpeed || m.mouseWheelEnabled != mouseWheel || m.mapBorderRadius != mapBorderRadius || m.calculateBorder != calculateBorder) { m.mapBorderRadius = mapBorderRadius; m.calculateBorder = calculateBorder; m.minZoom = minZoom; m.maxZoom = maxZoom; m.zoomSpeed = zoomSpeed; m.mouseWheelEnabled = mouseWheel; EditorUtility.SetDirty(m); } NJGEditorTools.EndContents(); EditorGUILayout.Separator(); } /*if (mColorMask != m.colorMask) * { * mColorMask = m.colorMask; * if (m.uiTexture != null) m.uiTexture.material.SetColor("_MaskColor", m.colorMask); * }*/ if (GUI.changed) { EditorUtility.SetDirty(m); } }
/// <summary> /// Draw the inspector. /// </summary> public override void OnInspectorGUI() { #if UNITY_4_3 EditorGUIUtility.LookLikeControls(120f); #else EditorGUIUtility.labelWidth = 120f; #endif m = target as UIMiniMapBase; PrefabType type = PrefabUtility.GetPrefabType(m.gameObject); if (m.material == null) { m.material = NJGEditorTools.GetMaterial(m, true); } NJGEditorTools.DrawEditMap(); DrawNotFound(); targetObj = (Transform)EditorGUILayout.ObjectField(new GUIContent("Map Target", "The object that this map is going to follow"), m.target, typeof(Transform), true); if (m.target == null) { if (Application.isPlaying) { EditorGUILayout.HelpBox("No target has been found, assign the tag to your target or drag it manually to the target field.", MessageType.Warning); } else { EditorGUILayout.HelpBox("No target has been assigned, the target can be set automatically by using a tag or drag it manually to the target field.", MessageType.Warning); } } targetTag = EditorGUILayout.TagField(new GUIContent("Target Tag", "Assign a tag to auto search for the Map Target"), m.targetTag); GUILayout.BeginHorizontal(); limitBounds = EditorGUILayout.Toggle("Limit Map Bounds", m.limitBounds, GUILayout.Width(140f)); GUI.contentColor = limitBounds ? Color.cyan : Color.gray; EditorGUILayout.LabelField("Prevent map to display beyond borders."); GUI.contentColor = Color.white; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); rotateWithPlayer = EditorGUILayout.Toggle("Lock Rotation", m.rotateWithPlayer, GUILayout.Width(140f)); GUI.contentColor = rotateWithPlayer ? Color.cyan : Color.gray; EditorGUILayout.LabelField("Makes the map follow target rotation."); GUI.contentColor = Color.white; GUILayout.EndHorizontal(); ShowSelector("World Map Key", m.mapKey, delegate(KeyCode k) { m.keysInUse[2] = k; m.mapKey = k; EditorUtility.SetDirty(m); }); ShowSelector("Lock Key", m.lockKey, delegate(KeyCode k) { m.keysInUse[0] = k; m.lockKey = k; EditorUtility.SetDirty(m); }); mShader = (NJGMapBase.ShaderType)EditorGUILayout.EnumPopup("Shader Type", m.shaderType); if (mShader == NJGMapBase.ShaderType.ColorMask) { EditorGUILayout.HelpBox("Use the camera background color for masking", MessageType.Info); //m.colorMask = EditorGUILayout.ColorField("Color Mask", m.colorMask); } /*if (mShader != NJGMapBase.ShaderType.FOW) * { * NJGMapBase.instance.fow.enabled = true; * m.shaderType = mShader = NJGMapBase.ShaderType.FOW; * m.material.shader = Shader.Find("NinjutsuGames/Map FOW"); * NJGEditorTools.RegisterUndo("UIMiniMap Setting", m); * //EditorGUILayout.HelpBox("Fog of War is enabled\nIn order to make it work the shader type should be FOW\nIgnore this warning if you don't want to use FOW for this instance.", MessageType.Warning); * } * else * { * NJGMapBase.instance.fow.enabled = false; * m.shaderType = mShader = NJGMapBase.ShaderType.TextureMask; * m.material.shader = Shader.Find("NinjutsuGames/Map TextureMask"); * NJGEditorTools.RegisterUndo("UIMiniMap Setting", m); * }*/ if (m.shaderType != mShader) { m.shaderType = mShader; Shader s = Shader.Find("NinjutsuGames/Map TextureMask"); switch (mShader) { case NJGMapBase.ShaderType.TextureMask: s = Shader.Find("NinjutsuGames/Map TextureMask"); NJGMapBase.instance.fow.enabled = false; break; case NJGMapBase.ShaderType.ColorMask: s = Shader.Find("NinjutsuGames/Map ColorMask"); m.material.SetColor("_MaskColor", NJGMapBase.instance.cameraBackgroundColor); NJGMapBase.instance.fow.enabled = false; break; case NJGMapBase.ShaderType.FOW: s = Shader.Find("NinjutsuGames/Map FOW"); NJGMapBase.instance.fow.enabled = true; break; } m.material.shader = s; if (m.planeRenderer != null) { if (Application.isPlaying) { m.planeRenderer.material.shader = s; } else { m.planeRenderer.sharedMaterial.shader = s; } } NJGEditorTools.RegisterUndo("UIMiniMap Shader Type", m); } m.maskTexture = (Texture2D)EditorGUILayout.ObjectField("Mask", m.maskTexture, typeof(Texture2D), false); if (mMask != m.maskTexture) { mMask = m.maskTexture; m.material.SetTexture("_Mask", m.maskTexture); NJGEditorTools.RegisterUndo("UIMiniMap Setting", m); } bool shouldBeOn = NJGEditorTools.DrawHeader("UI Settings"); if (shouldBeOn) { Color c = Color.grey; c.a = 0.5f; GUI.backgroundColor = c; NJGEditorTools.BeginContents(); GUI.backgroundColor = Color.white; DrawDepth(type == PrefabType.Prefab); mPivot = (UIMiniMapBase.Pivot)EditorGUILayout.EnumPopup("Alignment", m.pivot); if (m.pivot != mPivot) { m.pivot = mPivot; EditorUtility.SetDirty(m); m.UpdateAlignment(); } m.mapColor = EditorGUILayout.ColorField("Color", m.mapColor); if (mColor != m.mapColor) { mColor = m.mapColor; if (m.material != null) { m.material.color = m.mapColor; } NJGEditorTools.RegisterUndo("UIMiniMap Setting", m); } /*GUILayout.BeginHorizontal(); * EditorGUILayout.LabelField("Dimensions", GUILayout.Width(116f)); * EditorGUIUtility.LookLikeControls(10f); * mMapScale.x = EditorGUILayout.IntField((int)m.mapScale.x); * EditorGUIUtility.LookLikeControls(12f); * EditorGUILayout.LabelField("x", GUILayout.Width(15f)); * mMapScale.y = EditorGUILayout.IntField((int)m.mapScale.y); * EditorGUIUtility.LookLikeControls(80f); * GUILayout.EndHorizontal();*/ mMapScale = EditorGUILayout.Vector2Field("Dimensions", m.mapScale); if (m.mapScale != mMapScale) { mMapScale.x = (int)mMapScale.x; mMapScale.y = (int)mMapScale.y; m.mapScale = mMapScale; NJGEditorTools.RegisterUndo("UIMiniMap Setting", m); m.UpdateAlignment(); } /*GUILayout.BeginHorizontal(); * EditorGUILayout.LabelField("Margin", GUILayout.Width(116f)); * EditorGUIUtility.LookLikeControls(10f); * mMargin.x = EditorGUILayout.IntField((int)m.margin.x); * EditorGUIUtility.LookLikeControls(12f); * EditorGUILayout.LabelField("x", GUILayout.Width(15f)); * mMargin.y = EditorGUILayout.IntField((int)m.margin.y); * EditorGUIUtility.LookLikeControls(80f); * GUILayout.EndHorizontal();*/ mMargin = EditorGUILayout.Vector2Field("Margin", m.margin); if (m.margin != mMargin) { m.margin.x = (int)mMargin.x; m.margin.y = (int)mMargin.y; NJGEditorTools.RegisterUndo("UIMiniMap Setting", m); m.UpdateAlignment(); } GUILayout.BeginHorizontal(); EditorGUILayout.LabelField(new GUIContent("Culling Radius", "If icons get farther this radius they will dissapear"), GUILayout.Width(116f)); GUI.enabled = !m.calculateBorder; #if UNITY_4_3 mapBorderRadius = EditorGUILayout.FloatField(m.mapBorderRadius); #else mapBorderRadius = EditorGUILayout.FloatField(m.mapBorderRadius, GUILayout.Width(158f)); #endif GUI.enabled = true; calculateBorder = EditorGUILayout.Toggle(new GUIContent("Automatic", "Check this option if you want this value to be autmatically calculated at start."), m.calculateBorder); #if UNITY_4_3 EditorGUIUtility.LookLikeControls(120f); #else EditorGUIUtility.labelWidth = 120f; #endif GUILayout.EndHorizontal(); DrawFrameUI(); northIcon = (GameObject)EditorGUILayout.ObjectField(new GUIContent("North Icon", "Optional north icon. Will be automatically placed if its assigned."), m.northIcon, typeof(GameObject), true); //if (northIcon != null) // northIconOffset = EditorGUILayout.IntField(new GUIContent("North Icon Offset", "Adjust the north icon distance from map border"), m.northIconOffset); NJGEditorTools.EndContents(); EditorGUILayout.Separator(); } shouldBeOn = NJGEditorTools.DrawHeader("Zoom Settings"); if (shouldBeOn) { Color c = Color.grey; c.a = 0.5f; GUI.backgroundColor = c; NJGEditorTools.BeginContents(); GUI.backgroundColor = Color.white; //EditorGUILayout.LabelField("Zoom Settings", EditorStyles.boldLabel); GUILayout.BeginHorizontal(); mouseWheel = EditorGUILayout.Toggle("Mouse Wheel", m.mouseWheelEnabled, GUILayout.Width(140f)); GUI.contentColor = mouseWheel ? Color.cyan : Color.gray; EditorGUILayout.LabelField("Enable Mouse Wheel zoom."); GUI.contentColor = Color.white; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); zoom = EditorGUILayout.Slider(new GUIContent("Zoom", "Current zoom level"), m.zoom, m.minZoom, m.maxZoom); if (m.zoom != zoom) { if (!LeanTween.isTweening(m.gameObject)) { m.zoom = Mathf.Clamp(zoom, m.minZoom, m.maxZoom); } NJGEditorTools.RegisterUndo("UIMiniMap Setting", m); } GUILayout.EndHorizontal(); zoomAmount = EditorGUILayout.Slider(new GUIContent("Amount", "How much should zoom in/out when zoom function is called."), m.zoomAmount, 0.01f, 5); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField(new GUIContent("Range", "Min and Max level of zoom"), GUILayout.Width(116.0f)); minZoom = EditorGUILayout.FloatField(m.minZoom, GUILayout.Width(25.0f)); EditorGUILayout.MinMaxSlider(ref minZoom, ref maxZoom, 1, 30); maxZoom = EditorGUILayout.FloatField(m.maxZoom, GUILayout.Width(25.0f)); //minZoom = Mathf.Round(minZoom); //maxZoom = Mathf.Round(maxZoom); GUILayout.EndHorizontal(); mEasing = (LeanTweenType)EditorGUILayout.EnumPopup("Easing", m.zoomEasing); if (m.zoomEasing != mEasing) { m.zoomEasing = mEasing; NJGEditorTools.RegisterUndo("UIMiniMap Setting", m); } zoomSpeed = EditorGUILayout.Slider(new GUIContent("Speed", "Zoom animation speed"), m.zoomSpeed, 0f, 2f); ShowSelector("Zoom In Key", m.zoomInKey, delegate(KeyCode k) { m.keysInUse[0] = k; m.zoomInKey = k; NJGEditorTools.RegisterUndo("UIMiniMap Setting", m); }); ShowSelector("Zoom Out Key", m.zoomOutKey, delegate(KeyCode k) { m.keysInUse[1] = k; m.zoomOutKey = k; NJGEditorTools.RegisterUndo("UIMiniMap Setting", m); }); NJGEditorTools.EndContents(); EditorGUILayout.Separator(); } shouldBeOn = NJGEditorTools.DrawHeader("Panning Settings"); if (shouldBeOn) { Color c = Color.grey; c.a = 0.5f; GUI.backgroundColor = c; NJGEditorTools.BeginContents(); GUI.backgroundColor = Color.white; panning = EditorGUILayout.Toggle("Enabled", m.panning, GUILayout.Width(140f)); GUI.enabled = panning; panningEase = (LeanTweenType)EditorGUILayout.EnumPopup("Easing", m.panningEasing); panningSpeed = EditorGUILayout.Slider(new GUIContent("Speed", "How fast the panning should move"), m.panningSpeed, 0, 5); panningSensitivity = EditorGUILayout.Slider(new GUIContent("Sensitivy", "How fast the panning should respond on mouse move"), m.panningSensitivity, 0.1f, 10f); panningMoveBack = EditorGUILayout.Toggle(new GUIContent("Return on Release", "Moves back the panning to its original position"), m.panningMoveBack, GUILayout.Width(140f)); GUI.enabled = true; NJGEditorTools.EndContents(); EditorGUILayout.Separator(); } if (m.limitBounds != limitBounds || m.rotateWithPlayer != rotateWithPlayer || m.target != targetObj || m.targetTag != targetTag || m.minZoom != minZoom || m.maxZoom != maxZoom || m.zoomSpeed != zoomSpeed || m.mapBorderRadius != mapBorderRadius || m.northIcon != northIcon || //m.northIconOffset != northIconOffset || m.calculateBorder != calculateBorder || m.mouseWheelEnabled != mouseWheel || m.panning != panning || m.panningSpeed != panningSpeed || m.panningEasing != panningEase || m.panningMoveBack != panningMoveBack || m.panningSensitivity != panningSensitivity || m.zoomAmount != zoomAmount) { m.zoomAmount = zoomAmount; m.panningSensitivity = panningSensitivity; m.panningMoveBack = panningMoveBack; m.panning = panning; m.panningSpeed = panningSpeed; m.panningEasing = panningEase; m.limitBounds = limitBounds; m.rotateWithPlayer = rotateWithPlayer; m.target = targetObj; m.targetTag = targetTag; m.minZoom = minZoom; m.maxZoom = maxZoom; m.zoomSpeed = zoomSpeed; m.mapBorderRadius = mapBorderRadius; m.northIcon = northIcon; //m.northIconOffset = northIconOffset; m.calculateBorder = calculateBorder; m.mouseWheelEnabled = mouseWheel; NJGEditorTools.RegisterUndo("Changed Minimap Settings", m); } if (GUI.changed) { EditorUtility.SetDirty(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(); }
/// <summary> /// Draw the inspector. /// </summary> public override void OnInspectorGUI() { EditorGUIUtility.labelWidth = 120f; m = target as Map; //if (GUI.changed) // EditorUtility.SetDirty(mp); //PrefabType type = PrefabUtility.GetPrefabType(m.gameObject); if (m.material == null) { m.material = NJGEditorTools.GetMaterial(m, true); } NJGEditorTools.DrawEditMap(); DrawNotFound(); Map.Type mapType = (Map.Type)EditorGUILayout.EnumPopup("Map Type", m.mapType); if (m.mapType != mapType) { m.mapType = mapType; NJGEditorTools.RegisterUndo("Map Type", m); } targetObj = (Transform)EditorGUILayout.ObjectField(new GUIContent("Map Target", "The object that this map is going to follow"), m.target, typeof(Transform), true); if (m.target == null) { if (Application.isPlaying) { EditorGUILayout.HelpBox("No target has been found, assign the tag to your target or drag it manually to the target field.", MessageType.Warning); } else { EditorGUILayout.HelpBox("No target has been assigned, the target can be set automatically by using a tag or drag it manually to the target field.", MessageType.Warning); } } targetTag = EditorGUILayout.TagField(new GUIContent("Target Tag", "Assign a tag to auto search for the Map Target"), m.targetTag); GUILayout.BeginHorizontal(); bool isVisible = EditorGUILayout.Toggle("Visible", m.isVisible, GUILayout.Width(140f)); GUI.contentColor = isVisible ? Color.cyan : Color.gray; EditorGUILayout.LabelField("Toggle visbility."); GUI.contentColor = Color.white; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); limitBounds = EditorGUILayout.Toggle("Map Bounds", m.limitBounds, GUILayout.Width(140f)); GUI.contentColor = limitBounds ? Color.cyan : Color.gray; EditorGUILayout.LabelField("Prevent map to display beyond borders."); GUI.contentColor = Color.white; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); rotateWithPlayer = EditorGUILayout.Toggle("Lock Rotation", m.rotateWithPlayer, GUILayout.Width(140f)); GUI.contentColor = rotateWithPlayer ? Color.cyan : Color.gray; EditorGUILayout.LabelField("Makes the map follow target rotation."); GUI.contentColor = Color.white; GUILayout.EndHorizontal(); ShowSelector("Toggle Key", m.toggleKey, delegate(KeyCode k) { NJGMap.instance.keysInUse[0] = m.toggleKey = k; EditorUtility.SetDirty(m); }); ShowSelector("Lock Key", m.lockKey, delegate(KeyCode k) { NJGMap.instance.keysInUse[1] = m.lockKey = k; EditorUtility.SetDirty(m); }); /*mShader = (NJGMap.ShaderType)EditorGUILayout.EnumPopup("Shader Type", m.shaderType); * if (mShader == NJGMap.ShaderType.ColorMask) * { * EditorGUILayout.HelpBox("Use the camera background color for masking", MessageType.Info); * //m.colorMask = EditorGUILayout.ColorField("Color Mask", m.colorMask); * } * * if (m.shaderType != mShader) * { * m.shaderType = mShader; * Shader s = Shader.Find("Ninjutsu Games/Map TextureMask"); * switch (mShader) * { * case NJGMap.ShaderType.TextureMask: * s = Shader.Find("Ninjutsu Games/Map TextureMask"); * NJGMap.instance.fow.enabled = false; * break; * case NJGMap.ShaderType.ColorMask: * s = Shader.Find("Ninjutsu Games/Map ColorMask"); * m.material.SetColor("_MaskColor", NJGMap.instance.cameraBackgroundColor); * NJGMap.instance.fow.enabled = false; * break; * case NJGMap.ShaderType.FOW: * s = Shader.Find("Ninjutsu Games/Map FOW"); * NJGMap.instance.fow.enabled = true; * break; * } * m.material.shader = s; * if (m.mapRenderer != null) * { * m.mapRenderer.material.shader = s; * } * m.mapRenderer.enabled = false; * m.mapRenderer.enabled = true; * NJGEditorTools.RegisterUndo("Map Shader Type", m); * }*/ bool shouldBeOn = NJGEditorTools.DrawHeader("UI Settings"); if (shouldBeOn) { Color c = Color.grey; c.a = 0.5f; GUI.backgroundColor = c; NJGEditorTools.BeginContents(); GUI.backgroundColor = Color.white; /*mPivot = (Map.Pivot)EditorGUILayout.EnumPopup("Alignment", m.pivot); * if (m.pivot != mPivot) * { * m.pivot = mPivot; * EditorUtility.SetDirty(m); * m.UpdateAlignment(); * }*/ Sprite mMask = (Sprite)EditorGUILayout.ObjectField("Mask", m.maskTexture, typeof(Sprite), false); if (mMask != m.maskTexture) { m.maskTexture = mMask; m.material.SetTexture("_Mask", m.maskTexture.texture); m.mapRenderer.material.SetTexture("_Mask", m.maskTexture.texture); NJGEditorTools.RegisterUndo("Map Setting", m); } EditorGUILayout.Space(); m.mapColor = EditorGUILayout.ColorField("Color", m.mapColor); if (mColor != m.mapColor) { mColor = m.mapColor; if (m.material != null) { m.material.color = m.mapColor; } m.mapRenderer.enabled = false; m.mapRenderer.enabled = true; NJGEditorTools.RegisterUndo("Map Setting", m); } //mMapScale = EditorGUILayout.Vector2Field("Dimensions", m.mapScale); /*if (m.mapScale != mMapScale) * { * mMapScale.x = (int)mMapScale.x; * mMapScale.y = (int)mMapScale.y; * m.mapScale = mMapScale; * NJGEditorTools.RegisterUndo("Map Setting", m); * //m.UpdateAlignment(); * }*/ /*mMargin = EditorGUILayout.Vector2Field("Margin", m.margin); * * if (m.margin != mMargin) * { * m.margin.x = (int)mMargin.x; * m.margin.y = (int)mMargin.y; * NJGEditorTools.RegisterUndo("Map Setting", m); * m.UpdateAlignment(); * }*/ GUILayout.BeginHorizontal(); //EditorGUILayout.LabelField(new GUIContent("Culling Radius", "If icons get farther this radius they will dissapear"), GUILayout.Width(116f)); //GUI.enabled = !m.calculateBorder; //mapBorderRadius = EditorGUILayout.FloatField(m.mapBorderRadius, GUILayout.Width(158f)); //GUI.enabled = true; //calculateBorder = EditorGUILayout.Toggle(new GUIContent("Automatic", "Check this option if you want this value to be autmatically calculated at start."), m.calculateBorder); EditorGUIUtility.labelWidth = 120f; GUILayout.EndHorizontal(); northIcon = (GameObject)EditorGUILayout.ObjectField(new GUIContent("North Icon", "Optional north icon. Will be automatically placed if its assigned."), m.northIcon, typeof(GameObject), true); //if (northIcon != null) // northIconOffset = EditorGUILayout.IntField(new GUIContent("North Icon Offset", "Adjust the north icon distance from map border"), m.northIconOffset); NJGEditorTools.EndContents(); EditorGUILayout.Separator(); } shouldBeOn = NJGEditorTools.DrawHeader("Zoom Settings"); if (shouldBeOn) { Color c = Color.grey; c.a = 0.5f; GUI.backgroundColor = c; NJGEditorTools.BeginContents(); GUI.backgroundColor = Color.white; //EditorGUILayout.LabelField("Zoom Settings", EditorStyles.boldLabel); GUILayout.BeginHorizontal(); mouseWheel = EditorGUILayout.Toggle("Mouse Wheel", m.mouseWheelEnabled, GUILayout.Width(140f)); GUI.contentColor = mouseWheel ? Color.cyan : Color.gray; EditorGUILayout.LabelField("Enable Mouse Wheel zoom."); GUI.contentColor = Color.white; GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); zoom = EditorGUILayout.Slider(new GUIContent("Zoom", "Current zoom level"), m.zoom, m.minZoom, m.maxZoom); if (m.zoom != zoom) { if (!LeanTween.isTweening(m.gameObject)) { m.zoom = Mathf.Clamp(zoom, m.minZoom, m.maxZoom); } NJGEditorTools.RegisterUndo("Map Setting", m); } GUILayout.EndHorizontal(); zoomAmount = EditorGUILayout.Slider(new GUIContent("Amount", "How much should zoom in/out when zoom function is called."), m.zoomAmount, 0.01f, 5); GUILayout.BeginHorizontal(); EditorGUILayout.LabelField(new GUIContent("Range", "Min and Max level of zoom"), GUILayout.Width(116.0f)); minZoom = EditorGUILayout.FloatField(m.minZoom, GUILayout.Width(25.0f)); EditorGUILayout.MinMaxSlider(ref minZoom, ref maxZoom, 1, 30); maxZoom = EditorGUILayout.FloatField(m.maxZoom, GUILayout.Width(25.0f)); //minZoom = Mathf.Round(minZoom); //maxZoom = Mathf.Round(maxZoom); GUILayout.EndHorizontal(); mEasing = (LeanTweenType)EditorGUILayout.EnumPopup("Easing", m.zoomEasing); if (m.zoomEasing != mEasing) { m.zoomEasing = mEasing; NJGEditorTools.RegisterUndo("Map Setting", m); } zoomSpeed = EditorGUILayout.Slider(new GUIContent("Speed", "Zoom animation speed"), m.zoomSpeed, 0f, 2f); ShowSelector("Zoom In Key", m.zoomInKey, delegate(KeyCode k) { NJGMap.instance.keysInUse[2] = m.zoomInKey = k; NJGEditorTools.RegisterUndo("Map Setting", m); }); ShowSelector("Zoom Out Key", m.zoomOutKey, delegate(KeyCode k) { NJGMap.instance.keysInUse[3] = m.zoomOutKey = k; NJGEditorTools.RegisterUndo("Map Setting", m); }); NJGEditorTools.EndContents(); EditorGUILayout.Separator(); } shouldBeOn = NJGEditorTools.DrawHeader("Panning Settings"); if (shouldBeOn) { Color c = Color.grey; c.a = 0.5f; GUI.backgroundColor = c; NJGEditorTools.BeginContents(); GUI.backgroundColor = Color.white; panning = EditorGUILayout.Toggle("Enabled", m.panning, GUILayout.Width(140f)); GUI.enabled = panning; panningEase = (LeanTweenType)EditorGUILayout.EnumPopup("Easing", m.panningEasing); panningSpeed = EditorGUILayout.Slider(new GUIContent("Speed", "How fast the panning should move"), m.panningSpeed, 0, 5); panningSensitivity = EditorGUILayout.Slider(new GUIContent("Sensitivy", "How fast the panning should respond on mouse move"), m.panningSensitivity, 0.1f, 10f); panningMoveBack = EditorGUILayout.Toggle(new GUIContent("Return on Release", "Moves back the panning to its original position"), m.panningMoveBack, GUILayout.Width(140f)); GUI.enabled = true; NJGEditorTools.EndContents(); EditorGUILayout.Separator(); } if (m.limitBounds != limitBounds || m.rotateWithPlayer != rotateWithPlayer || m.target != targetObj || m.targetTag != targetTag || m.minZoom != minZoom || m.maxZoom != maxZoom || m.zoomSpeed != zoomSpeed || m.northIcon != northIcon || //m.northIconOffset != northIconOffset || m.mouseWheelEnabled != mouseWheel || m.panning != panning || m.panningSpeed != panningSpeed || m.panningEasing != panningEase || m.panningMoveBack != panningMoveBack || m.panningSensitivity != panningSensitivity || m.zoomAmount != zoomAmount || m.isVisible != isVisible) { m.zoomAmount = zoomAmount; m.panningSensitivity = panningSensitivity; m.panningMoveBack = panningMoveBack; m.panning = panning; m.panningSpeed = panningSpeed; m.panningEasing = panningEase; m.limitBounds = limitBounds; m.rotateWithPlayer = rotateWithPlayer; m.target = targetObj; m.targetTag = targetTag; m.minZoom = minZoom; m.maxZoom = maxZoom; m.zoomSpeed = zoomSpeed; m.northIcon = northIcon; //m.northIconOffset = northIconOffset; m.mouseWheelEnabled = mouseWheel; m.isVisible = isVisible; NJGEditorTools.RegisterUndo("Changed Minimap Settings", m); } if (m.mapRenderer.texture == null && !Application.isPlaying) { MapRenderer.instance.cam.targetTexture = UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/Ninjutsu Games/NJG MiniMap/Common/Materials/MapPreview.renderTexture", typeof(RenderTexture)) as RenderTexture; RenderTexture.active = MapRenderer.instance.cam.targetTexture; m.mapRenderer.texture = MapRenderer.instance.cam.targetTexture; MapRenderer.instance.cam.Render(); MapRenderer.instance.ConfigCamera(); MapRenderer.instance.cam.Render(); } else if (Application.isPlaying && MapRenderer.instance.cam.targetTexture != null) { MapRenderer.instance.cam.targetTexture = RenderTexture.active = null; } if (!Application.isPlaying && Time.time > lastRender) { lastRender = Time.time + 1f; MapRenderer.instance.cam.Render(); MapRenderer.instance.ConfigCamera(); MapRenderer.instance.cam.Render(); Debug.Log("ReRender"); } if (GUI.changed) { EditorUtility.SetDirty(m); } }
static void Create() { GameObject go = CreateUIElementRoot("Minimap", new Vector2(250, 250)); RectTransform rt = go.GetComponent <RectTransform>(); rt.anchorMin = Vector2.one; rt.anchorMax = Vector2.one; rt.pivot = Vector2.one; rt.anchoredPosition = new Vector2(rt.anchoredPosition.x - 10, rt.anchoredPosition.y - 10); Map map = go.AddComponent <Map>(); map.material = NJGEditorTools.GetMaterial(map, true); Image img = map.iconRoot.gameObject.GetComponent <Image>(); img.sprite = NJGEditorTools.GetDefaultMask(map == Map.miniMap); GameObject bg = new GameObject("Background"); bg.AddComponent <Image>().color = new Color(80f / 255f, 80f / 255f, 80f / 255f, 1f); bg.transform.SetParent(go.transform, false); bg.transform.SetAsFirstSibling(); rt = bg.GetComponent <RectTransform>(); rt.anchorMin = Vector2.zero; rt.anchorMax = Vector2.one; rt.sizeDelta = Vector2.zero; Canvas canvas = Selection.activeGameObject ? Selection.activeGameObject.GetComponent <Canvas>() : null; if (!canvas) { canvas = Object.FindObjectOfType <Canvas>(); } if (!canvas) { canvas = new GameObject("Canvas", typeof(Canvas), typeof(GraphicRaycaster), typeof(CanvasScaler)).GetComponent <Canvas>(); canvas.gameObject.layer = LayerMask.NameToLayer("UI"); canvas.renderMode = RenderMode.ScreenSpaceCamera; Undo.RegisterCreatedObjectUndo(canvas, "Create " + canvas.name); } if (canvas.worldCamera == null) { Camera cam = new GameObject("UICamera", typeof(Camera)).GetComponent <Camera>(); cam.cullingMask = 1 << LayerMask.NameToLayer("UI"); cam.clearFlags = CameraClearFlags.Depth; cam.orthographic = true; canvas.worldCamera = cam; } if (canvas) { go.transform.SetParent(canvas.transform, false); } EventSystem esys = Object.FindObjectOfType <EventSystem>(); if (esys == null) { var eventSystem = new GameObject("EventSystem"); GameObjectUtility.SetParentAndAlign(eventSystem, null); esys = eventSystem.AddComponent <EventSystem>(); eventSystem.AddComponent <StandaloneInputModule>(); //eventSystem.AddComponent<TouchInputModule>(); Undo.RegisterCreatedObjectUndo(eventSystem, "Create " + eventSystem.name); } Button zoomIn = CreateButton("Button - ZoomIn", "+", new Vector2(30, 30)); zoomIn.gameObject.AddComponent <ButtonZoom>().zoomIn = true; zoomIn.gameObject.GetComponent <ButtonZoom>().map = map; zoomIn.transform.SetParent(go.transform, false); rt = zoomIn.gameObject.GetComponent <RectTransform>(); rt.pivot = Vector2.one; rt.anchorMin = Vector2.one; rt.anchorMax = Vector2.one; Button zoomOut = CreateButton("Button - ZoomOut", "-", new Vector2(30, 30)); zoomOut.gameObject.AddComponent <ButtonZoom>().zoomIn = false; zoomOut.gameObject.GetComponent <ButtonZoom>().map = map; zoomOut.transform.SetParent(go.transform, false); rt = zoomOut.gameObject.GetComponent <RectTransform>(); rt.pivot = Vector2.one; rt.anchorMin = Vector2.one; rt.anchorMax = Vector2.one; rt.anchoredPosition = new Vector2(rt.anchoredPosition.x, rt.anchoredPosition.y - 32); Button lockMap = CreateButton("Button - Lock", "L", new Vector2(30, 30)); lockMap.gameObject.AddComponent <ButtonLockMap>().map = map; lockMap.transform.SetParent(go.transform, false); rt = lockMap.gameObject.GetComponent <RectTransform>(); rt.pivot = new Vector2(0, 1); rt.anchorMin = new Vector2(0, 1); rt.anchorMax = new Vector2(0, 1); Text text = new GameObject("WorldName", typeof(Text), typeof(WorldName)).GetComponent <Text>(); text.transform.SetParent(go.transform, false); SetDefaultTextValues(text); text.text = "World Name"; text.gameObject.AddComponent <Outline>(); text.fontSize = 18; text.alignment = TextAnchor.MiddleCenter; rt = text.gameObject.GetComponent <RectTransform>(); rt.pivot = new Vector2(0.5f, 1); rt.anchorMin = new Vector2(0, 1); rt.anchorMax = new Vector2(1, 1); rt.sizeDelta = new Vector2(-80f, 60f); text = new GameObject("MapCoords", typeof(Text), typeof(MapCoords)).GetComponent <Text>(); text.transform.SetParent(go.transform, false); SetDefaultTextValues(text); text.text = "x:0 y:0"; text.gameObject.AddComponent <Outline>(); text.fontSize = 14; text.alignment = TextAnchor.LowerCenter; rt = text.gameObject.GetComponent <RectTransform>(); rt.pivot = new Vector2(0.5f, 1); rt.anchorMin = new Vector2(0.5f, 0); rt.anchorMax = new Vector2(0.5f, 0); rt.sizeDelta = new Vector2(100f, 20f); rt.anchoredPosition = new Vector2(0, 25); SetLayerRecursively(go, LayerMask.NameToLayer("UI")); Undo.RegisterCreatedObjectUndo(go, "Create Minimap"); Selection.activeGameObject = go; }
/// <summary> /// Draw the inspector. /// </summary> public override void OnInspectorGUI() { #if UNITY_4_3 EditorGUIUtility.LookLikeControls(130f); #else EditorGUIUtility.labelWidth = 130f; #endif m = target as MapZone; if (renderLayers == null) { renderLayers = serializedObject.FindProperty("renderLayers"); } 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", NJGMap.instance.GetLevels(), m.level); string zone = NJGEditorTools.DrawList("Zone", NJGMap.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); GUILayout.BeginHorizontal(); bool generateOnTrigger = EditorGUILayout.Toggle("Render On Trigger", m.generateOnTrigger, GUILayout.Width(140f)); GUI.contentColor = generateOnTrigger ? Color.cyan : Color.gray; EditorGUILayout.LabelField("Render the map when the target collides with this zone."); GUI.contentColor = Color.white; GUILayout.EndHorizontal(); GUI.enabled = generateOnTrigger; GUILayout.BeginHorizontal(); bool useZoneBounds = EditorGUILayout.Toggle("Use Zone Bounds", m.useZoneBounds, GUILayout.Width(140f)); GUI.contentColor = useZoneBounds ? Color.cyan : Color.gray; EditorGUILayout.LabelField("Use this zone bounds to render the map."); GUI.contentColor = Color.white; GUILayout.EndHorizontal(); EditorGUILayout.PropertyField(renderLayers, new GUIContent("Render Layers", "Which layers are going to be used for rendering.")); GUILayout.BeginHorizontal(); float zoom = EditorGUILayout.Slider(new GUIContent("Zoom", "Custom zoom level"), m.zoom, m.minZoom, m.maxZoom); if (m.zoom != zoom) { m.zoom = Mathf.Clamp(zoom, m.minZoom, m.maxZoom); NJGEditorTools.RegisterUndo("NJGZone Settings", m); } GUILayout.EndHorizontal(); GUI.enabled = true; string name = "Zone - [" + MapZone.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.useZoneBounds != useZoneBounds) { m.name = name; m.level = level; m.zone = zone; m.triggerTag = triggerTag; m.colliderRadius = colliderRadius; m.zoneCollider.radius = colliderRadius; m.generateOnTrigger = generateOnTrigger; m.useZoneBounds = useZoneBounds; NJGEditorTools.RegisterUndo("NJG Zone Update", m); } /*if (NJGMap.instance != null) * { * if (NJGMap.instance.atlas != null) * { * extraSpace = Mathf.Max(0f, extraSpace - 30f); * } * }*/ EditorGUILayout.Separator(); 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(); }