본문 바로가기

Log

#09 새로 알게된 API 모음 그리고 도감 개발 [Unity 개발일지]

개발 현황

시스템 요약

  • 학습 문제를 풀면 '조합법(레시피)'를 획득한다.
    • 획득한 조합법은 도감에서 확인할 수 있다.
    • 조합법 획득 시 JSON 데이터에 결과가 저장된다.
  • 도감에선 조합법 목록과 조합 아이템의 조합법을 확인할 수 있다.
    • 획득하지 못한 조합법은 '?'로 표시된다.

개발 결과

[시스템 요약] 부분 모두 개발 완료! 

잘한 점

  • 전 프로젝트에선 도감 시스템 개발 시 게임 시작 시  List<T> 타입으로 Add() 했었다. 이번엔 방식을 바꿔 Scriptable Object 를 다 불러오는 방식으로 바뀌었다. 이게? 일일이 Add() 해주는 것보다 한 번에 보기도 쉬워서 잘 바꿨따!

아쉬운 점

  • 목록 표시할 때 이름와 Index 가 없어서 알아보기 불편한 것 같다. 나중에 추가해야지

 

새로 알게 된 정보들

Custom Inspector 를 만드는 법 - textArea

 

Unity - Scripting API: TextAreaAttribute

You can specify the minimum and maximum lines for the TextArea, and the field will expand according to the size of the text. A scrollbar will appear if the text is bigger than the area available. Note: The maximum lines refers to the maximum size of the Te

docs.unity3d.com

[CreateAssetMenu(menuName = "ScriptableObject/Recipe")]
public class RecipeSO : ScriptableObject
{
    public int id;
    public ItemSO outputItem;
    public List<ItemSO> ingredients;
    public RecipeType type;
    
    [TextArea]
    public string recipeDesc;
    // public bool isCollected;
}

public enum RecipeType {  
    Basic,
    Main,
}

  • Recipe를 Scriptable Object 로 생성했다. 
  • Recipe Desc : [Text Area] 를 이용하여 한 줄로만 나오는 Inspector의 GUI 를 수정했다.

API 정리

  • [TextArea(MIN,MAX)]
    • MIN, MAX : 표시되는 최소 줄과 최대 줄을 설정할 수 있다.

Resources.LoadAll()

    private void Awake() {
        recipes = Resources.LoadAll("SORecipes", typeof(RecipeSO)).Cast<RecipeSO>().ToList();
        recipes = recipes.OrderBy(x => x.id).ToList(); // id 순 정렬

        recipesCollected = new Dictionary<int, bool>();

        for (int i=0; i<recipes.Count; i++) {
            recipesCollected.Add(i, false);
        }

        currentType = RecipeType.Basic;

    }
  • 도감 Manager.cs : Scriptable Object인 Recipe를 모두 불러와 List 로 넣어준다.

API

 

Unity - Scripting API: Resources.LoadAll

If path refers to a folder, all assets in the folder will be returned. If path refers to a file, only that asset will be returned. The path is relative to any Resources folder inside the Assets folder of your project. Note: All asset names and paths in Uni

docs.unity3d.com

Destroy 불가 에러 : Can't remove RectTransform because Image (Script), Image (Script) depends on it

  • 하위 요소가 포함돼있어 Destroy 불가한 오류
    • 삭제하고자 하는 Transform 요소에 .gameObject 를 붙인다.
Destroy(children[i].gameObject);

그동안 개발일지엔 정보 정리가 많이 없었어서

한 번 열심ㅎ ㅣ 정리해봤다  ! 

 

오늘도 개발 화이팅!!!