コード例 #1
0
                /*
                 * private CreatureObject m_Creature = null;
                 * protected CreatureObject GetCreature()
                 * {
                 *      if( m_Creature == null )
                 *              m_Creature = m_Owner.GetComponent<ICECreatureControl>().Creature;
                 *
                 *      return m_Creature;
                 * }*/

                public TargetObject PrepareTarget(GameObject _owner, CreatureObject _creature)
                {
                    if (TargetReady() == false || _owner == null || _creature == null || _creature.Behaviour == null)
                    {
                        return(null);
                    }

                    // if the active target is not a OUTPOST or if the creature outside the max range it have to travel to reach its target
                    //if( _creature.ActiveTarget == null || _creature.ActiveTarget.Type != TargetType.OUTPOST || ! Target.TargetInMaxRange( _owner.transform.position ))
                    if (!Target.TargetInMaxRange(_owner.transform.position))
                    {
                        Target.BehaviourModeKey = BehaviourModeTravel;
                    }

                    // if the creature reached the TargetMovePosition it should do the rendezvous behaviour
                    else if (Target.TargetMoveComplete)
                    {
                        Target.BehaviourModeKey = BehaviourModeRendezvous;
                    }

                    // in all other case the creature should be standby and do some leisure activities
                    else if (Target.TargetRandomRange > 0)
                    {
                        Target.BehaviourModeKey = BehaviourModeLeisure;
                    }

                    return(Target);
                }
コード例 #2
0
        public TargetObject PrepareTarget(ICEWorldBehaviour _component, CreatureObject _creature)
        {
            if (!Enabled || !OwnerIsReady(_component) || _creature == null || Target.PrepareTargetGameObject(_component) == null || !Target.IsValidAndReady)
            {
                return(null);
            }

            Target.Behaviour.SetDefault();

            // if the creature has reached the target move position and the target doesn't move the creature should be standby or idle
            if (Target.TargetMoveComplete && Target.TargetVelocity == Vector3.zero)
            {
                if (Target.Behaviour.CurrentBehaviourModeKey == BehaviourModeStandby && _creature.Behaviour.BehaviourTimer > DurationStandby)
                {
                    Target.Behaviour.CurrentBehaviourModeKey = BehaviourModeIdle;
                }

                else if (Target.Behaviour.CurrentBehaviourModeKey != BehaviourModeIdle)
                {
                    Target.Behaviour.CurrentBehaviourModeKey = BehaviourModeStandby;
                }
            }

            else if (!Target.TargetInMaxRange(Owner.transform.position))
            {
                Target.Behaviour.CurrentBehaviourModeKey = BehaviourModeFollow;
            }

            else
            {
                Target.Behaviour.CurrentBehaviourModeKey = BehaviourModeEscort;
            }

            /*
             * else if ( Target.TargetMoveComplete && Target.TargetVelocity > 0 )
             *      Target.BehaviourModeKey = BehaviourModeEscort;
             *
             * else if( Target.TargetVelocity > 0 || _creature.Behaviour.BehaviourModeKey != BehaviourModeIdle )
             *      Target.BehaviourModeKey = BehaviourModeFollow;
             */
            return(Target);
        }
コード例 #3
0
                public TargetObject PrepareTarget(GameObject _owner, CreatureObject _creature)
                {
                    if (TargetReady() == false || _owner == null || _creature == null || _creature.Behaviour == null)
                    {
                        return(null);
                    }

                    // if the creature has reached the target move position and the target doesn't move the creature should be standby or idle
                    if (Target.TargetMoveComplete && Target.TargetVelocity == 0)
                    {
                        if (Target.BehaviourModeKey == BehaviourModeStandby && _creature.Behaviour.BehaviourTimer > DurationStandby)
                        {
                            Target.BehaviourModeKey = BehaviourModeIdle;
                        }

                        else if (Target.BehaviourModeKey != BehaviourModeIdle)
                        {
                            Target.BehaviourModeKey = BehaviourModeStandby;
                        }
                    }

                    else if (!Target.TargetInMaxRange(_owner.transform.position))
                    {
                        Target.BehaviourModeKey = BehaviourModeFollow;
                    }

                    else
                    {
                        Target.BehaviourModeKey = BehaviourModeEscort;
                    }

                    /*
                     * else if ( Target.TargetMoveComplete && Target.TargetVelocity > 0 )
                     *      Target.BehaviourModeKey = BehaviourModeEscort;
                     *
                     * else if( Target.TargetVelocity > 0 || _creature.Behaviour.BehaviourModeKey != BehaviourModeIdle )
                     *      Target.BehaviourModeKey = BehaviourModeFollow;
                     */
                    return(Target);
                }
コード例 #4
0
        /// <summary>
        /// Update surface handling.
        /// </summary>
        public void Update(CreatureObject _creature)
        {
            if (Enabled == false || _creature == null || _creature.Move.IsGrounded == false)
            {
                return;
            }

            Vector3 _velocity = _creature.Move.DesiredVelocity;

            if (_creature.Behaviour.ActiveBehaviourMode != null && _creature.Behaviour.ActiveBehaviourMode.Rule != null)
            {
                _velocity = _creature.Behaviour.ActiveBehaviourMode.Rule.Move.Motion.Velocity;
            }


            // Update Ground Texture Name - only required while creature is moving or texture name is empty
            if (_velocity.z > 0 || m_ActiveTextureName == "")
            {
                string _detected_texture_name = m_ActiveTextureName;

                m_GroundScanIntervalTimer += Time.deltaTime;
                if (m_GroundScanIntervalTimer >= GroundScanInterval)
                {
                    m_GroundScanIntervalTimer = 0;
                    _detected_texture_name    = _creature.Move.UpdateGroundTextureName();
                }

                if (_detected_texture_name != m_ActiveTextureName)
                {
                    m_ActiveTextureName = _detected_texture_name;

                    SurfaceDataObject _best_surface = null;
                    foreach (SurfaceDataObject _surface in Surfaces)
                    {
                        foreach (TextureDataObject _texture in _surface.Textures)
                        {
                            if (_texture != null && _texture.Image != null && _texture.Image.name == m_ActiveTextureName)
                            {
                                _best_surface = _surface;
                                break;
                            }
                        }
                    }

                    if (_best_surface != null)
                    {
                        if (m_ActiveSurface != _best_surface)
                        {
                            if (m_ActiveSurface != null)
                            {
                                m_ActiveSurface.Effect.Stop();
                            }

                            m_ActiveSurface = _best_surface;
                            m_ActiveSurface.Effect.Start(OwnerComponent);

                            AudioPlayer.Play(m_ActiveSurface.Audio);
                            FootstepPlayer.SetData(m_ActiveSurface.Footsteps);
                        }
                    }
                    else
                    {
                        if (m_ActiveSurface != null)
                        {
                            m_ActiveSurface.Effect.Stop();
                        }

                        m_ActiveSurface = null;

                        FootstepPlayer.SetData(null);
                        AudioPlayer.Stop();
                    }
                }
            }

            if (_velocity.z == 0)
            {
                AudioPlayer.Stop();
            }
            else
            {
                AudioPlayer.Update();
                FootstepPlayer.Update(_velocity.z);
            }
        }
コード例 #5
0
                /// <summary>
                /// Prepares a waypoint target.
                /// </summary>
                /// <returns>a waypoint target as potential target candidate</returns>
                /// <description>The UpdateTarget methods only prepares and/or preselect their targets to provide a potential
                /// target candidates for the final selection.
                /// </description>
                public TargetObject PrepareTarget(GameObject _owner, CreatureObject _creature)
                {
                    if (TargetReady() == false || _owner == null || _creature == null || _creature.Behaviour == null)
                    {
                        return(null);
                    }

                    // as long as the creature is inside the max range, the duration of stay will measured, otherwise the timer will adjusted to zero.
                    if (Target.TargetInMaxRange(_owner.transform.position))
                    {
                        if (m_DurationOfStayUpdateTime > 0)
                        {
                            m_DurationOfStayTimer += Time.time - m_DurationOfStayUpdateTime;
                        }

                        m_DurationOfStayUpdateTime = Time.time;
                    }
                    else
                    {
                        m_DurationOfStayUpdateTime = 0;
                        m_DurationOfStayTimer      = 0;
                    }

                    // if the active target is not a WAYPOINT we have to find the nearest waypoint and set the travel bahaviour
                    if (_creature.ActiveTarget == null || _creature.ActiveTarget.Type != TargetType.WAYPOINT)
                    {
                        // btw. GetWaypointByPosition() changes the target, so GetBehaviourModeTravel() returns the behaviour of the new waypoint,
                        // which means, that the travel behavour always specifies the approach and not the departure.
                        Waypoints.GetWaypointByPosition(_owner.transform.position);
                        Target.BehaviourModeKey = GetBehaviourModeTravel();
                    }

                    // our creature have reached the max range of the given target waypoint - the max range is the random range plus target stop distance,
                    // or if the random range is zero just the target stop distance.
                    else if (Target.TargetMoveComplete)
                    {
                        if (GetIsTransitPoint() || GetDesiredDurationOfStay() == 0 || m_DurationOfStayTimer >= GetDesiredDurationOfStay())
                        {
                            // btw. GetNextWaypoint() changes the target, so GetBehaviourModePatrol() returns the behaviour of the new waypoint,
                            // which means, that a patrol behavour always specifies the approach and not the departure.
                            Waypoints.GetNextWaypoint();
                            Target.BehaviourModeKey = GetBehaviourModePatrol();
                        }
                        else
                        {
                            Target.BehaviourModeKey = GetBehaviourModeRendezvous();
                        }
                    }
                    else if (!GetIsTransitPoint() && Target.TargetInMaxRange(_owner.transform.position))
                    {
                        Target.BehaviourModeKey = GetBehaviourModeLeisure();
                    }
                    else
                    {
                        // before our creature can start with the patrol behaviour, it has to reach the first waypoint, so we check the
                        // previous target and if this is null or not a waypoint our creature is still travelling to the nearest waypoint
                        // which we have found in the first rule.
                        if (_creature.PreviousTarget != null && _creature.PreviousTarget.Type != TargetType.WAYPOINT)
                        {
                            Target.BehaviourModeKey = GetBehaviourModeTravel();
                        }

                        // now it looks that our creature is on the way between two waypoints and so it should use the patrol behaviour
                        else
                        {
                            Target.BehaviourModeKey = GetBehaviourModePatrol();
                        }
                    }

/*
 *                                      if( _creature.Move.CurrentTarget == Target && _creature.Move.HasDetour && _creature.Move.DetourPositionReached( _owner.transform.position ) )
 *                                      {
 *                                      }*/

                    return(Target);
                }