Last active
June 12, 2017 19:36
-
-
Save KRNKRS/19a96a44355425832d62daf702330221 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//マネージャクラス(オブジェクトにアタッチするのはこれだけ) | |
public class HogeManager : MonoBehaviour | |
{ | |
//変数定義 | |
[SerializeField] | |
private int intHoge1; | |
[SerializeField] | |
private int intHoge2; | |
//Property定義 | |
public int IntHoge1 { get { return intHoge1; } } | |
public int IntHoge2 { get { return intHoge1; } } | |
void Awake() | |
{ | |
this.gameObject.AddComponent<Hoge1Component>(); | |
this.gameObject.AddComponent<Hoge2Component>(); | |
} | |
} | |
//マネージャ拡張クラス | |
[CustomEditor(typeof(HogeManager))] | |
public class HogeManagerEditor : Editor | |
{ | |
private Hoge1Editor hoge1Edit; | |
private Hoge2Editor hoge2Edit; | |
void OnEnable() | |
{ | |
hoge1Edit = new Hoge1Editor(); | |
hoge2Edit = new Hoge2Editor(); | |
hoge1Edit.LoadProperty(serializedObject); | |
hoge2Edit.LoadProperty(serializedObject); | |
} | |
public override void OnInspectorGUI() | |
{ | |
serializedObject.Update(); | |
{ | |
hoge1Comp.DrawProperty(); | |
hoge2Comp.DrawProperty(); | |
} | |
serializedObject.ApplyModifiedProperties(); | |
} | |
} | |
//Hoge1クラス | |
public class Hoge1Component : MonoBehaviour | |
{ | |
private HogeManager parent; | |
void Awake() | |
{ | |
parent = this.GetComponent<HogeManager>(); | |
} | |
//HogeManagerから持ってきた値で色々処理 | |
Debug.Log("parent.IntHoge1 = " + parent.IntHoge1); | |
} | |
//Hoge1拡張クラス | |
public class Hoge1Editor : Editor | |
{ | |
private SerializedProperty intHoge1; | |
public void LoadProperty(SerializedObject parent) | |
{ | |
intHoge1 = parent.FindProperty("intHoge1"); | |
} | |
public void DrawProperty() | |
{ | |
EditorGUILayout.PropertyField(intHoge1, new GUIContent("IntHoge1")); | |
} | |
} | |
//Hoge2クラス略 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment