Пример #1
0
    public override void OnInspectorGUI()
    {
        EditorGUILayout.BeginHorizontal("Box");

        GUILayout.Label(topLogo);

        //if (GUILayout.Button(iconStore, GUILayout.Width(40), GUILayout.Height(40)))
        //{
        //    TileWorldTileStore.InitStore();
        //}

        if (GUILayout.Button(iconOptionMenu, GUILayout.Height(40), GUILayout.Width(40)))
        {
            Event evt         = Event.current;
            Rect  contextRect = new Rect(0, 0, Screen.width, 300);

            Vector2 mousePos = evt.mousePosition;
            if (contextRect.Contains(mousePos))
            {
                // create menu
                GenericMenu menu = new GenericMenu();

                menu.AddItem(new GUIContent("Load Map"), false, Callback, "item 1");
                menu.AddItem(new GUIContent("Save Map"), false, Callback, "item 2");
                menu.AddSeparator("");
                //menu.AddItem(new GUIContent("Check for new tiles"), false, Callback, "item 3");
                menu.AddItem(new GUIContent("About"), false, Callback, "item 4");
                menu.AddItem(new GUIContent("Help"), false, Callback, "item 5");

                menu.ShowAsContext();
                evt.Use();
            }
        }

        EditorGUILayout.EndHorizontal();


        if (creator.configuration == null)
        {
            EditorGUILayout.HelpBox("Please create or load an asset configuration file.", MessageType.Info);
        }

        //CONFIGURATION FILE OPTIONS
        EditorGUILayout.BeginHorizontal();

        creator.configuration = (TileWorldConfiguration)EditorGUILayout.ObjectField(creator.configuration, typeof(TileWorldConfiguration), true) as TileWorldConfiguration;

        if (GUILayout.Button("create config.", "ToolBarButton"))
        {
            TileWorldConfigurationEditor.CreateConfigFile(creator);
        }

        if (GUILayout.Button("load config.", "ToolBarButton"))
        {
            var _configPath = EditorUtility.OpenFilePanel("load configuration file", "Assets", "asset");
            //make path relative
            if (_configPath != "")
            {
                _configPath = "Assets" + _configPath.Substring(Application.dataPath.Length);

                creator.configuration = (TileWorldConfiguration)UnityEditor.AssetDatabase.LoadAssetAtPath(_configPath, typeof(TileWorldConfiguration));
            }
        }

        EditorGUILayout.EndHorizontal();



        if (creator.configuration == null)
        {
            if (GUI.changed)
            {
                creator.firstTimeBuild = true;
#if  UNITY_5_3_OR_NEWER || UNITY_5_3
                EditorSceneManager.MarkSceneDirty(this.currentScene);
#else
                EditorApplication.MarkSceneDirty();
#endif
            }

            return;
        }

        // Show configuration editor
        //--------------------------
        TileWorldConfigurationEditor.ShowConfigurationEditor(creator.configuration);


        //SHOW EDIT MAP
        //-------------
        GUI.color = colorGUIFoldout3;
        EditorGUILayout.BeginVertical("Box");
        GUI.color = Color.white;
        GUILayout.BeginHorizontal("Box");
        creator.configuration.ui.showEdit = GUILayout.Toggle(creator.configuration.ui.showEdit, ("Edit map"), GUI.skin.GetStyle("foldout"), GUILayout.ExpandWidth(true), GUILayout.Height(18));

        if (GUILayout.Button(iconUndockWindow, "ToolbarButton", GUILayout.Width(25)))
        {
            TileWorldCreatorEditorEditMapWindow.InitWindow(creator.gameObject);
        }

        GUILayout.EndHorizontal();

        if (creator.configuration.ui.showEdit)
        {
            ShowEdit();
        }
        EditorGUILayout.EndVertical();

        if (GUILayout.Button("Generate New", GUILayout.Height(30)))
        {
            //reset undo stack
            undoStack = new TileWorldUndoStack <bool[]>();
            redoStack = new TileWorldUndoStack <bool[]>();

            //paintRegisterMap = new bool[creator.configuration.global.width, creator.configuration.global.height];


            creator.GenerateMaps();

            for (int li = 0; li < creator.configuration.global.layerCount; li++)
            {
                creator.configuration.worldMap[li].maskMap = new bool[creator.configuration.global.width, creator.configuration.global.height];
                creator.configuration.worldMap[li].maskMap = creator.iMasks[creator.configuration.worldMap[li].selectedMask].ApplyMask(creator.configuration.worldMap[li].cellMap, creator.GetComponent <TileWorldCreator>(), creator.configuration);
            }
        }

        if (GUILayout.Button("Build", GUILayout.Height(30)))
        {
            if (creator.firstTimeBuild)
            {
                //creator.BuildMapEditor();
                creator.BuildMapComplete(false, false, true);
            }
            else
            {
                if (creator.configuration.global.buildOverlappingTiles)
                {
                    //creator.BuildMapPartial(true);
                    //creator.BuildMapPartial(false, false, 0, 0);
                    creator.BuildMapPartial(false, false);
                }
                else
                {
                    creator.firstTimeBuild = true;
                    //creator.BuildMapEditor();
                    creator.BuildMapComplete(false, false, true);
                }
            }
        }


        if (creator.mergeReady)
        {
            GUI.enabled = true;
        }
        else
        {
            GUI.enabled = false;
        }

        if (GUILayout.Button("Merge", GUILayout.Height(30)))
        {
            Merge();
            creator.mergeReady = false;
        }

        GUI.enabled = true;


        SceneView.RepaintAll();

        if (GUI.changed)
        {
            creator.firstTimeBuild = true;
#if  UNITY_5_3_OR_NEWER || UNITY_5_3
            EditorSceneManager.MarkSceneDirty(this.currentScene);
#else
            EditorApplication.MarkSceneDirty();
#endif
        }

        EditorUtility.SetDirty(creator);

        if (creator.configuration != null)
        {
            EditorUtility.SetDirty(creator.configuration);
        }
    }
Пример #2
0
        //Initialize Editor
        public void Init(bool _buildMap)
        {
            creator.configuration.ui.autoBuild = true;

            if (_buildMap)
            {
                //use the settings from the tileworldcreator prefab
                //if this is false we will have to assign new settings like in the
                //runtime demoscene (new TileWorldCreator.Settings();)
                //creator.useSettingsFromReference = true;

                //first generate a new map
                creator.GenerateMaps();

                //assign a new mask map to layers which are using one
                for (int l = 0; l < creator.configuration.global.layerCount; l++)
                {
                    if (creator.configuration.worldMap[l].useMask)
                    {
                        creator.AddNewMask(l);
                    }
                }

                // Build the map with coroutine set to false, merge false and optimization set to true.
                creator.BuildMapComplete(false, false, true);

                //bool array for painted cells
                cellMap          = new bool[creator.configuration.global.width, creator.configuration.global.height];
                cellInstancedMap = new bool[creator.configuration.global.width, creator.configuration.global.height];

                for (int w = 0; w < creator.configuration.global.width; w++)
                {
                    for (int h = 0; h < creator.configuration.global.height; h++)
                    {
                        cellMap[w, h]          = false;
                        cellInstancedMap[w, h] = false;
                    }
                }
            }


            //setup camera
            editorCam.transform.position = new Vector3(creator.configuration.global.width / 2 + creator.transform.position.x, 10, creator.configuration.global.height / 2 + creator.transform.position.z);
            editorCam.transform.rotation = Quaternion.Euler(new Vector3(90, 0, 0));
            editorCam.orthographic       = true;

            float _h = ((float)creator.configuration.global.height / 2);
            float _w = ((float)creator.configuration.global.width / (float)creator.configuration.global.height) * 3;

            editorCam.orthographicSize = _h + _w;
            maxDistance = _h + _w;
            camDistance = maxDistance;

            if (grid != null)
            {
                Destroy(grid.gameObject);
            }
            if (cell != null)
            {
                Destroy(cell.gameObject);
            }
            if (cursor != null)
            {
                Destroy(cursor.gameObject);
            }

            //setup editor
            //generate grid plane
            //matGrid = new Material(Shader.Find("Particles/Additive")); -> does not work in builds, becuase shader will no be included in build
            matGrid = new Material(mainMaterial);
            if (showGrid)
            {
                matGrid.SetTexture("_MainTex", gridTexture);
                matGrid.SetColor("_TintColor", gridColorActive);
            }
            else
            {
                matGrid.SetColor("_TintColor", gridColorDeactive);
            }

            grid = GeneratePlane(creator.configuration.global.width, creator.configuration.global.height, matGrid, "grid");

            //generate cell plane and material add and material remove
            //which will be used for the cells

            //material add cell
            //matCellAdd = new Material(Shader.Find("Particles/Additive"));
            matCellAdd = new Material(mainMaterial);
            matCellAdd.SetColor("_TintColor", cellAddColor);

            ////material remove cell
            //matCellRemove = new Material(Shader.Find("Particles/Additive"));
            matCellRemove = new Material(mainMaterial);
            matCellRemove.SetColor("_TintColor", cellRemoveColor);

            cell = GeneratePlane(1, 1, matCellAdd, "cell");
            //move cell
            cell.transform.position = new Vector3(-1000, -1000, -1000);

            //generate cursor
            //matCursor = new Material(Shader.Find("Particles/Additive"));
            matCursor = new Material(mainMaterial);
            matCursor.SetColor("_TintColor", cursorColor);
            cursor = GeneratePlane(2, 2, matCursor, "cursor");

            mapReady = true;

            //parent grid, cell and cursor object
            cell.transform.parent   = this.transform;
            grid.transform.parent   = this.transform;
            cursor.transform.parent = this.transform;

            this.transform.position = creator.transform.position;

            //initialize layers and build arrays
            InitLayers();
        }