Merge pull request #1365 from ousttrue/fix10/update_meta

[1.0] meta の Editor 仕様に追随
This commit is contained in:
PoChang007 2021-11-08 20:35:51 +09:00 committed by GitHub
commit 85bf65ff20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 172 additions and 139 deletions

View File

@ -5,78 +5,30 @@ using UnityEngine;
namespace UniVRM10
{
/// <summary>
/// Editor for VRM10ObjectMeta
/// </summary>
public class VRM10MetaEditor : SerializedPropertyEditor
{
class ValidateProperty
{
public SerializedProperty m_prop;
public delegate (string, MessageType) Validator(SerializedProperty prop);
Validator m_validator;
public ValidateProperty(SerializedProperty prop, Validator validator)
{
m_prop = prop;
m_validator = validator;
}
public void OnGUI()
{
// var old = m_prop.stringValue;
if (m_prop.propertyType == SerializedPropertyType.Generic)
{
if (m_prop.arrayElementType != null)
{
EditorGUILayout.LabelField(m_prop.name);
var depth = m_prop.depth;
var iterator = m_prop.Copy();
for (var enterChildren = true; iterator.NextVisible(enterChildren); enterChildren = false)
{
if (iterator.depth < depth)
break;
depth = iterator.depth;
// using (new EditorGUI.DisabledScope("m_Script" == iterator.propertyPath))
EditorGUILayout.PropertyField(iterator, true);
}
}
else
{
throw new System.NotImplementedException();
}
}
else
{
EditorGUILayout.PropertyField(m_prop);
}
var (msg, msgType) = m_validator(m_prop);
if (!string.IsNullOrEmpty(msg))
{
EditorGUILayout.HelpBox(msg, msgType);
}
// return old != m_prop.stringValue;
}
}
SerializedProperty m_exporterVersion;
SerializedProperty m_thumbnail;
ValidateProperty m_title;
ValidateProperty m_version;
ValidateProperty m_author;
ValidateProperty m_contact;
ValidateProperty m_reference;
VRM10MetaProperty m_name;
VRM10MetaProperty m_version;
VRM10MetaProperty m_copyright;
VRM10MetaProperty m_authors;
VRM10MetaProperty m_references;
VRM10MetaProperty m_contact;
VRM10MetaProperty m_thirdPartyLicenses;
VRM10MetaProperty m_OtherLicenseUrl;
SerializedProperty m_AllowedUser;
SerializedProperty m_AvatarPermission;
SerializedProperty m_ViolentUssage;
SerializedProperty m_SexualUssage;
SerializedProperty m_CommercialUssage;
SerializedProperty m_PoliticalOrReligiousUsage;
SerializedProperty m_OtherPermissionUrl;
SerializedProperty m_LicenseType;
SerializedProperty m_OtherLicenseUrl;
SerializedProperty m_AntisocialOrHateUsage;
SerializedProperty m_CreditNotation;
SerializedProperty m_Redistribution;
SerializedProperty m_Modification;
static string RequiredMessage(string name)
{
@ -103,22 +55,46 @@ namespace UniVRM10
[LangMsg(Languages.en, "A person who can perform with this avatar")]
ALLOWED_USER,
[LangMsg(Languages.ja, "このアバターを用いて暴力表現を演じることの許可")]
[LangMsg(Languages.ja, "このアバターを用いて暴力表現を演じること")]
[LangMsg(Languages.en, "Violent acts using this avatar")]
VIOLENT_USAGE,
[LangMsg(Languages.ja, "このアバターを用いて性的表現を演じることの許可")]
[LangMsg(Languages.ja, "このアバターを用いて性的表現を演じること")]
[LangMsg(Languages.en, "Sexuality acts using this avatar")]
SEXUAL_USAGE,
[LangMsg(Languages.ja, "商用利用の許可")]
[LangMsg(Languages.ja, "商用利用")]
[LangMsg(Languages.en, "For commercial use")]
COMMERCIAL_USAGE,
[LangMsg(Languages.ja, "政治・宗教用途での利用")]
[LangMsg(Languages.en, "Permits to use this model in political or religious contents")]
POLITICAL_USAGE,
[LangMsg(Languages.ja, "反社会的・憎悪表現を含むコンテンツでの利用")]
[LangMsg(Languages.en, "Permits to use this model in contents contain anti-social activities or hate speeches")]
ANTI_USAGE,
[LangMsg(Languages.ja, "再配布・改変に関する許諾範囲")]
[LangMsg(Languages.en, "Redistribution / Modifications License")]
REDISTRIBUTION_MODIFICATIONS,
[LangMsg(Languages.ja, "クレジット表記")]
[LangMsg(Languages.en, "Forces or abandons to display the credit")]
MOD_CREDIT,
[LangMsg(Languages.ja, "再配布")]
[LangMsg(Languages.en, "Permits redistribution")]
MOD_REDISTRIBUTION,
[LangMsg(Languages.ja, "改変")]
[LangMsg(Languages.en, "Controls the condition to modify")]
MOD_MODIFICATION,
[LangMsg(Languages.ja, "その他のライセンス条件があれば、そのURL")]
[LangMsg(Languages.en, "The URL links of other license")]
MOD_OTHER,
// [LangMsg(Languages.ja, "")]
// [LangMsg(Languages.en, "")]
}
@ -165,12 +141,14 @@ namespace UniVRM10
return result;
}
VRM10MetaProperty CreateValidation(string name, VRM10MetaPropertyValidator validator = null)
{
return new VRM10MetaProperty(m_rootProperty.FindPropertyRelative(name), validator);
}
public VRM10MetaEditor(SerializedObject serializedObject, SerializedProperty property) : base(serializedObject, property)
{
m_exporterVersion = m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.ExporterVersion));
m_thumbnail = m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.Thumbnail));
m_title = new ValidateProperty(m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.Name)), prop =>
m_name = CreateValidation(nameof(VRM10ObjectMeta.Name), prop =>
{
if (string.IsNullOrEmpty(prop.stringValue))
{
@ -178,15 +156,8 @@ namespace UniVRM10
}
return ("", MessageType.None);
});
m_version = new ValidateProperty(m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.Version)), prop =>
{
// if (string.IsNullOrEmpty(prop.stringValue))
// {
// return (RequiredMessage(prop.name), MessageType.Error);
// }
return ("", MessageType.None);
});
m_author = new ValidateProperty(m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.Authors)), prop =>
m_version = CreateValidation(nameof(VRM10ObjectMeta.Version));
m_authors = CreateValidation(nameof(VRM10ObjectMeta.Authors), prop =>
{
if (prop.arraySize == 0)
{
@ -194,25 +165,24 @@ namespace UniVRM10
}
return ("", MessageType.None);
});
m_contact = new ValidateProperty(m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.ContactInformation)), prop =>
{
return ("", MessageType.None);
});
m_reference = new ValidateProperty(m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.References)), prop =>
{
return ("", MessageType.None);
});
m_AllowedUser = m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.AllowedUser));
m_copyright = CreateValidation(nameof(VRM10ObjectMeta.CopyrightInformation));
m_contact = CreateValidation(nameof(VRM10ObjectMeta.ContactInformation));
m_references = CreateValidation(nameof(VRM10ObjectMeta.References));
m_thirdPartyLicenses = CreateValidation(nameof(VRM10ObjectMeta.ThirdPartyLicenses));
m_OtherLicenseUrl = CreateValidation(nameof(VRM10ObjectMeta.OtherLicenseUrl));
m_thumbnail = m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.Thumbnail));
// AvatarPermission
m_AvatarPermission = m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.AvatarPermission));
m_ViolentUssage = m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.ViolentUsage));
m_SexualUssage = m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.SexualUsage));
m_CommercialUssage = m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.CommercialUsage));
m_PoliticalOrReligiousUsage = m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.PoliticalOrReligiousUsage));
m_OtherPermissionUrl = m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.OtherLicenseUrl));
m_AntisocialOrHateUsage = m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.AntisocialOrHateUsage));
// Mod
m_CreditNotation = m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.CreditNotation));
m_Redistribution = m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.Redistribution));
m_Modification = m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.Modification));
// m_LicenseType = m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.));
m_OtherLicenseUrl = m_rootProperty.FindPropertyRelative(nameof(VRM10ObjectMeta.OtherLicenseUrl));
}
public static VRM10MetaEditor Create(SerializedObject serializedObject)
@ -222,18 +192,10 @@ namespace UniVRM10
protected override void RecursiveProperty(SerializedProperty root)
{
if (VRMVersion.IsNewer(m_exporterVersion.stringValue))
{
EditorGUILayout.HelpBox("Check UniVRM new version. https://github.com/dwango/UniVRM/releases", MessageType.Warning);
}
// texture
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.BeginVertical();
GUI.enabled = false;
EditorGUILayout.PropertyField(m_exporterVersion);
GUI.enabled = true;
EditorGUILayout.PropertyField(m_thumbnail);
EditorGUILayout.EndVertical();
m_thumbnail.objectReferenceValue = TextureField("", (Texture2D)m_thumbnail.objectReferenceValue, 100);
@ -243,34 +205,37 @@ namespace UniVRM10
m_foldoutInfo = EditorGUILayout.Foldout(m_foldoutInfo, "Information");
if (m_foldoutInfo)
{
m_title.OnGUI();
m_name.OnGUI();
m_version.OnGUI();
m_author.OnGUI();
m_authors.OnGUI();
m_copyright.OnGUI();
m_contact.OnGUI();
m_reference.OnGUI();
m_references.OnGUI();
m_thirdPartyLicenses.OnGUI();
m_OtherLicenseUrl.OnGUI();
}
// EditorGUILayout.LabelField("License ", EditorStyles.boldLabel);
m_foldoutPermission = EditorGUILayout.Foldout(m_foldoutPermission, Msg(MessageKeys.PERSONATION));
if (m_foldoutPermission)
{
var backup = EditorGUIUtility.labelWidth;
RightFixedPropField(m_AllowedUser, Msg(MessageKeys.ALLOWED_USER));
RightFixedPropField(m_AvatarPermission, Msg(MessageKeys.ALLOWED_USER));
RightFixedPropField(m_ViolentUssage, Msg(MessageKeys.VIOLENT_USAGE));
RightFixedPropField(m_SexualUssage, Msg(MessageKeys.SEXUAL_USAGE));
RightFixedPropField(m_CommercialUssage, Msg(MessageKeys.COMMERCIAL_USAGE));
EditorGUILayout.PropertyField(m_OtherPermissionUrl, new GUIContent("Other License Url"));
RightFixedPropField(m_PoliticalOrReligiousUsage, Msg(MessageKeys.POLITICAL_USAGE));
RightFixedPropField(m_AntisocialOrHateUsage, Msg(MessageKeys.ANTI_USAGE));
EditorGUIUtility.labelWidth = backup;
}
m_foldoutDistribution = EditorGUILayout.Foldout(m_foldoutDistribution, Msg(MessageKeys.REDISTRIBUTION_MODIFICATIONS));
if (m_foldoutDistribution)
{
// var licenseType = m_LicenseType;
// EditorGUILayout.PropertyField(licenseType);
// if ((LicenseType)licenseType.intValue == LicenseType.Other)
// {
// EditorGUILayout.PropertyField(m_OtherLicenseUrl);
// }
var backup = EditorGUIUtility.labelWidth;
RightFixedPropField(m_CreditNotation, Msg(MessageKeys.MOD_CREDIT));
RightFixedPropField(m_Redistribution, Msg(MessageKeys.MOD_REDISTRIBUTION));
RightFixedPropField(m_Modification, Msg(MessageKeys.MOD_MODIFICATION));
EditorGUIUtility.labelWidth = backup;
}
}
}

View File

@ -0,0 +1,64 @@
using UnityEditor;
namespace UniVRM10
{
delegate (string, MessageType) VRM10MetaPropertyValidator(SerializedProperty prop);
class VRM10MetaProperty
{
public SerializedProperty m_prop;
VRM10MetaPropertyValidator m_validator;
public VRM10MetaProperty(SerializedProperty prop,
VRM10MetaPropertyValidator validator = null)
{
m_prop = prop;
if (validator == null)
{
// no validation
validator = _ => ("", MessageType.None);
}
m_validator = validator;
}
public void OnGUI()
{
// var old = m_prop.stringValue;
if (m_prop.propertyType == SerializedPropertyType.Generic)
{
if (m_prop.arrayElementType != null)
{
EditorGUILayout.LabelField(m_prop.name);
var depth = m_prop.depth;
var iterator = m_prop.Copy();
for (var enterChildren = true; iterator.NextVisible(enterChildren); enterChildren = false)
{
if (iterator.depth < depth)
break;
depth = iterator.depth;
// using (new EditorGUI.DisabledScope("m_Script" == iterator.propertyPath))
EditorGUILayout.PropertyField(iterator, true);
}
}
else
{
throw new System.NotImplementedException();
}
}
else
{
EditorGUILayout.PropertyField(m_prop);
}
var (msg, msgType) = m_validator(m_prop);
if (!string.IsNullOrEmpty(msg))
{
EditorGUILayout.HelpBox(msg, msgType);
}
// return old != m_prop.stringValue;
}
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 57e782f0f79ef4d4abcd4f1c5438e9e7
guid: f0f1ce72ffff9a9498f2d4f73dd370f5
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -10,9 +10,6 @@ namespace UniVRM10
[Serializable]
public class VRM10ObjectMeta
{
[SerializeField]
public string ExporterVersion;
#region Info
[SerializeField]
public string Name;
@ -21,10 +18,10 @@ namespace UniVRM10
public string Version;
[SerializeField]
public string CopyrightInformation;
public List<string> Authors = new List<string>();
[SerializeField]
public List<string> Authors = new List<string>();
public string CopyrightInformation;
[SerializeField]
public string ContactInformation;
@ -32,13 +29,16 @@ namespace UniVRM10
[SerializeField]
public List<string> References = new List<string>();
[SerializeField]
public string ThirdPartyLicenses;
[SerializeField]
public Texture2D Thumbnail;
#endregion
#region AvatarPermission
[SerializeField, Tooltip("A person who can perform with this avatar")]
public UniGLTF.Extensions.VRMC_vrm.AvatarPermissionType AllowedUser;
public UniGLTF.Extensions.VRMC_vrm.AvatarPermissionType AvatarPermission;
[SerializeField, Tooltip("Violent acts using this avatar")]
public bool ViolentUsage;
@ -49,17 +49,11 @@ namespace UniVRM10
[SerializeField, Tooltip("For commercial use")]
public UniGLTF.Extensions.VRMC_vrm.CommercialUsageType CommercialUsage;
[SerializeField]
public bool GameUsage;
[SerializeField]
public bool PoliticalOrReligiousUsage;
[SerializeField]
public bool AntisocialOrHateUsage;
[SerializeField, Tooltip("Other License Url")]
public string OtherPermissionUrl;
#endregion
#region Distribution License
@ -70,7 +64,7 @@ namespace UniVRM10
public bool Redistribution;
[SerializeField]
public UniGLTF.Extensions.VRMC_vrm.ModificationType ModificationLicense;
public UniGLTF.Extensions.VRMC_vrm.ModificationType Modification;
[SerializeField]
public string OtherLicenseUrl;
@ -96,7 +90,6 @@ namespace UniVRM10
public void CopyTo(VRM10ObjectMeta dst)
{
dst.ExporterVersion = ExporterVersion;
dst.Name = Name;
dst.Version = Version;
dst.CopyrightInformation = CopyrightInformation;
@ -110,17 +103,16 @@ namespace UniVRM10
}
dst.ContactInformation = ContactInformation;
dst.References = References;
dst.ThirdPartyLicenses = ThirdPartyLicenses;
dst.Thumbnail = Thumbnail;
dst.AllowedUser = AllowedUser;
dst.AvatarPermission = AvatarPermission;
dst.ViolentUsage = ViolentUsage;
dst.SexualUsage = SexualUsage;
dst.CommercialUsage = CommercialUsage;
dst.GameUsage = GameUsage;
dst.PoliticalOrReligiousUsage = PoliticalOrReligiousUsage;
dst.OtherPermissionUrl = OtherPermissionUrl;
dst.CreditNotation = CreditNotation;
dst.Redistribution = Redistribution;
dst.ModificationLicense = ModificationLicense;
dst.Modification = Modification;
dst.OtherLicenseUrl = OtherLicenseUrl;
}
}

View File

@ -686,8 +686,8 @@ namespace UniVRM10
vrm.Meta.CopyrightInformation = meta.CopyrightInformation;
vrm.Meta.ContactInformation = meta.ContactInformation;
vrm.Meta.References = meta.References.ToList();
// vrm.Meta.ThirdPartyLicenses =
vrm.Meta.AvatarPermission = meta.AllowedUser;
vrm.Meta.ThirdPartyLicenses = meta.ThirdPartyLicenses;
vrm.Meta.AvatarPermission = meta.AvatarPermission;
vrm.Meta.AllowExcessivelyViolentUsage = meta.ViolentUsage;
vrm.Meta.AllowExcessivelySexualUsage = meta.SexualUsage;
vrm.Meta.CommercialUsage = meta.CommercialUsage;
@ -695,7 +695,7 @@ namespace UniVRM10
vrm.Meta.AllowAntisocialOrHateUsage = meta.AntisocialOrHateUsage;
vrm.Meta.CreditNotation = meta.CreditNotation;
vrm.Meta.AllowRedistribution = meta.Redistribution;
vrm.Meta.Modification = meta.ModificationLicense;
vrm.Meta.Modification = meta.Modification;
vrm.Meta.OtherLicenseUrl = meta.OtherLicenseUrl;
int? thumbnailTextureIndex = default;
if (meta.Thumbnail != null)

View File

@ -361,8 +361,9 @@ namespace UniVRM10
meta.Name = src.Name;
meta.Version = src.Version;
meta.ContactInformation = src.ContactInformation;
meta.ThirdPartyLicenses = src.ThirdPartyLicenses;
// avatar
meta.AllowedUser = src.AvatarPermission;
meta.AvatarPermission = src.AvatarPermission;
meta.ViolentUsage = src.AllowExcessivelyViolentUsage.GetValueOrDefault();
meta.SexualUsage = src.AllowExcessivelySexualUsage.GetValueOrDefault();
meta.CommercialUsage = src.CommercialUsage;
@ -372,7 +373,7 @@ namespace UniVRM10
meta.CreditNotation = src.CreditNotation;
meta.Redistribution = src.AllowRedistribution.GetValueOrDefault();
meta.ModificationLicense = src.Modification;
meta.Modification = src.Modification;
meta.OtherLicenseUrl = src.OtherLicenseUrl;
//
if (src.References != null)

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 09c88afc4ee72dc4099b705970f5a13e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -1 +1 @@
Subproject commit 04e3bb25258670c2460c554dfe3db2e05543b87c
Subproject commit f2d8f158297fc883aef9c3071ca68fbe46b03f45