Beispiel #1
0
    void ConfigCamera()
    {
        map.UpdateBounds();
        Bounds bounds = map.bounds;

        GetComponent <Camera>().depth           = -100;
        GetComponent <Camera>().backgroundColor = map.cameraBackgroundColor;
        GetComponent <Camera>().cullingMask     = map.renderLayers;
        GetComponent <Camera>().clearFlags      = (CameraClearFlags)map.cameraClearFlags;
        GetComponent <Camera>().orthographic    = true;

        float z = 0;

        GetComponent <Camera>().farClipPlane = bounds.size.y * 1.1f;
        z = bounds.extents.z;
        GetComponent <Camera>().aspect = bounds.size.x / bounds.size.z;

        GetComponent <Camera>().farClipPlane     = GetComponent <Camera>().farClipPlane * 5f;
        GetComponent <Camera>().orthographicSize = z;


        cachedTransform.eulerAngles     = new Vector3(90f, 0, 0);
        cachedTransform.localScale      = Vector3.one;
        cachedTransform.position        = new Vector3(bounds.max.x - bounds.extents.x, bounds.size.y * 2f, bounds.center.z);
        GetComponent <Camera>().enabled = true;
    }
Beispiel #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();
        }
    }