Skip to content

Instantly share code, notes, and snippets.

@kou-yeung kou-yeung/PureECSBridge.cs Secret
Last active Nov 8, 2018

Embed
What would you like to do?
using UnityEngine;
using Unity.Rendering;
using Unity.Transforms;
[RequireComponent(typeof(PositionComponent), typeof(RotationComponent)/*, typeof(ScaleComponent)*/)] // Transform 関連
[RequireComponent(typeof(CopyTransformFromGameObjectComponent))] // GameObjectのTransform情報 -> PositionComponent & RotationComponent コピー
[RequireComponent(typeof(MeshInstanceRendererComponent))] // 描画関連
[DisallowMultipleComponent]
public class PureECSBridge : MonoBehaviour
{
private void Awake()
{
// MeshFilter や MeshRenderer を取得する
var meshFilter = GetComponent<MeshFilter>();
var renderer = GetComponent<MeshRenderer>();
// あれば、MeshInstanceRendererに情報を複製する
if (meshFilter != null && renderer != null)
{
var instanceRenderer = GetComponent<MeshInstanceRendererComponent>();
var w = instanceRenderer.Value;
w.mesh = meshFilter.sharedMesh; // メッシュ情報
w.material = renderer.sharedMaterial; // マテリアル情報 : Enable GPU Instancing が 有効しないと遅くなる
instanceRenderer.Value = w;
renderer.enabled = false; // 従来のシステムで描画しないため、無効にする
}
}
}
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.