본문 바로가기
개발/Unity

Unity ) 스크립팅이 가능한 오브젝트 (ScriptableObject)

by 테샤르 2021. 2. 26.

스크립팅이 가능한 오브젝트 (ScriptableObject)

Unity에서는 스트립팅이 가능한 오브젝트라는 데이터를 관리할 수 있는 스크립팅을 지원한다.

 

ScriptableObject는 스크립트 인스턴스로부터 독립한 대량의 공유 데이터를 저장할 수 있기 때문에 프로퍼티나 설정 값에 주로 많이 사용한다. 위에 인스펙터에서 수정이가능한 형태로 제공되기 때문에. 간단한 데이터나 빌드에 대한 정보 같은 프로퍼티 설정에 많이 사용한다.

public class SHC_SriptableObject : ScriptableObject
{
	[SerializeField]
    private string VersionName ="";

}
 if (GUILayout.Button("Confirm", GUILayout.Width(GUILayoutWidth)))
 {
     SHC_ScriptableObject scriptObject = Resources.Load("SHC_SriptableObject") as SHC_ScriptableObject;
     if (null == scriptObject)
     {
       Debug.LogErrorFormat("SHC_SriptableObject Not Exist !!");
       return;
     }

    scriptObject.SetAppName(this.m_strAppName);
    scriptObject.SetVersion(this.m_strVersion);
    scriptObject.SetPlayType(this.m_strPlayType);
    scriptObject.SetVersionCode(int.Parse(this.m_strVersionCode));
    scriptObject.SetDebugFlag(this.m_bDebugFlag);
    scriptObject.SetPakageName(this.m_strPakageName);

    this.m_AdMob_Reward_ID_AOS = new List<string>();
    string[] tokenInfo = this.m_AdMob_RewardValue.Split('\n');
    for(int i =0 ;i< tokenInfo.Length;i++){
      this.m_AdMob_Reward_ID_AOS.Add(tokenInfo[i]);
      Logger.LogFormat("reward id :{0}",tokenInfo[i]);
    }

    EditorUtility.DisplayDialog("설정","설정변경되었습니다.", "확인");
    this.UpdateSetting();
    this.SaveSetting();

    EditorUtility.SetDirty(scriptObject);
}

ScriptableObject에서 Class를 처리하는 방법

   [System.Serializable]
    public class Firebase_Terms
    {
        public string jsonString = string.Empty;

        public string GetPolicyURL()
        {
            return string.Empty;
        }
        public string GetTermsURL()
        {
            return string.Empty;
        }
    }
    
    public class FirebaseConfigScriptableObject : ScriptableObject
    {
    	[Header("-----terms")]
    	public Firebase_Terms terms= new Firebase_Terms();
    }

 

 

URL : https://docs.unity3d.com/kr/530/Manual/class-ScriptableObject.html

 

유니티 - 매뉴얼: 스크립팅 가능한 오브젝트(ScriptableObject)

스크립팅 가능한 오브젝트(ScriptableObject) ScriptableObject는 스크립트 인스턴스로부터 독립한 대량의 공유 데이터를 저장할 수 있는 클래스입니다. SerializableObject와 혼동하기 쉽지만, 이쪽은 에디터 클래스이며, 목적도 다릅니다. 예를 들어 integer가 1만 행 있는 배열의 스크립트 프리팹을 작성했다고 가정합니다. 배열은 4MB의 메모리를 점유하고, 프리팹이 오너입니다. 프리팹을 인스턴스화 할 때마다 그 배열이

docs.unity3d.com

 

 

 

 

반응형

댓글