Example #1
0
        static void _MakeAtlas()
        {
            //Debug.Log(string.Format("UI Texture To Prefab"));

            string spriteDir = Application.dataPath + "/Resources/UI/Sprites/";

            var filesPath = GKFileUtil.GetFilesInDirectory(Application.dataPath + "/Art/_UI/Sprite2Prefab/");

            foreach (var str in filesPath)
            {
                if (string.Empty != GKString.GetFromSuffix(str, ".png", true) ||
                    string.Empty != GKString.GetFromSuffix(str, ".jpg", true))
                {
                    string     allPath   = str;
                    string     assetPath = allPath.Substring(allPath.IndexOf("Assets"));
                    Sprite     sprite    = AssetDatabase.LoadAssetAtPath <Sprite>(assetPath);
                    GameObject go        = new GameObject(sprite.name);
                    go.AddComponent <SpriteRenderer>().sprite = sprite;
                    var dir = GKFileUtil.GetDirctoryName(allPath);
                    allPath = string.Format("{0}{1}/{2}.prefab", spriteDir, dir, sprite.name);
                    GKFileUtil.CreateDirectoryFromFileName(allPath);
                    string prefabPath = allPath.Substring(allPath.IndexOf("Assets"));
                    PrefabUtility.CreatePrefab(prefabPath, go);
                    GameObject.DestroyImmediate(go);
                }
            }
        }
Example #2
0
        static public int GetArrayElementPropIndex(SerializedProperty prop)
        {
            var ext = System.IO.Path.GetExtension(prop.propertyPath);
            var s   = GKString.GetFromPrefix(ext, ".data[", false);

            if (string.IsNullOrEmpty(s))
            {
                return(-1);
            }

            s = GKString.GetFromSuffix(s, "]", false);
            if (string.IsNullOrEmpty(s))
            {
                return(-2);
            }

            int i;

            if (!int.TryParse(s, out i))
            {
                return(-3);
            }

            return(i);
        }
Example #3
0
        static public T TryLoadResource <T>(string filename) where T : UnityEngine.Object
        {
            var fullpath = System.IO.Path.GetFullPath(filename).Replace('\\', '/');
            var pwd      = System.IO.Directory.GetCurrentDirectory().Replace('\\', '/') + "/";
            var relPath  = GKString.GetFromPrefix(fullpath, pwd, true);
            var o        = (T)AssetDatabase.LoadAssetAtPath(relPath, typeof(T));

            return(o);
        }
Example #4
0
        // [MenuItem("GK/File Tools/Delete Empty Folders")]
        static void MenuItem_DeleteEmptyFolders()
        {
            var list = DeleteEmptyFolders("Assets");

            Debug.Log("== Deleted folder " + list.Count + " ==\n" + GKString.FromList(list, "\n"));
        }