-
Notifications
You must be signed in to change notification settings - Fork 877
Expand file tree
/
Copy pathProfileFactory.cs
More file actions
102 lines (90 loc) · 3.8 KB
/
Copy pathProfileFactory.cs
File metadata and controls
102 lines (90 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using UnityEngine;
using UnityEditor.ProjectWindowCallback;
using System.IO;
using UnityEngine.SceneManagement;
using UnityEngine.Rendering.PostProcessing;
#pragma warning disable CS0618 // Type or member is obsolete
namespace UnityEditor.Rendering.PostProcessing
{
/// <summary>
/// An utility class to help the creation of new post-processing profile assets.
/// </summary>
public sealed class ProfileFactory
{
[MenuItem("Assets/Create/Post-processing Profile", priority = 201)]
static void CreatePostProcessProfile()
{
//var icon = EditorGUIUtility.FindTexture("ScriptableObject Icon");
#if UNITY_6000_4_OR_NEWER
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(EntityId.None, ScriptableObject.CreateInstance<DoCreatePostProcessProfile>(), "New Post-processing Profile.asset", null, null);
#else
ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, ScriptableObject.CreateInstance<DoCreatePostProcessProfile>(), "New Post-processing Profile.asset", null, null);
#endif
}
/// <summary>
/// Creates a post-processing profile asset at the given location.
/// </summary>
/// <param name="path">The path to use relative to the project folder</param>
/// <returns>The newly created profile</returns>
public static PostProcessProfile CreatePostProcessProfileAtPath(string path)
{
var profile = ScriptableObject.CreateInstance<PostProcessProfile>();
profile.name = Path.GetFileName(path);
AssetDatabase.CreateAsset(profile, path);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
return profile;
}
/// <summary>
/// Creates a post-processing profile asset and automatically put it in a sub folder next
/// to the given scene.
/// </summary>
/// <param name="scene">A scene</param>
/// <param name="targetName">A name for the new profile</param>
/// <returns>The newly created profile</returns>
public static PostProcessProfile CreatePostProcessProfile(Scene scene, string targetName)
{
var path = string.Empty;
if (string.IsNullOrEmpty(scene.path))
{
path = "Assets/";
}
else
{
var scenePath = Path.GetDirectoryName(scene.path);
var extPath = scene.name + "_Profiles";
var profilePath = scenePath + "/" + extPath;
if (!AssetDatabase.IsValidFolder(profilePath))
AssetDatabase.CreateFolder(scenePath, extPath);
path = profilePath + "/";
}
path += targetName + " Profile.asset";
path = AssetDatabase.GenerateUniqueAssetPath(path);
var profile = ScriptableObject.CreateInstance<PostProcessProfile>();
AssetDatabase.CreateAsset(profile, path);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
return profile;
}
}
#if UNITY_6000_4_OR_NEWER
class DoCreatePostProcessProfile : AssetCreationEndAction
{
public override void Action(EntityId entityId, string pathName, string resourceFile)
{
var profile = ProfileFactory.CreatePostProcessProfileAtPath(pathName);
ProjectWindowUtil.ShowCreatedAsset(profile);
}
}
#else
class DoCreatePostProcessProfile : EndNameEditAction
{
public override void Action(int instanceId, string pathName, string resourceFile)
{
var profile = ProfileFactory.CreatePostProcessProfileAtPath(pathName);
ProjectWindowUtil.ShowCreatedAsset(profile);
}
}
#endif
}
#pragma warning restore CS0618 // Type or member is obsolete