VRMMetaInformation.cs
2.93 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
using System;
using System.IO;
using UnityEngine;
using UniGLTF;
namespace VRM
{
[Obsolete("reimport, use VRMMeta. Please reimport")]
[Serializable]
[DisallowMultipleComponent]
public class VRMMetaInformation : MonoBehaviour, IEquatable<VRMMetaInformation>
{
#region Info
[SerializeField, Header("Information")]
public string Title;
[SerializeField]
public string Author;
[SerializeField]
public string ContactInformation;
[SerializeField]
public Texture2D Thumbnail;
[SerializeField]
public string Reference;
#endregion
#region License
[SerializeField, Header("License")]
public LicenseType LicenseType;
[SerializeField]
public string OtherLicenseUrl;
#endregion
public bool Equals(VRMMetaInformation other)
{
return
Author == other.Author
&& Title == other.Title
&& UniGLTF.MonoBehaviourComparator.AssetAreEquals(Thumbnail, other.Thumbnail)
;
}
private void Reset()
{
Title = name;
}
#if UNITY_EDITOR
[ContextMenu("CreateThumbnail")]
void CreateThumbnailMenu()
{
var lookAt = GetComponent<VRMLookAt>();
if (lookAt != null)
{
var texture = lookAt.CreateThumbnail();
#if false
var assetPath = string.Format("Assets/{0}.thumbnail.asset", name);
assetPath = UnityEditor.AssetDatabase.GenerateUniqueAssetPath(assetPath);
UnityEditor.AssetDatabase.CreateAsset(texture, assetPath);
#else
var assetPath = string.Format("Assets/{0}.thumbnail.jpg", name);
assetPath = UnityEditor.AssetDatabase.GenerateUniqueAssetPath(assetPath);
File.WriteAllBytes(assetPath.AssetPathToFullPath(), texture.EncodeToJPG());
if (Application.isPlaying)
{
UnityEngine.Object.Destroy(texture);
}
else
{
UnityEngine.Object.DestroyImmediate(texture);
}
UnityEditor.AssetDatabase.ImportAsset(assetPath);
Thumbnail = UnityEditor.AssetDatabase.LoadAssetAtPath<Texture2D>(assetPath);
#endif
}
}
#endif
public void CopyTo(GameObject _dst)
{
var dst = _dst.AddComponent<VRMMetaInformation>();
dst.Title = Title;
dst.Author = Author;
dst.Thumbnail = Thumbnail;
}
public void OnValidate()
{
if (Thumbnail != null)
{
if (Thumbnail.width != 2048 || Thumbnail.height != 2048)
{
Thumbnail = null;
Debug.LogError("Thumbnail must 2048 x 2048");
}
}
}
}
}