예제 #1
0
        private void PlanetAttachmentSuccess(object asset, object cookie)
        {
            PlanetAttachmentTO planetAttachmentTO = (PlanetAttachmentTO)cookie;
            SmartEntity        entity             = planetAttachmentTO.Entity;
            GameObject         locator            = planetAttachmentTO.Locator;

            if (entity == null || entity.GameObjectViewComp == null)
            {
                return;
            }
            GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(asset as GameObject);

            gameObject.SetActive(false);
            gameObject.transform.parent           = locator.transform;
            gameObject.transform.localScale       = Vector3.one;
            gameObject.transform.localPosition    = Vector3.zero;
            gameObject.transform.localEulerAngles = Vector3.zero;
            gameObject.SetActive(true);
        }
예제 #2
0
        private void PrepareEntityView(SmartEntity entity, GameObject gameObject)
        {
            EntityRef entityRef = gameObject.AddComponent <EntityRef>();

            entityRef.Entity = entity;
            StaticDataController    staticDataController = Service.StaticDataController;
            GameObjectViewComponent gameObjectViewComponent;

            if (entity.GameObjectViewComp != null)
            {
                gameObjectViewComponent = entity.GameObjectViewComp;
                Vector3 position = gameObjectViewComponent.MainTransform.position;
                UnityEngine.Object.Destroy(gameObjectViewComponent.MainGameObject);
                gameObjectViewComponent.MainGameObject         = gameObject;
                gameObjectViewComponent.MainTransform.position = position;
            }
            else
            {
                float tooltipHeightOffset = 0f;
                if (entity.BuildingComp != null)
                {
                    tooltipHeightOffset = entity.BuildingComp.BuildingType.TooltipHeightOffset;
                    EffectsTypeVO effectsTypeVO = staticDataController.Get <EffectsTypeVO>("effect203");
                    AssetManager  assetManager  = Service.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.StaticDataController.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.BuildingController.PurchasingBuilding != entity)
                {
                    Service.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.Find("Contents");
                if (component2 == null)
                {
                    Service.Logger.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.Logger.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.Logger.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.Find(trapComp.Type.TurretTED.TurretAnimatorName);
                        if (transform3 == null)
                        {
                            Service.Logger.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.Logger.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]);
                    }
                }
            }
            if (entity.TroopComp != null)
            {
                TroopTypeVO troopTypeVO2 = (TroopTypeVO)entity.TroopComp.TroopType;
                if (!string.IsNullOrEmpty(troopTypeVO2.PlanetAttachmentId))
                {
                    string uid = Service.WorldTransitioner.GetMapDataLoader().GetPlanetData().Uid;
                    List <PlanetAttachmentVO> list = new List <PlanetAttachmentVO>();
                    foreach (PlanetAttachmentVO current in staticDataController.GetAll <PlanetAttachmentVO>())
                    {
                        if (current.AttachmentId == troopTypeVO2.PlanetAttachmentId && current.Planets != null && Array.IndexOf <string>(current.Planets, uid) != -1)
                        {
                            list.Add(current);
                        }
                    }
                    AssetManager assetManager2 = Service.AssetManager;
                    for (int j = 0; j < list.Count; j++)
                    {
                        if (list[j] == null)
                        {
                            Service.Logger.ErrorFormat("Attachment is null for troop {0}, asset {1}", new object[]
                            {
                                troopTypeVO2.Uid,
                                troopTypeVO2.AssetName
                            });
                        }
                        else
                        {
                            AssetHandle        assetHandle2       = AssetHandle.Invalid;
                            PlanetAttachmentTO planetAttachmentTO = new PlanetAttachmentTO();
                            planetAttachmentTO.Entity  = entity;
                            planetAttachmentTO.Locator = UnityUtils.FindGameObject(gameObjectViewComponent.MainGameObject, list[j].Locator);
                            if (planetAttachmentTO.Locator == null)
                            {
                                Service.Logger.ErrorFormat("Locator {0} not found in asset {1}, and it should be according to PlanetAttachmentData {2}", new object[]
                                {
                                    list[j].Locator,
                                    troopTypeVO2.AssetName,
                                    list[j].Uid
                                });
                                planetAttachmentTO.Locator = gameObjectViewComponent.MainGameObject;
                            }
                            assetManager2.Load(ref assetHandle2, list[j].AssetName, new AssetSuccessDelegate(this.PlanetAttachmentSuccess), null, planetAttachmentTO);
                        }
                    }
                }
            }
            FactoryComponent factoryComp = entity.FactoryComp;

            if (factoryComp != null)
            {
                EffectsTypeVO effectsTypeVO2 = staticDataController.Get <EffectsTypeVO>("effect203");
                AssetManager  assetManager3  = Service.AssetManager;
                assetManager3.RegisterPreloadableAsset(effectsTypeVO2.AssetName);
                AssetHandle assetHandle3 = AssetHandle.Invalid;
                assetManager3.Load(ref assetHandle3, effectsTypeVO2.AssetName, new AssetSuccessDelegate(this.SparkFxSuccess), null, entity);
            }
            this.SetupGunLocators(entity, component4);
            if (entity.TroopShieldHealthComp != null && entity.TroopShieldViewComp == null)
            {
                TroopTypeVO troop = Service.StaticDataController.Get <TroopTypeVO>(entity.TroopComp.TroopType.Uid);
                entity.Add <TroopShieldViewComponent>(new TroopShieldViewComponent(troop));
            }
            gameObject.SetActive(false);
            this.CheckHealthView(entity);
            this.CheckMeterShaderView(entity);
            Service.EntityRenderController.UpdateNewEntityView(entity);
        }