Esempio n. 1
0
        public void RotateGameObject(SmartEntity entity, float dx, float dz, float dt)
        {
            GameObjectViewComponent gameObjectViewComp = entity.GameObjectViewComp;
            TransformComponent      transformComp      = entity.TransformComp;

            if (entity.TroopComp != null && entity.TroopComp.TroopShooterVO.TargetSelf && transformComp.RotationInitialized)
            {
                return;
            }
            float                     num                     = transformComp.Rotation;
            bool                      flag                    = dx != 0f || dz != 0f;
            SmartEntity               smartEntity             = null;
            GameObjectViewComponent   gameObjectViewComponent = null;
            SecondaryTargetsComponent secondaryTargetsComp    = entity.SecondaryTargetsComp;
            ShooterComponent          shooterComp             = entity.ShooterComp;

            if (secondaryTargetsComp != null && shooterComp != null)
            {
                ShooterController shooterController = Service.Get <ShooterController>();
                smartEntity = shooterController.GetTroopTarget(secondaryTargetsComp, shooterComp);
                if (smartEntity != null && (gameObjectViewComponent = smartEntity.GameObjectViewComp) == null)
                {
                    smartEntity = shooterController.GetPrimaryTarget(shooterComp);
                    if (smartEntity != null)
                    {
                        gameObjectViewComponent = smartEntity.GameObjectViewComp;
                    }
                }
            }
            else
            {
                PathingComponent pathingComp = entity.PathingComp;
                if (pathingComp != null)
                {
                    smartEntity = pathingComp.Target;
                    if (smartEntity != null)
                    {
                        gameObjectViewComponent = smartEntity.GameObjectViewComp;
                    }
                }
            }
            bool flag2 = !transformComp.RotationInitialized;

            if (flag2 && smartEntity == null && (entity.DefenderComp != null || TroopController.IsEntityHealer(entity)))
            {
                gameObjectViewComp.MainGameObject.SetActive(true);
                transformComp.RotationInitialized = true;
            }
            else
            {
                bool flag3 = flag2 || entity.StateComp.CurState == EntityState.Attacking || entity.StateComp.CurState == EntityState.Turning;
                if (flag3 && gameObjectViewComponent != null)
                {
                    gameObjectViewComp.ComputeRotationToTarget(gameObjectViewComponent, ref num);
                    flag = false;
                    if (flag2)
                    {
                        gameObjectViewComp.MainGameObject.SetActive(true);
                        transformComp.Rotation            = num;
                        transformComp.RotationInitialized = true;
                    }
                }
            }
            if (flag)
            {
                num = Mathf.Atan2(dz, dx);
            }
            num = MathUtils.MinAngle(transformComp.Rotation, num);
            float num2       = (float)entity.WalkerComp.SpeedVO.RotationSpeed / 1000f;
            float smoothTime = 0.7853982f / num2;
            float num3       = (dt == 0f) ? transformComp.Rotation : Mathf.SmoothDampAngle(transformComp.Rotation, num, ref transformComp.RotationVelocity, smoothTime, num2, dt);

            num3 = MathUtils.WrapAngle(num3);
            gameObjectViewComp.Rotate(num3 + -1.57079637f);
            transformComp.Rotation = num3;
        }