Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

activeInHierarchy が prefab にヒットする件 #540

Merged
merged 1 commit into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Assets/VRM/UniVRM/Editor/ExporterExtensions.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
11 changes: 11 additions & 0 deletions Assets/VRM/UniVRM/Editor/ExporterExtensions.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions Assets/VRM/UniVRM/Editor/FirstPerson/VRMFirstPersonValidator.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 1 addition & 15 deletions Assets/VRM/UniVRM/Editor/Format/VRMExporterWizard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,6 @@ static Vector3 GetForward(Transform l, Transform r)
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);
Expand Down Expand Up @@ -389,7 +375,7 @@ private void OnGUI()
}

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static IEnumerable<Validation> Validate(GameObject root)
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;
Expand Down
23 changes: 0 additions & 23 deletions Assets/VRM/UniVRM/Scripts/FirstPerson/VRMFirstPerson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,6 @@ public Mesh SharedMesh
[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>();
Expand Down