/// <summary>
        /// 毎フレーム呼ばれる
        /// </summary>
        private void Update()
        {
            if (_needSetCallbacks)
            {
                CustomUI.Initialize();
                ConvertUtility.Initialize();
                _needSetCallbacks           = false;
                Selection.selectionChanged += this.Extract;
                this.Extract();
            }

            this.Repaint();
        }
Exemple #2
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        public ParameterData(ParameterInfo parameterInfo)
        {
            this.ParameterInfo = parameterInfo;
            var parameterType = this.ParameterInfo.ParameterType;

            if (parameterType.IsArray)
            {
                var headerLabel = parameterInfo.Name + " : " + parameterType.Name;
                this.ReorderableList = CustomUI.CreateReorderableList(headerLabel, parameterType);
            }
            else
            {
                this.Value = GetDefaultValue(parameterInfo.ParameterType);
            }
        }
        /// <summary>
        /// EditorWindowの描画
        /// </summary>
        private void OnGUI()
        {
            CustomUI.VersionLabel(VersionLabel);

            EditorGUILayout.LabelField("選択しているオブジェクトのメソッド一覧が表示されます。");
            EditorGUILayout.Space();

            if (this.componentDatas == null)
            {
                return;
            }

            this.scrollPosition = EditorGUILayout.BeginScrollView(this.scrollPosition);
            this.ShowComponents();

            EditorGUILayout.EndScrollView();
        }
        /// <summary>
        /// コンポーネントとメソッドの一覧を表示
        /// </summary>
        private void ShowComponents()
        {
            foreach (var item in this.componentDatas.Select((data, i) => new { componentData = data, index = i }))
            {
                var index = item.index;
                if (index >= isOpen.Length)
                {
                    return;
                }

                // コンポーネント 表示
                var componentData  = item.componentData;
                var componentType  = componentData.ComponentType;
                var objectType     = componentData.ObjectType;
                var scriptType     = componentData.ScriptType;
                var componentLabel = this.GetComponentLabel(componentType, objectType, scriptType);
                isOpen[index] = CustomUI.Foldout(componentLabel, isOpen[index]);
                GUILayout.Space(-22f);
                CustomUI.ScriptOpenButton(componentType.Name);

                GUILayout.Space(18f);

                if (isOpen[index] == false)
                {
                    continue;
                }
                GUILayout.Space(-2f);

                // メソッド一覧 表示
                this.componentDatas[index].MethodDatas.ToList().ForEach(method =>
                {
                    GUILayout.Space(3f);
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(IndentSize);

                    if (GUILayout.Button("実行", GUILayout.Width(MethodCallButtonWidth), GUILayout.Height(MethodCallButtonHeight))) // メソッド実行ボタン
                    {
                        try
                        {
                            var parameters = method.Parameters
                                             .Select(p =>
                            {
                                if (p.ReorderableList == null)
                                {
                                    return(Convert.ChangeType(p.Value, p.ParameterInfo.ParameterType));
                                }
                                else      // 配列
                                {
                                    var elementType = p.ParameterInfo.ParameterType.GetElementType();
                                    return((IList)TypeUtility.ToArray(p.ReorderableList.list, elementType));
                                }
                            })
                                             .ToArray();

                            object result = null;
                            if (IsEditorScript(componentType)) // Editor script
                            {
                                result = InvokeEditorScriptMethod(method, componentType, parameters);
                            }
                            else
                            if (componentType.IsSubclassOf(typeof(MonoBehaviour))) // MonoBehaviour script
                            {
                                result = InvokeMonobehaviourMethod(method, componentType, objectType, parameters, item.componentData.Object);
                            }
                            else // other script
                            {
                                result = InvokeOtherMethod(method, componentType, parameters);
                            }

                            var msg             = method.MethodInfo.Name + " ( " + ToString(parameters) + " )";
                            var isMonobehaviour = componentType.IsSubclassOf(typeof(MonoBehaviour));
                            var isCoroutine     = method.MethodInfo.ReturnType == typeof(IEnumerator);
                            if (!(isMonobehaviour && isCoroutine)) // コルーチンの場合はメソッド返却値を表示させない
                            {
                                msg += "\n-> " + ConvertUtility.Convert(result, method.MethodInfo.ReturnType);
                            }
                            Debug.Log(msg);

                            if (EditorApplication.isPaused && objectType == ObjectType.GameObject)
                            {
                                // 全てのシーンにDirtyフラグを入れる
                                Enumerable.Range(0, EditorSceneManager.sceneCount)
                                .Select(i => EditorSceneManager.GetSceneAt(i))
                                .ToList()
                                .ForEach(s => EditorSceneManager.MarkSceneDirty(s));
                            }
                        }
                        catch (Exception e)
                        {
                            Debug.LogException(e);
                        }
                    }

                    // メソッド表示
                    EditorGUILayout.LabelField(method.MethodInfo.Name + " : " + method.MethodInfo.ReturnType.Name);

                    EditorGUILayout.EndHorizontal();

                    GUILayout.Space(1f);

                    // メソッドが引数を持っていた場合は引数入力フィールドを出す
                    method.Parameters.ToList().ForEach(p =>
                    {
                        string label = this.GetParameterLabel(p.ParameterInfo);

                        GUILayout.Space(-1f);
                        EditorGUI.indentLevel += 2;
                        p.Value = CustomUI.InputField(label, p.ParameterInfo.ParameterType, p.Value);
                        EditorGUI.indentLevel -= 2;

                        // 配列入力フィールドの表示
                        var reorderableList = p.ReorderableList;
                        if (reorderableList != null)
                        {
                            CustomUI.DoLayoutReorderableList(reorderableList);
                            GUILayout.Space(reorderableList.GetHeight() - 19f);
                        }
                    });

                    GUILayout.Space(1f);
                    this.Line(1);
                });

                GUILayout.Space(12f);
            }
        }