private bool LoadAddOns(EntityViewParams viewParams) { TrapComponent trapComp = viewParams.Entity.TrapComp; if (trapComp == null) { return(false); } if (trapComp.Type.AddOns == null || trapComp.Type.AddOns.Count == 0) { return(false); } AssetManager assetManager = Service.AssetManager; List <string> list = new List <string>(); List <object> list2 = new List <object>(); int i = 0; int count = trapComp.Type.AddOns.Count; while (i < count) { AssetHandle item = AssetHandle.Invalid; viewParams.Entity.AssetComp.AddOnsAssetHandles.Add(item); AddOnMapping addOnMapping = trapComp.Type.AddOns[i]; string model = addOnMapping.Model; AddOnViewParams item2 = new AddOnViewParams(viewParams.Entity, addOnMapping.Parent); list.Add(model); list2.Add(item2); assetManager.RegisterPreloadableAsset(model); i++; } assetManager.MultiLoad(viewParams.Entity.AssetComp.AddOnsAssetHandles, list, new AssetSuccessDelegate(this.AddOnSuccess), null, list2, new AssetsCompleteDelegate(this.OnAllAddonsLoaded), viewParams); return(true); }
private void OnAllAddonsLoaded(object cookie) { EntityViewParams entityViewParams = (EntityViewParams)cookie; bool isBuilding = entityViewParams.Entity.BuildingComp != null; bool isDroid = entityViewParams.Entity.DroidComp != null; this.SendAssetReadyEvent(isBuilding, false, isDroid, entityViewParams); }
public void LoadEntityAsset(Entity e, string assetName, bool createCollider) { SmartEntity smartEntity = (SmartEntity)e; EntityViewParams entityViewParams = new EntityViewParams(smartEntity, createCollider); AssetComponent assetComp = smartEntity.AssetComp; if (assetComp == null) { Service.Get <StaRTSLogger>().Error("Entity is missing asset component: " + assetName); this.AssetFailure(entityViewParams); return; } if (assetComp.RequestedAssetName == assetName) { bool isBuilding = smartEntity.BuildingComp != null; bool flag = assetName == null; bool isDroid = smartEntity.DroidComp != null; if (!flag) { GameObjectViewComponent gameObjectViewComp = smartEntity.GameObjectViewComp; if (gameObjectViewComp == null || gameObjectViewComp.MainGameObject == null) { return; } } this.SendAssetReadyEvent(isBuilding, flag, isDroid, entityViewParams); return; } if (assetComp.RequestedAssetHandle != AssetHandle.Invalid) { this.UnloadEntityAsset(smartEntity); } assetComp.RequestedAssetName = assetName; if (assetName == null) { this.AssetFailure(entityViewParams); return; } AssetManager assetManager = Service.Get <AssetManager>(); assetManager.RegisterPreloadableAsset(assetName); WorldPreloadAsset preloadedAsset = Service.Get <WorldPreloader>().GetPreloadedAsset(assetName); if (preloadedAsset == null) { AssetHandle requestedAssetHandle = AssetHandle.Invalid; assetManager.Load(ref requestedAssetHandle, assetName, new AssetSuccessDelegate(this.AssetSuccess), new AssetFailureDelegate(this.AssetFailure), entityViewParams); assetComp.RequestedAssetHandle = requestedAssetHandle; return; } assetComp.RequestedAssetHandle = preloadedAsset.Handle; if (preloadedAsset.GameObj == null) { this.AssetFailure(entityViewParams); return; } this.AssetSuccess(preloadedAsset.GameObj, entityViewParams); }
private void AssetFailure(object cookie) { EntityViewParams entityViewParams = cookie as EntityViewParams; BuildingComponent buildingComp = entityViewParams.Entity.BuildingComp; if (buildingComp != null) { GameObject asset = new GameObject(); this.ProcessGameObject(asset, cookie, true); } }
private void ProcessGameObject(object asset, object cookie, bool isMissingAsset) { GameObject gameObject = asset as GameObject; EntityViewParams entityViewParams = cookie as EntityViewParams; SmartEntity entity = entityViewParams.Entity; BuildingComponent buildingComp = entity.BuildingComp; TroopComponent troopComp = entity.TroopComp; TransportComponent transportComp = entity.TransportComp; DroidComponent droidComp = entity.DroidComp; bool flag = buildingComp != null; bool flag2 = troopComp != null; bool flag3 = transportComp != null; bool isDroid = droidComp != null; if (flag2) { gameObject.name = "Troop " + troopComp.TroopType.Uid + " #" + entity.ID.ToString(); } else if (flag) { gameObject.name = "Building " + buildingComp.BuildingType.Uid + " #" + entity.ID.ToString(); } else if (flag3) { gameObject.name = "Transport " + transportComp.TransportType.Uid + " #" + entity.ID.ToString(); transportComp.GameObj = gameObject; transportComp.ShadowGameObject = gameObject.transform.Find("shadowMesh").gameObject; transportComp.ShadowMaterial = UnityUtils.EnsureMaterialCopy(transportComp.ShadowGameObject.GetComponent <Renderer>()); transportComp.ShadowMaterial.shader = Service.AssetManager.Shaders.GetShader("TransportShadow"); return; } if (isMissingAsset) { gameObject.name += " MISSING"; } bool createCollider = entityViewParams.CreateCollider; this.PrepareGameObject(entity, gameObject, createCollider); if (isMissingAsset || !this.LoadAddOns(entityViewParams)) { this.SendAssetReadyEvent(flag, isMissingAsset, isDroid, entityViewParams); } }
private void SendAssetReadyEvent(bool isBuilding, bool isMissingAsset, bool isDroid, EntityViewParams viewParams) { EventId id; if (isBuilding) { id = ((!isMissingAsset) ? EventId.BuildingViewReady : EventId.BuildingViewFailed); } else { id = ((!isDroid) ? EventId.TroopViewReady : EventId.DroidViewReady); } Service.EventManager.SendEvent(id, viewParams); }
private void ProcessGameObject(object asset, object cookie, bool isMissingAsset) { GameObject gameObject = asset as GameObject; EntityViewParams entityViewParams = cookie as EntityViewParams; SmartEntity entity = entityViewParams.Entity; BuildingComponent buildingComp = entity.BuildingComp; TroopComponent troopComp = entity.TroopComp; TransportComponent transportComp = entity.TransportComp; DroidComponent droidComp = entity.DroidComp; bool flag = buildingComp != null; bool flag2 = troopComp != null; bool flag3 = transportComp != null; bool isDroid = droidComp != null; AssetMeshDataMonoBehaviour component = gameObject.GetComponent <AssetMeshDataMonoBehaviour>(); if (component != null && component.ShadowGameObject != null) { Vector3 position = component.ShadowGameObject.transform.position; position.y = 0.0225f; component.ShadowGameObject.transform.position = position; } Transform transform = gameObject.transform.FindChild("MASTER_MOVER"); if (transform != null) { Transform transform2 = transform.FindChild("shadowMesh"); if (transform2 != null) { Vector3 position2 = transform2.position; position2.y = 0.0225f; transform2.position = position2; } } if (flag2) { gameObject.name = "Troop " + troopComp.TroopType.Uid + " #" + entity.ID.ToString(); } else if (flag) { gameObject.name = "Building " + buildingComp.BuildingType.Uid + " #" + entity.ID.ToString(); } else if (flag3) { gameObject.name = "Transport " + transportComp.TransportType.Uid + " #" + entity.ID.ToString(); transportComp.GameObj = gameObject; transportComp.ShadowGameObject = gameObject.transform.Find("shadowMesh").gameObject; transportComp.ShadowMaterial = UnityUtils.EnsureMaterialCopy(transportComp.ShadowGameObject.GetComponent <Renderer>()); transportComp.ShadowMaterial.shader = Service.Get <AssetManager>().Shaders.GetShader("TransportShadow"); return; } if (isMissingAsset) { gameObject.name += " MISSING"; } bool createCollider = entityViewParams.CreateCollider; this.PrepareGameObject(entity, gameObject, createCollider); if (isMissingAsset || !this.LoadAddOns(entityViewParams)) { this.SendAssetReadyEvent(flag, isMissingAsset, isDroid, entityViewParams); } }