-
-
Save kou-yeung/95d9e53b166cd6fc8c1de6505901cb54 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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