mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-12 05:48:47 -05:00
add VRM scripts
This commit is contained in:
106
Scripts/Meta/VRMMetaInformation.cs
Normal file
106
Scripts/Meta/VRMMetaInformation.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UniGLTF;
|
||||
|
||||
|
||||
namespace VRM
|
||||
{
|
||||
[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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Scripts/Meta/VRMMetaInformation.cs.meta
Normal file
12
Scripts/Meta/VRMMetaInformation.cs.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ea874a3d9d53e54a86ff1724ede087f
|
||||
timeCreated: 1520239812
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user