public EatResponse OnEvent(EventId id, object cookie) { IState currentState = Service.Get <GameStateMachine>().CurrentState; if (id <= EventId.WorldLoadComplete) { if (id <= EventId.StorageDoorEvent) { if (id != EventId.BuildingViewReady) { switch (id) { case EventId.CurrencyCollected: { CurrencyCollectionTag currencyCollectionTag = cookie as CurrencyCollectionTag; SmartEntity smartEntity = (SmartEntity)currencyCollectionTag.Building; if (smartEntity != null) { BuildingAnimationComponent buildingAnimationComp = smartEntity.BuildingAnimationComp; if (buildingAnimationComp != null) { this.UpdateAnimation(smartEntity, currentState, buildingAnimationComp, true); } } break; } case EventId.GeneratorJustFilled: this.UpdateAnimationOnGeneratorFull((SmartEntity)cookie, currentState); break; case EventId.StorageDoorEvent: { SmartEntity smartEntity = (SmartEntity)cookie; if (smartEntity != null && smartEntity.BuildingAnimationComp != null && smartEntity.StorageComp != null && smartEntity.StorageComp.CurrentFullnessPercentage < 1f) { BuildingAnimationComponent buildingAnimationComp = smartEntity.BuildingAnimationComp; if (this.BuildingEligibleForActiveAnimation(smartEntity, currentState, buildingAnimationComp)) { buildingAnimationComp.Anim.Stop(); int num = this.storageOpenCloseAnims.Length; for (int i = 0; i < num; i++) { this.EnqueueAnimation(buildingAnimationComp, this.storageOpenCloseAnims[i]); } } } break; } } } else { EntityViewParams entityViewParams = cookie as EntityViewParams; SmartEntity smartEntity = entityViewParams.Entity; GameObject mainGameObject = smartEntity.GameObjectViewComp.MainGameObject; Animation component = mainGameObject.GetComponent <Animation>(); if (!(component == null)) { AssetMeshDataMonoBehaviour component2 = mainGameObject.GetComponent <AssetMeshDataMonoBehaviour>(); this.UpdateAnimation(smartEntity, currentState, new BuildingAnimationComponent(component, component2 ? component2.ListOfParticleSystems : null), true); } } } else if (id != EventId.TroopRecruited) { if (id == EventId.WorldLoadComplete) { this.UpdateAnimations(currentState); } } else { ContractEventData contractEventData = cookie as ContractEventData; if (contractEventData.Contract.DeliveryType == DeliveryType.Infantry) { SmartEntity smartEntity = (SmartEntity)contractEventData.Entity; if (smartEntity != null) { BuildingAnimationComponent buildingAnimationComp = smartEntity.BuildingAnimationComp; if (buildingAnimationComp != null && this.BuildingEligibleForActiveAnimation(smartEntity, currentState, buildingAnimationComp)) { buildingAnimationComp.Anim.Stop(); for (int j = 0; j < this.barracksOpenCloseAnims.Length; j++) { this.EnqueueAnimation(buildingAnimationComp, this.barracksOpenCloseAnims[j]); } } } } } } else if (id <= EventId.ContractStopped) { if (id != EventId.GameStateChanged) { switch (id) { case EventId.ContractStarted: case EventId.ContractContinued: { ContractEventData contractEventData2 = (ContractEventData)cookie; this.StartAnimationOnContractStarted(contractEventData2.Entity, contractEventData2.Contract, currentState); break; } case EventId.ContractStopped: this.UpdateAnimationOnContractStopped((Entity)cookie, currentState); break; } } else { this.UpdateAnimations(currentState); } } else if (id != EventId.ScreenClosing) { switch (id) { case EventId.EntityPostBattleRepairStarted: case EventId.EntityPostBattleRepairFinished: { SmartEntity smartEntity = (SmartEntity)cookie; if (smartEntity != null) { BuildingAnimationComponent buildingAnimationComp = smartEntity.BuildingAnimationComp; if (buildingAnimationComp != null) { this.UpdateAnimation(smartEntity, currentState, buildingAnimationComp, true); } } break; } case EventId.AllPostBattleRepairFinished: break; case EventId.ShuttleAnimStateChanged: { ShuttleAnim shuttleAnim = (ShuttleAnim)cookie; SmartEntity smartEntity = (SmartEntity)shuttleAnim.Starport; if (smartEntity.BuildingComp.BuildingType.Type == BuildingType.Armory) { Service.Get <ShuttleController>().DestroyArmoryShuttle(smartEntity); } else { this.UpdateContraBandGeneratorAnimation(smartEntity, shuttleAnim); } break; } default: if (id == EventId.EquipmentDeactivated) { NodeList <ArmoryNode> armoryNodeList = Service.Get <BuildingLookupController>().ArmoryNodeList; for (ArmoryNode armoryNode = armoryNodeList.Head; armoryNode != null; armoryNode = armoryNode.Next) { this.UpdateArmoryAnimation((SmartEntity)armoryNode.Entity); } } break; } } else if (cookie is ArmoryScreen) { NodeList <ArmoryNode> armoryNodeList2 = Service.Get <BuildingLookupController>().ArmoryNodeList; for (ArmoryNode armoryNode2 = armoryNodeList2.Head; armoryNode2 != null; armoryNode2 = armoryNode2.Next) { this.UpdateArmoryAnimation((SmartEntity)armoryNode2.Entity); } } return(EatResponse.NotEaten); }
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); } }
private void PrepareEntityView(SmartEntity entity, GameObject gameObject) { EntityRef entityRef = gameObject.AddComponent <EntityRef>(); entityRef.Entity = entity; IDataController dataController = Service.Get <IDataController>(); GameObjectViewComponent gameObjectViewComponent; if (entity.GameObjectViewComp != null) { gameObjectViewComponent = entity.GameObjectViewComp; UnityEngine.Object.Destroy(gameObjectViewComponent.MainGameObject); gameObjectViewComponent.MainGameObject = gameObject; } else { float tooltipHeightOffset = 0f; if (entity.BuildingComp != null) { tooltipHeightOffset = entity.BuildingComp.BuildingType.TooltipHeightOffset; EffectsTypeVO effectsTypeVO = dataController.Get <EffectsTypeVO>("effect203"); AssetManager assetManager = Service.Get <AssetManager>(); assetManager.RegisterPreloadableAsset(effectsTypeVO.AssetName); AssetHandle assetHandle = AssetHandle.Invalid; assetManager.Load(ref assetHandle, effectsTypeVO.AssetName, new AssetSuccessDelegate(this.SparkFxSuccess), null, entity); } else if (entity.TroopComp != null) { TroopTypeVO troopTypeVO = Service.Get <IDataController>().Get <TroopTypeVO>(entity.TroopComp.TroopType.Uid); tooltipHeightOffset = troopTypeVO.TooltipHeightOffset; } gameObjectViewComponent = new GameObjectViewComponent(gameObject, tooltipHeightOffset); entity.Add(gameObjectViewComponent); } SupportComponent supportComp = entity.SupportComp; SupportViewComponent supportViewComp = entity.SupportViewComp; if (supportComp != null && supportViewComp == null) { SupportViewComponent component = new SupportViewComponent(); entity.Add <SupportViewComponent>(component); if (Service.Get <BuildingController>().PurchasingBuilding != entity) { Service.Get <BuildingTooltipController>().EnsureBuildingTooltip(entity); } } GeneratorComponent generatorComp = entity.GeneratorComp; GeneratorViewComponent generatorViewComponent = entity.GeneratorViewComp; if (generatorComp != null && generatorViewComponent == null) { generatorViewComponent = new GeneratorViewComponent(entity); entity.Add <GeneratorViewComponent>(generatorViewComponent); } TrapComponent trapComp = entity.TrapComp; TrapViewComponent trapViewComponent = entity.TrapViewComp; if (trapComp != null && trapViewComponent == null) { Animator component2 = gameObjectViewComponent.MainGameObject.GetComponent <Animator>(); Transform transform = gameObjectViewComponent.MainGameObject.transform.FindChild("Contents"); if (component2 == null) { Service.Get <StaRTSLogger>().ErrorFormat("A trap has been added that does not have a MecAnim controller. Building Uid: {0}, AssetName: {1}", new object[] { entity.BuildingComp.BuildingType.Uid, entity.BuildingComp.BuildingType.AssetName }); } else if (transform == null) { Service.Get <StaRTSLogger>().ErrorFormat("A trap has been added that does not have a Contents transform. Building Uid: {0}, AssetName: {1}", new object[] { entity.BuildingComp.BuildingType.Uid, entity.BuildingComp.BuildingType.AssetName }); } else { GameObject gameObject2 = transform.gameObject; if (gameObject2 == null) { Service.Get <StaRTSLogger>().ErrorFormat("A trap has been added that does not have a Contents GameObject. Building Uid: {0}, AssetName: {1}", new object[] { entity.BuildingComp.BuildingType.Uid, entity.BuildingComp.BuildingType.AssetName }); } trapViewComponent = new TrapViewComponent(component2); if (trapComp.Type.EventType == TrapEventType.Turret) { Transform transform2 = gameObjectViewComponent.MainGameObject.transform; Transform transform3 = transform2.FindChild(trapComp.Type.TurretTED.TurretAnimatorName); if (transform3 == null) { Service.Get <StaRTSLogger>().ErrorFormat("Trap {0}: Cannot find a gameobject in path {1}", new object[] { entity.BuildingComp.BuildingType.Uid, trapComp.Type.TurretTED.TurretAnimatorName }); } else { Animator component3 = transform3.gameObject.GetComponent <Animator>(); if (component3 == null) { Service.Get <StaRTSLogger>().ErrorFormat("Trap {0}: Cannot find an animator on gameobject in path {1}", new object[] { entity.BuildingComp.BuildingType.Uid, trapComp.Type.TurretTED.TurretAnimatorName }); } else { trapViewComponent.TurretAnim = component3; } } } entity.Add <TrapViewComponent>(trapViewComponent); } } AssetMeshDataMonoBehaviour component4 = gameObjectViewComponent.MainGameObject.GetComponent <AssetMeshDataMonoBehaviour>(); if (component4 != null && component4.OtherGameObjects != null) { for (int i = 0; i < component4.OtherGameObjects.Count; i++) { if (component4.OtherGameObjects[i].name.Contains("center_of_mass")) { gameObjectViewComponent.CenterOfMass = component4.OtherGameObjects[i]; } else if (component4.OtherGameObjects[i].name.Contains("locator_hit")) { gameObjectViewComponent.HitLocators.Add(component4.OtherGameObjects[i]); } else if (component4.OtherGameObjects[i].name.Contains("locator_vehicle")) { gameObjectViewComponent.VehicleLocator = component4.OtherGameObjects[i]; } else if (component4.OtherGameObjects[i].name.Contains("locator_effect")) { gameObjectViewComponent.EffectLocators.Add(component4.OtherGameObjects[i]); } } } FactoryComponent factoryComp = entity.FactoryComp; if (factoryComp != null) { EffectsTypeVO effectsTypeVO2 = dataController.Get <EffectsTypeVO>("effect203"); AssetManager assetManager2 = Service.Get <AssetManager>(); assetManager2.RegisterPreloadableAsset(effectsTypeVO2.AssetName); AssetHandle assetHandle2 = AssetHandle.Invalid; assetManager2.Load(ref assetHandle2, effectsTypeVO2.AssetName, new AssetSuccessDelegate(this.SparkFxSuccess), null, entity); } this.SetupGunLocators(entity, component4); if (entity.TroopShieldHealthComp != null && entity.TroopShieldViewComp == null) { TroopTypeVO troop = Service.Get <IDataController>().Get <TroopTypeVO>(entity.TroopComp.TroopType.Uid); entity.Add <TroopShieldViewComponent>(new TroopShieldViewComponent(troop)); } gameObject.SetActive(false); this.CheckHealthView(entity); this.CheckMeterShaderView(entity); Service.Get <EntityRenderController>().UpdateNewEntityView(entity); }
private void OnAssetSuccess(object asset, object cookie) { string text = cookie as string; bool flag = !Service.AssetManager.IsAssetCloned(text); GameObject gameObject; if (flag) { gameObject = UnityEngine.Object.Instantiate <GameObject>(asset as GameObject); } else { gameObject = (asset as GameObject); } if (text == this.parent.Config.AssetName) { this.parent.Config.MainAsset = gameObject; int i = 0; int count = this.orphans.Count; while (i < count) { this.orphans[i].transform.parent = this.parent.Config.MainAsset.transform; i++; } this.orphans.Clear(); AssetMeshDataMonoBehaviour component = gameObject.GetComponent <AssetMeshDataMonoBehaviour>(); if (component != null && component.ShadowGameObject != null) { component.ShadowGameObject.SetActive(false); } } else if (this.parent.Config.MainAsset == null) { this.orphans.Add(gameObject); } else { gameObject.transform.parent = this.parent.Config.MainAsset.transform; } if (gameObject.activeSelf) { gameObject.SetActive(false); this.loadedAssets.Add(gameObject); } this.outstandingAssets--; if (this.outstandingAssets > 0) { return; } int j = 0; int count2 = this.loadedAssets.Count; while (j < count2) { this.loadedAssets[j].SetActive(true); j++; } this.loadedAssets.Clear(); Renderer[] componentsInChildren = gameObject.GetComponentsInChildren <Renderer>(true); int k = 0; int num = componentsInChildren.Length; while (k < num) { Renderer renderer = componentsInChildren[k]; if (renderer.sharedMaterial != null && renderer.sharedMaterial.HasProperty("_OutlineInnerWidth") && renderer.sharedMaterial.HasProperty("_Outline")) { renderer.sharedMaterial.SetFloat("_Outline", 0f); renderer.sharedMaterial.SetFloat("_OutlineInnerWidth", 0f); } k++; } this.parent.Config.AssetReady = true; this.ExecuteCallback(0u, this.onLoadedCompleteCallback); }