-
Notifications
You must be signed in to change notification settings - Fork 868
Expand file tree
/
Copy pathRenderPipelineConverterAssetItem.cs
More file actions
138 lines (115 loc) · 4.74 KB
/
RenderPipelineConverterAssetItem.cs
File metadata and controls
138 lines (115 loc) · 4.74 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using System;
using UnityEditor.SceneManagement;
using UnityEngine;
namespace UnityEditor.Rendering.Converter
{
[Serializable]
internal class RenderPipelineConverterAssetItem : IRenderPipelineConverterItem
{
[SerializeField]
private string m_AssetPath;
public string assetPath
{
get => m_AssetPath;
protected set => m_AssetPath = value;
}
[SerializeField]
private string m_GUID;
public string guid
{
get => m_GUID;
protected set => m_GUID = value;
}
[SerializeField]
private string m_GlobalObjectId;
public string GlobalObjectId => m_GlobalObjectId;
[SerializeField]
private string m_Name;
public string name
{
get => string.IsNullOrEmpty(m_Name) ? System.IO.Path.GetFileNameWithoutExtension(assetPath) : m_Name;
set => m_Name = value;
}
[SerializeField]
private string m_Info;
public string info
{
get => m_Info;
set => m_Info = value;
}
public bool isEnabled { get; set; } = true;
public string isDisabledMessage { get; set; } = string.Empty;
public Texture2D icon
{
get
{
if (!string.IsNullOrEmpty(assetPath))
{
// Get the cached icon without loading the asset
var icon = AssetDatabase.GetCachedIcon(assetPath);
if (icon != null)
return icon as Texture2D;
}
return null;
}
}
public RenderPipelineConverterAssetItem(string id)
{
if (!UnityEditor.GlobalObjectId.TryParse(id, out var gid))
throw new ArgumentException(nameof(id), $"Unable to perform GlobalObjectId.TryParse with the given id {id}");
m_AssetPath = AssetDatabase.GUIDToAssetPath(gid.assetGUID);
m_GlobalObjectId = gid.ToString();
m_GUID = gid.assetGUID.ToString();
}
public RenderPipelineConverterAssetItem(GlobalObjectId gid, string assetPath)
{
if (!AssetDatabase.AssetPathExists(assetPath))
throw new ArgumentException(nameof(assetPath), $"{assetPath} does not exist");
m_AssetPath = assetPath;
m_GlobalObjectId = gid.ToString();
m_GUID = AssetDatabase.AssetPathToGUID(assetPath);
}
public UnityEngine.Object LoadObject()
{
UnityEngine.Object obj = null;
if (UnityEditor.GlobalObjectId.TryParse(GlobalObjectId, out var globalId))
{
// Try loading the object
// TODO: Upcoming changes to GlobalObjectIdentifierToObjectSlow will allow it
// to return direct references to prefabs and their children.
// Once that change happens there are several items which should be adjusted.
obj = UnityEditor.GlobalObjectId.GlobalObjectIdentifierToObjectSlow(globalId);
// If the object was not loaded, it is probably part of an unopened scene or prefab;
// if so, then the solution is to first load the scene here.
var objIsInSceneOrPrefab = globalId.identifierType == 2; // 2 is IdentifierType.kSceneObject
if (!obj &&
objIsInSceneOrPrefab)
{
// Open the Containing Scene Asset or Prefab in the Hierarchy so the Object can be manipulated
var mainAssetPath = AssetDatabase.GUIDToAssetPath(globalId.assetGUID);
var mainAsset = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(mainAssetPath);
AssetDatabase.OpenAsset(mainAsset);
// If a prefab stage was opened, then mainAsset is the root of the
// prefab that contains the target object, so reference that for now,
// until GlobalObjectIdentifierToObjectSlow is updated
if (PrefabStageUtility.GetCurrentPrefabStage() != null)
{
obj = mainAsset;
}
// Reload object if it is still null (because it's in a previously unopened scene)
if (!obj)
{
obj = UnityEditor.GlobalObjectId.GlobalObjectIdentifierToObjectSlow(globalId);
}
}
}
return obj;
}
public void OnClicked()
{
var obj = LoadObject();
if (obj != null)
EditorGUIUtility.PingObject(obj);
}
}
}