Пример #1
0
    public static void UpdateHolderThemes(ImageThemeHolder imageHolder)
    {
        if (_themeTypeList == null || _themeTypeList.Count == 0)
        {
            CheckSavedFile();
        }

        List <ImageThemeInfo> tempList = new List <ImageThemeInfo>(imageHolder.ThemeInfoList);

        //Removal of old themes
        foreach (var item in tempList)
        {
            if (!_themeTypeList.Contains(item.ThemeName))
            {
                imageHolder.ThemeInfoList.Remove(item);
            }
        }

        //Adding newly created themes
        foreach (var themeName in _themeTypeList)
        {
            if (imageHolder.ThemeInfoList.Find(t => t.ThemeName == themeName) != null)
            {
                continue;
            }

            ImageThemeInfo newThemeImageHolder = new ImageThemeInfo();
            newThemeImageHolder.ThemeName   = themeName;
            newThemeImageHolder.SpritePath  = "";
            newThemeImageHolder.SpriteColor = Color.white;

            imageHolder.ThemeInfoList.Add(newThemeImageHolder);
        }
    }
Пример #2
0
    public void SetImageAndColor(int themeType)
    {
        ImageThemeInfo appThemeInfo = ThemeInfoList[themeType];

        if (appThemeInfo == null || string.IsNullOrEmpty(appThemeInfo.SpritePath))
        {
            if (EnableDebug)
            {
                Debug.Log("Empty Sprite: NAME: " + name + " THEME: " + themeType);
            }

            return;
        }

        string resourcesRelatedPath = appThemeInfo.SpritePath.Split(new string[] { "Resources/" }, System.StringSplitOptions.None)[1];
        string ext = Path.GetExtension(resourcesRelatedPath);

        resourcesRelatedPath = resourcesRelatedPath.Replace(ext, "");

        Sprite sprite = Resources.Load <Sprite>(resourcesRelatedPath);

        if (EnableDebug)
        {
            Debug.Log("Full Path: " + appThemeInfo.SpritePath);
            Debug.Log("Resources Related Path: " + resourcesRelatedPath);
        }

        _image.sprite = sprite;
        _image.color  = appThemeInfo.SpriteColor;

        _image.SetNativeSize();
    }
Пример #3
0
    public static GUIContent GetButtonContent(ImageThemeInfo holder, Sprite defaultSprite)
    {
        GUIContent buttonContent = new GUIContent(defaultSprite.texture);

        if (!string.IsNullOrEmpty(holder.SpritePath))
        {
            Sprite targetSprite = AssetDatabase.LoadAssetAtPath <Sprite>(holder.SpritePath);

            if (targetSprite != null)
            {
                buttonContent = new GUIContent(targetSprite.texture);
            }
        }

        return(buttonContent);
    }
Пример #4
0
    public static string UpdateThemeHolderSpritePath(ImageThemeInfo holder)
    {
        string newAssetPath = holder.SpritePath;

        if (!string.IsNullOrEmpty(holder.SpritePath))
        {
            Sprite targetSprite = AssetDatabase.LoadAssetAtPath <Sprite>(holder.SpritePath);

            if (targetSprite == null)
            {
                string[] guids = AssetDatabase.FindAssets(holder.SpriteName + " t:Sprite");

                if (guids.Length > 0)
                {
                    string targetGuid = guids[0];

                    newAssetPath = AssetDatabase.GUIDToAssetPath(targetGuid);
                }
            }
        }

        return(newAssetPath);
    }