Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        private void OnDelayedLoad(uint id, object cookie)
        {
            this.numShipsScheduled--;
            SpecialAttack specialAttack = cookie as SpecialAttack;

            if (specialAttack == null)
            {
                return;
            }
            string            assetName      = specialAttack.VO.AssetName;
            WorldPreloadAsset preloadedAsset = Service.WorldPreloader.GetPreloadedAsset(assetName);

            if (preloadedAsset == null)
            {
                Service.AssetManager.Load(ref specialAttack.Handle, assetName, new AssetSuccessDelegate(this.OnAssetSuccess), null, specialAttack);
            }
            else
            {
                specialAttack.Handle = preloadedAsset.Handle;
                if (preloadedAsset.GameObj != null)
                {
                    this.OnAssetSuccess(preloadedAsset.GameObj, specialAttack);
                }
            }
            uint num = specialAttack.VO.AnimationDelay;

            if (specialAttack.VO.IsDropship || specialAttack.VO.HasDropoff)
            {
                this.numHoveringInbound++;
                this.EnsureShadowAnimator(specialAttack, null);
                specialAttack.ShadowAnimator.PlayShadowAnim(true);
                Service.ViewTimerManager.CreateViewTimer(3f, false, new TimerDelegate(this.OnDropshipLandedTimer), specialAttack);
                Service.ViewTimerManager.CreateViewTimer(3u * num, false, new TimerDelegate(this.UnregisterShadowAnimator), specialAttack.ShadowAnimator);
            }
            if (specialAttack.VO.IsDropship)
            {
                this.simTimers.Add(Service.SimTimerManager.CreateSimTimer(num, false, new TimerDelegate(this.OnSpawnDropshipTroopsTimer), specialAttack));
            }
            else
            {
                uint shotCount = specialAttack.VO.ShotCount;
                int  num2      = 0;
                while ((long)num2 < (long)((ulong)shotCount))
                {
                    this.simTimers.Add(Service.SimTimerManager.CreateSimTimer(num, false, new TimerDelegate(this.SpawnProjectile), specialAttack));
                    this.numAttackScheduled++;
                    num += specialAttack.VO.ShotDelay;
                    num2++;
                }
            }
            this.viewTimers.Add(Service.ViewTimerManager.CreateViewTimer(specialAttack.VO.DestroyDelay, false, new TimerDelegate(this.DestroyFromCookie), specialAttack));
        }