示例#1
0
    private void Start()
    {
        UnitManager.AddUnit(this);

        if (!m_photonView.isMine)
        {
            this.gameObject.tag = "EnemyUnit";
        }
    }
 public int AddUnit(Unit unit)
 {
     try
     {
         return(_unitManager.AddUnit(unit));
     }
     catch (Exception ex)
     {
         ErrorManager.LogApplicationError(ex.StackTrace, ex.Source, ex.Message);
         return(0);
     }
 }
    void Start()
    {
        unitManager = Toolbox.GetScript <UnitManager>();

        if (!unitManager)
        {
            Debug.LogError("No reference for unitManager");
        }

        unitManager.AddUnit(this);

        unitAnimator = GetComponent <Animator>();
    }
示例#4
0
 private void ProcessAddedViews(float dt)
 {
     foreach (var view in _viewsToProcess)
     {
         if (view.Id != 0 && Units.ContainsKey(view.Id))
         {
             continue;
         }
         _unitManager.AddUnit(view.GetComponentInChildren <UnitObject>(), view.Faction, view.GetInstalledParts());
     }
     _viewsToProcess.Clear();
     _timeManager.StopUpdate(ref _updateAddedViews);
 }
示例#5
0
        public Unit(Game game, UnitStats stats, Player owner) : base(game)
        {
            this.stats    = stats;
            this.owner    = owner;
            coordinates   = new Vector2();
            currentMorale = stats.BaseMorale;
            currentMove   = stats.BaseMove;
            placed        = false;
            id            = Guid.NewGuid();
            State         = States.Waiting;

            owner.addUnit(this);
            UnitManager.AddUnit(this);
        }
示例#6
0
    // Start is called before the first frame update
    void Start()
    {
        if (Player == Enums.Player.Player1)
        {
            _cC = FindObjectOfType <CursorController>();
            _cC.OnCursorMoveEvent += OnCursorMove;
        }

        if (!OnCooldown)
        {
            UnitManager?.AddUnit(this, true);
        }

        switch (Player)
        {
        case Enums.Player.Player2:
            _defaultLook = -1;
            _sR.color    = Colors.Player2;
            break;

        default:
            _defaultLook = 1;
            break;
        }

        try
        {
            var uiParent     = GameObject.FindGameObjectWithTag("UI");
            var minimapPanel = uiParent.FindObject("UnitIcons");
            _minimapIcon = Instantiate(MinimapIconImage);
            _minimapIcon.rectTransform.SetParent(minimapPanel.transform);
            _minimapIcon.rectTransform.anchoredPosition = Utility.UITilePosition(_minimapIcon.rectTransform, transform);
            _minimapIcon.color = Player == Enums.Player.Player1 ? Colors.Player_Idle : Colors.Enemy_Idle;
        }
        catch { Debug.Log("failed unit minimap"); }

        gameObject.name = $"P{((int)Player) + 1}_" + gameObject.name;

        BoxCollider.size = ColliderSizeIdle;
        ResetLook();

        if (OffCooldownObject != null)
        {
            Instantiate(OffCooldownObject, transform.position, Quaternion.identity);
        }
    }
示例#7
0
 // Update is called once per frame
 void Update()
 {
     if (curHealth <= 0.0f)
     {
         if (unitManager.NumUnits() < unitManager.numUnitsAllowed)
         {
             GameObject instance = Instantiate(zombieUnit, transform.position, zombieUnit.transform.rotation) as GameObject;
             unitManager.SelectAdditionalUnit(instance);
             unitManager.AddUnit();
         }
         if (gameObject.name.Contains("Civilian"))
         {
             civManager.RemoveCivilian();
         }
         Object.Destroy(gameObject);
     }
 }
示例#8
0
    public static int GenerateUnit(Unit.Type _type, Player.Type _info, bool _active = true)
    {
        Unit unit;

        switch (_type)
        {
        case Unit.Type.KNIGHT:
            unit = GameObject.Instantiate(Resources.Load <Unit>("Prefabs/Knight"));
            break;

        case Unit.Type.ARCHER:
            unit = GameObject.Instantiate(Resources.Load <Unit>("Prefabs/Archer"));
            break;

        case Unit.Type.WARHOUND:
            unit = GameObject.Instantiate(Resources.Load <Unit>("Prefabs/Warhound"));
            break;

        default:
            Debug.Log("ERROR: Unit type not found");
            return(-1);
        }

        switch (_info)
        {
        case Player.Type.PLAYER1:
            unit.FaceDirection(WarforgedMonoBehaviour.Direction.RIGHT);
            break;

        case Player.Type.PLAYER2:
            unit.FaceDirection(WarforgedMonoBehaviour.Direction.LEFT);
            break;

        default:
            Debug.Log("ERROR: Unit owner unassigned at generation");
            break;
        }
        unit.SetOwner(_info);
        unit.InitializeVariables();
        unit.gameObject.SetActive(_active);
        return(UnitManager.AddUnit(unit));
    }
示例#9
0
    public void SelectCard(int index)
    {
        if (!getTargetCardInSlot(index).Equals(emptySprite))
        {
            selectedList[index] = !selectedList[index];
            if (trueCount(selectedList) == 2)
            {
                int    idx1 = GetSelectedCardIndexInArray(selectedList)[0];
                int    idx2 = GetSelectedCardIndexInArray(selectedList)[1];
                string gen  = GetGenealogy(GetCardCodeInSlot(idx1), GetCardCodeInSlot(idx2));

                ShowGenealogy(gen);
                m_unitManager.AddUnit(gen);

                selectedList[idx1] = false;
                selectedList[idx2] = false;
                // destroy
                // sort
                SortCardList(idx1, idx2);
                ShowCardList();
            }
        }
    }
示例#10
0
    void Update()
    {
        if (CooldownTimer <= 0)
        {
            if (PlusAction > 0)
            {
                PlusAction          -= Time.deltaTime;
                PlusActionText.alpha = PlusAction / PLUSACTIONTIME;
            }
            else if (PlusAction <= 0 && _unitState == Enums.UnitState.PlusAction && !_selected)
            {
                _unitState = Enums.UnitState.Idle;
            }

            //if (_unitState == Enums.UnitState.Idle && CurrentGridBlock != null && CurrentGridBlock.CurrentUnit != this) // This is a redundency in case the gridblock is out of sync with the current unit
            //    CurrentGridBlock.CurrentUnit = this;

            if ((_nextPoint != null || _movePositions.Count > 0) && _unitState != Enums.UnitState.Attacking && _unitState != Enums.UnitState.Hurt)
            {
                if (_nextPoint == null)
                {
                    GetNextPoint();
                }

                Vector2 moveVector = Vector2.MoveTowards(transform.position, _nextPoint.Position, Speed * Time.deltaTime);
                _minimapIcon.rectTransform.anchoredPosition = Utility.UITilePosition(_minimapIcon.rectTransform, transform);

                transform.position = moveVector;
                if (transform.position.V2() == _nextPoint.Position)
                {
                    Log("Arrived at point");
                    _prevPositions.FirstOrDefault()?.Path_Delete(this);
                    _prevPositions.Push(_nextPoint);

                    if (CurrentGridBlock.CurrentUnit == null && _attackWhenInRange && _attackTarget != null && Position.GridDistance(_attackTarget.Position) <= MaxAttackDistance && CurrentGridBlock?.CurrentUnit == this)
                    {
                        DeleteSavedPath();
                        _nextPoint = null;
                    }
                    else if (!_movePositions.IsEmpty())
                    {
                        Log("Get next point");
                        GetNextPoint();
                    }
                    else
                    {
                        if (CurrentGridBlock != _nextPoint) // Arrived at the last point, make sure it's the currentgridblock
                        {
                            CurrentGridBlock = _nextPoint;
                        }
                        Log("Last move");
                        _nextPoint = null;
                    }

                    if (_movePositions.IsEmpty() && _nextPoint == null)
                    {
                        if (CurrentGridBlock.CurrentUnit == null)
                        {
                            Log($"Ends move");
                            Moving = false;
                            Moved  = true;

                            CurrentGridBlock.SetCurrentUnit(this);
                            _unitState = Enums.UnitState.Idle;
                        }
                        else
                        {
                            FindGoodPreviousSpot();
                        }
                    }
                }
            }

            if (!_attack && Target != null && _movePositions.IsEmpty() && _nextPoint == null)
            {
                Log($"checks for attack");
                CheckAttack();
            }

            if (!_selected && !Moving && _animator.GetBool("Moving"))
            {
                _animator.SetBool("Moving", false);
            }

            if (_attack && !_animator.GetCurrentAnimatorStateInfo(0).IsName("Launch") && !Attacked)
            {
                Log($"attacks");
                Attack();
            }

            if (_nextPoint == null && _unitState == Enums.UnitState.Idle && _tasked && !Moving && !_attack && (Moved || Attacked))
            {
                Log($"goes on cooldown");
                if (!Utility.TrueNull(CurrentGridBlock.CurrentUnit) && CurrentGridBlock.CurrentUnit != this)
                {
                    FindGoodPreviousSpot();
                }
                else
                {
                    GoOnCooldown();
                }
            }
        }

        if (CooldownTimer > 0)
        {
            CooldownTimer -= Time.deltaTime;
            if (CooldownTimer <= 0)
            {
                Log($"Come of cooldown");
                if (Type == Enums.UnitType.Melee)
                {
                    CooldownReduction?.gameObject.SetActive(false);
                }

                if (UnitManager?.AvailableUnits <= 0)
                {
                    _cC?.SetPosition(transform.position);
                }

                _animator.SetBool("Cooldown", OnCooldown = false);
                _minimapIcon.color = Player == Enums.Player.Player1 ? Colors.Player_Idle : Colors.Enemy_Idle;

                if (OffCooldownObject != null)
                {
                    Log("Create cooldown object");
                    Instantiate(OffCooldownObject, transform.position, Quaternion.identity);
                }

                if (Player != Enums.Player.Player1) // This is for non player units to make sure all units are looped through
                {
                    UnitManager?.AddUnit(this);
                }

                _unitState = Enums.UnitState.Idle;
            }
        }

        if (Player != Enums.Player.Player1 && _nextPoint == null && _unitState == Enums.UnitState.Idle && !OnCooldown && !Moving && !Moved && !Attacked)
        {
            if (!UnitManager.PlayerInfo.Units.Contains(this))
            {
                Log($"added to unit list");
                UnitManager.AddUnit(this);
            }
        }
    }
示例#11
0
 private void OnMouseDown()
 {
     _unitManager.AddUnit(gameObject);
 }