public LookupData(SimAssetBank bank) { if (bank == null) { throw new ArgumentNullException(nameof(bank)); } SimAssetTechTypes = new NativeList <ViewTechType>(Allocator.Persistent); SimAssets = new List <SimAsset>(bank._simAssets.Count); EditIdToRuntimeId = new Dictionary <string, SimAssetId>(bank._simAssets.Count); int count = bank._simAssets.Count; for (int i = 0; i < count; i++) { var asset = bank._simAssets[i]; if (asset != null) { int v = SimAssets.Count + 1; if (v > ushort.MaxValue) { Log.Error($"Too many SimAssets! We are exceeding the maximal SimAssetId value of {ushort.MaxValue}."); break; } SimAssetId assetId = new SimAssetId((ushort)v); SimAssets.Add(asset); EditIdToRuntimeId.Add(asset.Guid, assetId); SimAssetTechTypes.Add(asset.ViewTechType); } } }
public static GameActionAuth FindActionAuth(SimAssetId itemID) { GameObject itemPrefab = FindSimAssetPrefab(itemID); if (itemPrefab != null) { return(itemPrefab.GetComponent <GameActionAuth>()); } return(null); }
public SimAsset GetSimAsset(SimAssetId simAssetId) { int i = simAssetId.Value - 1; if (i >= 0 && i < _lookupData.SimAssets.Count) { return(_lookupData.SimAssets[i]); } return(null); }
public bool TryGetViewTechType(SimAssetId simAssetId, out ViewTechType viewTechType) { int i = simAssetId.Value - 1; if (i >= 0 && i < _lookupData.SimAssetTechTypes.Length) { viewTechType = _lookupData.SimAssetTechTypes[i]; return(true); } viewTechType = default; return(false); }
private void UpdateViewEntities(SimAssetBank.JobLookup simAssetBank, EntityQuery simEntityQuery) { if (simEntityQuery.IsEmpty) { return; } EntityCommandBuffer ecb = _ecb.CreateCommandBuffer(); NativeArray <Entity> simEntities = simEntityQuery.ToEntityArrayAsync(Allocator.TempJob, out JobHandle job1); NativeArray <SimAssetId> simAssetIds = simEntityQuery.ToComponentDataArrayAsync <SimAssetId>(Allocator.TempJob, out JobHandle job2); EntityArchetype viewArchetypeTile = _viewArchetypeTile; EntityArchetype viewArchetypeGameObject = _viewArchetypeGameObject; NativeHashMap <Entity, Entity> sim2ViewMap = _sim2ViewMap; ComponentDataFromEntity <SimAssetId> viewSimAssetIds = GetComponentDataFromEntity <SimAssetId>(isReadOnly: true); var jobHandle = Job.WithCode(() => { for (int i = 0; i < simEntities.Length; i++) { SimAssetId viewAssetId = SimAssetId.Invalid; SimAssetId simAssetId = simAssetIds[i]; Entity simEntity = simEntities[i]; if (sim2ViewMap.TryGetValue(simEntity, out Entity viewEntity)) { if (viewSimAssetIds.HasComponent(viewEntity)) { viewAssetId = viewSimAssetIds[viewEntity]; } } if (viewAssetId != simAssetId) { if (viewEntity != Entity.Null) { ecb.DestroyEntity(viewEntity); } TryCreateViewEntity(simAssetBank, ecb, simEntities[i], simAssetId, viewArchetypeTile, viewArchetypeGameObject); } } }) .WithReadOnly(sim2ViewMap) .WithReadOnly(viewSimAssetIds) .WithDisposeOnCompletion(simAssetIds) .WithDisposeOnCompletion(simEntities) .Schedule(JobHandle.CombineDependencies(Dependency, job1, job2)); Dependency = jobHandle; }
private Entity FindItemFromAssetId(SimAssetId ID, Entity itemOwner) { if (SimWorld.TryGetBufferReadOnly(itemOwner, out DynamicBuffer <InventoryItemReference> inventory)) { foreach (InventoryItemReference item in inventory) { if (SimWorld.TryGetComponent(item.ItemEntity, out SimAssetId itemID)) { if (itemID.Value == ID.Value) { return(item.ItemEntity); } } } } return(Entity.Null); }
private static void TryCreateViewEntity(SimAssetBank.JobLookup simAssetBank, EntityCommandBuffer ecb, Entity simEntity, SimAssetId simAssetId, EntityArchetype tileArchetype, EntityArchetype gameObjectArchetype) { if (simAssetBank.TryGetViewTechType(simAssetId, out ViewTechType viewTechType)) { var archetype = viewTechType == ViewTechType.Tile ? tileArchetype : gameObjectArchetype; Entity viewEntity = ecb.CreateEntity(archetype); ecb.SetComponent(viewEntity, (BindedSimEntity)simEntity); ecb.SetComponent(viewEntity, simAssetId); } }
public static GameObject FindSimAssetPrefab(SimAssetId simAssetId) { return(SimAssetBankInstance.GetLookup().GetSimAsset(simAssetId)?.gameObject); }