示例#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();
        }
示例#2
0
        private void BuildSettingList()
        {
            _foldoutList.Clear();
            _statusList.Clear();

            if (_groupSetting.Settings != null)
            {
                foreach (var setting in _groupSetting.Settings)
                {
                    if (setting == null)
                    {
                        continue;
                    }

                    var status  = new TemplateSettingStatus(new SerializedObject(setting));
                    var foldout = new FoldoutInfo(setting.name, () =>
                    {
                        status.TargetSerializedObject.Update();
                        DrawSetting(status);
                        status.TargetSerializedObject.ApplyModifiedProperties();
                    }
                                                  );

                    foldout.IsFoldout = false;
                    _foldoutList.Add(foldout);
                    _statusList.Add(status);
                }
            }

            UpdateReplaceList(true);
        }
示例#3
0
        private void OnEnable()
        {
            _instanceId   = target.GetInstanceID().ToString();
            SettingStatus = new TemplateSettingStatus(serializedObject);

            _foldouts = new FoldoutInfo[]
            {
                new FoldoutInfo("Code", () => DrawCode(SettingStatus)),
                new FoldoutInfo("Replace Texts", () => DrawReplace(_replaceList, _instanceId)),
                new FoldoutInfo("Pre Process", () => DrawChain(SettingStatus)),
            };

            var property = SettingStatus.GetProperty(TemplateSettingStatus.Property.IsFoldouts);

            for (int i = 0; i < _foldouts.Length; ++i)
            {
                if (property.arraySize <= i)
                {
                    break;
                }

                _foldouts[i].IsFoldout = property.GetArrayElementAtIndex(i).boolValue;
            }

            _descriptionFoldout           = new FoldoutInfo("Description", DrawDescription);
            _descriptionFoldout.IsFoldout = string.IsNullOrEmpty(SettingStatus.GetProperty(TemplateSettingStatus.Property.Description).stringValue) == false;

            UpdateReplaceList(true);
        }
        protected string ReplaceCode(ProcessDictionary result)
        {
            object obj;

            result.TryGetValue(result.GetLastConvertReplaceWord(TemplateSetting.ResultKey), out obj);
            var setting = obj as TemplateSetting;

            if (setting == null)
            {
                Debug.LogErrorFormat("Not {0} object", TemplateSetting.ResultKey);
                return(null);
            }

            var status = new TemplateSettingStatus(new SerializedObject(setting));

            TemplateSettingEditor.ExecuteChain(status, result);
            var words = ReplaceProcessor.GetReplaceWords(
                status.GetProperty(TemplateSettingStatus.Property.Path).stringValue,
                status.GetProperty(TemplateSettingStatus.Property.ScriptName).stringValue,
                status.GetProperty(TemplateSettingStatus.Property.Code).stringValue
                );
            var replaces = TemplateSettingEditor.CreateReplaceList(new List <ReplaceInfo>(0), words.ToArray());

            foreach (var replace in replaces)
            {
                result.Add(replace.Key, replace.ReplaceWord);
            }

            return(TemplateSettingEditor.Replace(
                       status.GetProperty(TemplateSettingStatus.Property.Code).stringValue,
                       result
                       ));
        }
示例#5
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();
 }
示例#6
0
        public static void ExecuteChain(TemplateSettingStatus status, ProcessDictionary result)
        {
            var metadata = new ProcessMetadata(status.TargetTemplateSetting);
            var property = status.GetProperty(TemplateSettingStatus.Property.Chain);

            for (int i = 0; i < property.arraySize; ++i)
            {
                TemplateUtility.ExecuteProcessChain(property.GetArrayElementAtIndex(i).objectReferenceValue, metadata, result);
            }
        }
示例#7
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();
 }
示例#8
0
        public static void CreateScript(TemplateSettingStatus status, List <ReplaceInfo> replaces, ProcessDictionary result = null, bool isRefresh = true)
        {
            if (result == null)
            {
                result = new ProcessDictionary();
            }

            if (replaces != null)
            {
                foreach (var replace in replaces)
                {
                    if (string.IsNullOrEmpty(replace.ReplaceWord))
                    {
                        continue;
                    }

                    result[replace.Key] = replace.ReplaceWord;
                }
            }

            ExecuteChain(status, result);

            // 生成ディレクトリが指定されていなければアクティブなパスへ作成
            var createDirectory = status.GetProperty(TemplateSettingStatus.Property.Path).stringValue;
            var createPath      = Path.Combine(
                string.IsNullOrEmpty(createDirectory) == false ? createDirectory : TemplateUtility.GetActiveFolder(),
                status.GetProperty(TemplateSettingStatus.Property.ScriptName).stringValue
                );
            var code = status.GetProperty(TemplateSettingStatus.Property.Code).stringValue;

            var path = Replace(createPath, result);

            TemplateUtility.CreateScript(
                path,
                Replace(code, result),
                (TemplateUtility.OverwriteType)status.GetProperty(TemplateSettingStatus.Property.Overwrite).enumValueIndex
                );

            if (isRefresh)
            {
                AssetDatabase.ImportAsset(path);
                TemplateUtility.RefreshEditor();
            }

            // プレハブ生成登録
            var prefabObject = status.GetProperty(TemplateSettingStatus.Property.DuplicatePrefab).objectReferenceValue as GameObject;
            var targetObject = status.GetProperty(TemplateSettingStatus.Property.AttachTarget).objectReferenceValue as GameObject;

            if (prefabObject != null && targetObject != null)
            {
                TemplatePrefabCreator.AddTempCreatePrefabSetting(status.TargetTemplateSetting, path);
            }
        }
示例#9
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();
            }
        }
示例#10
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();
        }
示例#11
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();
        }