예제 #1
0
        public static ThemeSkinset Import(string path)
        {
            path = path.Replace("\\", "/");
            var skinset   = new ThemeSkinset();
            var isVariant = path.GetPathTerm().Contains("+");

            skinset.name = path.GetPathTerm().Remove("+");
            skinset.path = path;
            foreach (var skinFile in FileManager.FindAll(path + "/*.guiskin", Theme.debug))
            {
                if (!isVariant && skinFile.path.Contains("/+"))
                {
                    continue;
                }
                var active   = skinset.skins.AddNew();
                var filter   = skinFile.name.Contains("#") ? skinFile.name.Parse("#", ".") : "";
                var skinName = skinFile.name.Remove("#" + filter);
                if (skinName == skinset.name)
                {
                    skinset.skins.Remove(active);
                    active = skinset.main.AddNew();
                }
                active.name = skinName;
                active.path = skinFile.path;
                active.skin = skinFile.GetAsset <GUISkin>();
                if (active.skin.IsNull())
                {
                    Debug.LogWarning("[Themes] GUISkin could not be loaded. This usually occurs when the guiSkin was saved as binary in a newer version.");
                    skinset.skins.Remove(active);
                    continue;
                }
                active.skinset = skinset;
                var field      = skinName.Split(".").Last();
                var parent     = skinName.Replace("." + field, "");
                var typeDirect = Utility.GetUnityType(skinName);
                var typeParent = Utility.GetUnityType(parent);
                var flags      = field.Contains("s_Current") ? ObjectExtension.privateFlags : ObjectExtension.staticFlags;
                if (typeDirect.IsNull() && (typeParent.IsNull() || !typeParent.HasVariable(field)))
                {
                    if (Theme.debug)
                    {
                        Debug.LogWarning("[Themes] No matching class/field found for GUISkin -- " + skinFile.name + ". Possible version conflict.");
                    }
                    continue;
                }
                active.GetScope     = () => { return(!typeDirect.IsNull() ? typeDirect : typeParent.InstanceVariable(field)); };
                active.scopedStyles = !typeDirect.IsNull() ? active.GetScope().GetVariables <GUIStyle>(null, flags) : active.GetScope().GetVariables <GUIStyle>();
            }
            foreach (var variantPath in Directory.GetDirectories(path).Where(x => x.GetPathTerm().Contains("+")))
            {
                var variant = ThemeSkinset.Import(variantPath);
                variant.active = false;
                skinset.variants.Add(variant);
            }
            return(skinset);
        }
예제 #2
0
        //=================================
        // Files
        //=================================
        public static List <ThemeSkinset> Import()
        {
            var imported = new List <ThemeSkinset>();

            foreach (var path in Directory.GetDirectories(Theme.storagePath + "Skinsets"))
            {
                imported.Add(ThemeSkinset.Import(path));
            }
            return(imported);
        }
예제 #3
0
 public static void Load()
 {
     if (Theme.loaded)
     {
         return;
     }
     Theme.loaded     = true;
     ThemeFontset.all = ThemeFontset.Import();
     ThemePalette.all = ThemePalette.Import();
     ThemeSkinset.all = ThemeSkinset.Import();
     ThemeIconset.all = ThemeIconset.Import();
     Theme.all        = Theme.Import().OrderBy(x => x.name != "Default").ToList();
 }