Exemple #1
0
        private bool DrawEditTargetContentsGUI(EventMethodInfo editTarget)
        {
            var requestSave = false;

            using (new ContentsScope())
            {
                EditorGUI.BeginChangeCheck();

                var target = EditorGUILayout.ObjectField("Target", editTarget.InvokeTarget, typeof(GameObject), true) as GameObject;

                if (EditorGUI.EndChangeCheck())
                {
                    editTarget.SetInvokeTarget(target);
                    requestSave = true;
                }

                EditorGUI.BeginChangeCheck();

                var eventType = (EventType)EditorGUILayout.EnumPopup("Event", editTarget.EventType);

                if (EditorGUI.EndChangeCheck())
                {
                    editTarget.SetEventType(eventType);
                    requestSave = true;
                }

                if (editTarget.InvokeTarget != null)
                {
                    if (editTarget.CallbackMethods.IsEmpty())
                    {
                        GUILayout.Space(3f);

                        var message = "TimeLineEvent attribute function is not defined.";

                        EditorGUILayout.HelpBox(message, MessageType.Warning);
                    }
                    else
                    {
                        //------ Method ------

                        if (editTarget.CallbackMethods.Any())
                        {
                            var index  = editTarget.CallbackMethods.IndexOf(x => x == editTarget.MethodName);
                            var labels = editTarget.CallbackMethodNames.ToArray();

                            // 「None」の分ずらす.
                            index = index != -1 ? index + 1 : 0;

                            EditorGUI.BeginChangeCheck();

                            index = EditorGUILayout.Popup("Method", index, labels, GUILayout.ExpandWidth(true));

                            if (EditorGUI.EndChangeCheck())
                            {
                                var methodName = 0 < index ? editTarget.CallbackMethods[index - 1] : null;

                                editTarget.SetMethodName(methodName);
                                requestSave = true;
                            }
                        }

                        //------ Argument ------

                        if (editTarget.Arguments.Any())
                        {
                            EditorGUILayout.Separator();

                            using (new EditorGUILayout.HorizontalScope())
                            {
                                GUILayout.Space(20f);

                                using (new EditorGUILayout.VerticalScope())
                                {
                                    EditorLayoutTools.ContentTitle("Argument");

                                    using (new ContentsScope())
                                    {
                                        foreach (var argument in editTarget.Arguments)
                                        {
                                            var name = argument.info.Name;
                                            var type = argument.info.ParameterType;

                                            if (type == typeof(GameObject))
                                            {
                                                EditorGUI.BeginChangeCheck();

                                                var value = EditorLayoutTools.ObjectField(name, argument.value as Object, true);

                                                if (EditorGUI.EndChangeCheck())
                                                {
                                                    if (!AssetDatabase.IsMainAsset(value))
                                                    {
                                                        argument.value = value;
                                                        requestSave    = true;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                var space = 154f;

                                                object value = null;

                                                EditorGUI.BeginChangeCheck();

                                                if (type == typeof(string))
                                                {
                                                    value = EditorLayoutTools.DelayedTextField(name, (string)argument.value, space);
                                                }
                                                else if (type == typeof(int))
                                                {
                                                    value = EditorLayoutTools.DelayedIntField(name, (int)(argument.value ?? 0), space);
                                                }
                                                else if (type == typeof(float))
                                                {
                                                    value = EditorLayoutTools.DelayedFloatField(name, (float)(argument.value ?? 0f), space);
                                                }
                                                else if (type == typeof(bool))
                                                {
                                                    value = EditorLayoutTools.BoolField(name, (bool)(argument.value ?? false), space);
                                                }
                                                else if (type.IsEnum)
                                                {
                                                    var names     = Enum.GetNames(type);
                                                    var values    = Enum.GetValues(type).Cast <int>().ToArray();
                                                    var enumValue = (int)(argument.value ?? -1);
                                                    var index     = Math.Max(Array.IndexOf(values, enumValue), 0);

                                                    index = EditorGUILayout.Popup(name, index, names, GUILayout.ExpandWidth(true));

                                                    value = 0 <= index ? (int)values[index] : -1;
                                                }

                                                if (EditorGUI.EndChangeCheck())
                                                {
                                                    argument.value = value;
                                                    requestSave    = true;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                using (new EditorGUILayout.HorizontalScope())
                {
                    GUILayout.FlexibleSpace();

                    using (new EditorGUILayout.VerticalScope(GUILayout.Width(50f)))
                    {
                        GUILayout.Space(3f);

                        if (GUILayout.Button("delete", EditorStyles.miniButton))
                        {
                            if (EditorUtility.DisplayDialog("Confirm", "Delete this event?", "delete", "cancel"))
                            {
                                deleteTargets.Add(editTarget);
                                requestSave = true;
                            }
                        }
                    }
                }
            }

            return(requestSave);
        }