Resource change of the same picture

1. Create a dress-up resource in the same psb file

(1) When making art resources in ps, place all the dressing resources of a game object in a good position
(2) When we import this resource, we should pay attention to whether to import hidden layers

Edit the bone information and grouping category of the dress-up resource:

Note: The bones associated with each part should be clearly set and grouped for different equipment of the same part

  • How to dress up:

Two key components
SpriteLibrary——Sprite library, which determines the category grouping information
SpriteResolver——Sprite solver, used to determine the part category and the pictures used
One data file
SpriteLibraryAsset——Sprite library resource, which specifically records the category grouping information

  • code change
//1.获取各部位的SpriteResolver(需要引用命名空间)
//2.使用SpriteResolver的API进行装备切换
//GetCategory() 获取当前部位默认的类别名
//SetCategoryAndLabel 设置当前部位想要切换的图片信息
//sr.SetCategoryAndLabel(sr.GetCategory(), "CASK 1");

SpriteResolver[] srs = this.GetComponentsInChildren<SpriteResolver>();
for (int i = 0; i < srs.Length; i++)
{
    equipDic.Add(srs[i].GetCategory(), srs[i]);
}

ChangeEquip("Cask", "CASK 1");

// ----------------------------------------------------------
public void ChangeEquip(string category, string equipName)
{
    if( equipDic.ContainsKey(category) )
    {
        equipDic[category].SetCategoryAndLabel(category, equipName);
    }
}

2. Make dressup resources in different psb files

(1) Guarantee the unity of each part in the PS file
(2) The basic parts can be selectively hidden

Edit the bone information of the dress-up resource:

Note: The bone information of different files must be unified, so we directly use the copy method

Manually add key components and data files:

(1) First create the SpriteLibraryAsset data file
(2) Add SpriteLibrary to the object and associate the data file
(3) Associate the SpriteResolver for the replacement part

3. Summary

How to choose the same file and different files to make two options for changing resources

Games with fewer outfit changes, such as facial expressions, can use the same psb file scheme.
Games with more outfit changes, such as n types of equipment in each part, can use different psb file schemes. Different
psb files are more scalable.

Guess you like

Origin blog.csdn.net/Go_Accepted/article/details/128461868