Beispiel #1
0
    void Start()
    {
        animator = GetComponent <Animator>();
        if (isBarricade)
        {
            return;
        }
        unitAttack = GetComponent <UnitAttack>();
        unitMover  = GetComponent <UnitMover>();


        FindNewEnemy(true);
        Rigidbody rb = gameObject.AddComponent <Rigidbody>();

        rb.mass        = 10;
        rb.constraints = RigidbodyConstraints.FreezeRotation;
        SetTeamColor();
        ragdollControl = GetComponent <RagdollConfig>().Init();
        torso          = transform.Find("Man:Hips/Man:Torso");
        rightHand      = torso.Find("Man:RightUpperArm/Man:RightLowerArm/Man:Attach_RightHand");
        leftHand       = torso.Find("Man:LeftUpperArm/Man:LeftLowerArm/Man:Attach_LeftHand");

        if (isWaiting)
        {
            rb.isKinematic = true;
        }
    }
    // do the move computation
    public override void ProcessUpdate(UnitMover unitMover)
    {
        Vector3 flockCenter       = ComputeFlockCenter(allyPositions.Values);
        float   distToFlockCenter = Vector3.Distance(flockCenter, this.transform.position);

        if (distToFlockCenter <= SeperationRadius) // to close spread out
        {
            Vector3 seperation    = ComputeSeperation(allyPositions.Values);
            Vector3 resultingMove = seperation;
            resultingMove.Normalize();
            unitMover.Move(resultingMove);
        }
        else if (distToFlockCenter <= DesiredRadiusToPlayer) // just right hang out
        {
            unitMover.Move(Vector3.zero);
        }
        else // flock
        {
            Vector3 allignment = ComputeAlignment(allyPositions.Values);
            Vector3 cohesion   = ComputeCohesion(allyPositions.Values);
            Vector3 seperation = ComputeSeperation(allyPositions.Values);

            Vector3 resultingMove = (allignment * allignmentPercent) + (cohesion * cohesionPercent) + (seperation * seperationPercent);
            resultingMove.Normalize();

            unitMover.Move(resultingMove);
        }
    }
Beispiel #3
0
    public override void ProcessUpdate(UnitMover unitMover)
    {
        Vector3 dir = beelineTarget.transform.position - this.transform.position;

        dir.Normalize();
        unitMover.Move(dir);
    }
Beispiel #4
0
        /// <summary>
        /// Initializes the object.
        /// </summary>
        public virtual void Init()
        {
            // Initializes the weapon
            Weapon = GetComponentInChildren <Weapon>();
            if (Weapon != null)
            {
                Weapon.Init(this);
            }

            // Initializes moving
            mover = gameObject.GetOrAddComponent <UnitMover>();
            mover.Init(moveSpeed, turnSpeed);

            // Initializes health
            Health = new Health(this, startingHealth);

            // Registers to listen to the UnitDied event
            Health.UnitDied += OnUnitDied;

            // Sets spawn position and rotation
            _defaultPosition = transform.position;
            _startRotation   = transform.rotation;

            if (unitBody == null)
            {
                Debug.LogError("Unit model is not set.");
            }
        }
Beispiel #5
0
 void Start()
 {
     anim     = GetComponent <Animator>();
     mover    = GetComponent <UnitMover>();
     myHealth = GetComponent <PlayerHealth>();
     myWeapon = GetComponent <PlayerWeapon>();
 }
Beispiel #6
0
        public Form1(
            IAxisFactory axisFactory,
            IMazeViewDataFactory mazeViewDataFactory,
            MazeNodeDataBuilder mazeNodeDataBuilder,
            IVisualizer visualizer,
            UnitMover unitMover,
            Maze maze,
            Keybindings keybindings)
        {
            _maze                = maze;
            _unitMover           = unitMover;
            _visualizer          = visualizer;
            _mazeNodeDataBuilder = mazeNodeDataBuilder;
            _keybindings         = keybindings;

            InitializeComponent();
            InitializeMaze(axisFactory, mazeViewDataFactory);
            InitializeKeybindings(axisFactory);

            DoubleBuffered = true;

            fAnimator = new Timer()
            {
                Interval = 500,
            };
            fAnimator.Tick += FAnimator_Tick1;
            fAnimator.Start();
        }
Beispiel #7
0
 void UnitsMoveToPosition(Vector3 movePos, Unit[] units)
 {
     Vector3[] destinations = UnitMover.GetUnitGroupDestinations(movePos, units.Length, 2);
     for (int i = 0; i < units.Length; i++)
     {
         units[i].MoveToPosition(destinations[i]);
     }
 }
Beispiel #8
0
 override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
 {
     if (!unitMover)
     {
         unitMover = animator.GetComponent <UnitMover>();
     }
     unitMover.IsMoving = true;
 }
Beispiel #9
0
 void UnitsMoveToPosition(Vector3 movePosition, Unit[] units)
 {
     Vector3[] destinations = UnitMover.GetUnitGroupDestinations(movePosition, units.Length, 2);
     for (int x = 0; x < units.Length; x++)
     {
         units[x].MoveToPosition(destinations[x]);
     }
 }
Beispiel #10
0
    public void Init()
    {
        gameManager   = GameManager.Instance;
        cameraControl = gameManager.CameraControl;

        gameObject.tag   = "Unit";
        gameObject.layer = LayerMask.NameToLayer("Units");

        CapsuleCollider collision = gameObject.AddComponent <CapsuleCollider>();

        collision.radius = 0.1f;
        collision.height = 1.8f;
        collision.center = new Vector3(0.0f, 1.0f, 0.0f);

        animator = GetComponent <Animator>();

        unitMover = gameObject.AddComponent <UnitMover>();
        unitMover.Init();
        unitAttack = gameObject.AddComponent <UnitAttack>();
        unitAttack.Init();

        TeamName = teamName;

        hitPoint = maxHits;

        SkeletonConfig skeletonConfig = gameObject.AddComponent <SkeletonConfigCombot>();

        if (skeletonConfig)
        {
            skeletonControl = skeletonConfig.Init();
        }

        if (startAsPlayer)
        {
            gameManager.ActiveUnit = this;
        }

        if (addAI)
        {
            aiControl = gameObject.AddComponent <AIController>();
        }

        InventoryObject.PlayerEntry playerData =
            gameManager.inventory.GetPlayerEntry(unitName);
        if (playerData == null)
        {
            Debug.Log("No PlayerData Found, Adding It");
            playerData                  = new InventoryObject.PlayerEntry();
            playerData.name             = unitName;
            playerData.primaryWeapon    = "AssaultRifle";
            playerData.primaryMagazines = 2;

            gameManager.inventory.AddPlayerEntry(playerData);
        }

        AddWeapon(playerData.primaryWeapon, playerData.primaryMagazines);
        AddWeapon(playerData.secondaryWeapon, playerData.secondaryMagazines);
    }
Beispiel #11
0
 public virtual void StateInit()
 {
     gameManager = GameManager.Instance;
     ai          = GetComponent <AIController>();
     unitControl = GetComponent <UnitControl>();
     unitAttack  = GetComponent <UnitAttack>();
     unitMover   = GetComponent <UnitMover>();
     mapControl  = gameManager.ActiveMap;
 }
Beispiel #12
0
    protected virtual void Start()
    {
        unitModel = GetComponent <UnitModel>();
        unitMover = GetComponent <UnitMover>();

        RefreshUnitAbilities();

        unitModel.OnDeath += UnitModel_OnDeath;
    }
Beispiel #13
0
 public override void ProcessUpdate(UnitMover unitMover)
 {
     if (meleeAbility == null)
     {
         Debug.LogError("unassigned MeleeAbility");
         return;
     }
     meleeAbility.Use();
 }
Beispiel #14
0
        private void Awake()
        {
            _unitMover = new UnitMover(transform, GetComponent <Rigidbody>());

            _unitAttacker = GetComponent <UnitAttacker>();

            _targetSetter = new TargetSetter(transform);

            _navMeshAgent = GetComponent <NavMeshAgent>();
        }
Beispiel #15
0
    void Start()
    {
        unitModel = GetComponent <UnitModel>();
        unitMover = GetComponent <UnitMover>();

        targetMovePoint = transform.position;
        targetMoveTimer = Random.Range(1f, 3f);

        unitModel.OnDeath += UnitModel_OnDeath;
    }
Beispiel #16
0
    public void Init()
    {
        gameManager = GameManager.instance;

        gameObject.tag   = "Unit";
        gameObject.layer = LayerMask.NameToLayer("Units");

        animator = GetComponent <Animator>();

        unitMover  = gameObject.AddComponent <UnitMover>();
        unitAttack = gameObject.AddComponent <UnitAttack>();
        //navAgent = gameObject.AddComponent<NavMeshAgent>();

        TeamName = teamName;

        AddWeapon(TempPrimaryWeapon);

        if (!TempSecondaryWeapon.Equals(""))
        {
            AddWeapon(TempSecondaryWeapon);
        }

        if (!squad && teamName.Equals("Player"))
        {
            squad = gameManager.PlayerSquad;
        }
        if (!squad)
        {
            Debug.Log(transform.name + " has no squad");
        }

        UnitId = squad.AddUnit(this);

        animator.SetFloat("AnimOffset", (float)UnitId / 4.0f);

        transform.position = SquadPosition;
        transform.rotation = squad.transform.rotation;

        CapsuleCollider collision = gameObject.AddComponent <CapsuleCollider>();

        collision.radius = 0.5f;
        collision.height = 2.0f;
        collision.center = new Vector3(0.0f, 1.0f, 0.0f);

        hitPoint = maxHits;


        RagdollConfig ragdollConfig = gameObject.AddComponent <RagdollConfigCombot>();

        if (ragdollConfig)
        {
            ragdollControl = ragdollConfig.Init();
        }
    }
Beispiel #17
0
    void Start()
    {
        target         = GameObject.FindGameObjectWithTag("Player").transform;
        anim           = GetComponent <Animator>();
        mover          = GetComponent <UnitMover>();
        spriteRenderer = GetComponent <SpriteRenderer>();
        original       = spriteRenderer.color;
//		if(weapon!=null)
//		{
//			currentWeapon = weapon.GetComponent<Weapon>();
//		}
    }
Beispiel #18
0
    void Start()
    {
        unitModel = GetComponent <UnitModel>();
        unitMover = GetComponent <UnitMover>();

        revivableCorpses = new List <GameObject>();

        if (gameCamera == null)
        {
            gameCamera = GameObject.FindWithTag(Tags.MainCamera).GetComponent <Camera>();
        }
    }
    private void Start()
    {
        _taskQ = new Queue <Task>();

        _unitMover      = GetComponent <UnitMover>();
        _unitRotater    = GetComponent <UnitRotater>();
        _unitInteractor = GetComponent <UnitInteractor>();

        _unitMover.taskDone      += TaskDone;
        _unitRotater.taskDone    += TaskDone;
        _unitInteractor.taskDone += TaskDone;
    }
Beispiel #20
0
    private void Start()
    {
        appearance = GetComponent <UnitAppearance>();
        animations = GetComponent <UnitAnimations>();
        mover      = GetComponent <UnitMover>();
        physics    = GetComponent <UnitPhysics>();

        SubscribeToGlobalEvents();

        physics.SetCallbackForCollisionWithFinishPoint(OnColideWithFinishPoint);
        physics.SetCallbackForCollisionWithUnit(OnColideWithAnotherUnit);
        physics.SetCallbackForCollisionWithObstacle(OnColideWithObstacle);
    }
Beispiel #21
0
 // if we're going to collect a resource, move away if we collide with another unit
 void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.CompareTag("Unit"))
     {
         if (state == UnitState.MoveToResource)
         {
             if (Vector3.Distance(transform.position, curResourceSource.transform.position) < 2)
             {
                 navAgent.SetDestination(UnitMover.GetUnitDestinationAroundResource(curResourceSource.transform.position));
             }
         }
     }
 }
Beispiel #22
0
    // find a nearby resource to gather from
    void FindNewResource()
    {
        ResourceSource resourceToGet = playerAI.GetClosestResource(transform.position);

        if (resourceToGet != null)
        {
            unit.GatherResource(resourceToGet, UnitMover.GetUnitDestinationAroundResource(resourceToGet.transform.position));
        }
        else
        {
            PursueEnemy();
        }
    }
Beispiel #23
0
 //pozivanje funkcije koja prikuplja resurse
 void UnitsGatherResource(ResourceSource resource, Unit[] units)
 {
     if (units.Length == 1)
     {
         units[0].GatherResource(resource, UnitMover.GetUnitDestinationAroundResource(resource.transform.position));
     }
     else
     {
         Vector3[] destinations = UnitMover.GetUnitGroupDestinationsAroundResource(resource.transform.position, units.Length);
         for (int x = 0; x < units.Length; x++)
         {
             units[x].GatherResource(resource, destinations[x]);
         }
     }
 }
    // do the move computation
    public override void ProcessUpdate(UnitMover unitMover)
    {
        Vector3 flockCenter       = ComputeFlockCenter(allyPositions.Values);
        float   distToFlockCenter = Vector3.Distance(flockCenter, this.transform.position);

        if (distToFlockCenter <= SeperationRadius) // just right hang out
        {
            unitMover.Move(Vector3.zero);
        }
        else // flock
        {
            Vector3 resultingMove = ComputeFLockingMove(SeperationRadius);
            unitMover.Move(resultingMove);
        }
    }
Beispiel #25
0
 protected virtual void Start()
 {
     myCollider = GetComponent <Collider>();
     anim       = GetComponent <Animator>();
     if (anim == null)
     {
         anim = GetComponentInChildren <Animator>();
     }
     mover         = GetComponent <UnitMover>();
     unitID        = TotalCreated;
     TotalCreated += 1;
     //transform.position = new Vector3(Location.x,Location.y,ZOrderer.NormalZ(Location.y));
     //		if(weapon!=null)
     //		{
     //			currentWeapon = weapon.GetComponent<Weapon>();
     //		}
 }
Beispiel #26
0
    // called when we command units to move somewhere
    void UnitsMoveToPosition(Vector3 movePos, Unit[] units)
    {
        // are just selecting 1 unit?
        if (units.Length == 1)
        {
            units[0].MoveToPosition(movePos);
        }
        // otherwise, calculate the unit group formation
        else
        {
            Vector3[] destinations = UnitMover.GetUnitGroupDestinations(movePos, units, 2);

            for (int x = 0; x < units.Length; x++)
            {
                units[x].MoveToPosition(destinations[x]);
            }
        }
    }
Beispiel #27
0
    // called when we command units to gather a resource
    void UnitsGatherResource(ResourceSource resource, Unit[] units)
    {
        // are just selecting 1 unit?
        if (units.Length == 1)
        {
            units[0].GatherResource(resource, UnitMover.GetUnitDestinationAroundResource(resource.transform.position));
        }
        // otherwise, calculate the unit group formation
        else
        {
            Vector3[] destinations = UnitMover.GetUnitGroupDestinationsAroundResource(resource.transform.position, units);

            for (int x = 0; x < units.Length; x++)
            {
                units[x].GatherResource(resource, destinations[x]);
            }
        }
    }
Beispiel #28
0
    public override void ProcessUpdate(UnitMover unitMover)
    {
        // wander randomly for short distances
        targetMoveTimer = Mathf.MoveTowards(targetMoveTimer, 0f, Time.deltaTime);
        if (targetMoveTimer == 0f)
        {
            // Pick new target position
            targetMovePoint = new Vector3(Random.Range(targetMovePoint.x - 8f, targetMovePoint.x + 8f), 0f, Random.Range(targetMovePoint.z - 8f, targetMovePoint.z + 8f));

            targetMoveTimer = Random.Range(1.5f, 5f);
        }

        Vector3 toTarget = targetMovePoint - transform.position;

        if (toTarget.magnitude > 1f)
        {
            unitMover.Move(toTarget.normalized);
        }
    }
Beispiel #29
0
    public override void ProcessUpdate(UnitMover unitMover)
    {
        // Temp behavior: wander near origin
        targetMoveTimer = Mathf.MoveTowards(targetMoveTimer, 0f, Time.deltaTime);
        if (targetMoveTimer == 0f)
        {
            // Pick new target position
            targetMovePoint = new Vector3(Random.Range(-8f, 8f), 0f, Random.Range(-8f, 8f));

            targetMoveTimer = Random.Range(1.5f, 5f);
        }

        Vector3 toTarget = targetMovePoint - transform.position;

        if (toTarget.magnitude > 1f)
        {
            unitMover.Move(toTarget.normalized);
        }
    }
Beispiel #30
0
 public abstract void ProcessUpdate(UnitMover unitMover);