diff --git a/Assets/VRM/UniVRM/Editor/ExporterExtensions.cs b/Assets/VRM/UniVRM/Editor/ExporterExtensions.cs new file mode 100644 index 000000000..6416636bd --- /dev/null +++ b/Assets/VRM/UniVRM/Editor/ExporterExtensions.cs @@ -0,0 +1,18 @@ +using System.Linq; +using UnityEngine; + +namespace VRM +{ + public static class ExporterExtensions + { + public static bool EnableForExport(this Component mono) + { + if (mono.transform.GetComponentsInParent().Any(x => !x.gameObject.activeSelf)) + { + // 自分か祖先に !activeSelf がいる + return false; + } + return true; + } + } +} diff --git a/Assets/VRM/UniVRM/Editor/ExporterExtensions.cs.meta b/Assets/VRM/UniVRM/Editor/ExporterExtensions.cs.meta new file mode 100644 index 000000000..91082a7cd --- /dev/null +++ b/Assets/VRM/UniVRM/Editor/ExporterExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 84a3f0f4ae5319a46839f08a76ae0edd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM/UniVRM/Editor/FirstPerson/VRMFirstPersonValidator.cs b/Assets/VRM/UniVRM/Editor/FirstPerson/VRMFirstPersonValidator.cs new file mode 100644 index 000000000..c74b74195 --- /dev/null +++ b/Assets/VRM/UniVRM/Editor/FirstPerson/VRMFirstPersonValidator.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using System.Linq; +using UnityEngine; + +namespace VRM +{ + public static class VRMFirstPersonValidator + { + public static IEnumerable Validate(this VRMFirstPerson self) + { + var hierarchy = self.GetComponentsInChildren(true); + + for (int i = 0; i < self.Renderers.Count; ++i) + { + var r = self.Renderers[i]; + if (r.Renderer == null) + { + yield return Validation.Error($"[VRMFirstPerson]{self.name}.Renderers[{i}].Renderer is null"); + } + if (!hierarchy.Contains(r.Renderer.transform)) + { + yield return Validation.Error($"[VRMFirstPerson]{self.name}.Renderers[{i}].Renderer is out of hierarchy"); + } + if (!r.Renderer.EnableForExport()) + { + yield return Validation.Error($"[VRMFirstPerson]{self.name}.Renderers[{i}].Renderer is not active"); + } + } + yield break; + } + } +} diff --git a/Assets/VRM/UniVRM/Editor/FirstPerson/VRMFirstPersonValidator.cs.meta b/Assets/VRM/UniVRM/Editor/FirstPerson/VRMFirstPersonValidator.cs.meta new file mode 100644 index 000000000..1c881b701 --- /dev/null +++ b/Assets/VRM/UniVRM/Editor/FirstPerson/VRMFirstPersonValidator.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 48854dc6374b64d45a8a5e099bf5ced0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/VRM/UniVRM/Editor/Format/VRMExporterWizard.cs b/Assets/VRM/UniVRM/Editor/Format/VRMExporterWizard.cs index f5fb27905..97854aecd 100644 --- a/Assets/VRM/UniVRM/Editor/Format/VRMExporterWizard.cs +++ b/Assets/VRM/UniVRM/Editor/Format/VRMExporterWizard.cs @@ -139,20 +139,6 @@ namespace VRM return Vector3.Cross(lr, Vector3.up); } - static bool EnableRenderer(Renderer renderer) - { - if (renderer.transform.GetComponentsInParent().Any(x => !x.gameObject.activeSelf)) - { - // 自分か祖先に !activeSelf がいる - return false; - } - if (!renderer.enabled) - { - return false; - } - return true; - } - static string Msg(VRMExporterWizardMessages key) { return M17N.Getter.Msg(key); @@ -389,7 +375,7 @@ namespace VRM } var renderers = ExportRoot.GetComponentsInChildren(); - if (renderers.All(x => !EnableRenderer(x))) + if (renderers.All(x => !x.EnableForExport())) { Validation.Error(Msg(VRMExporterWizardMessages.NO_ACTIVE_MESH)).DrawGUI(); return; diff --git a/Assets/VRM/UniVRM/Editor/SpringBone/VRMSpringBoneValidator.cs b/Assets/VRM/UniVRM/Editor/SpringBone/VRMSpringBoneValidator.cs index d0e9beae2..ee6968c99 100644 --- a/Assets/VRM/UniVRM/Editor/SpringBone/VRMSpringBoneValidator.cs +++ b/Assets/VRM/UniVRM/Editor/SpringBone/VRMSpringBoneValidator.cs @@ -33,7 +33,7 @@ namespace VRM yield return Validation.Error($"[VRMSpringBone]{sb.name}.RootBones[{i}] is out of hierarchy"); continue; } - if (!springRoot.gameObject.activeInHierarchy) + if (!springRoot.transform.EnableForExport()) { yield return Validation.Error($"[VRMSpringBone]{sb.name}.RootBones[{i}] is not active"); continue; diff --git a/Assets/VRM/UniVRM/Scripts/FirstPerson/VRMFirstPerson.cs b/Assets/VRM/UniVRM/Scripts/FirstPerson/VRMFirstPerson.cs index 480032843..b69fcc1b2 100644 --- a/Assets/VRM/UniVRM/Scripts/FirstPerson/VRMFirstPerson.cs +++ b/Assets/VRM/UniVRM/Scripts/FirstPerson/VRMFirstPerson.cs @@ -50,29 +50,6 @@ namespace VRM [SerializeField] public List Renderers = new List(); - public IEnumerable Validate() - { - var hierarchy = GetComponentsInChildren(true); - - for (int i = 0; i < Renderers.Count; ++i) - { - var r = Renderers[i]; - if (r.Renderer == null) - { - yield return Validation.Error($"[VRMFirstPerson]{name}.Renderers[{i}].Renderer is null"); - } - if (!hierarchy.Contains(r.Renderer.transform)) - { - yield return Validation.Error($"[VRMFirstPerson]{name}.Renderers[{i}].Renderer is out of hierarchy"); - } - if (!r.Renderer.gameObject.activeInHierarchy) - { - yield return Validation.Error($"[VRMFirstPerson]{name}.Renderers[{i}].Renderer is not active"); - } - } - yield break; - } - public void CopyTo(GameObject _dst, Dictionary map) { var dst = _dst.AddComponent();