Пример #1
0
        /// <summary>
        /// Sets the active target.
        /// </summary>
        /// <param name="_target">_target.</param>
        public void SetActiveTarget(TargetObject _target)
        {
            if (Status.IsDead)
            {
                return;
            }

            if (Move.Deadlocked)
            {
                Move.ResetDeadlock();
                if (Move.DeadlockAction == DeadlockActionType.BEHAVIOUR)
                {
                    Behaviour.SetBehaviourModeByKey(Move.DeadlockBehaviour);
                    return;
                }
                else if (Move.DeadlockAction == DeadlockActionType.UPDATE && m_ActiveTarget != null)
                {
                    m_ActiveTarget.UpdateOffset();
                }
                else
                {
                    Status.Kill();
                    return;
                }
            }


            if (_target == null || Status.RecreationRequired)
            {
                _target = Essentials.Target;
            }

            if (_target == null || !_target.IsValid)
            {
                Debug.LogError(m_Owner.name + " have no target!");
                return;
            }

            if (IsTargetUpdatePermitted(_target))
            {
                if (m_ActiveTarget != _target)
                {
                    m_PreviousTarget = m_ActiveTarget;

                    if (m_PreviousTarget != null)
                    {
                        m_PreviousTarget.SetActive(false);
                    }

                    m_ActiveTarget = _target;

                    if (m_ActiveTarget != null)
                    {
                        m_ActiveTarget.SetActive(true);
                    }

                    m_TargetChanged = true;
                }

                if (m_ActiveTarget != null)
                {
                    Behaviour.SetBehaviourModeByKey(ActiveTarget.BehaviourModeKey);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Draws the interaction.
        /// </summary>
        public void DrawInteraction()
        {
            if (CreatureControl.Creature.Interaction.Interactors.Count == 0 || ShowInteractor == false)
            {
                return;
            }

            for (int i = 0; i < CreatureControl.Creature.Interaction.Interactors.Count; i++)
            {
                InteractorObject _interactor = CreatureControl.Creature.Interaction.Interactors[i];

                if (!_interactor.Enabled)
                {
                    continue;
                }

                List <GameObject> _target_game_objects = GetCreaturesByName(_interactor.Name);

                if (_target_game_objects != null && _target_game_objects.Count > 0)
                {
                    foreach (GameObject _target_game_object in _target_game_objects)
                    {
                        Vector3 _interactor_pos = _target_game_object.transform.position;

                        TargetObject _target = new TargetObject(TargetType.INTERACTOR);

                        _target.TargetGameObject = _target_game_object;
                        _target.BehaviourModeKey = _interactor.BehaviourModeKey;
                        _target.Selectors.Copy(_interactor.Selectors);
                        _target.UpdateOffset(_interactor.DefaultOffset);
                        _target.TargetStopDistance          = _interactor.DefaultStopDistance;
                        _target.TargetRandomRange           = _interactor.DefaultRandomRange;
                        _target.TargetSmoothingMultiplier   = 0;                      //_interactor.DefaultSmoothingMultiplier; // TODO:REWORK TargetSmoothingMultiplier
                        _target.TargetIgnoreLevelDifference = _interactor.DefaultIgnoreLevelDifference;

                        DrawTargetGizmos(_target);

                        // DIRECTION
                        CustomGizmos.Arrow(_target.TargetPosition, _target.TargetDirection * _target.TargetStopDistance, 0.5f, 20);

                        Vector3 _last_move_position = _target.TargetMovePosition;
                        float   _last_stop_distance = _target.TargetStopDistance;

                        _last_move_position.y = GetLevel();

                        Color _default_color = Gizmos.color;
                        Color _target_color  = (_target.Active?ActiveTargetColor:TargetColor);

                        foreach (InteractorRuleObject _rule in _interactor.Rules)
                        {
                            if (!_rule.Enabled)
                            {
                                continue;
                            }

                            _target = new TargetObject(TargetType.INTERACTOR);

                            _target.TargetGameObject = _target_game_object;
                            _target.BehaviourModeKey = _rule.BehaviourModeKey;
                            _target.Selectors.Copy(_rule.Selectors);

                            _target.UpdateOffset(_interactor.DefaultOffset);
                            _target.TargetStopDistance          = _interactor.DefaultStopDistance;
                            _target.TargetRandomRange           = _interactor.DefaultRandomRange;
                            _target.TargetSmoothingMultiplier   = 0;                          //_interactor.DefaultSmoothingMultiplier; // TODO:REWORK TargetSmoothingMultiplier
                            _target.TargetIgnoreLevelDifference = _interactor.DefaultIgnoreLevelDifference;

                            if (_rule.OverrideTargetMovePosition)
                            {
                                _target.UpdateOffset(_rule.Offset);
                                _target.TargetStopDistance          = _rule.StopDistance;
                                _target.TargetRandomRange           = _rule.RandomRange;
                                _target.TargetSmoothingMultiplier   = 0;
                                _target.TargetIgnoreLevelDifference = _rule.IgnoreLevelDifference;
                            }

                            DrawTargetGizmos(_target);

                            Vector3 _move_position = _target.TargetMovePosition;
                            _move_position.y = GetLevel();

                            Gizmos.color = _target_color;
                            if (_last_move_position != Vector3.zero)
                            {
                                CustomGizmos.OffsetPath(_last_move_position, _last_stop_distance, _move_position, _target.TargetStopDistance, true);
                            }

                            _last_stop_distance = _target.TargetStopDistance;
                            _last_move_position = _move_position;
                        }

                        Gizmos.color = _target_color;
                        if (_last_move_position != Vector3.zero)
                        {
                            CustomGizmos.OffsetPath(_last_move_position, _last_stop_distance, _interactor_pos, 0, false);
                        }

                        Gizmos.color = _default_color;
                        //CustomGizmos.OffsetPath( _default_data.OffsetPosition, _default_data.StopDistance, _interactor_pos, 0 );
                    }
                }
            }
        }