private static void TrackPlaymodeChanges(TileLayer layer, TileLayerEditor editor)
    {
        TileLayer[] layers = (TileLayer[])GameObject.FindObjectsOfType(typeof(TileLayer));
        if (Application.isPlaying && keepRealtimeChanges)
        {
            playModeTiles[layer] = layer.tileData.Clone();
        }
        else
        {
            if (wasPlayingLastUpdate && keepRealtimeChanges && !Application.isPlaying)
            {
                foreach (TileLayer l in layers)
                {
                    if (playModeTiles.Contains(l))
                    {
                        l.tileData = (TileInstance[])playModeTiles[l];
                        editor.RebuildMap(l.layerSize);
                        TileLayerEditor.InstantiatePrefabs(l);
                    }
                }

                //Undo.RegisterSceneUndo("Playmode changes to tile layers");
            }

            playModeTiles.Clear();
        }
        wasPlayingLastUpdate = Application.isPlaying;
    }
Example #2
0
    private static void CreateObjectButton(TileLayer layer)
    {
        GUILayout.BeginHorizontal();
        GUILayout.Label("B", GUILayout.ExpandWidth(false), GUILayout.MinWidth(20));

        if (GUILayout.Button(new GUIContent("Create objects", "Instantiate tile prefabs and box colliders.")) ||
            Event.current.keyCode == KeyCode.B)
        {
            //Undo.RegisterSceneUndo("Create Objects");
            TileLayerEditor.InstantiatePrefabs(layer);
        }

        GUILayout.EndHorizontal();
    }
Example #3
0
    private void OnInspectorGUI_Properties(TileLayer layer)
    {
        EditorGUILayout.BeginVertical();

        showProperties = EditorGUILayout.Foldout(showProperties, "Layer Properties");

        if (layer.material != null && layer.tileset == null)
        {
            this.GetTileset(layer);
        }

        if (showProperties)
        {
            propertiesEditor.OnInspectorGUI(layer);

            if (layer.material != null)
            {
                GUILayout.BeginHorizontal();

                int length = 2 + layer.tileset.templates.Length;

                string[] templates = new string[length];
                templates[0] = "Choose a template";
                for (int i = 0; i < layer.tileset.templates.Length; i++)
                {
                    templates[i + 1] = i.ToString() + " - " + layer.tileset.templates[i].name;
                }

                templates[length - 1] = "Add current selection as a template";
                int newSelectedTemplate = EditorGUILayout.Popup("Template", Mathf.Min(selectedTemplate + 1, length - 2), templates);
                selectedTemplate = newSelectedTemplate - 1;
                if (newSelectedTemplate == length - 1)
                {
                    UniTileTemplate[] newList = new UniTileTemplate[layer.tileset.templates.Length + 1];
                    for (int i = 0; i < layer.tileset.templates.Length; i++)
                    {
                        newList[i] = layer.tileset.templates[i];
                    }
                    newList[newList.Length - 1] = new UniTileTemplate();
                    newList[newList.Length - 1].Init(selection);
                    layer.tileset.templates = newList;
                }
                else if (newSelectedTemplate > 0)
                {
                    //layer.tileset.templates[selection - 1].Use();
                    SelectTemplate(layer.tileset.templates[newSelectedTemplate - 1]);
                }

                if (selectedTemplate >= 0 && selectedTemplate < layer.tileset.templates.Length && layer.tileset.templates[selectedTemplate] != null)
                {
                    layer.tileset.templates[selectedTemplate].name = EditorGUILayout.TextField(layer.tileset.templates[selectedTemplate].name);
                    if (GUILayout.Button("Delete"))
                    {
                        List <UniTileTemplate> newList = new List <UniTileTemplate>();
                        foreach (UniTileTemplate t in layer.tileset.templates)
                        {
                            if (t != layer.tileset.templates[selectedTemplate])
                            {
                                newList.Add(t);
                            }
                        }
                        layer.tileset.templates = newList.ToArray();
                    }
                }
                GUILayout.EndHorizontal();

                UniTileMarker.Instance.Init(this.selection);
            }

            m_Object.Update();
            EditorGUILayout.PropertyField(material);
            if (layer.material != material.objectReferenceValue)
            {
                layer.material = (Material)material.objectReferenceValue;
                m_Object.ApplyModifiedProperties();
                this.GetTileset(layer);
            }
        }

        EditorGUILayout.EndVertical();

        if (showProperties)
        {
            int x = 5;
            GUILayout.BeginHorizontal();

            if (layer.parent == null)
            {
                if (GUILayout.Button(new GUIContent("Rebuild map", "Apply changes to the size properties."), GUILayout.Width(80), GUILayout.Height(30)))
                {
                    //Undo.RegisterSceneUndo("Resize map");
                    Vector2 prevLayerSize = layer.layerSize;
                    propertiesEditor.SetPropertiesTo(layer);

                    for (int i = 0; i < layer.transform.childCount; i++)
                    {
                        TileLayer child = layer.transform.GetChild(i).GetComponent <TileLayer>();
                        if (child != null)
                        {
                            propertiesEditor.SetPropertiesTo(child);
                        }
                    }

                    this.RebuildMap(prevLayerSize);

                    UniTileMarker.Instance.Init(selection);
                }

                x += 80;

                if (GUILayout.Button(new GUIContent("Revert", "Cancel changes to the size properties."), GUILayout.Width(50), GUILayout.Height(30)))
                {
                    propertiesEditor.SetPropertiesFrom(layer);
                }

                x += 50;
            }

            if (GUILayout.Button(new GUIContent("Clear layer", "Erase all tile data from the layer."), GUILayout.Width(70), GUILayout.Height(30)))
            {
                //Undo.RegisterSceneUndo("Clear layer");
                this.ClearMap();
            }


            x += 70;

            if (GUILayout.Button(new GUIContent("Create objects", "Instantiate tile prefabs and box colliders."), GUILayout.Width(90), GUILayout.Height(30)))
            {
                //Undo.RegisterSceneUndo("Clear layer");
                TileLayerEditor.InstantiatePrefabs(layer);
            }


            x += 90;

            if (layer.parent == null && layer.material != null && layer.material.mainTexture != null)
            {
                if (GUILayout.Button(new GUIContent("Padder", "Add padding to textures."), GUILayout.Width(50), GUILayout.Height(30)))
                {
                    PadderEditorWindow window = PadderEditorWindow.CreateInstance <PadderEditorWindow>();
                    window.Setup((Texture2D)layer.material.mainTexture, layer.tileSize, layer.borderSize);
                    window.ShowUtility();
                }
            }

            x += 50;

            if (selection.selectedTilesList.Length > 0 && layer.material != null && layer.material.mainTexture != null)
            {
                if (GUILayout.Button(new GUIContent("Edit Tiles", "Edit currently selected tiles."), GUILayout.Width(70), GUILayout.Height(30)))
                {
                    TileEditorWindow window = TileEditorWindow.CreateInstance <TileEditorWindow>();
                    window.Setup(this, selection.selectedTilesList);
                    window.ShowUtility();
                }
            }

            GUILayout.EndHorizontal();
        }
    }