activeInHierarchy が prefab にヒットする件

This commit is contained in:
ousttrue
2020-09-01 19:59:38 +09:00
parent 873aec208c
commit 103c5c2822
7 changed files with 74 additions and 39 deletions

View File

@@ -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<Transform>().Any(x => !x.gameObject.activeSelf))
{
// 自分か祖先に !activeSelf がいる
return false;
}
return true;
}
}
}

View File

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

View File

@@ -0,0 +1,32 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace VRM
{
public static class VRMFirstPersonValidator
{
public static IEnumerable<Validation> Validate(this VRMFirstPerson self)
{
var hierarchy = self.GetComponentsInChildren<Transform>(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;
}
}
}

View File

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

View File

@@ -139,20 +139,6 @@ namespace VRM
return Vector3.Cross(lr, Vector3.up);
}
static bool EnableRenderer(Renderer renderer)
{
if (renderer.transform.GetComponentsInParent<Transform>().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<Renderer>();
if (renderers.All(x => !EnableRenderer(x)))
if (renderers.All(x => !x.EnableForExport()))
{
Validation.Error(Msg(VRMExporterWizardMessages.NO_ACTIVE_MESH)).DrawGUI();
return;

View File

@@ -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;

View File

@@ -50,29 +50,6 @@ namespace VRM
[SerializeField]
public List<RendererFirstPersonFlags> Renderers = new List<RendererFirstPersonFlags>();
public IEnumerable<Validation> Validate()
{
var hierarchy = GetComponentsInChildren<Transform>(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<Transform, Transform> map)
{
var dst = _dst.AddComponent<VRMFirstPerson>();