Exemplo n.º 1
0
        private void OnEnable()
        {
            mActionEditors.Clear();
            if (!mScript)
            {
                return;
            }
            foreach (var actionKitVisualAction in mScript.Acitons)
            {
                AddEditor(actionKitVisualAction);
            }

            this.AddChild(
                EasyIMGUI.Horizontal()
                .AddChild(EasyIMGUI.Label().Text("Actions").FontBold().FontSize(12))
                .AddChild(EasyIMGUI.FlexibleSpace())
                .AddChild(EasyIMGUI.Button().Text("+").FontBold().FontSize(12).OnClick(() =>
            {
                ActionBrowser.Open((t) =>
                {
                    var visualAction       = mScript.gameObject.AddComponent(t) as ActionKitVisualAction;
                    visualAction.hideFlags = HideFlags.HideInInspector;
                    mScript.Acitons.Add(visualAction);
                    AddEditor(visualAction);

                    Save();
                });
            }))
                );
        }
Exemplo n.º 2
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            for (var i = 0; i < mOnStart.ActionsDatas.Count; i++)
            {
                GUILayout.BeginVertical("box");

                var type = ActionTypeDB.GetTypeByFullName(mOnStart.ActionsDatas[i].ActionName);
                var obj  = JsonUtility.FromJson(mOnStart.ActionsDatas[i].AcitonData, type);

                GUILayout.BeginHorizontal("box");
                GUILayout.Label(type.Name);

                GUILayout.FlexibleSpace();

                if (i != 0 && GUILayout.Button("Up", GUILayout.Width(40)))
                {
                    var previousActionData = mOnStart.ActionsDatas[i - 1];
                    mOnStart.ActionsDatas[i - 1] = mOnStart.ActionsDatas[i];
                    mOnStart.ActionsDatas[i]     = previousActionData;

                    Save();
                    break;
                }

                if (i != mOnStart.ActionsDatas.Count - 1 && GUILayout.Button("Down", GUILayout.Width(40)))
                {
                    var nextActionData = mOnStart.ActionsDatas[i + 1];
                    mOnStart.ActionsDatas[i + 1] = mOnStart.ActionsDatas[i];
                    mOnStart.ActionsDatas[i]     = nextActionData;


                    Save();
                    break;
                }

                if (GUILayout.Button("-", GUILayout.Width(20)))
                {
                    mOnStart.ActionsDatas.RemoveAt(i);

                    UnityEditor.EditorUtility.SetDirty(target);
                    UnityEditor.SceneManagement.EditorSceneManager
                    .MarkSceneDirty(SceneManager.GetActiveScene());

                    GUIUtility.ExitGUI();
                    break;
                }

                GUILayout.EndHorizontal();

                GUILayout.BeginVertical();

                foreach (var fieldInfo in type.GetFields())
                {
                    if (fieldInfo.GetCustomAttributes(false).Cast <SerializeField>().Any())
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Label(fieldInfo.Name);

                        if (fieldInfo.FieldType.IsEnum)
                        {
                            var oldValue = (Enum)fieldInfo.GetValue(obj);

                            var value = UnityEditor.EditorGUILayout.EnumPopup(oldValue);

                            if (!Equals(oldValue, value))
                            {
                                fieldInfo.SetValue(obj, value);

                                UnityEditor.EditorUtility.SetDirty(target);
                                UnityEditor.SceneManagement.EditorSceneManager
                                .MarkSceneDirty(SceneManager.GetActiveScene());
                            }
                        }
                        else if (fieldInfo.FieldType == typeof(string) || fieldInfo.FieldType == typeof(float) ||
                                 fieldInfo.FieldType == typeof(int))
                        {
                            var oldValue = fieldInfo.GetValue(obj).ToString();
                            var value    = GUILayout.TextField(oldValue);

                            if (oldValue != value)
                            {
                                if (fieldInfo.FieldType == typeof(string))
                                {
                                    fieldInfo.SetValue(obj, value);
                                }
                                else if (fieldInfo.FieldType == typeof(float))
                                {
                                    fieldInfo.SetValue(obj, float.Parse(value));
                                }
                                else if (fieldInfo.FieldType == typeof(int))
                                {
                                    fieldInfo.SetValue(obj, int.Parse(value));
                                }

                                mOnStart.ActionsDatas[i].AcitonData = JsonUtility.ToJson(obj);

                                EditorUtility.SetDirty(target);
                                UnityEditor.SceneManagement.EditorSceneManager
                                .MarkSceneDirty(SceneManager.GetActiveScene());
                            }
                        }
                        else if (fieldInfo.FieldType == typeof(bool))
                        {
                            var oldValue = bool.Parse(fieldInfo.GetValue(obj).ToString());
                            var value    = GUILayout.Toggle(oldValue, "");

                            if (oldValue != value)
                            {
                                fieldInfo.SetValue(obj, value);

                                mOnStart.ActionsDatas[i].AcitonData = JsonUtility.ToJson(obj);

                                EditorUtility.SetDirty(target);
                                UnityEditor.SceneManagement.EditorSceneManager
                                .MarkSceneDirty(SceneManager.GetActiveScene());
                            }
                        }


                        GUILayout.EndHorizontal();
                    }
                }

                GUILayout.EndVertical();

                GUILayout.EndVertical();
            }

            if (GUILayout.Button("+"))
            {
                ActionBrowser.Open((type) =>
                {
                    mOnStart.ActionsDatas.Add(new ActionData()
                    {
                        ActionName = type.FullName,
                        AcitonData = JsonUtility.ToJson(Activator.CreateInstance(type))
                    });

                    UnityEditor.EditorUtility.SetDirty(target);
                    UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene());
                });
            }
        }