예제 #1
0
        TileEditorInfo GetTileEditorInfo(int id)
        {
            if (tileEditorInfo == null)
            {
                tileEditorInfo = new Dictionary <int, TileEditorInfo> ();
            }

            TileEditorInfo info;

            if (!tileEditorInfo.TryGetValue(id, out info))
            {
                info = new TileEditorInfo();
                tileEditorInfo [id] = info;
            }
            return(info);
        }
예제 #2
0
        void TileInfoUI(TileAtlas atlas, TileInfo tile)
        {
            GUILayout.BeginVertical("HelpBox");

            EditorGUI.indentLevel++;

            TileEditorInfo info = GetTileEditorInfo(tile.id);

            EditorGUILayout.BeginHorizontal();

            info.isRevealed = EditorGUILayout.Foldout(info.isRevealed, "ID:" + tile.id + " " + tile.name);

            GUILayout.FlexibleSpace();

            Sprite mainSprite = tile.GetSprite();

            if (mainSprite != null)
            {
                DrawOnGUISprite(mainSprite);
            }

            if (GUILayout.Button("remove", GUILayout.MaxWidth(80)))
            {
                atlas.RemoveTile(tile.id);

                atlas.BumpMajor();
            }
            EditorGUILayout.EndHorizontal();

            if (info.isRevealed)
            {
                string old = EditorGUILayout.TextField("Name", tile.name);
                if (old != tile.name)
                {
                    tile.name = old;

                    atlas.BumpMinor();
                }

                if (tile.tileGO == null)
                {
                    TileShape shape = (TileShape)EditorGUILayout.EnumPopup("Shape", tile.shape);
                    if (shape != tile.shape)
                    {
                        tile.shape = shape;

                        atlas.BumpMinor();
                    }

                    bool isVertical;

                    if (TileShapeHelper.IsTriangle(tile.shape))
                    {
                        isVertical = EditorGUILayout.Toggle("Triangle can stretch vertically", tile.isVertical);
                        isVertical = !EditorGUILayout.Toggle("Triangle can stretch horizontally", !tile.isVertical);
                    }
                    else
                    {
                        isVertical = tile.shape == TileShape.LEFT_ONEWAY || tile.shape == TileShape.RIGHT_ONEWAY;
                    }

                    if (tile.isVertical != isVertical)
                    {
                        tile.isVertical = isVertical;

                        atlas.BumpMinor();
                    }

                    bool isTrigger = EditorGUILayout.Toggle("Is trigger?", tile.isTrigger);
                    if (isTrigger != tile.isTrigger)
                    {
                        tile.isTrigger = isTrigger;

                        atlas.BumpMinor();
                    }
                    int layer = EditorGUILayout.LayerField("Layer", tile.layer);
                    if (layer != tile.layer)
                    {
                        tile.layer = layer;

                        atlas.BumpMinor();
                    }
                    string tag = EditorGUILayout.TagField("Tag", tile.tag);
                    if (tag != tile.tag)
                    {
                        tile.tag = tag;

                        atlas.BumpMinor();
                    }
                }
                else
                {
                    if (tile.shape != TileShape.EMPTY)
                    {
                        tile.shape = TileShape.EMPTY;

                        atlas.BumpMinor();
                    }
                }

                GameObject obj = EditorGUILayout.ObjectField("Tile GO", tile.tileGO, typeof(GameObject), false) as GameObject;
                if (tile.tileGO != obj)
                {
                    tile.tileGO = obj;

                    atlas.BumpMajor();
                }
                if (tile.tileGO != null)
                {
                    bool val = EditorGUILayout.Toggle("Tile GO is detached", tile.isGODetached);
                    if (val != tile.isGODetached)
                    {
                        tile.isGODetached = val;

                        atlas.BumpMinor();
                    }
                }

                bool isTriangle = TileShapeHelper.IsTriangle(tile.shape);

                if (isTriangle)
                {
                    TriangleSpriteChooser(tile, tile.idSpriteInfo, 0);

                    if (tile.subIdSpriteInfo != null)
                    {
                        for (int i = 0; i < tile.subIdSpriteInfo.Length; i++)
                        {
                            TriangleSpriteChooser(tile, tile.subIdSpriteInfo [i], i);
                        }
                    }
                }
                else
                {
                    Sprite sprite = (Sprite)EditorGUILayout.ObjectField("Main sprite", tile.idSpriteInfo.importedSprite, typeof(Sprite), false);
                    if (tile.idSpriteInfo.importedSprite != sprite)
                    {
                        tile.idSpriteInfo.importedSprite = sprite;

                        atlas.BumpMinor();
                    }

                    if (tile.subIdSpriteInfo != null)
                    {
                        for (int i = 0; i < tile.subIdSpriteInfo.Length; i++)
                        {
                            if (tile.subIdSpriteInfo [i] != null)
                            {
                                sprite = (Sprite)EditorGUILayout.ObjectField("Sub id sprite " + i, tile.subIdSpriteInfo [i].importedSprite, typeof(Sprite), false);

                                if (sprite != tile.subIdSpriteInfo[i].importedSprite)
                                {
                                    tile.subIdSpriteInfo [i].importedSprite = sprite;

                                    atlas.BumpMinor();
                                }
                            }
                        }
                    }
                }

                if (GUILayout.Button("Add sub id sprite"))
                {
                    tile.AddSubId();

                    atlas.BumpMinor();
                }
                if (GUILayout.Button("Remove sub id sprite"))
                {
                    tile.RemoveSubId();

                    atlas.BumpMajor();
                }

                EditorGUILayout.BeginHorizontal();

                EditorGUILayout.EndHorizontal();
            }

            EditorGUI.indentLevel--;

            GUILayout.EndVertical();

            if (GUI.changed)
            {
                EditorUtility.SetDirty(target);
            }
        }