protected override IEnumerator SurveyRoutine(Context context, List <GameAction.ParameterData> result, System.Action complete, System.Action cancel)
    {
        //Setup
        _trajectoryDisplay = TrajectoryDisplaySystem.Instance.CreateTrajectory();

        _weaponPreview.SetActive(false);

        _shootAimingState = ShootAimingState.SelectingDirection;

        _vectorDesc = context.GetQueryParam <GameActionParameterVector.Description>();
        if (_vectorDesc.UsePreviousParameterOriginLocation && context.CurrentData.Count > 0)
        {
            // could fetch all previous to find a valid one
            if (context.CurrentData[context.CurrentData.Count - 1] is GameActionParameterPosition.Data posData)
            {
                transform.position = posData.Position.ToUnityVec();
            }
            else if (context.CurrentData[context.CurrentData.Count - 1] is GameActionParameterEntity.Data entityData)
            {
                _originEntity = entityData.Entity;
                if (SimWorld.TryGetComponent(_originEntity, out FixTranslation fixTranslation))
                {
                    transform.position = fixTranslation.Value.ToUnityVec();
                }
            }
        }

        while (_shootAimingState != ShootAimingState.Aiming)
        {
            UpdateDirection();

            if (Input.GetKeyDown(KeyCode.Mouse0))
            {
                _shootAimingState = ShootAimingState.Aiming;
            }

            yield return(null);
        }

        _weaponPreview.SetActive(true);
        SetupAimingRotationAnimation();

        while (_shootAimingState != ShootAimingState.Shoot)
        {
            if (Input.GetKeyDown(KeyCode.Mouse0))
            {
                _rotatingAnimation.Kill();
                _shootAimingState = ShootAimingState.Shoot;
            }

            yield return(null);
        }

        Vector2 _finalVector = ViewToSimVector((_line.position - transform.position) * 2);

        result.Add(new GameActionParameterVector.Data((fix2)_finalVector));

        complete();
    }
Ejemplo n.º 2
0
    protected override IEnumerator SurveyRoutine(Context context, List <GameAction.ParameterData> result, System.Action complete, System.Action cancel)
    {
        _trajectoryDisplay = TrajectoryDisplaySystem.Instance.CreateTrajectory();
        _vectorDesc        = context.GetQueryParam <GameActionParameterVector.Description>();

        if (_vectorDesc.UsePreviousParameterOriginLocation && context.CurrentData.Count > 0)
        {
            // could fetch all previous to find a valid one
            if (context.CurrentData[context.CurrentData.Count - 1] is GameActionParameterPosition.Data posData)
            {
                transform.position = posData.Position.ToUnityVec();
            }
            else if (context.CurrentData[context.CurrentData.Count - 1] is GameActionParameterEntity.Data entityData)
            {
                _originEntity = entityData.Entity;
                if (SimWorld.TryGetComponent(_originEntity, out FixTranslation fixTranslation))
                {
                    transform.position = fixTranslation.Value.ToUnityVec();
                }
            }
        }

        Update(); // force first update to avoid visual issue on first frame. We should find a more general fix

        // wait for drag to start
        while (_dragState != DragState.Releasing)
        {
            yield return(null);
        }

        // wait for release anim to be complete
        while (!Mathf.Approximately(_dragTarget.position.x, _center.position.x) || !Mathf.Approximately(_dragTarget.position.y, _center.position.y))
        {
            yield return(null);
        }

        // submit drag vector
        result.Add(new GameActionParameterVector.Data((fix2)_releaseVector));

        complete();
    }
Ejemplo n.º 3
0
    protected override IEnumerator SurveyRoutine(Context context, List <GameAction.ParameterData> result, System.Action complete, System.Action cancel)
    {
        var desc = context.GetQueryParam <GameActionParameterVector.Description>();

        if (_useSpaceInputInsted)
        {
            _state             = State.PollingStrength;
            _trajectoryDisplay = TrajectoryDisplaySystem.Instance.CreateTrajectory();
            _strength          = (float)desc.SpeedMin;

            bool _reverseStrength = false;
            while (Input.GetKey(KeyCode.Space))
            {
                _dir = (Cache.PointerWorldPosition - (Vector2)_transform.position).normalized;

                if (_reverseStrength)
                {
                    _strength = Mathf.MoveTowards(_strength, (float)desc.SpeedMin, _growSpeed * Time.deltaTime);
                }
                else
                {
                    _strength = Mathf.MoveTowards(_strength, (float)desc.SpeedMax, _growSpeed * Time.deltaTime);
                }

                if (_strength >= (float)desc.SpeedMax)
                {
                    _reverseStrength = true;
                }

                if (_strength <= (float)desc.SpeedMin)
                {
                    _reverseStrength = false;
                }

                yield return(null);
            }

            _state = State.Released;

            Vector2 resultVector = _dir * _strength;

            result.Add(new GameActionParameterVector.Data((fix2)resultVector));
            complete();
            yield break;
        }
        else
        {
            // Poll angle
            _state = State.PollingDirection;
            while (!Input.GetMouseButtonDown(0))
            {
                _dir = (Cache.PointerWorldPosition - (Vector2)_transform.position).normalized;
                yield return(null);
            }

            _trajectoryDisplay = TrajectoryDisplaySystem.Instance.CreateTrajectory();

            // Poll strength
            _state    = State.PollingStrength;
            _strength = (float)desc.SpeedMin; // start at minimum
            while (Input.GetMouseButton(0))
            {
                _strength = Mathf.MoveTowards(_strength, (float)desc.SpeedMax, _growSpeed * Time.deltaTime);
                yield return(null);
            }

            _state = State.Released;

            Vector2 resultVector = _dir * _strength;

            result.Add(new GameActionParameterVector.Data((fix2)resultVector));
            complete();
            yield break;
        }
    }