Today I Learned :
GetLength
GetLength 메서드는 다차원 배열에서 특정 차원의 길이를 반환하는 메서드입니다. 배열의 특정 차원에 대한 길이를 가져올 수 있습니다.
다차원 배열에서는 각 차원마다 길이가 다르기 때문에, GetLength 메서드를 사용하여 특정 차원의 길이를 확인할 수 있습니다.
int[,] arr = new int[3, 4];
int rows = arr.GetLength(0); // rows에는 3이 저장됨
int columns = arr.GetLength(1); // columns에는 4가 저장됨
유니티 미숙으로 인한 스파게티
유니티와 코드 사이에 컨트롤이 필요한데 강의를 통해 배운 구조는 너무 멀리간듯
아직은 익숙해지지 않아 어느위치에서 스크립트를 만들어서 컴포넌트로 넣고 참조시킬지 어렵다.
싱글톤문제
중복생성되는 현상이 발생.
정확한 수정은 아직 완료하지 못함.
using UnityEngine;
public abstract class Singleton<T> : MonoBehaviour where T : Component
{
private static T instance;
public static T Instance
{
get
{
if (instance == null)
{
instance = (T)FindAnyObjectByType(typeof(T));
if (instance == null)
{
GameObject obj = new GameObject(typeof(T).Name, typeof(T));
instance = obj.GetComponent<T>();
}
}
return instance;
}
}
//private static T _instance;
//public static T Instance
//{
// get
// {
// if (_instance != null)
// return _instance;
// _instance = FindAnyObjectByType<T>();
// if (_instance != null)
// return _instance;
// GameObject obj = new() { name = typeof(T).Name };
// _instance = obj.AddComponent<T>();
// return _instance;
// }
//}
protected virtual void Awake()
{
if (transform.parent != null && transform.root != null)
{
// DontDestroyOnLoad 의 경우 하위에 포함되어 있는 경우 제대로 동작을 하지 않는 경우가 있다.
// 최상위를 파괴불가로 해준다(매니저 모음같은 경우)
DontDestroyOnLoad(this.transform.root.gameObject);
}
else
{
DontDestroyOnLoad(this.gameObject);
}
//if (_instance == null)
// _instance = this as T;
//else
// Destroy(gameObject);
//DontDestroyOnLoad(gameObject);
}
}
//using UnityEngine;
//public class Singleton<T> : MonoBehaviour where T : MonoBehaviour
//{
// private static T instance;
// public static T Instance
// {
// get
// {
// if (instance == null)
// {
// instance = (T)FindAnyObjectByType(typeof(T));
// if (instance == null)
// {
// GameObject obj = new GameObject(typeof(T).Name, typeof(T));
// instance = obj.GetComponent<T>();
// }
// }
// return instance;
// }
// }
// private void Awake()
// {
// if (transform.parent != null && transform.root != null)
// {
// // DontDestroyOnLoad 의 경우 하위에 포함되어 있는 경우 제대로 동작을 하지 않는 경우가 있다.
// // 최상위를 파괴불가로 해준다(매니저 모음같은 경우)
// DontDestroyOnLoad(this.transform.root.gameObject);
// }
// else
// {
// DontDestroyOnLoad(this.gameObject);
// }
// }
//}
'TIL' 카테고리의 다른 글
20240124 TIL (1) | 2024.01.24 |
---|---|
20240123 TIL (1) | 2024.01.23 |
20240119 TIL (0) | 2024.01.19 |
20240118 TIL (0) | 2024.01.18 |
20240117 TIL (0) | 2024.01.17 |