blob: 9359b86cbba7b3f6093447e33e9ff300d85cadfb (
plain)
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
|
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
// Disable 'obsolete' warnings
#pragma warning disable 0618
[DisallowMultipleComponent]
public class BakeryLightmappedPrefab : MonoBehaviour
{
#if UNITY_EDITOR
public bool enableBaking = true;
public string errorMessage;
public bool IsValid()
{
errorMessage = "";
if (!enableBaking)
{
return false;
}
bool isPartOfPrefab = PrefabUtility.GetPrefabType(gameObject) == PrefabType.PrefabInstance;
if (!isPartOfPrefab)
{
errorMessage = "this GameObject is not a prefab";
return false;
}
bool prefabIsRoot = PrefabUtility.FindPrefabRoot(gameObject) == gameObject;
if (!prefabIsRoot)
{
errorMessage = "this GameObject is not a root prefab object";
return false;
}
var transforms = GetComponentsInChildren<Transform>();
for(int i=0; i<transforms.Length; i++)
{
if (PrefabUtility.FindPrefabRoot(transforms[i].gameObject) != gameObject)
{
errorMessage = "prefab contains unapplied object (" + transforms[i].name + ")";
return false;
}
}
var prefabRootObj = PrefabUtility.GetPrefabObject(gameObject);
//var prefabRootObj2 = PrefabUtility.FindPrefabRoot(gameObject);
var mods = PrefabUtility.GetPropertyModifications(gameObject);
if (mods != null)
{
for(int i=0; i<mods.Length; i++)
{
if (mods[i] == null) continue;
#if UNITY_2018_3_OR_NEWER
if (PrefabUtility.IsDefaultOverride(mods[i])) continue;
#endif
if (mods[i].propertyPath == "m_RootOrder") continue;
if (mods[i].propertyPath == "errorMessage") continue;
if (mods[i].propertyPath == "enableBaking") continue;
if (mods[i].propertyPath.IndexOf("idremap") >= 0) continue;
if (mods[i].target != null && mods[i].target.name == gameObject.name)
{
if (mods[i].propertyPath.Contains("m_LocalPosition")) continue;
if (mods[i].propertyPath.Contains("m_LocalRotation")) continue;
if (mods[i].propertyPath.Contains("m_LocalScale")) continue;
}
errorMessage = "prefab contains unapplied data (" + mods[i].target+"."+mods[i].propertyPath + ")";
return false;
}
}
var comps = gameObject.GetComponents<Component>();
var comps2 = gameObject.GetComponentsInChildren<Component>();
for(int t=0; t<2; t++)
{
var comps3 = t == 0 ? comps : comps2;
for(int c=0; c<comps3.Length; c++)
{
var prefabObj = PrefabUtility.GetPrefabObject(comps3[c]);
if (prefabObj != prefabRootObj)
{
errorMessage = "prefab contains unapplied component (" + comps3[c] + ")";
return false;
}
/*bool isRoot = comps3[c].gameObject == gameObject;
var mods = PrefabUtility.GetPropertyModifications(comps3[c]);
if (mods == null) continue;
for(int i=0; i<mods.Length; i++)
{
if (mods[i].propertyPath == "m_RootOrder") continue;
if (isRoot)
{
if (mods[i].propertyPath == "errorMessage") continue;
if (mods[i].propertyPath == "enableBaking") continue;
if (mods[i].propertyPath.Contains("m_LocalPosition")) continue;
if (mods[i].propertyPath.Contains("m_LocalRotation")) continue;
if (mods[i].propertyPath.Contains("m_LocalScale")) continue;
}
else
{
if (mods[i].propertyPath.Contains("m_LocalPosition"))
{
var dist = (comps3[c].transform.position - (PrefabUtility.GetPrefabParent(comps3[c].gameObject) as GameObject).transform.position).sqrMagnitude;
Debug.LogError(dist);
if (dist < 0.001f) continue;
}
else if (mods[i].propertyPath.Contains("m_LocalRotation"))
{
continue;
}
}
errorMessage = "Error: prefab contains unapplied data (" + mods[i].target+"."+mods[i].propertyPath + ")";
return false;
}*/
}
}
return true;
}
#endif
}
|