Exemplo n.º 1
0
    /*
     * Method to visualize the field of view in the editor
     */
    private void OnSceneGUI()
    {
        VisionSystem fov = (VisionSystem)target;

        Handles.color = Color.white;

        Handles.DrawWireArc(
            fov.fovOrigin,
            Vector3.up,
            Vector3.forward,
            360,
            fov.viewRadius
            );

        Vector3 leftViewAngle  = fov.DirectionFromAngle(-fov.viewAngle / 2, false);
        Vector3 rightViewAngle = fov.DirectionFromAngle(fov.viewAngle / 2, false);

        Handles.DrawLine(
            fov.fovOrigin,
            fov.fovOrigin + leftViewAngle * fov.viewRadius
            );
        Handles.DrawLine(
            fov.fovOrigin,
            fov.fovOrigin + rightViewAngle * fov.viewRadius
            );

        Handles.color = Color.red;
        foreach (Transform transform in fov.visibleTargets)
        {
            Handles.DrawLine(fov.fovOrigin, transform.position);
        }
    }
Exemplo n.º 2
0
 public Engine(IEntityManager entityManager, WorldSystem worldSystem, MovementSystem movementSystem,
               DrawingSystem drawingSystem, VisionSystem visionSystem, TimeTrackingSystem timeTrackingSystem)
 {
     this.entityManager      = entityManager;
     this.worldSystem        = worldSystem;
     this.movementSystem     = movementSystem;
     this.drawingSystem      = drawingSystem;
     this.visionSystem       = visionSystem;
     this.timeTrackingSystem = timeTrackingSystem;
 }
Exemplo n.º 3
0
    void Awake()
    {
        actionPoints = GetComponent <ActionPointSystem>();
        lifeSystem   = GetComponent <LifeSystem>();
        motor        = GetComponent <CharacterMotor>();
        vision       = GetComponentInChildren <VisionSystem>();
        combat       = GetComponentInChildren <CombatSystem>();

        motor.FinishedMoving  += OnFinishedMOving;
        combat.CombatFinished += OnCombatFinished;
    }
Exemplo n.º 4
0
    /*
     * Initialization method
     */
    private void Awake()
    {
        agent = GetComponent <NavMeshAgent>();
        animatorController = GetComponent <Animator>();
        visionSystem       = GetComponent <VisionSystem>();
        hearingSystem      = GetComponent <HearingSystem>();
        currentState       = EnemyState.IDLE;

        if (visionSystem != null)
        {
            StartCoroutine(visionSystem.FindTargets());
        }

        GameObject playerGameObject = GameObject.FindGameObjectWithTag("Player");

        // Ignore collisions between noise enemy collider and player body collider
        if (GetComponent <SphereCollider>() != null)
        {
            Physics.IgnoreCollision(playerGameObject.GetComponent <BoxCollider>(), GetComponent <SphereCollider>());
        }
    }
Exemplo n.º 5
0
        protected override void Initialize()
        {
            _grid = new AdjacencyGrid(_settings.WorldWidth, _settings.WorldHeight, 25);

            _renderSystem             = new RenderSystem(EntityManager, this);
            _transformHierarchySystem = new TransformHierarchySystem(EntityManager, _grid);
            _velocitySystem           = new VelocitySystem(EntityManager);

            // Declare rigidbody collision system
            _rigidbodyCollisionSystem = new SortAndSweep(EntityManager,
                                                         (e) => e.HasComponents(typeof(CircleColliderComponent), typeof(RigidBodyComponent)),
                                                         (e1, e2) => true); // All collisions should be resolved

            _mouthCollisionSystem = new SortAndSweep(EntityManager,
                                                     (e) => e.HasComponents(typeof(CircleColliderComponent)) &&
                                                     (e.HasComponents(typeof(MouthComponent)) || e.HasComponents(typeof(EdibleComponent))),
                                                     // Only resolve if 1 has a food and the other a mouth (but not both)
                                                     (e1, e2) =>
                                                     (e1.HasComponent <MouthComponent>() && e2.HasComponent <EdibleComponent>())
                                                     ^ (e2.HasComponent <MouthComponent>() && e1.HasComponent <EdibleComponent>())
                                                     );

            _weaponHealthCollisionSystem = new SortAndSweep(EntityManager,
                                                            (e) => e.HasComponents(typeof(CircleColliderComponent)) &&
                                                            (e.HasComponent <HealthComponent>() || e.HasComponent <WeaponComponent>()),
                                                            // Only resolve if 1 is a weapon and the other a health
                                                            (e1, e2) =>
                                                            (e1.HasComponent <HealthComponent>() && e2.HasComponent <WeaponComponent>())
                                                            ^ (e2.HasComponent <HealthComponent>() && e1.HasComponent <WeaponComponent>())
                                                            );

            _rigidBodySystem       = new RigidBodySystem(EntityManager);
            _dragSystem            = new DragSystem(EntityManager, _settings.MassDensity);
            _movementControlSystem = new MovementControlSystem(EntityManager);
            _brainSystem           = new BrainSystem(EntityManager, Settings);
            WorldBorderSystem      = new WorldBorderSystem(EntityManager, _worldWidth, _worldHeight);
            _visionSystem          = new VisionSystem(EntityManager, _grid);

            // These systems take a reference to a list of collisions. This means that should collision code checking change, the objects do not.
            RigidbodyCollisionSystem = new RigidBodyCollisionSystem(_rigidbodyCollisionSystem.Collisions);
            MouthFoodCollisionSystem = new MouthFoodCollisionSystem(EntityManager, _mouthCollisionSystem.Collisions);
            InfoRenderSystem         = new InfoRenderSystem(EntityManager, this);
            _noseSystem = new NoseSystem(EntityManager, _grid);

            // Global energy manager. This Ensures a closed system so there is a fixed amount of enegry in the simulation
            _energyManager = new EnergyManager(_settings.InitialWorldEnergy);

            // These are systems that take into account energy and need the energy manager system

            EnergyDeathSystem = new EnergyDeathSystem(EntityManager);
            HealthDeathSystem = new HealthDeathSystem(EntityManager, this, _energyManager);
            OldAgeDeathSystem = new OldAgeDeathSystem(EntityManager, this, _energyManager, _settings.OldAgeEnabled, _settings.OldAgeMultiplier);

            WeaponSystem = new WeaponSystem(EntityManager, _weaponHealthCollisionSystem.Collisions, _energyManager);
            _movementControlEnergyCostSystem = new MovementControlEnergyCostSystem(EntityManager, _energyManager);

            InnovationIdManager innovationIdManager = new InnovationIdManager(100, 100);

            // So textures are constantly refreshed
            _renderSystem.EditorMode = true;
        }
Exemplo n.º 6
0
 public Camera(PositionComponent position, int Width, VisionSystem visionSystem)
 {
     this.visionSystem = visionSystem;
     width             = Width;
     this.position     = position;
 }
Exemplo n.º 7
0
 public void SetVisionSystem(VisionSystem visSystem)
 {
     visionSystem = visSystem;
 }