Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
//マネージャクラス(オブジェクトにアタッチするのはこれだけ)
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