Ejemplo n.º 1
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();
            }
        }
Ejemplo n.º 2
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();
        }