Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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();
 }
 public Theme Use(Theme other)
 {
     this.UseVariables(other, typeof(InternalAttribute).AsList());
     if (this.name.IsEmpty())
     {
         this.name = other.name;
     }
     if (this.path.IsEmpty())
     {
         this.path = other.path;
     }
     this.skinset = other.skinset;
     this.iconset = other.iconset;
     return(this);
 }
 public void Deserialize(string data)
 {
     foreach (var line in data.GetLines())
     {
         if (line.Trim().IsEmpty())
         {
             continue;
         }
         var term  = line.Parse("", " ").Trim();
         var value = line.Parse(" ").Trim().Trim("=").Trim();
         if (term.Matches("CustomizablePalette", true))
         {
             this.customizablePalette = value.ToBool();
         }
         else if (term.Matches("CustomizableFontset", true))
         {
             this.customizableFontset = value.ToBool();
         }
         else if (term.Matches("CustomizableIconset", true))
         {
             this.customizableIconset = value.ToBool();
         }
         else if (term.Matches("Palette", true))
         {
             this.palette = ThemePalette.all.Find(x => x.name == value) ?? new ThemePalette();
         }
         else if (term.Matches("Fontset", true))
         {
             this.fontset = ThemeFontset.all.Find(x => x.name == value) ?? new ThemeFontset();
         }
         else if (term.Matches("Iconset", true))
         {
             this.iconset = ThemeIconset.all.Find(x => x.name == value) ?? new ThemeIconset();
         }
         else if (term.Matches("Skinset", true))
         {
             var variants = value.Split("+");
             this.defaultVariants = variants.Skip(1).ToArray();
             this.skinset         = ThemeSkinset.all.Find(x => x.name == variants[0]) ?? new ThemeSkinset();
         }
     }
 }
Beispiel #6
0
 public static void DumpAssets()
 {
     ThemeSkinset.DumpAssets("");
 }
Beispiel #7
0
 public static void DumpAssetsAll()
 {
     ThemeSkinset.DumpAssets("", true);
 }