UniVRM/Core/Scripts/Format/MonoBehaviourComparator.cs
ousttrue 2a19c831f8 Squashed 'UniGLTF/' content from commit 690847a
git-subtree-dir: UniGLTF
git-subtree-split: 690847a1a5a0bd3df55187e1f1cb6f338c09225b
2018-12-28 19:53:19 +09:00

69 lines
2.0 KiB
C#

using System;
using UnityEngine;
namespace UniGLTF
{
public static class MonoBehaviourComparator
{
public static bool AssertAreEquals(GameObject l, GameObject r)
{
return
l.name == r.name
&& AssertAreEquals<Transform>(l, r,
(x, y) => AssertAreEquals(x[0], y[0]))
&& AssertAreEquals<MeshFilter>(l, r,
(x, y) => AssertAreEquals(x[0], y[0]))
&& AssertAreEquals<MeshRenderer>(l, r,
(x, y) => AssertAreEquals(x[0], y[0]))
&& AssertAreEquals<SkinnedMeshRenderer>(l, r,
(x, y) => AssertAreEquals(x[0], y[0]))
;
}
public static bool AssertAreEquals<T>(GameObject l, GameObject r, Func<T[], T[], bool> pred) where T : Component
{
var ll = l.GetComponents<T>();
var rr = r.GetComponents<T>();
if (ll.Length != rr.Length)
{
return false;
}
if (ll.Length == 0)
{
return true;
}
return pred(ll, rr);
}
public static bool AssertAreEquals(Transform l, Transform r)
{
return
(l.localPosition == r.localPosition)
&& (l.localRotation == r.localRotation)
&& (l.localScale == r.localScale)
;
}
public static bool AssertAreEquals(MeshFilter l, MeshFilter r)
{
throw new NotImplementedException();
}
public static bool AssertAreEquals(MeshRenderer l, MeshRenderer r)
{
throw new NotImplementedException();
}
public static bool AssertAreEquals(SkinnedMeshRenderer l, SkinnedMeshRenderer r)
{
throw new NotImplementedException();
}
public static bool AssetAreEquals(Texture2D l, Texture2D r)
{
throw new NotImplementedException();
}
}
}