C#類結構建議排列

類內部成員架構建議順序:

類
{
    //public 為外界能獲取成員
    public 字段(欄位)

    public 屬性

    public 方法

    //private或protected 為內部私有成員
    private 字段(欄位)

    private 屬性

    private 方法

    protected 字段(欄位)

    protected 屬性

    protected 方法
}

Unity3d-C#可視化自定義class

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;

[System.Serializable]
public class People
{
    public GameObject person;
    public string name;
    public int age;
    public float height;
    public Vector3 location;
    public int[] itemarray = new int[0];
}

public class PeopleList : MonoBehaviour {

    public List<People> people_list = new List<People>();
	// Use this for initialization
	void AddNew()
    {
        people_list.Add(new People());
	}

	// Update is called once per frame
	void Remove(int index)
    {
        people_list.RemoveAt(index);
	}
}
[CustomEditor(typeof(PeopleList))]
public class PeopleListEditor : Editor
{
    PeopleList N;
    SerializedObject GetTarget;
    SerializedProperty TheNewList;
    int ListSize;

    void OnEnable()
    {
        N = (PeopleList)target;
        GetTarget = new SerializedObject(N);
        TheNewList = GetTarget.FindProperty("people_list");// Find the List in our script and create a refrence of it
    }
    public override void OnInspectorGUI()
    {
        GetTarget.Update();
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Define the list size with a number");
        ListSize = TheNewList.arraySize;
        ListSize = EditorGUILayout.IntField("List Size", ListSize);

        if (ListSize != TheNewList.arraySize)
        {
            while (ListSize > TheNewList.arraySize)
            {
                TheNewList.InsertArrayElementAtIndex(TheNewList.arraySize);
            }
            while (ListSize < TheNewList.arraySize)
            {
                TheNewList.DeleteArrayElementAtIndex(TheNewList.arraySize - 1);
            }
        }

        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        EditorGUILayout.Space();

        //Or add a new item to the List<> with a button
        EditorGUILayout.LabelField("Add a new item with a button");

        if (GUILayout.Button("Add New"))
        {
            N.people_list.Add(new People());
        }

        EditorGUILayout.Space();
        EditorGUILayout.Space();

        for (int i = 0; i < TheNewList.arraySize; i++)
        {
            SerializedProperty TheNewListRef = TheNewList.GetArrayElementAtIndex(i);
            SerializedProperty Person = TheNewListRef.FindPropertyRelative("person");
            SerializedProperty Name = TheNewListRef.FindPropertyRelative("name");
            SerializedProperty Age = TheNewListRef.FindPropertyRelative("age");
            SerializedProperty Height = TheNewListRef.FindPropertyRelative("height");
            SerializedProperty Location = TheNewListRef.FindPropertyRelative("location");
            SerializedProperty Itemarray = TheNewListRef.FindPropertyRelative("itemarray");

            EditorGUILayout.LabelField("List (" + i.ToString() + ")");
            Person.objectReferenceValue = EditorGUILayout.ObjectField("Person Object", Person.objectReferenceValue, typeof(GameObject), true);
            Name.stringValue = EditorGUILayout.TextField("Person Name", Name.stringValue);
            Age.intValue = EditorGUILayout.IntField("Person Age", Age.intValue);
            Height.floatValue = EditorGUILayout.FloatField("Person Height", Height.floatValue);
            Location.vector3Value = EditorGUILayout.Vector3Field("Person Location", Location.vector3Value);
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Item Array");
            if (GUILayout.Button("Add New Item", GUILayout.MaxWidth(130), GUILayout.MaxHeight(20)))
            {
                Itemarray.InsertArrayElementAtIndex(Itemarray.arraySize);
                Itemarray.GetArrayElementAtIndex(Itemarray.arraySize - 1).intValue = 0;
            }

            for (int a = 0; a < Itemarray.arraySize; a++)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Item Index (" + a.ToString() + ")", GUILayout.MaxWidth(120));
                Itemarray.GetArrayElementAtIndex(a).intValue = EditorGUILayout.IntField("", Itemarray.GetArrayElementAtIndex(a).intValue, GUILayout.MaxWidth(100));
                if (GUILayout.Button("-", GUILayout.MaxWidth(15), GUILayout.MaxHeight(15)))
                {
                    Itemarray.DeleteArrayElementAtIndex(a);
                }
                EditorGUILayout.EndHorizontal();

            }
            EditorGUILayout.Space();

            //Remove this index from the List
            EditorGUILayout.LabelField("Remove an index from the List<> with a button");
            if (GUILayout.Button("Remove This Index (" + i.ToString() + ")"))
            {
                TheNewList.DeleteArrayElementAtIndex(i);
            }
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.Space();
        }
        GetTarget.ApplyModifiedProperties();
    }

}