Exemplo n.º 1
0
        public static void DrawCode(TemplateSettingStatus status)
        {
            var minHeight = status.GetProperty(TemplateSettingStatus.Property.CodeAreaMinHeight);
            var maxHeight = status.GetProperty(TemplateSettingStatus.Property.CodeAreaMaxHeight);

            if (maxHeight.floatValue > 0f && maxHeight.floatValue < minHeight.floatValue)
            {
                maxHeight.floatValue = minHeight.floatValue;
            }

            EditorGUILayout.BeginHorizontal(EditorGUIHelper.GetScopeStyle());
            {
                EditorGUILayout.PropertyField(minHeight, new GUIContent("Min Height"));
                EditorGUILayout.PropertyField(maxHeight, new GUIContent("Max Height"));
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
            {
                var code       = status.GetProperty(TemplateSettingStatus.Property.Code).stringValue;
                var scrollPos  = status.GetProperty(TemplateSettingStatus.Property.ScrollPos);
                var scroll     = scrollPos.vector2Value;
                var editedCode = SyntaxHighlightUtility.DrawCSharpCode(ref scroll, code, 12, minHeight.floatValue, maxHeight.floatValue);
                scrollPos.vector2Value = scroll;
                if (editedCode != code)
                {
                    status.GetProperty(TemplateSettingStatus.Property.Code).stringValue = editedCode;
                    status.IsUpdateText = true;
                    Undo.IncrementCurrentGroup();
                }
            }
            EditorGUILayout.EndVertical();
        }
Exemplo n.º 2
0
 private void DrawDescription()
 {
     EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
     {
         _descriptionProperty.stringValue = EditorGUILayout.TextArea(_descriptionProperty.stringValue);
     }
     EditorGUILayout.EndVertical();
 }
Exemplo n.º 3
0
 public static void DrawOverwrite(TemplateSettingStatus status)
 {
     EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
     {
         var property = status.GetProperty(TemplateSettingStatus.Property.Overwrite);
         EditorGUILayout.PropertyField(property, new GUIContent("Overwrite Type"));
     }
     EditorGUILayout.EndVertical();
 }
Exemplo n.º 4
0
 private void DrawSetting(TemplateSettingStatus status)
 {
     EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
     {
         TemplateSettingEditor.DrawHeader(status);
         TemplateSettingEditor.DrawCode(status);
         TemplateSettingEditor.DrawChain(status);
         TemplateSettingEditor.DrawOverwrite(status);
         TemplateSettingEditor.DrawPrefab(status);
     }
     EditorGUILayout.EndVertical();
 }
Exemplo n.º 5
0
 private void DrawDescription()
 {
     EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
     {
         var property = SettingStatus.GetProperty(TemplateSettingStatus.Property.Description);
         // TODO : Cache
         var style = new GUIStyle(GUI.skin.textArea)
         {
             wordWrap = true,
         };
         property.stringValue = EditorGUILayout.TextArea(property.stringValue, style);
     }
     EditorGUILayout.EndVertical();
 }
Exemplo n.º 6
0
        public static void DrawHeader(TemplateSettingStatus status)
        {
            EditorGUI.BeginChangeCheck();
            {
                // setting create path
                EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
                {
                    var property = status.GetProperty(TemplateSettingStatus.Property.Path);
                    EditorGUILayout.PropertyField(property, new GUIContent("Create Path"));

                    var paths = EditorGUIHelper.DrawDragAndDropArea();
                    if (paths != null && paths.Length > 0)
                    {
                        // Index 0 のパスを使用する
                        property.stringValue = TemplateUtility.GetDirectoryPath(paths[0]);
                    }

                    var createPath = status.TargetTemplateSetting.Path;
                    if (string.IsNullOrEmpty(createPath))
                    {
                        EditorGUILayout.HelpBox("If empty, the script will be created in active folder", MessageType.Info);
                    }
                    EditorGUILayout.HelpBox("Example: Assets/Folder", MessageType.Info);
                }
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
                {
                    EditorGUILayout.PropertyField(status.GetProperty(TemplateSettingStatus.Property.ScriptName), new GUIContent("Script Name"));
                    if (string.IsNullOrEmpty(status.TargetTemplateSetting.ScriptName))
                    {
                        EditorGUILayout.HelpBox("Example: Example.cs", MessageType.Info);
                    }
                    else if (Regex.IsMatch(status.TargetTemplateSetting.ScriptName, @"\..+$", RegexOptions.Compiled) == false)
                    {
                        EditorGUILayout.HelpBox("Extension required", MessageType.Warning);
                    }
                }
                EditorGUILayout.EndVertical();
            }

            if (EditorGUI.EndChangeCheck())
            {
                status.IsUpdateText = true;
                Undo.IncrementCurrentGroup();
            }
        }
Exemplo n.º 7
0
        private void DrawIsAssetsMenuItem()
        {
            EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
            {
                var cache = _groupSetting.IsAssetsMenuItem;
                EditorGUILayout.PropertyField(_isAssetsMenuItemProperty, new GUIContent("Add Assets Menu"));

                // 生成時に設定反映が間に合わないため
                _groupSetting.IsAssetsMenuItem = _isAssetsMenuItemProperty.boolValue;

                if (cache != _groupSetting.IsAssetsMenuItem)
                {
                    AssetsMenuItemProcessor.Execute();
                }
            }
            EditorGUILayout.EndVertical();
        }
Exemplo n.º 8
0
        private void DrawCreate()
        {
            EditorGUILayout.BeginHorizontal(EditorGUIHelper.GetScopeStyle());
            {
                if (GUILayout.Button("Create"))
                {
                    CreateScript(_replaceList, true);
                    return;
                }

                if (GUILayout.Button("No Refresh Create"))
                {
                    CreateScript(_replaceList, false);
                    return;
                }
            }
            EditorGUILayout.EndHorizontal();
        }
Exemplo n.º 9
0
        private void DrawIsAssetsMenuItem()
        {
            EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
            {
                var cache = SettingStatus.TargetTemplateSetting.IsAssetsMenuItem;
                var isAssetMenuProperty = SettingStatus.GetProperty(TemplateSettingStatus.Property.AssetsMenuItem);
                EditorGUILayout.PropertyField(isAssetMenuProperty, new GUIContent("Add Asset Menu"));

                // 生成時に設定反映が間に合わないため
                SettingStatus.TargetTemplateSetting.IsAssetsMenuItem = isAssetMenuProperty.boolValue;

                if (cache != SettingStatus.TargetTemplateSetting.IsAssetsMenuItem)
                {
                    AssetsMenuItemProcessor.Execute();
                }

                EditorGUILayout.HelpBox("Add a menu item to \"Assets/Create/Template/~\"", MessageType.Info);
            }
            EditorGUILayout.EndVertical();
        }
Exemplo n.º 10
0
        public override void OnInspectorGUI()
        {
            SettingStatus.TargetSerializedObject.Update();
            {
                _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos);
                {
                    DrawHeader(SettingStatus);
                    EditorGUIHelper.DrawFoldouts(_foldouts);
                    DrawOverwrite(SettingStatus);
                    DrawIsAssetsMenuItem();
                    DrawPrefab(SettingStatus);
                    EditorGUIHelper.DrawFoldout(_descriptionFoldout);
                }
                EditorGUILayout.EndScrollView();

                DrawCreate();
                UpdateFoldout();
                UpdateReplaceList();
            }
            SettingStatus.TargetSerializedObject.ApplyModifiedProperties();
        }
Exemplo n.º 11
0
        public static void DrawChain(TemplateSettingStatus status)
        {
            EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
            {
                status.ChainReorderableList.DoLayoutList();

                var selectIndex = status.ChainReorderableList.index;
                if (selectIndex >= 0)
                {
                    var select = status.ChainReorderableList.serializedProperty.GetArrayElementAtIndex(selectIndex);
                    var chain  = TemplateUtility.ConvertProcessChianInstanceFromObject(select.objectReferenceValue);
                    if (chain != null)
                    {
                        var builder = new StringBuilder();
                        builder.AppendLine("[Used Variables]");
                        foreach (var word in chain.GetReplaceWords())
                        {
                            builder.AppendLine(ReplaceProcessor.GetReplaceText(word));
                        }

                        // TODO : Cache
                        var style = new GUIStyle(GUI.skin.label)
                        {
                            wordWrap = true,
                        };
                        var label   = builder.ToString();
                        var content = new GUIContent(label);
                        var rect    = GUILayoutUtility.GetRect(content, style);
                        EditorGUI.SelectableLabel(rect, label, style);
                        EditorGUILayout.LabelField("[Description]\n" + chain.GetDescription(), style);
                    }
                }
                else
                {
                    EditorGUILayout.HelpBox("When you select item, description will be displayed", MessageType.Info, true);
                }
            }
            EditorGUILayout.EndVertical();
        }
Exemplo n.º 12
0
        public override void OnInspectorGUI()
        {
            var isChanged = false;

            serializedObject.Update();
            {
                isChanged = DrawSettingList();

                EditorGUIHelper.DrawFoldouts(_foldoutList);
                TemplateSettingEditor.DrawReplace(_replaceList, _groupSetting.GetInstanceID().ToString());
                DrawIsAssetsMenuItem();
                DrawCreate();
                EditorGUIHelper.DrawFoldout(_descriptionFoldout);

                UpdateReplaceList();
            }
            serializedObject.ApplyModifiedProperties();

            if (isChanged)
            {
                BuildSettingList();
            }
        }
Exemplo n.º 13
0
        public static void DrawReplace(List <ReplaceInfo> replaces, string savePrefix)
        {
            EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
            if (replaces.Count == 0)
            {
                EditorGUILayout.HelpBox("{<Foo>} in 'Create Path' and 'Script Name' and 'Code' will be replace\nNote: Variables used in 'Pre Process' are not listed here.", MessageType.Info);
            }
            else
            {
                foreach (var replace in replaces)
                {
                    var str = EditorGUILayout.TextField(ReplaceProcessor.GetReplaceText(replace.Key), replace.ReplaceWord);
                    if (str == replace.ReplaceWord)
                    {
                        continue;
                    }

                    // 置き換え文字をUnityへキャッシュ
                    replace.ReplaceWord = str;
                    TemplateUtility.SetConfigValue(savePrefix + replace.Key, replace.ReplaceWord);
                }
            }
            EditorGUILayout.EndVertical();
        }
Exemplo n.º 14
0
        public static void DrawPrefab(TemplateSettingStatus status)
        {
            EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
            {
                var prefabProperty = status.GetProperty(TemplateSettingStatus.Property.DuplicatePrefab);
                var targetProperty = status.GetProperty(TemplateSettingStatus.Property.AttachTarget);

                var oldObj = prefabProperty.objectReferenceValue as GameObject;
                EditorGUILayout.PropertyField(prefabProperty, new GUIContent("Attach Prefab"), true);

                var obj = prefabProperty.objectReferenceValue as GameObject;
                if (obj == null || PrefabUtility.GetPrefabType(obj) != PrefabType.Prefab)
                {
                    targetProperty.objectReferenceValue = null;

                    EditorGUILayout.EndVertical();
                    return;
                }

                if (oldObj != obj)
                {
                    targetProperty.objectReferenceValue = prefabProperty.objectReferenceValue = PrefabUtility.FindRootGameObjectWithSameParentPrefab(obj);
                }

                EditorGUILayout.BeginHorizontal(EditorGUIHelper.GetScopeStyle());
                {
                    if (GUILayout.Button("Change Attach Target"))
                    {
                        PrefabTreeViewWindow.Open(obj, targetProperty.objectReferenceValue as GameObject, (targetObj) =>
                        {
                            status.TargetSerializedObject.Update();
                            status.GetProperty(TemplateSettingStatus.Property.AttachTarget).objectReferenceValue = targetObj;
                            status.TargetSerializedObject.ApplyModifiedProperties();
                        });
                    }

                    EditorGUILayout.LabelField(targetProperty.objectReferenceValue == null ? string.Empty : targetProperty.objectReferenceValue.name);
                }
                EditorGUILayout.EndHorizontal();

                EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
                {
                    var pathProperty = status.GetProperty(TemplateSettingStatus.Property.PrefabPath);
                    EditorGUILayout.PropertyField(pathProperty, new GUIContent("Create Prefab Path"), true);

                    var paths = EditorGUIHelper.DrawDragAndDropArea();
                    if (paths != null && paths.Length > 0)
                    {
                        pathProperty.stringValue = paths[0];
                    }

                    if (string.IsNullOrEmpty(pathProperty.stringValue))
                    {
                        EditorGUILayout.HelpBox("If empty, the script will be created in active folder", MessageType.Info);
                    }

                    EditorGUILayout.HelpBox("Example: Assets/Folder", MessageType.Info);
                }
                EditorGUILayout.EndVertical();

                EditorGUILayout.BeginVertical(EditorGUIHelper.GetScopeStyle());
                {
                    var nameProperty = status.GetProperty(TemplateSettingStatus.Property.PrefabName);
                    EditorGUILayout.PropertyField(nameProperty, new GUIContent("Prefab Name"), true);

                    if (string.IsNullOrEmpty(nameProperty.stringValue))
                    {
                        EditorGUILayout.HelpBox("Example: ExamplePrefab", MessageType.Info);
                    }
                }
                EditorGUILayout.EndVertical();
            }
            EditorGUILayout.EndVertical();
        }