Esempio n. 1
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. 2
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();
        }
    }