Esempio n. 1
0
    public static string PlatformPopup(tk2dSystem system, string label, string platform)
    {
        if (system == null)
        {
            return(label);
        }

        int selectedIndex = -1;

        string[] platformNames = new string[system.assetPlatforms.Length];

        for (int i = 0; i < system.assetPlatforms.Length; ++i)
        {
            platformNames[i] = system.assetPlatforms[i].name;
            if (platformNames[i] == platform)
            {
                selectedIndex = i;
            }
        }

        selectedIndex = EditorGUILayout.Popup(label, selectedIndex, platformNames);
        if (selectedIndex == -1)
        {
            return("");
        }
        else
        {
            return(platformNames[selectedIndex]);
        }
    }
Esempio n. 2
0
    // Returns the path to the global resources directory
    // It is /Assets/TK2DSYSTEM/Resources by default, but can be moved anywhere
    // When the tk2dSystem object exists, the path to the object will be returned
    public static string GetOrCreateResourcesDir()
    {
        tk2dSystem inst      = tk2dSystem.inst;
        string     assetPath = AssetDatabase.GetAssetPath(inst);

        if (assetPath.Length > 0)
        {
            // This has already been serialized, just return path as is
            return(System.IO.Path.GetDirectoryName(assetPath).Replace('\\', '/'));            // already serialized
        }
        else
        {
            // Create the system asset
            const string resPath = "Assets/Resources";
            if (!System.IO.Directory.Exists(resPath))
            {
                System.IO.Directory.CreateDirectory(resPath);
            }

            const string basePath = resPath + "/tk2d";
            if (!System.IO.Directory.Exists(basePath))
            {
                System.IO.Directory.CreateDirectory(basePath);
            }

            assetPath = basePath + "/" + tk2dSystem.assetFileName;
            AssetDatabase.CreateAsset(inst, assetPath);

            return(basePath);
        }
    }
Esempio n. 3
0
    // Returns the path to the global resources directory
    // Will not create if it doesn't exists
    static string GetResourcesDir()
    {
        tk2dSystem inst = tk2dSystem.inst_NoCreate;

        if (inst == null)
        {
            return("");
        }
        else
        {
            return(GetOrCreateResourcesDir());         // this already exists, so this function will follow the correct path
        }
    }
Esempio n. 4
0
    public static tk2dAssetPlatform GetAssetPlatform(string platform)
    {
        tk2dSystem inst = tk2dSystem.inst_NoCreate;

        if (inst == null)
        {
            return(null);
        }

        for (int i = 0; i < inst.assetPlatforms.Length; ++i)
        {
            if (inst.assetPlatforms[i].name == platform)
            {
                return(inst.assetPlatforms[i]);
            }
        }
        return(null);
    }
        void DrawMaterialEditor()
        {
            // Upgrade
            int numAltMaterials = 0;

            foreach (var v in SpriteCollection.altMaterials)
            {
                if (v != null)
                {
                    numAltMaterials++;
                }
            }

            if ((SpriteCollection.altMaterials.Length == 0 || numAltMaterials == 0) && SpriteCollection.atlasMaterials.Length != 0)
            {
                SpriteCollection.altMaterials = new Material[1] {
                    SpriteCollection.atlasMaterials[0]
                }
            }
            ;

            if (SpriteCollection.altMaterials.Length > 0)
            {
                GUILayout.BeginHorizontal();
                DrawHeaderLabel("Materials");
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("+", EditorStyles.miniButton))
                {
                    int sourceIndex = -1;
                    int i;
                    for (i = 0; i < SpriteCollection.altMaterials.Length; ++i)
                    {
                        if (SpriteCollection.altMaterials[i] != null)
                        {
                            sourceIndex = i;
                            break;
                        }
                    }
                    for (i = 0; i < SpriteCollection.altMaterials.Length; ++i)
                    {
                        if (SpriteCollection.altMaterials[i] == null)
                        {
                            break;
                        }
                    }
                    if (i == SpriteCollection.altMaterials.Length)
                    {
                        System.Array.Resize(ref SpriteCollection.altMaterials, SpriteCollection.altMaterials.Length + 1);
                    }

                    Material mtl = null;
                    if (sourceIndex == -1)
                    {
                        Debug.LogError("Sprite collection has null materials. Fix this in the debug inspector.");
                    }
                    else
                    {
                        mtl = DuplicateMaterial(SpriteCollection.altMaterials[sourceIndex]);
                    }

                    SpriteCollection.altMaterials[i] = mtl;
                    SpriteCollection.Trim();

                    if (SpriteCollection.platforms.Count > 1)
                    {
                        SpriteCollection.platforms[0].spriteCollection.altMaterials = SpriteCollection.altMaterials;
                        EditorUtility.SetDirty(SpriteCollection.platforms[0].spriteCollection);

                        for (int j = 1; j < SpriteCollection.platforms.Count; ++j)
                        {
                            if (!SpriteCollection.platforms[j].Valid)
                            {
                                continue;
                            }
                            tk2dSpriteCollection data = SpriteCollection.platforms[j].spriteCollection;
                            System.Array.Resize(ref data.altMaterials, SpriteCollection.altMaterials.Length);
                            data.altMaterials[i] = DuplicateMaterial(data.altMaterials[sourceIndex]);
                            EditorUtility.SetDirty(data);
                        }
                    }

                    host.Commit();
                }
                GUILayout.EndHorizontal();

                if (SpriteCollection.altMaterials != null)
                {
                    EditorGUI.indentLevel++;

                    for (int i = 0; i < SpriteCollection.altMaterials.Length; ++i)
                    {
                        if (SpriteCollection.altMaterials[i] == null)
                        {
                            continue;
                        }

                        bool deleteMaterial = false;

                        Material newMaterial = EditorGUILayout.ObjectField(SpriteCollection.altMaterials[i], typeof(Material), false) as Material;
                        if (newMaterial == null)
                        {
                            // Can't delete the last one
                            if (numAltMaterials > 1)
                            {
                                bool inUse = false;
                                foreach (var v in SpriteCollection.textureParams)
                                {
                                    if (v.materialId == i)
                                    {
                                        inUse = true;
                                        break;
                                    }
                                }
                                foreach (var v in SpriteCollection.fonts)
                                {
                                    if (v.materialId == i)
                                    {
                                        inUse = true;
                                        break;
                                    }
                                }

                                if (inUse)
                                {
                                    if (EditorUtility.DisplayDialog("Delete material",
                                                                    "This material is in use. Deleting it will reset materials on " +
                                                                    "sprites that use this material.\n" +
                                                                    "Do you wish to proceed?", "Yes", "Cancel"))
                                    {
                                        deleteMaterial = true;
                                    }
                                }
                                else
                                {
                                    deleteMaterial = true;
                                }
                            }
                        }
                        else
                        {
                            SpriteCollection.altMaterials[i] = newMaterial;
                        }

                        if (deleteMaterial)
                        {
                            SpriteCollection.altMaterials[i] = null;

                            // fix up all existing materials
                            int targetMaterialId;
                            for (targetMaterialId = 0; targetMaterialId < SpriteCollection.altMaterials.Length; ++targetMaterialId)
                            {
                                if (SpriteCollection.altMaterials[targetMaterialId] != null)
                                {
                                    break;
                                }
                            }
                            foreach (var sprite in SpriteCollection.textureParams)
                            {
                                if (sprite.materialId == i)
                                {
                                    sprite.materialId = targetMaterialId;
                                }
                            }
                            foreach (var font in SpriteCollection.fonts)
                            {
                                if (font.materialId == i)
                                {
                                    font.materialId = targetMaterialId;
                                }
                            }
                            SpriteCollection.Trim();

                            // Do the same on inherited sprite collections
                            for (int j = 0; j < SpriteCollection.platforms.Count; ++j)
                            {
                                if (!SpriteCollection.platforms[j].Valid)
                                {
                                    continue;
                                }
                                tk2dSpriteCollection data = SpriteCollection.platforms[j].spriteCollection;
                                data.altMaterials[i] = null;

                                for (int lastIndex = data.altMaterials.Length - 1; lastIndex >= 0; --lastIndex)
                                {
                                    if (data.altMaterials[lastIndex] != null)
                                    {
                                        int count = data.altMaterials.Length - 1 - lastIndex;
                                        if (count > 0)
                                        {
                                            System.Array.Resize(ref data.altMaterials, lastIndex + 1);
                                        }
                                        break;
                                    }
                                }

                                EditorUtility.SetDirty(data);
                            }

                            host.Commit();
                        }
                    }

                    EditorGUI.indentLevel--;
                }
            }
        }

        void DrawHeaderLabel(string name)
        {
            GUILayout.Label(name, EditorStyles.boldLabel);
        }

        void BeginHeader(string name)
        {
            DrawHeaderLabel(name);
            GUILayout.Space(2);
            EditorGUI.indentLevel++;
        }

        void EndHeader()
        {
            EditorGUI.indentLevel--;
            GUILayout.Space(8);
        }

        void DrawSystemSettings()
        {
            BeginHeader("System");

            // Loadable
            bool allowSwitch = SpriteCollection.spriteCollection != null;
            bool loadable    = SpriteCollection.spriteCollection?SpriteCollection.loadable:false;
            bool newLoadable = EditorGUILayout.Toggle("Loadable asset", loadable);

            if (newLoadable != loadable)
            {
                if (!allowSwitch)
                {
                    EditorUtility.DisplayDialog("Please commit the sprite collection before attempting to make it loadable.", "Make loadable.", "Ok");
                }
                else
                {
                    if (newLoadable)
                    {
                        if (SpriteCollection.assetName.Length == 0)
                        {
                            SpriteCollection.assetName = SpriteCollection.spriteCollection.spriteCollectionName;                             // guess something
                        }
                        tk2dSystemUtility.MakeLoadableAsset(SpriteCollection.spriteCollection, SpriteCollection.assetName);
                    }
                    else
                    {
                        if (tk2dSystemUtility.IsLoadableAsset(SpriteCollection.spriteCollection))
                        {
                            tk2dSystemUtility.UnmakeLoadableAsset(SpriteCollection.spriteCollection);
                        }
                    }
                    loadable = newLoadable;
                    SpriteCollection.loadable = loadable;
                }
            }
            if (loadable)
            {
                SpriteCollection.assetName = EditorGUILayout.TextField("Asset Name/Path", SpriteCollection.assetName);
            }

            // Clear data
            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("References");
            if (GUILayout.Button("Clear References", EditorStyles.miniButton))
            {
                if (EditorUtility.DisplayDialog("Clear references",
                                                "Clearing references will clear references to data (atlases, materials) owned by this sprite collection. " +
                                                "This will only remove references, and will not delete the data or textures. " +
                                                "Use after duplicating a sprite collection to sever links with the original.\n\n" +
                                                "Are you sure you want to do this?"
                                                , "Yes", "No"))
                {
                    SpriteCollection.altMaterials     = new Material[0];
                    SpriteCollection.atlasMaterials   = new Material[0];
                    SpriteCollection.atlasTextures    = new Texture2D[0];
                    SpriteCollection.spriteCollection = null;
                    foreach (tk2dSpriteCollectionPlatform plat in SpriteCollection.platforms)
                    {
                        plat.spriteCollection = null;
                    }
                }
            }
            GUILayout.EndHorizontal();

            EndHeader();
        }

        void DrawPlatforms()
        {
            // Asset Platform
            BeginHeader("Platforms");
            tk2dSystem system = tk2dSystem.inst_NoCreate;

            if (system == null && GUILayout.Button("Add Platform Support"))
            {
                system = tk2dSystem.inst;                 // force creation
            }
            if (system)
            {
                int toDelete = -1;
                for (int i = 0; i < SpriteCollection.platforms.Count; ++i)
                {
                    tk2dSpriteCollectionPlatform currentPlatform = SpriteCollection.platforms[i];

                    GUILayout.BeginHorizontal();
                    string label = (i == 0)?"Current platform":"Platform";
                    currentPlatform.name = tk2dGuiUtility.PlatformPopup(system, label, currentPlatform.name);
                    bool displayDelete = ((SpriteCollection.platforms.Count == 1 && SpriteCollection.platforms[0].name.Length > 0) ||
                                          (SpriteCollection.platforms.Count > 1 && i > 0));
                    if (displayDelete && GUILayout.Button("Delete", EditorStyles.miniButton, GUILayout.MaxWidth(50)))
                    {
                        toDelete = i;
                    }
                    GUILayout.EndHorizontal();
                }

                if (toDelete != -1)
                {
                    tk2dSpriteCollection deletedSpriteCollection = null;
                    if (SpriteCollection.platforms.Count == 1)
                    {
                        if (SpriteCollection.platforms[0].spriteCollection != null && SpriteCollection.platforms[0].spriteCollection.spriteCollection != null)
                        {
                            deletedSpriteCollection = SpriteCollection.platforms[0].spriteCollection;
                        }
                        SpriteCollection.platforms[0].name             = "";
                        SpriteCollection.platforms[0].spriteCollection = null;
                    }
                    else
                    {
                        if (SpriteCollection.platforms[toDelete].spriteCollection != null && SpriteCollection.platforms[toDelete].spriteCollection.spriteCollection != null)
                        {
                            deletedSpriteCollection = SpriteCollection.platforms[toDelete].spriteCollection;
                        }
                        SpriteCollection.platforms.RemoveAt(toDelete);
                    }
                    if (deletedSpriteCollection != null)
                    {
                        foreach (tk2dSpriteCollectionFont f in deletedSpriteCollection.fonts)
                        {
                            tk2dSystemUtility.UnmakeLoadableAsset(f.data);
                        }
                        tk2dSystemUtility.UnmakeLoadableAsset(deletedSpriteCollection.spriteCollection);
                    }
                }

                if (SpriteCollection.platforms.Count > 1 ||
                    (SpriteCollection.platforms.Count == 1 && SpriteCollection.platforms[0].name.Length > 0))
                {
                    GUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel(" ");
                    if (GUILayout.Button("Add new platform", EditorStyles.miniButton))
                    {
                        SpriteCollection.platforms.Add(new tk2dSpriteCollectionPlatform());
                    }
                    GUILayout.EndHorizontal();
                }
            }

            EndHeader();
        }

        void DrawTextureSettings()
        {
            BeginHeader("Texture Settings");

            SpriteCollection.filterMode                 = (FilterMode)EditorGUILayout.EnumPopup("Filter Mode", SpriteCollection.filterMode);
            SpriteCollection.textureCompression         = (tk2dSpriteCollection.TextureCompression)EditorGUILayout.EnumPopup("Compression", SpriteCollection.textureCompression);
            SpriteCollection.userDefinedTextureSettings = EditorGUILayout.Toggle("User Defined", SpriteCollection.userDefinedTextureSettings);
            if (SpriteCollection.userDefinedTextureSettings)
            {
                GUI.enabled = false;
            }
            SpriteCollection.wrapMode      = (TextureWrapMode)EditorGUILayout.EnumPopup("Wrap Mode", SpriteCollection.wrapMode);
            SpriteCollection.anisoLevel    = (int)EditorGUILayout.IntSlider("Aniso Level", SpriteCollection.anisoLevel, 0, 9);
            SpriteCollection.mipmapEnabled = EditorGUILayout.Toggle("Mip Maps", SpriteCollection.mipmapEnabled);
            GUI.enabled = true;

            EndHeader();
        }

        void DrawSpriteCollectionSettings()
        {
            BeginHeader("Sprite Collection Settings");

            SpriteCollection.padAmount = EditorGUILayout.IntPopup("Pad Amount", SpriteCollection.padAmount, padAmountLabels, padAmountValues);
            if (SpriteCollection.padAmount == 0 && SpriteCollection.filterMode != FilterMode.Point)
            {
                tk2dGuiUtility.InfoBox("Filter mode is not set to Point." +
                                       " Some bleeding will occur at sprite edges.",
                                       tk2dGuiUtility.WarningLevel.Info);
            }

            SpriteCollection.premultipliedAlpha   = EditorGUILayout.Toggle("Premultiplied Alpha", SpriteCollection.premultipliedAlpha);
            SpriteCollection.physicsDepth         = EditorGUILayout.FloatField("Collider depth", SpriteCollection.physicsDepth);
            SpriteCollection.disableTrimming      = EditorGUILayout.Toggle("Disable Trimming", SpriteCollection.disableTrimming);
            SpriteCollection.normalGenerationMode = (tk2dSpriteCollection.NormalGenerationMode)EditorGUILayout.EnumPopup("Normal Generation", SpriteCollection.normalGenerationMode);

            bool newUseTk2dCamera = EditorGUILayout.Toggle("Use tk2dCamera", SpriteCollection.useTk2dCamera);

            if (SpriteCollection.useTk2dCamera != newUseTk2dCamera)
            {
                SpriteCollection.useTk2dCamera = newUseTk2dCamera;
                if (SpriteCollection.useTk2dCamera && SpriteCollection.physicsDepth < 1 &&
                    EditorUtility.DisplayDialog("Use tk2dCamera", "Would you like to adjust the collider depth to work better with the tk2dCamera? A depth of 1 or above works best.", "Yes", "No"))
                {
                    SpriteCollection.physicsDepth = 1;
                }
            }
            if (!SpriteCollection.useTk2dCamera)
            {
                EditorGUI.indentLevel            = EditorGUI.indentLevel + 1;
                SpriteCollection.targetHeight    = EditorGUILayout.IntField("Target Height", SpriteCollection.targetHeight);
                SpriteCollection.targetOrthoSize = EditorGUILayout.FloatField("Target Ortho Size", SpriteCollection.targetOrthoSize);
                EditorGUI.indentLevel            = EditorGUI.indentLevel - 1;
            }

            EndHeader();
        }

        void DrawAtlasSettings()
        {
            BeginHeader("Atlas Settings");

            int[]    allowedAtlasSizes       = { 64, 128, 256, 512, 1024, 2048, 4096 };
            string[] allowedAtlasSizesString = new string[allowedAtlasSizes.Length];
            for (int i = 0; i < allowedAtlasSizes.Length; ++i)
            {
                allowedAtlasSizesString[i] = allowedAtlasSizes[i].ToString();
            }

            SpriteCollection.forceTextureSize = EditorGUILayout.Toggle("Force Atlas Size", SpriteCollection.forceTextureSize);
            EditorGUI.indentLevel++;
            if (SpriteCollection.forceTextureSize)
            {
                SpriteCollection.forcedTextureWidth  = EditorGUILayout.IntPopup("Width", SpriteCollection.forcedTextureWidth, allowedAtlasSizesString, allowedAtlasSizes);
                SpriteCollection.forcedTextureHeight = EditorGUILayout.IntPopup("Height", SpriteCollection.forcedTextureHeight, allowedAtlasSizesString, allowedAtlasSizes);
            }
            else
            {
                SpriteCollection.maxTextureSize   = EditorGUILayout.IntPopup("Max Size", SpriteCollection.maxTextureSize, allowedAtlasSizesString, allowedAtlasSizes);
                SpriteCollection.forceSquareAtlas = EditorGUILayout.Toggle("Force Square", SpriteCollection.forceSquareAtlas);
            }
            EditorGUI.indentLevel--;

            bool allowMultipleAtlases = EditorGUILayout.Toggle("Multiple Atlases", SpriteCollection.allowMultipleAtlases);

            if (allowMultipleAtlases != SpriteCollection.allowMultipleAtlases)
            {
                // Disallow switching if using unsupported features
                if (allowMultipleAtlases == true)
                {
                    bool hasDicing = false;
                    for (int i = 0; i < SpriteCollection.textureParams.Count; ++i)
                    {
                        if (SpriteCollection.textureParams[i].texture != null &
                            SpriteCollection.textureParams[i].dice)
                        {
                            hasDicing = true;
                            break;
                        }
                    }

                    if (SpriteCollection.fonts.Count > 0 || hasDicing)
                    {
                        EditorUtility.DisplayDialog("Multiple atlases",
                                                    "Multiple atlases not allowed. This sprite collection contains fonts and/or " +
                                                    "contains diced sprites.", "Ok");
                        allowMultipleAtlases = false;
                    }
                }

                SpriteCollection.allowMultipleAtlases = allowMultipleAtlases;
            }

            if (SpriteCollection.allowMultipleAtlases)
            {
                tk2dGuiUtility.InfoBox("Sprite collections with multiple atlas spanning enabled cannot be used with the Static Sprite" +
                                       " Batcher, Fonts, the TileMap Editor and doesn't support Sprite Dicing and material level optimizations.\n\n" +
                                       "Avoid using it unless you are simply importing a" +
                                       " large sequence of sprites for an animation.", tk2dGuiUtility.WarningLevel.Info);
            }

            if (SpriteCollection.allowMultipleAtlases)
            {
                EditorGUILayout.LabelField("Num Atlases", SpriteCollection.atlasTextures.Length.ToString());
            }
            else
            {
                EditorGUILayout.LabelField("Atlas Width", SpriteCollection.atlasWidth.ToString());
                EditorGUILayout.LabelField("Atlas Height", SpriteCollection.atlasHeight.ToString());
                EditorGUILayout.LabelField("Atlas Wastage", SpriteCollection.atlasWastage.ToString("0.00") + "%");
            }

            EndHeader();
        }
Esempio n. 6
0
        void DrawMaterialEditor()
        {
            // Upgrade
            int numAltMaterials = 0;

            foreach (var v in SpriteCollection.altMaterials)
            {
                if (v != null)
                {
                    numAltMaterials++;
                }
            }

            if ((SpriteCollection.altMaterials.Length == 0 || numAltMaterials == 0) && SpriteCollection.atlasMaterials.Length != 0)
            {
                SpriteCollection.altMaterials = new Material[1] {
                    SpriteCollection.atlasMaterials[0]
                }
            }
            ;

            if (SpriteCollection.altMaterials.Length > 0)
            {
                GUILayout.BeginHorizontal();
                DrawHeaderLabel("Materials");
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("+", EditorStyles.miniButton))
                {
                    int sourceIndex = -1;
                    int i;
                    for (i = 0; i < SpriteCollection.altMaterials.Length; ++i)
                    {
                        if (SpriteCollection.altMaterials[i] != null)
                        {
                            sourceIndex = i;
                            break;
                        }
                    }
                    for (i = 0; i < SpriteCollection.altMaterials.Length; ++i)
                    {
                        if (SpriteCollection.altMaterials[i] == null)
                        {
                            break;
                        }
                    }
                    if (i == SpriteCollection.altMaterials.Length)
                    {
                        System.Array.Resize(ref SpriteCollection.altMaterials, SpriteCollection.altMaterials.Length + 1);
                    }

                    Material mtl = null;
                    if (sourceIndex == -1)
                    {
                        CustomDebug.LogError("Sprite collection has null materials. Fix this in the debug inspector.");
                    }
                    else
                    {
                        mtl = DuplicateMaterial(SpriteCollection.altMaterials[sourceIndex]);
                    }

                    SpriteCollection.altMaterials[i] = mtl;
                    SpriteCollection.Trim();

                    if (SpriteCollection.platforms.Count > 1)
                    {
                        SpriteCollection.platforms[0].spriteCollection.altMaterials = SpriteCollection.altMaterials;
                        EditorUtility.SetDirty(SpriteCollection.platforms[0].spriteCollection);

                        for (int j = 1; j < SpriteCollection.platforms.Count; ++j)
                        {
                            if (!SpriteCollection.platforms[j].Valid)
                            {
                                continue;
                            }
                            tk2dSpriteCollection data = SpriteCollection.platforms[j].spriteCollection;
                            System.Array.Resize(ref data.altMaterials, SpriteCollection.altMaterials.Length);
                            data.altMaterials[i] = DuplicateMaterial(data.altMaterials[sourceIndex]);
                            EditorUtility.SetDirty(data);
                        }
                    }

                    host.Commit();
                }
                GUILayout.EndHorizontal();

                if (SpriteCollection.altMaterials != null)
                {
                    EditorGUI.indentLevel++;

                    for (int i = 0; i < SpriteCollection.altMaterials.Length; ++i)
                    {
                        if (SpriteCollection.altMaterials[i] == null)
                        {
                            continue;
                        }

                        bool deleteMaterial = false;

                        Material newMaterial = EditorGUILayout.ObjectField(SpriteCollection.altMaterials[i], typeof(Material), false) as Material;
                        if (newMaterial == null)
                        {
                            // Can't delete the last one
                            if (numAltMaterials > 1)
                            {
                                bool inUse = false;
                                foreach (var v in SpriteCollection.textureParams)
                                {
                                    if (v.materialId == i)
                                    {
                                        inUse = true;
                                        break;
                                    }
                                }
                                foreach (var v in SpriteCollection.fonts)
                                {
                                    if (v.materialId == i)
                                    {
                                        inUse = true;
                                        break;
                                    }
                                }

                                if (inUse)
                                {
                                    if (EditorUtility.DisplayDialog("Delete material",
                                                                    "This material is in use. Deleting it will reset materials on " +
                                                                    "sprites that use this material.\n" +
                                                                    "Do you wish to proceed?", "Yes", "Cancel"))
                                    {
                                        deleteMaterial = true;
                                    }
                                }
                                else
                                {
                                    deleteMaterial = true;
                                }
                            }
                        }
                        else
                        {
                            SpriteCollection.altMaterials[i] = newMaterial;
                        }

                        if (deleteMaterial)
                        {
                            SpriteCollection.altMaterials[i] = null;

                            // fix up all existing materials
                            int targetMaterialId;
                            for (targetMaterialId = 0; targetMaterialId < SpriteCollection.altMaterials.Length; ++targetMaterialId)
                            {
                                if (SpriteCollection.altMaterials[targetMaterialId] != null)
                                {
                                    break;
                                }
                            }
                            foreach (var sprite in SpriteCollection.textureParams)
                            {
                                if (sprite.materialId == i)
                                {
                                    sprite.materialId = targetMaterialId;
                                }
                            }
                            foreach (var font in SpriteCollection.fonts)
                            {
                                if (font.materialId == i)
                                {
                                    font.materialId = targetMaterialId;
                                }
                            }
                            SpriteCollection.Trim();

                            // Do the same on inherited sprite collections
                            for (int j = 0; j < SpriteCollection.platforms.Count; ++j)
                            {
                                if (!SpriteCollection.platforms[j].Valid)
                                {
                                    continue;
                                }
                                tk2dSpriteCollection data = SpriteCollection.platforms[j].spriteCollection;
                                data.altMaterials[i] = null;

                                for (int lastIndex = data.altMaterials.Length - 1; lastIndex >= 0; --lastIndex)
                                {
                                    if (data.altMaterials[lastIndex] != null)
                                    {
                                        int count = data.altMaterials.Length - 1 - lastIndex;
                                        if (count > 0)
                                        {
                                            System.Array.Resize(ref data.altMaterials, lastIndex + 1);
                                        }
                                        break;
                                    }
                                }

                                EditorUtility.SetDirty(data);
                            }

                            host.Commit();
                        }
                    }

                    EditorGUI.indentLevel--;
                }
            }
        }

        void DrawHeaderLabel(string name)
        {
            GUILayout.Label(name, EditorStyles.boldLabel);
        }

        void BeginHeader(string name)
        {
            DrawHeaderLabel(name);
            GUILayout.Space(2);
            EditorGUI.indentLevel++;
        }

        void EndHeader()
        {
            EditorGUI.indentLevel--;
            GUILayout.Space(8);
        }

        void DrawSystemSettings()
        {
            BeginHeader("System");

            // Loadable
            bool allowSwitch = SpriteCollection.spriteCollection != null;
            bool loadable    = SpriteCollection.spriteCollection?SpriteCollection.loadable:false;
            bool newLoadable = EditorGUILayout.Toggle("Loadable asset", loadable);

            if (newLoadable != loadable)
            {
                if (!allowSwitch)
                {
                    EditorUtility.DisplayDialog("Please commit the sprite collection before attempting to make it loadable.", "Make loadable.", "Ok");
                }
                else
                {
                    if (newLoadable)
                    {
                        if (SpriteCollection.assetName.Length == 0)
                        {
                            SpriteCollection.assetName = SpriteCollection.spriteCollection.spriteCollectionName;                             // guess something
                        }
                        tk2dSystemUtility.MakeLoadableAsset(SpriteCollection.spriteCollection, SpriteCollection.assetName);
                    }
                    else
                    {
                        if (tk2dSystemUtility.IsLoadableAsset(SpriteCollection.spriteCollection))
                        {
                            tk2dSystemUtility.UnmakeLoadableAsset(SpriteCollection.spriteCollection);
                        }
                    }
                    loadable = newLoadable;
                    SpriteCollection.loadable = loadable;
                }
            }
            if (loadable)
            {
                SpriteCollection.assetName = EditorGUILayout.TextField("Asset Name/Path", SpriteCollection.assetName);
            }

            // Clear data
            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("References");
            if (GUILayout.Button("Clear References", EditorStyles.miniButton))
            {
                if (EditorUtility.DisplayDialog("Clear references",
                                                "Clearing references will clear references to data (atlases, materials) owned by this sprite collection. " +
                                                "This will only remove references, and will not delete the data or textures. " +
                                                "Use after duplicating a sprite collection to sever links with the original.\n\n" +
                                                "Are you sure you want to do this?"
                                                , "Yes", "No"))
                {
                    SpriteCollection.ClearReferences();

                    foreach (tk2dSpriteCollectionPlatform plat in SpriteCollection.platforms)
                    {
                        plat.spriteCollection = null;
                    }
                }
            }
            GUILayout.EndHorizontal();

            EndHeader();
        }

        void DrawPlatforms()
        {
            // Asset Platform
            BeginHeader("Platforms");
            tk2dSystem system = tk2dSystem.inst_NoCreate;

            if (system == null && GUILayout.Button("Add Platform Support"))
            {
                system = tk2dSystem.inst;                 // force creation
            }
            if (system)
            {
                int toDelete = -1;
                for (int i = 0; i < SpriteCollection.platforms.Count; ++i)
                {
                    tk2dSpriteCollectionPlatform currentPlatform = SpriteCollection.platforms[i];

                    GUILayout.BeginHorizontal();
                    string label = (i == 0)?"Current platform":"Platform";
                    currentPlatform.name = tk2dGuiUtility.PlatformPopup(system, label, currentPlatform.name);
                    bool displayDelete = ((SpriteCollection.platforms.Count == 1 && SpriteCollection.platforms[0].name.Length > 0) ||
                                          (SpriteCollection.platforms.Count > 1 && i > 0));
                    if (displayDelete && GUILayout.Button("Delete", EditorStyles.miniButton, GUILayout.MaxWidth(50)))
                    {
                        toDelete = i;
                    }
                    GUILayout.EndHorizontal();
                }

                if (toDelete != -1)
                {
                    tk2dSpriteCollection deletedSpriteCollection = null;
                    if (SpriteCollection.platforms.Count == 1)
                    {
                        if (SpriteCollection.platforms[0].spriteCollection != null && SpriteCollection.platforms[0].spriteCollection.spriteCollection != null)
                        {
                            deletedSpriteCollection = SpriteCollection.platforms[0].spriteCollection;
                        }
                        SpriteCollection.platforms[0].name             = "";
                        SpriteCollection.platforms[0].spriteCollection = null;
                    }
                    else
                    {
                        if (SpriteCollection.platforms[toDelete].spriteCollection != null && SpriteCollection.platforms[toDelete].spriteCollection.spriteCollection != null)
                        {
                            deletedSpriteCollection = SpriteCollection.platforms[toDelete].spriteCollection;
                        }
                        SpriteCollection.platforms.RemoveAt(toDelete);
                    }
                    if (deletedSpriteCollection != null)
                    {
                        foreach (tk2dSpriteCollectionFont f in deletedSpriteCollection.fonts)
                        {
                            tk2dSystemUtility.UnmakeLoadableAsset(f.data);
                        }
                        tk2dSystemUtility.UnmakeLoadableAsset(deletedSpriteCollection.spriteCollection);
                    }
                }

                if (SpriteCollection.platforms.Count > 1 ||
                    (SpriteCollection.platforms.Count == 1 && SpriteCollection.platforms[0].name.Length > 0))
                {
                    GUILayout.BeginHorizontal();
                    EditorGUILayout.PrefixLabel(" ");
                    if (GUILayout.Button("Add new platform", EditorStyles.miniButton))
                    {
                        SpriteCollection.platforms.Add(new tk2dSpriteCollectionPlatform());
                    }
                    GUILayout.EndHorizontal();
                }
            }

            EndHeader();
        }

        void DrawTextureSettings()
        {
            BeginHeader("Texture Settings");

            SpriteCollection.forceA8     = EditorGUILayout.Toggle("Force A8", SpriteCollection.forceA8);
            SpriteCollection.forceShader = EditorGUILayout.ObjectField("Force Shader", SpriteCollection.forceShader, typeof(Shader), false) as Shader;

            tk2dSpriteCollection.AtlasFormat tk2dAtlasFormat = SpriteCollection.atlasFormat;
            if (SpriteCollection.forceA8)
            {
                if (tk2dAtlasFormat == tk2dSpriteCollection.AtlasFormat.StreamingPNG)
                {
                    tk2dAtlasFormat = tk2dSpriteCollection.AtlasFormat.Png;
                }
                int index = (tk2dAtlasFormat == tk2dSpriteCollection.AtlasFormat.UnityTexture) ? (0) : (1);
                index           = EditorGUILayout.Popup("Atlas Format", index, new string[] { "Unity Texture", "Png" });
                tk2dAtlasFormat = (index == 0) ? (tk2dSpriteCollection.AtlasFormat.UnityTexture) : (tk2dSpriteCollection.AtlasFormat.Png);

                SpriteCollection.textureCompression = tk2dSpriteCollection.TextureCompression.Alpha8;
                EditorGUILayout.LabelField("Compression", tk2dSpriteCollection.TextureCompression.Alpha8.ToString());
            }
            else
            {
                tk2dAtlasFormat = (tk2dSpriteCollection.AtlasFormat)EditorGUILayout.EnumPopup("Atlas Format", SpriteCollection.atlasFormat);
            }

            SpriteCollection.atlasFormat = tk2dAtlasFormat;
            if (SpriteCollection.atlasFormat == tk2dSpriteCollection.AtlasFormat.UnityTexture)
            {
                SpriteCollection.filterMode = (FilterMode)EditorGUILayout.EnumPopup("Filter Mode", SpriteCollection.filterMode);
                if (!SpriteCollection.forceA8)
                {
                    SpriteCollection.textureCompression = (tk2dSpriteCollection.TextureCompression)EditorGUILayout.EnumPopup("Compression", SpriteCollection.textureCompression);
                }
                SpriteCollection.userDefinedTextureSettings = EditorGUILayout.Toggle("User Defined", SpriteCollection.userDefinedTextureSettings);
                if (SpriteCollection.userDefinedTextureSettings)
                {
                    GUI.enabled = false;
                }
                EditorGUI.indentLevel++;
                SpriteCollection.wrapMode      = (TextureWrapMode)EditorGUILayout.EnumPopup("Wrap Mode", SpriteCollection.wrapMode);
                SpriteCollection.anisoLevel    = (int)EditorGUILayout.IntSlider("Aniso Level", SpriteCollection.anisoLevel, 0, 9);
                SpriteCollection.mipmapEnabled = EditorGUILayout.Toggle("Mip Maps", SpriteCollection.mipmapEnabled);
                EditorGUI.indentLevel--;
                GUI.enabled = true;
            }
            else if (SpriteCollection.atlasFormat == tk2dSpriteCollection.AtlasFormat.Png)
            {
                tk2dGuiUtility.InfoBox("Png atlases will decrease on disk game asset sizes, at the expense of increased load times.",
                                       tk2dGuiUtility.WarningLevel.Warning);
                if (!SpriteCollection.forceA8)
                {
                    SpriteCollection.textureCompression = (tk2dSpriteCollection.TextureCompression)EditorGUILayout.EnumPopup("Compression", SpriteCollection.textureCompression);
                }
                SpriteCollection.filterMode    = (FilterMode)EditorGUILayout.EnumPopup("Filter Mode", SpriteCollection.filterMode);
                SpriteCollection.mipmapEnabled = EditorGUILayout.Toggle("Mip Maps", SpriteCollection.mipmapEnabled);
            }
            else if (SpriteCollection.atlasFormat == tk2dSpriteCollection.AtlasFormat.StreamingPNG)
            {
                tk2dGuiUtility.InfoBox("Png atlases will decrease on disk game asset sizes, at the expense of increased load times. Streaming allow dynamically load textures",
                                       tk2dGuiUtility.WarningLevel.Warning);
                SpriteCollection.premultipliedAlpha = true;
                SpriteCollection.textureCompression = tk2dSpriteCollection.TextureCompression.Uncompressed;
                EditorGUILayout.LabelField("Compression", tk2dSpriteCollection.TextureCompression.Uncompressed.ToString());
                SpriteCollection.filterMode    = (FilterMode)EditorGUILayout.EnumPopup("Filter Mode", SpriteCollection.filterMode);
                SpriteCollection.mipmapEnabled = EditorGUILayout.Toggle("Mip Maps", SpriteCollection.mipmapEnabled);
            }


            int curRescaleSelection = 0;

            if (SpriteCollection.globalTextureRescale > 0.4 && SpriteCollection.globalTextureRescale < 0.6)
            {
                curRescaleSelection = 1;
            }
            if (SpriteCollection.globalTextureRescale > 0.2 && SpriteCollection.globalTextureRescale < 0.3)
            {
                curRescaleSelection = 2;
            }
            int newRescaleSelection = EditorGUILayout.Popup("Rescale", curRescaleSelection, new string[] { "1", "0.5", "0.25" });

            switch (newRescaleSelection)
            {
            case 0: SpriteCollection.globalTextureRescale = 1.0f; break;

            case 1: SpriteCollection.globalTextureRescale = 0.5f; break;

            case 2: SpriteCollection.globalTextureRescale = 0.25f; break;
            }

            SpriteCollection.asyncLoadEnabled = EditorGUILayout.Toggle("Async Load", SpriteCollection.asyncLoadEnabled);

            EndHeader();
        }

        void DrawSpriteCollectionSettings()
        {
            BeginHeader("Sprite Collection Settings");

            tk2dGuiUtility.SpriteCollectionSize(SpriteCollection.sizeDef);

            GUILayout.Space(4);

            SpriteCollection.padAmount = EditorGUILayout.IntPopup("Pad Amount", SpriteCollection.padAmount, padAmountLabels, padAmountValues);
            if (SpriteCollection.padAmount == 0 && SpriteCollection.filterMode != FilterMode.Point)
            {
                tk2dGuiUtility.InfoBox("Filter mode is not set to Point." +
                                       " Some bleeding will occur at sprite edges.",
                                       tk2dGuiUtility.WarningLevel.Info);
            }

            SpriteCollection.innerPadAmount = EditorGUILayout.IntPopup("Inner Pad Amount", SpriteCollection.innerPadAmount, innerPadAmountLabels, innerPadAmountValues);
            if (SpriteCollection.innerPadAmount != 0)
            {
                tk2dGuiUtility.InfoBox("Inner Pad is not set to Zero." +
                                       " Maybe need replace source texture.",
                                       tk2dGuiUtility.WarningLevel.Info);
            }

            SpriteCollection.premultipliedAlpha = EditorGUILayout.Toggle("Premultiplied Alpha", SpriteCollection.premultipliedAlpha);
            SpriteCollection.disableTrimming    = EditorGUILayout.Toggle("Disable Trimming", SpriteCollection.disableTrimming);
            GUIContent gc = new GUIContent("Disable rotation", "Disable rotation of sprites in atlas. Use this if you need consistent UV direction for shader special effects.");

            SpriteCollection.disableRotation      = EditorGUILayout.Toggle(gc, SpriteCollection.disableRotation);
            SpriteCollection.normalGenerationMode = (tk2dSpriteCollection.NormalGenerationMode)EditorGUILayout.EnumPopup("Normal Generation", SpriteCollection.normalGenerationMode);

            EndHeader();
        }

        void DrawPhysicsSettings()
        {
            BeginHeader("Physics Settings");

#if (UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2)
            GUI.enabled = false;
            SpriteCollection.physicsEngine = tk2dSpriteDefinition.PhysicsEngine.Physics3D;
#endif
            SpriteCollection.physicsEngine = (tk2dSpriteDefinition.PhysicsEngine)EditorGUILayout.EnumPopup("Physics Engine", SpriteCollection.physicsEngine);
#if (UNITY_3_5 || UNITY_4_0 || UNITY_4_0_1 || UNITY_4_1 || UNITY_4_2)
            GUI.enabled = false;
#endif
            GUI.enabled = SpriteCollection.physicsEngine == tk2dSpriteDefinition.PhysicsEngine.Physics3D;
            SpriteCollection.physicsDepth = EditorGUILayout.FloatField("Collider depth", SpriteCollection.physicsDepth);
            GUI.enabled = true;

            EndHeader();
        }

        void DrawAtlasSettings()
        {
            BeginHeader("Atlas Settings");

            int[]    allowedAtlasSizes       = { 64, 128, 256, 512, 1024, 2048, 4096 };
            string[] allowedAtlasSizesString = new string[allowedAtlasSizes.Length];
            for (int i = 0; i < allowedAtlasSizes.Length; ++i)
            {
                allowedAtlasSizesString[i] = allowedAtlasSizes[i].ToString();
            }

            SpriteCollection.freeSizeAtlas = EditorGUILayout.Toggle("Free Atlas Size", SpriteCollection.freeSizeAtlas);
            SpriteCollection.amountOfPixelsToExtendFreeSize = EditorGUILayout.IntField("Additional size to extend free atlas", SpriteCollection.amountOfPixelsToExtendFreeSize);

            SpriteCollection.forceTextureSize = EditorGUILayout.Toggle("Force Atlas Size", SpriteCollection.forceTextureSize);
            EditorGUI.indentLevel++;
            if (SpriteCollection.forceTextureSize)
            {
                SpriteCollection.forcedTextureWidth  = EditorGUILayout.IntPopup("Width", SpriteCollection.forcedTextureWidth, allowedAtlasSizesString, allowedAtlasSizes);
                SpriteCollection.forcedTextureHeight = EditorGUILayout.IntPopup("Height", SpriteCollection.forcedTextureHeight, allowedAtlasSizesString, allowedAtlasSizes);
            }
            else
            {
                SpriteCollection.maxTextureSize   = EditorGUILayout.IntPopup("Max Size", SpriteCollection.maxTextureSize, allowedAtlasSizesString, allowedAtlasSizes);
                SpriteCollection.forceSquareAtlas = EditorGUILayout.Toggle("Force Square", SpriteCollection.forceSquareAtlas);
            }
            EditorGUI.indentLevel--;

            bool allowMultipleAtlases = EditorGUILayout.Toggle("Multiple Atlases", SpriteCollection.allowMultipleAtlases);

            if (allowMultipleAtlases != SpriteCollection.allowMultipleAtlases)
            {
                // Disallow switching if using unsupported features
                if (allowMultipleAtlases == true)
                {
                    bool hasDicing = false;
                    for (int i = 0; i < SpriteCollection.textureParams.Count; ++i)
                    {
                        if (SpriteCollection.textureParams[i].texture != null &
                            SpriteCollection.textureParams[i].dice)
                        {
                            hasDicing = true;
                            break;
                        }
                    }

                    if (SpriteCollection.fonts.Count > 0 || hasDicing)
                    {
                        EditorUtility.DisplayDialog("Multiple atlases",
                                                    "Multiple atlases not allowed. This sprite collection contains fonts and/or " +
                                                    "contains diced sprites.", "Ok");
                        allowMultipleAtlases = false;
                    }
                }

                SpriteCollection.allowMultipleAtlases = allowMultipleAtlases;
            }

            if (SpriteCollection.allowMultipleAtlases)
            {
                tk2dGuiUtility.InfoBox("Sprite collections with multiple atlas spanning enabled cannot be used with the Static Sprite" +
                                       " Batcher, Fonts, the TileMap Editor and doesn't support Sprite Dicing and material level optimizations.\n\n" +
                                       "Avoid using it unless you are simply importing a" +
                                       " large sequence of sprites for an animation.", tk2dGuiUtility.WarningLevel.Info);
            }

            if (SpriteCollection.allowMultipleAtlases)
            {
                EditorGUILayout.LabelField("Num Atlases", SpriteCollection.atlasTextures.Length.ToString());
            }
            else
            {
                EditorGUILayout.LabelField("Atlas Width", SpriteCollection.atlasWidth.ToString());
                EditorGUILayout.LabelField("Atlas Height", SpriteCollection.atlasHeight.ToString());
                EditorGUILayout.LabelField("Atlas Wastage", SpriteCollection.atlasWastage.ToString("0.00") + "%");
            }

            if (SpriteCollection.atlasFormat == tk2dSpriteCollection.AtlasFormat.Png)
            {
                int totalAtlasSize = 0;
                foreach (TextAsset ta in SpriteCollection.atlasTextureFiles)
                {
                    if (ta != null)
                    {
                        totalAtlasSize += ta.bytes.Length;
                    }
                }
                EditorGUILayout.LabelField("Atlas File Size", EditorUtility.FormatBytes(totalAtlasSize));
            }

            if (SpriteCollection.atlasFormat == tk2dSpriteCollection.AtlasFormat.StreamingPNG)
            {
                int totalAtlasSize = 0;
                foreach (string fp in SpriteCollection.atlasTexturePaths)
                {
                    if (fp != null)
                    {
                        var file = new System.IO.FileInfo(fp);
                        if (file.Exists)
                        {
                            totalAtlasSize += (int)file.Length;
                        }
                    }
                }
                EditorGUILayout.LabelField("Atlas File Size", EditorUtility.FormatBytes(totalAtlasSize));
            }

            GUIContent remDuplicates = new GUIContent("Remove Duplicates", "Remove duplicate textures after trimming and other processing.");

            SpriteCollection.removeDuplicates = EditorGUILayout.Toggle(remDuplicates, SpriteCollection.removeDuplicates);

            SpriteCollection.usePosterize   = EditorGUILayout.Toggle("Use Posterize: ", SpriteCollection.usePosterize);
            SpriteCollection.posterizeValue = EditorGUILayout.IntField("Posterize Value: ", SpriteCollection.posterizeValue);

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Use tk2dplatform scale vertex (NOT GUI)");
            SpriteCollection.enablePlatformScaleVertex = EditorGUILayout.Toggle("Enable platfrom scale: ", SpriteCollection.enablePlatformScaleVertex);

            EndHeader();
        }
Esempio n. 7
0
	public static string PlatformPopup(tk2dSystem system, string label, string platform)
	{
		if (system == null)
			return label;

		int selectedIndex = -1;
		string[] platformNames = new string[system.assetPlatforms.Length];

		for (int i = 0; i < system.assetPlatforms.Length; ++i)
		{
			platformNames[i] = system.assetPlatforms[i].name;
			if (platformNames[i] == platform) selectedIndex = i;
		}

		selectedIndex = EditorGUILayout.Popup(label, selectedIndex, platformNames);
		if (selectedIndex == -1) return "";
		else return platformNames[selectedIndex];
	}
Esempio n. 8
0
    public static void RebuildResources()
    {
        // Delete all existing resources
        string systemFileName = tk2dSystem.assetFileName.ToLower();
        string tk2dIndexDir   = "Assets/Resources/tk2d";

        if (System.IO.Directory.Exists(tk2dIndexDir))
        {
            string[] files = System.IO.Directory.GetFiles(tk2dIndexDir);
            foreach (string file in files)
            {
                string filename = System.IO.Path.GetFileName(file).ToLower();
                if (filename.IndexOf(systemFileName) != -1)
                {
                    continue;                                                         // don't delete system object
                }
                if (filename.IndexOf("tk2d_") == -1)
                {
                    CustomDebug.LogError(string.Format("Unknown file '{0}' in tk2d resources directory, ignoring.", filename));
                    continue;
                }
                AssetDatabase.DeleteAsset(file);
            }
        }

        // Delete all referenced resources, in the event they've been moved out of the directory
        if (tk2dSystem.inst_NoCreate != null)
        {
            tk2dSystem             sys = tk2dSystem.inst;
            tk2dResourceTocEntry[] toc = sys.Editor__Toc;
            for (int i = 0; i < toc.Length; ++i)
            {
                string path = AssetDatabase.GUIDToAssetPath(toc[i].resourceGUID);
                if (path.Length > 0)
                {
                    AssetDatabase.DeleteAsset(path);
                }
            }
            sys.Editor__Toc = new tk2dResourceTocEntry[0];             // clear index
            EditorUtility.SetDirty(sys);
            AssetDatabase.SaveAssets();
        }

        AssetDatabase.Refresh();

        // Need to create new index?
        tk2dSpriteCollectionIndex[] spriteCollectionIndex = tk2dEditorUtility.GetExistingIndex().GetSpriteCollectionIndex();
        tk2dGenericIndexItem[]      fontIndex             = tk2dEditorUtility.GetExistingIndex().GetFonts();
        int numLoadableAssets = 0;

        foreach (tk2dGenericIndexItem font in fontIndex)
        {
            if (font.managed || font.loadable)
            {
                numLoadableAssets++;
            }
        }
        foreach (tk2dSpriteCollectionIndex sc in spriteCollectionIndex)
        {
            if (sc.managedSpriteCollection || sc.loadable)
            {
                numLoadableAssets++;
            }
        }

        // Need an index
        if (numLoadableAssets > 0)
        {
            // If it already existed, the index would have been cleared by now
            tk2dSystem sys = tk2dSystem.inst;

            foreach (tk2dGenericIndexItem font in fontIndex)
            {
                if (font.managed || font.loadable)
                {
                    AddFontFromIndex(font);
                }
                tk2dEditorUtility.CollectAndUnloadUnusedAssets();
            }
            foreach (tk2dSpriteCollectionIndex sc in spriteCollectionIndex)
            {
                if (sc.managedSpriteCollection || sc.loadable)
                {
                    AddSpriteCollectionFromIndex(sc);
                }
                tk2dEditorUtility.CollectAndUnloadUnusedAssets();
            }
            sys.SetUsePlatform(tk2dPreferences.inst.platform);
            EditorUtility.SetDirty(sys);
            AssetDatabase.SaveAssets();

            Debug.Log(string.Format("Rebuilt {0} resources for tk2dSystem", sys.Editor__Toc.Length));
        }

        tk2dEditorUtility.CollectAndUnloadUnusedAssets();
    }
Esempio n. 9
0
    void OnGUI()
    {
        tk2dPreferences prefs = tk2dPreferences.inst;

        scroll = GUILayout.BeginScrollView(scroll, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
        tk2dGuiUtility.LookLikeControls(150.0f);

        prefs.displayTextureThumbs = EditorGUILayout.Toggle(label_spriteThumbnails, prefs.displayTextureThumbs);

        prefs.autoRebuild = EditorGUILayout.Toggle(label_autoRebuild, prefs.autoRebuild);

        prefs.showIds = EditorGUILayout.Toggle(label_showIds, prefs.showIds);

        prefs.gridType = (tk2dGrid.Type)EditorGUILayout.EnumPopup("Grid Type", prefs.gridType);
        if (prefs.gridType == tk2dGrid.Type.Custom)
        {
            EditorGUI.indentLevel++;
            prefs.customGridColor0 = EditorGUILayout.ColorField("Color 0", prefs.customGridColor0);
            prefs.customGridColor1 = EditorGUILayout.ColorField("Color 1", prefs.customGridColor1);
            EditorGUI.indentLevel--;
        }

        GUILayout.BeginHorizontal();
        EditorGUILayout.PrefixLabel(" ");
        Rect r = GUILayoutUtility.GetRect(64, 64);

        GUILayout.FlexibleSpace();
        tk2dGrid.Draw(r);
        GUILayout.EndHorizontal();

        if (GUILayout.Button("Reset Editor Sizes"))
        {
            prefs.spriteCollectionListWidth      = tk2dPreferences.Defaults.spriteCollectionListWidth;
            prefs.spriteCollectionInspectorWidth = tk2dPreferences.Defaults.spriteCollectionInspectorWidth;
            prefs.animListWidth      = tk2dPreferences.Defaults.animListWidth;
            prefs.animInspectorWidth = tk2dPreferences.Defaults.animInspectorWidth;
            prefs.animFrameWidth     = tk2dPreferences.Defaults.animFrameWidth;
            GUI.changed = true;
        }

        if (tk2dSystem.inst_NoCreate != null)
        {
            string newPlatform = tk2dGuiUtility.PlatformPopup(tk2dSystem.inst_NoCreate, "Platform", prefs.platform);
            if (newPlatform != prefs.platform)
            {
                prefs.platform = newPlatform;
                UnityEditor.EditorPrefs.SetString("tk2d_platform", newPlatform);
                tk2dSystem.CurrentPlatform = prefs.platform;         // mirror to where it matters
                tk2dSystemUtility.PlatformChanged();                 // tell the editor things have changed
                tk2dEditorUtility.UnloadUnusedAssets();

                tk2dSystem sys = tk2dSystem.inst;
                sys.SetUsePlatform(prefs.platform);
                EditorUtility.SetDirty(sys);
                AssetDatabase.SaveAssets();
            }
        }

        prefs.enableSpriteHandles = EditorGUILayout.Toggle(label_enableSpriteHandles, prefs.enableSpriteHandles);
        bool oldGuiEnable = GUI.enabled;

        GUI.enabled = prefs.enableSpriteHandles;
        EditorGUI.indentLevel++;
        prefs.enableMoveHandles = EditorGUILayout.Toggle(label_enableMoveHandles, prefs.enableMoveHandles);
        EditorGUI.indentLevel--;
        GUI.enabled = oldGuiEnable;

        EditorGUILayout.LabelField("Tilemap Paint Mode Colors");
        ++EditorGUI.indentLevel;
        EditorGUI.BeginChangeCheck();
        prefs.tileMapToolColor_brush       = EditorGUILayout.ColorField("Brush", prefs.tileMapToolColor_brush);
        prefs.tileMapToolColor_brushRandom = EditorGUILayout.ColorField("Random", prefs.tileMapToolColor_brushRandom);
        prefs.tileMapToolColor_erase       = EditorGUILayout.ColorField("Erase", prefs.tileMapToolColor_erase);
        prefs.tileMapToolColor_eyedropper  = EditorGUILayout.ColorField("Eyedropper", prefs.tileMapToolColor_eyedropper);
        prefs.tileMapToolColor_cut         = EditorGUILayout.ColorField("Cut", prefs.tileMapToolColor_cut);
        if (EditorGUI.EndChangeCheck())
        {
            updateTilemapCursorColor = true;
        }
        --EditorGUI.indentLevel;

        GUILayout.EndScrollView();

        if (GUI.changed)
        {
            tk2dPreferences.inst.Save();
        }
    }