/// <summary> /// 获取Prefab /// </summary> public Entity GetPrefab(AssetRef Ref) { //如果Prefab已经加载出来了,直接返回,如果没有,就加载 if (collection.Contains(Ref)) { return(collection[Ref]); } else { return(LoadPrefab(ref Ref)); } }
/// <summary> /// 将一个Prefab加载并转换成Entity /// </summary> protected Entity LoadPrefab(ref AssetRef Ref) //用ref是为了减少开销,虽然估计也没减少多少,回头可能会删? { var prefabGO = Ref.Get <GameObject>(); if (prefabGO == null) { throw new ArgumentException("Ref的类型必须是GameObject", "Ref"); } //转换Prefab var prefabEntity = GameObjectConversionUtility.ConvertGameObjectHierarchy(prefabGO, GameObjectConversionSettings.FromWorld(this.World, store)); //为Prefab实体添加Prefab信息组件 EntityManager.AddComponentData(prefabEntity, new PrefabInfo() { Ref = Ref }); EntityManager.AddComponentData(prefabEntity, new InitializingTag()); //Update系统组,对新的Prefab实体进行处理 this.Update(); EntityManager.RemoveComponent <InitializingTag>(prefabEntity); return(prefabEntity); }
/// <summary> /// 通过AssetRef获得对应Entity /// </summary> public Entity this[AssetRef Ref] { get => RefToEntity[Ref];