Skip to content

Instantly share code, notes, and snippets.

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

Embed
What would you like to do?
using UnityEngine;
using System.Linq;
using Unity.Entities; // 追加
using Unity.Rendering; // 追加
using Unity.Transforms; // 追加
public class Manager : MonoBehaviour
{
public GameObject prefab;
public float numOfObject = 10000; // 生成するオブジェクトの数
public float distance = 100; // ランダム生成の範囲(中心からの距離)
void Start()
{
var manager = World.Active.GetOrCreateManager<EntityManager>();
var archetype = prefab.Archetype(manager); // ※ Prefab から Archetype 取得
var look = prefab.CreateMeshInstanceRenderer(); // ※ MeshFilter & MeshRenderer の情報から MeshInstanceRenderer を生成
for (int i = 0; i < numOfObject; i++)
{
var entity = manager.CreateEntity(archetype);
manager.AddSharedComponentData(entity, look);
// 情報をランダムで設定する
manager.SetComponentData(entity, new Position { Value = Random.insideUnitSphere * distance });
manager.SetComponentData(entity, new Rotation { Value = Random.rotation });
}
}
}
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.