Skip to content

Instantly share code, notes, and snippets.

@kou-yeung kou-yeung/GameObjectEx.cs Secret
Created Nov 9, 2018

Embed
What would you like to do?
public static class GameObjectEx
{
/// <summary>
/// ComponentDataWrapper<T> の一覧を取得し、Archetypeを返す
/// </summary>
/// <returns></returns>
public static EntityArchetype Archetype(this GameObject @this, EntityManager manager)
{
// Get All ComponentDataWrapperBase in GameObject
var wrapper = @this.GetComponents<ComponentDataWrapperBase>();
// get the BaseType GenericArguments
var componentType = wrapper.Select(w => (ComponentType)w.GetType().BaseType.GetGenericArguments()[0]);
// maybe gameobject has a MeshInstanceRendererComponent. so erase SharedComponentDataWrapper
// and CreateArchetype
return manager.CreateArchetype(componentType.Where(c => !c.IsSharedComponent).ToArray());
}
/// <summary>
/// MeshInstanceRenderer を生成する
/// </summary>
/// <param name="this"></param>
/// <returns></returns>
public static MeshInstanceRenderer CreateMeshInstanceRenderer(this GameObject @this)
{
// 従来システムの MeshFilter や MeshRenderer を取得する
var meshFilter = @this.GetComponent<MeshFilter>();
var renderer = @this.GetComponent<MeshRenderer>();
var res = new MeshInstanceRenderer();
if (meshFilter != null && renderer != null)
{
res.mesh = meshFilter.sharedMesh;
res.material = renderer.sharedMaterial;
}
return res;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.