public void Cleanup() { if (this.loadedAssets) { if (this.effectObj != null) { UnityEngine.Object.Destroy(this.effectObj); } UnityUtils.DestroyMaterial(this.troopCardMaterial); AssetManager assetManager = Service.Get <AssetManager>(); if (this.effectHandle != AssetHandle.Invalid) { assetManager.Unload(this.effectHandle); this.effectHandle = AssetHandle.Invalid; } if (this.troopHandle != AssetHandle.Invalid) { assetManager.Unload(this.troopHandle); this.troopHandle = AssetHandle.Invalid; } } if (this.shuttle == null) { Service.Get <EventManager>().UnregisterObserver(this, EventId.ShuttleAnimStateChanged); } else { this.shuttle = null; } if (this.timerId != 0u) { Service.Get <ViewTimerManager>().KillViewTimer(this.timerId); } else { this.timerId = 0u; } if (this.animPosition != null) { Service.Get <AnimController>().CompleteAndRemoveAnim(this.animPosition); } this.troopVO = null; this.troopEntity = null; this.starportEntity = null; this.entityFader = null; this.onFinished = null; this.effectObj = null; this.troopCardPS = null; this.shuttleGlowPS = null; this.troopCardTexture = null; this.troopCardMaterial = null; this.animPosition = null; this.showFullEffect = false; this.pathReached = false; Service.Get <EventManager>().UnregisterObserver(this, EventId.TroopViewReady); Service.Get <EventManager>().UnregisterObserver(this, EventId.BuildingMovedOnBoard); Service.Get <EventManager>().UnregisterObserver(this, EventId.BuildingReplaced); }
private void TryShowEffect() { if (this.troopEntity == null) { Service.Get <StaRTSLogger>().Error("TryShowEffect with Null troopEntity"); return; } bool flag = !this.showFullEffect || (this.troopCardTexture != null && this.effectObj != null && this.effectObj.transform != null); if (!this.ShuttleReadyForShowEffect()) { this.shuttle = Service.Get <ShuttleController>().GetShuttleForStarport(this.starportEntity); } if (!flag || !this.pathReached || !this.ShuttleReadyForShowEffect()) { if (!this.ShuttleReadyForShowEffect()) { Service.Get <EventManager>().RegisterObserver(this, EventId.ShuttleAnimStateChanged, EventPriority.Default); } return; } GameObjectViewComponent gameObjectViewComponent = this.troopEntity.Get <GameObjectViewComponent>(); if (gameObjectViewComponent == null) { Service.Get <EventManager>().RegisterObserver(this, EventId.TroopViewReady, EventPriority.Default); return; } Service.Get <EventManager>().SendEvent(EventId.TroopLoadingIntoStarport, this.troopEntity); if (this.entityFader == null || gameObjectViewComponent.MainGameObject == null) { this.Finish(); return; } Vector3 position = this.shuttle.CenterOfMass.transform.position; this.animPosition = new AnimPosition(gameObjectViewComponent.MainGameObject, 0.8f, position); Service.Get <AnimController>().Animate(this.animPosition); this.entityFader.FadeOut(this.troopEntity, 0f, 0.3f, null, new FadingDelegate(this.OnFadeOutComplete)); AssetMeshDataMonoBehaviour component = gameObjectViewComponent.MainGameObject.GetComponent <AssetMeshDataMonoBehaviour>(); if (component != null && component.ShadowGameObject != null) { component.ShadowGameObject.SetActive(false); } this.timerId = Service.Get <ViewTimerManager>().CreateViewTimer(2f, false, new TimerDelegate(this.OnEffectTimer), null); if (this.showFullEffect) { this.effectObj.SetActive(true); position.y = 1.2f; this.effectObj.transform.position = position; this.troopCardMaterial = UnityUtils.EnsureMaterialCopy(this.troopCardPS.GetComponent <Renderer>()); this.troopCardMaterial.mainTexture = this.troopCardTexture; this.troopCardPS.Play(); this.shuttleGlowPS.Play(); this.shuttle.PulseOutline(); } }
private void OnFadeOutComplete(object fadedObject) { Entity entity = (Entity)fadedObject; if (this.animPosition != null) { Service.Get <AnimController>().CompleteAndRemoveAnim(this.animPosition); this.animPosition = null; } Service.Get <EntityFactory>().DestroyEntity(entity, true, false); }
private void SetupAnimation() { if (!SpatialUnderstandingManager.Instance.AllowSpatialUnderstanding) { return; } // Calculate the forward distance for the animation start point Vector3 rayPos = CameraCache.Main.transform.position; Vector3 rayVec = CameraCache.Main.transform.forward * InitialPositionForwardMaxDistance; IntPtr raycastResultPtr = SpatialUnderstandingManager.Instance.UnderstandingDLL.GetStaticRaycastResultPtr(); SpatialUnderstandingDll.Imports.PlayspaceRaycast( rayPos.x, rayPos.y, rayPos.z, rayVec.x, rayVec.y, rayVec.z, raycastResultPtr); SpatialUnderstandingDll.Imports.RaycastResult rayCastResult = SpatialUnderstandingManager.Instance.UnderstandingDLL.GetStaticRaycastResult(); Vector3 animOrigin = (rayCastResult.SurfaceType != SpatialUnderstandingDll.Imports.RaycastResult.SurfaceTypes.Invalid) ? rayPos + rayVec.normalized * Mathf.Max((rayCastResult.IntersectPoint - rayPos).magnitude - 0.3f, 0.0f) : rayPos + rayVec * InitialPositionForwardMaxDistance; // Create the animation (starting it on the ground in front of the camera SpatialUnderstandingDll.Imports.QueryPlayspaceAlignment(SpatialUnderstandingManager.Instance.UnderstandingDLL.GetStaticPlayspaceAlignmentPtr()); SpatialUnderstandingDll.Imports.PlayspaceAlignment alignment = SpatialUnderstandingManager.Instance.UnderstandingDLL.GetStaticPlayspaceAlignment(); AnimPosition.AddKey(TimeDelay + 0.0f, new Vector3(animOrigin.x, alignment.FloorYValue, animOrigin.z)); AnimPosition.AddKey(TimeDelay + AnimationTime * 0.5f, new Vector3(animOrigin.x, alignment.FloorYValue + 1.25f, animOrigin.z)); AnimPosition.AddKey(TimeDelay + AnimationTime * 0.6f, new Vector3(animOrigin.x, alignment.FloorYValue + 1.0f, animOrigin.z)); AnimPosition.AddKey(TimeDelay + AnimationTime * 0.95f, Center); AnimPosition.AddKey(TimeDelay + AnimationTime * 1.0f, Center); AnimScale.AddKey(TimeDelay + 0.0f, 0.0f); AnimScale.AddKey(TimeDelay + AnimationTime * 0.5f, 0.5f); AnimScale.AddKey(TimeDelay + AnimationTime * 0.8f, 1.0f); AnimScale.AddKey(TimeDelay + AnimationTime * 1.0f, 1.0f); AnimRotation.AddKey(TimeDelay + 0.0f, -1.5f); AnimRotation.AddKey(TimeDelay + AnimationTime * 0.2f, -0.5f); AnimRotation.AddKey(TimeDelay + AnimationTime * 0.9f, 0.0f); AnimRotation.AddKey(TimeDelay + AnimationTime * 1.0f, 0.0f); IsAnimationSetup = true; }