コード例 #1
0
        public static void SyncSpriteArgs()
        {
            // get paths to Sprite args
            string[] guids = AssetDatabase.FindAssets($"t:{nameof(SpriteArgs)}");

            Type spriteArgsType = typeof(SpriteArgs);
            Type spriteType     = typeof(Sprite);

            foreach (string guid in guids)
            {
                PathString path = AssetDatabase.GUIDToAssetPath(guid);
                SpriteArgs args = AssetDatabase.LoadAssetAtPath <SpriteArgs>(path);

                string head = path.RelativeTo("So").ToString('/', false);

                foreach (FieldInfo f in spriteArgsType.GetFields())
                {
                    if (f.FieldType != spriteType)
                    {
                        continue;
                    }

                    UnityPath spritePath = "Assets/Art/Sprites/" + head + $"@{f.Name}.png";

                    Sprite sprite = AssetDatabase.LoadAssetAtPath <Sprite>(spritePath.AssetDatabaseAssetPath);
                    if (sprite != null)
                    {
                        f.SetValue(args, sprite);
                    }
                }
            }

            AssetDatabase.Refresh();
        }
コード例 #2
0
        public void ApplyToImage(Image image, EUiVisualState state = EUiVisualState.Neutral)
        {
            if (Neutral == null)
            {
                SpriteArgs def = DefaultUXUI.Instance.DefaultSpriteArg;
                def.ApplyToImage(image, state);
                return;
            }

            image.sprite = GetSprite(state);
            if (OverrideColor)
            {
                image.color = Color;
            }
        }