/// <summary>指定のコンポーネントのフィールドを選択可能なポップアップで表示する</summary>
    public static void FieldsPopupFromComponent(ref int selectedIndex, ref object selectedField, Component component, Type filterType = null, Type filterAttr = null)
    {
        if (component == null)
        {
            MyGUIUtil.BeginContentColorChange(Color.yellow);
            EditorGUILayout.LabelField("[!]Component is null");
            MyGUIUtil.EndContentColorChange();
            return;
        }

        var fields = component.GetType()
                     .GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static)
                     .ToArray();

        var props = component.GetType()
                    .GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static)
                    .ToArray();

        if (filterType != null)
        {
            fields = fields.Where(item => item.FieldType == filterType).ToArray();
            props  = props.Where(item => item.PropertyType == filterType).ToArray();
        }
        if (filterAttr != null)
        {
            fields = fields.Where(item => Attribute.GetCustomAttribute(item, filterAttr) != null).ToArray();
            props  = props.Where(item => Attribute.GetCustomAttribute(item, filterAttr) != null).ToArray();
        }

        var members = fields
                      .Cast <MemberInfo>()
                      .Union(props.Cast <MemberInfo>())
                      .ToArray();

        if (members.Count() > 0)
        {
            selectedIndex = EditorGUILayout.Popup(selectedIndex, members.Select(item => item.Name).ToArray());
        }
        else
        {
            MyGUIUtil.BeginContentColorChange(Color.yellow);
            EditorGUILayout.LabelField("[!]No fields matched condition");
            MyGUIUtil.EndContentColorChange();
            return;
        }

        var selectedMember = members[selectedIndex];
        var prop           = selectedMember as PropertyInfo;
        var field          = selectedMember as FieldInfo;

        if (prop != null)
        {
            selectedField = prop.GetValue(component, null);
        }
        if (field != null)
        {
            selectedField = field.GetValue(component);
        }
    }
Esempio n. 2
0
            public override void OnInspectorGUI()
            {
                var self = target as ObjectPool;

                serializedObject.Update();

                EditorGUI.BeginChangeCheck();

                //追加ボタン
                if (GUILayout.Button("Add Profile"))
                {
                    self.AddProfile();
                }

                //profile表示
                var remIndexes = new List <int>();
                var profiles   = serializedObject.FindProperty("_profiles");

                for (var i = 0; i < profiles.arraySize; i++)
                {
                    var prof = profiles.GetArrayElementAtIndex(i);

                    EditorGUILayout.BeginHorizontal("box");
                    EditorGUILayout.PropertyField(prof);
                    MyGUIUtil.BeginBackgroundColorChange(Color.red);
                    if (GUILayout.Button("X", GUILayout.Width(16), GUILayout.Height(32)))
                    {
                        remIndexes.Add(i);
                    }
                    MyGUIUtil.EndBackgroundColorChange();
                    EditorGUILayout.EndHorizontal();
                }

                foreach (var index in remIndexes)
                {
                    profiles.DeleteArrayElementAtIndex(index);
                }
                serializedObject.ApplyModifiedProperties();

                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(this, "ObjectPoolInspector Changed");
                }
            }
    public static Component ComponentsPopupFromGameObject(Component selected, GameObject gameObject)
    {
        if (gameObject == null)
        {
            MyGUIUtil.BeginContentColorChange(Color.yellow);
            EditorGUILayout.LabelField("[!]GameObject is null");
            MyGUIUtil.EndContentColorChange();
            return(null);
        }

        var components = gameObject.GetComponents <Component>();
        int cmpIndex   = 0;

        if (selected != null)
        {
            cmpIndex = components
                       .Select((item, index) => new { Index = index, Value = item })
                       .Where(item => item.Value == selected)
                       .Select(item => item.Index)
                       .FirstOrDefault();
        }

        if (components.Count() > 0)
        {
            cmpIndex = EditorGUILayout.Popup(cmpIndex, components.Select(item => item.GetType().Name).ToArray());
        }
        else
        {
            MyGUIUtil.BeginContentColorChange(Color.yellow);
            EditorGUILayout.LabelField("[!]No attached components");
            MyGUIUtil.EndContentColorChange();
            return(null);
        }

        return(components[cmpIndex]);
    }
Esempio n. 4
0
 void Start()
 {
     instance_ = this;
 }
Esempio n. 5
0
        public override void OnInspectorGUI()
        {
            var self = target as TextInjector;

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.LabelField("Text");
            var text = EditorGUILayout.TextArea(self._format, GUILayout.Height(80));

            /*
             * if (!StringUtil.CheckValidFormat(self._format))
             * {
             *      MyGUIUtil.BeginContentColorChange(Color.red);
             *      EditorGUILayout.LabelField("[Invalid format]");
             *      MyGUIUtil.EndContentColorChange();
             * }
             */

            EditorGUILayout.LabelField("Arguments");

            if (self._arguments.Count == 0)
            {
                MyGUIUtil.BeginContentColorChange(Color.yellow);
                EditorGUILayout.LabelField("[No Arguments]");
                MyGUIUtil.EndContentColorChange();
            }
            else
            {
                _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos, GUILayout.Height(160f));
                serializedObject.Update();
                var args = serializedObject.FindProperty("_arguments");

                for (int i = 0; i < args.arraySize; i++)
                {
                    EditorGUILayout.LabelField(i.ToString() + ".");
                    EditorGUILayout.BeginVertical("box");

                    var arg       = args.GetArrayElementAtIndex(i);
                    var instance  = (GameObject)arg.FindPropertyRelative(Argument.P_Instance).objectReferenceValue;
                    var index     = arg.FindPropertyRelative(Argument.P_SelectedMemberIndex).intValue;
                    var component = (Component)arg.FindPropertyRelative(Argument.P_Component).objectReferenceValue;
                    var path      = arg.FindPropertyRelative(Argument.P_PropertyPath).stringValue;

                    EditorGUILayout.PropertyField(arg.FindPropertyRelative(Argument.P_Instance), new GUIContent("インスタンス"));
                    arg.FindPropertyRelative(Argument.P_Component).objectReferenceValue =
                        MyEditorGUILayout.ComponentsPopupFromGameObject(component, instance);

                    MyEditorGUILayout.FieldsPopupFromComponent(ref index, ref path, component, null, typeof(Extractable));
                    arg.FindPropertyRelative(Argument.P_PropertyPath).stringValue     = path;
                    arg.FindPropertyRelative(Argument.P_SelectedMemberIndex).intValue = index;

                    EditorGUILayout.EndVertical();
                }
                serializedObject.ApplyModifiedProperties();
                EditorGUILayout.EndScrollView();
            }

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(target, "Changed TextInjectorInspector");
                self._format = text;

                self.Resize();
                self.TextAplly();
            }

            //base.OnInspectorGUI();
        }