Example #1
0
 protected void Save(bool force)
 {
     if (GUI.changed || force)
     {
         GenerateMapTools.RegisterUndo("NJG Map Settings", m);
     }
 }
Example #2
0
    void DrawGeneralUI()
    {
        EditorGUILayout.Separator();
        EditorGUILayout.LabelField("General Settings", EditorStyles.boldLabel);
        EditorGUILayout.Separator();

        mWorldName = EditorGUILayout.TextField(new GUIContent("Level Name", "Input level name!!!."), m.mapLevel);
        if (m.mapLevel != mWorldName)
        {
            m.mapLevel = mWorldName;
            GenerateMapTools.RegisterUndo("World name", m);
        }

        GUILayout.Space(5);
        bool dontDestroy = EditorGUILayout.Toggle("Dont Destroy", m.dontDestroy);

        m.dontDestroy = dontDestroy;

        GUILayout.Space(5);
        bool showBounds = EditorGUILayout.Toggle("Display Bounds", m.showBounds);

        if (m.showBounds != showBounds)
        {
            m.showBounds = showBounds;
            m.UpdateBounds();
            GenerateMapTools.RegisterUndo("Map bounds", m);
        }


        GUILayout.Space(5);
        GenerateMapTools.BeginContents();
        EditorGUILayout.PropertyField(renderLayers, new GUIContent("Render Layers", "Which layers are going to be used for rendering."));
        EditorGUILayout.PropertyField(boundLayers, new GUIContent("Boundary Layers", "Which layers are going to be used for bounds calculation."));
        GenerateMapTools.EndContents();


        EditorGUILayout.BeginVertical();
        GUILayout.Space(20f);
        EditorGUIUtility.labelWidth = 100f;
        GUI.enabled         = !m.generateMapTexture && !Application.isPlaying || m.generateMapTexture && Application.isPlaying;
        GUI.backgroundColor = !m.generateMapTexture || m.generateMapTexture && Application.isPlaying ? Color.green : Color.gray;
        if (GUILayout.Button(new GUIContent(m.generateMapTexture ? (Application.isPlaying ? "Regenerate" : "Click Play to generate") : "Generate New Map Texture", "Click to generate map texture"), GUILayout.Height(40f)))
        {
            Resources.UnloadUnusedAssets();
            if (m.mapTexture != null && !Application.isPlaying)
            {
                NGUITools.DestroyImmediate(m.mapTexture);
            }
            if (GenerateMapTools.GetTexture() != null)
            {
                AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(GenerateMapTools.GetTexture()));
            }

            GenerateMapTools.GetMainGameView().Focus();
            m.GenerateMap();
            saveTexture = true;
            GenerateMapTools.RegisterUndo("Map texture change");
        }

        GUI.backgroundColor = Color.white;
        EditorGUILayout.EndVertical();


        if (saveTexture)
        {
            if (GenerateMapTools.GetTexture() != null)
            {
                AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(GenerateMapTools.GetTexture()));
            }

            m.userMapTexture = GenerateMapTools.SaveTexture(m.userMapTexture);
            saveTexture      = false;
            GenerateMapTools.RegisterUndo("Map texture change");
            if (!Application.isPlaying)
            {
                if (GenerateMapRender.instance != null)
                {
                    NGUITools.DestroyImmediate(GenerateMapRender.instance);
                }
                if (GameObject.Find("_NJGMapRenderer"))
                {
                    NGUITools.DestroyImmediate(GameObject.Find("_NJGMapRenderer"));
                }
            }
            Resources.UnloadUnusedAssets();
        }
    }