コード例 #1
0
    private void Edit_Int_Param <T>(ref Dictionary <TRANS_PARAM_ID, T> dic, ref bool isShow, ref TRANS_PARAM_ID param_id)
    {
        System.TypeCode typecode = System.Type.GetTypeCode(typeof(T));

        EditorGUILayout.BeginHorizontal("box");

        if (GUILayout.Button(isShow ? "-":"+", GUILayout.Width(50)))
        {
            isShow = !isShow;
        }

        if (dic != null)
        {
            GUILayout.Label(typecode.ToString() + " Param (" + dic.Count + ")");
        }

        EditorGUILayout.EndHorizontal();

        if (!isShow)
        {
            return;
        }

        EditorGUILayout.BeginHorizontal();

        param_id = (TRANS_PARAM_ID)EditorGUILayout.EnumPopup(param_id, GUILayout.Width(250));
        if (GUILayout.Button("추가", GUILayout.Width(50)))
        {
            switch (typecode)
            {
            case System.TypeCode.Int32:
                curFSM.AddParamInt(param_id);
                break;

            case System.TypeCode.Single:
                curFSM.AddParamFloat(param_id);
                break;

            case System.TypeCode.Boolean:
                curFSM.AddParamBool(param_id);
                break;
            }
        }

        EditorGUILayout.EndHorizontal();

        //int 파라메터 키/초기화값
        if (dic != null)
        {
            TRANS_PARAM_ID[] keys = new TRANS_PARAM_ID[dic.Count];
            dic.Keys.CopyTo(keys, 0);

            foreach (TRANS_PARAM_ID key in keys)
            {
                EditorGUILayout.BeginHorizontal();

                GUILayout.Label(key.ToString(), GUILayout.Width(250));
                switch (typecode)
                {
                case System.TypeCode.Int32:
                    dic[key] = (T)(object)EditorGUILayout.IntField((int)(object)dic[key], GUILayout.Width(100));
                    break;

                case System.TypeCode.Single:
                    dic[key] = (T)(object)EditorGUILayout.FloatField((float)(object)dic[key], GUILayout.Width(100));
                    break;

                case System.TypeCode.Boolean:
                    dic[key] = (T)(object)EditorGUILayout.Toggle((bool)(object)dic[key], GUILayout.Width(100));
                    break;
                }

                if (GUILayout.Button("삭제", GUILayout.Width(50)))
                {
                    dic.Remove(key);
                }

                EditorGUILayout.EndHorizontal();
            }
        }
    }