-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathpb_ObjectArray.cs
More file actions
79 lines (75 loc) · 2.35 KB
/
pb_ObjectArray.cs
File metadata and controls
79 lines (75 loc) · 2.35 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
using UnityEngine;
using System.Collections;
using UnityEngine.ProBuilder;
namespace UnityEditor.ProBuilder
{
/**
* Used to store arrays of materials. Made obsolete by pb_MaterialArray.
*
* Notes:
* - In the Editor folder because WebGL doesn't like ProceduralMaterial types.
* - Named pb_ObjectArray because this was initially intended to be a base type for
* other save-able object types. It is only used for materials, but changing the name
* to something more suitable would mean breaking existing material palettes for
* lots of people.
*/
[System.Obsolete(
"pb_ObjectArray is deprecated. ProBuilder Material Editor now saves material palettes as pb_MaterialArray. You may safely delete this asset.")]
[System.Serializable]
// ReSharper disable once InconsistentNaming
sealed class pb_ObjectArray : ScriptableObject, IHasDefault
{
// Stored as object for backwards compatibility.
[SerializeField] public Object[] array;
public T[] GetArray<T>()
{
T[] arr = new T[array.Length];
for (int i = 0; i < array.Length; i++)
{
#if UNITY_6000_6_OR_NEWER
if (array[i] is T)
{
arr[i] = (T)System.Convert.ChangeType(array[i], typeof(T));
}
else
{
arr[i] = default(T);
}
#else
if (array[i] is ProceduralMaterial)
{
arr[i] = (T)System.Convert.ChangeType(array[i], typeof(ProceduralMaterial));
}
else
{
if (array[i] is T)
{
arr[i] = (T)System.Convert.ChangeType(array[i], typeof(T));
}
else
{
arr[i] = default(T);
}
}
#endif
}
return (T[])arr;
}
public void SetDefaultValues()
{
array = new Material[10]
{
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
};
}
}
}