예제 #1
0
    //place a new unit
    public void placeUnit(Vector3 position, bool placingGridCell)
    {
        //check if the position is valid
        if (canPlace(position, placingGridCell))
        {
            //create a new unit/character and prevent it from moving
            GameObject unit = Instantiate(troops[selected].deployableTroops, position, Quaternion.identity);
            disableUnit(unit);
            if (levelData.grid)
            {
                var unitComp = unit.GetComponent <Unit>();
                GridManager.Instance.SetCurrentTileUnit(position, unitComp);
            }

            //set the correct rotation
            updateRotation(unit);

            //add it to the list of placed units
            placedUnits.Add(unit);
            if (levelData.playMode == PlayMode.GROUP)
            {
                currentGroup.AddUnit(unit.GetComponent <Unit>());
            }
            //decrease the number of coins left
            coins         -= troops[selected].troopCosts;
            coinsText.text = coins + "";
        }
    }
예제 #2
0
 /// <summary>
 /// Removes this unit from its current group and adds it the the specified group.
 /// </summary>
 /// <param name="group">Group to add this unit to.</param>
 public void TransferGroup(UnitGroup group)
 {
     //Debug.Log("transferint unit from " + Group.ID + " to " + group.ID);
     Group.SubtractUnit();
     Group = group;
     Group.AddUnit();
 }
예제 #3
0
    IEnumerator spawnEnemies(int levelIndex)
    {
        //get the gridsize and the space in between grid cells
        int levelGridSize = levelData.levels[levelIndex].gridSize;
        int sizeGrid      = 2;

        //find the 3d start position for the grid
        Vector3 startPosition   = new Vector3(transform.position.x + ((float)sizeGrid * ((float)levelGridSize / 2f)), 100, transform.position.z + ((float)sizeGrid * ((float)levelGridSize / 2f)));
        int     currentPosition = 0;

        if (playMode == PlayMode.GROUP)
        {
            List <EnemyGroup> enemyGroups = levelData.levels[levelIndex].group;
            for (int i = 0; i < enemyGroups.Count; i++)
            {
                UnitGroup unitGroup = UnitGroupManager.Instance.GetValidGroup("enemy");
                var       per_group = enemyGroups[i];
                for (int delta = 0; delta < per_group.units.Count; delta++)
                {
                    EnemyUnit  enemyUnit = per_group.units[delta];
                    int        offset_x  = enemyUnit.index / levelGridSize;
                    int        offset_z  = enemyUnit.index % levelGridSize;
                    Vector3    position  = new Vector3(startPosition.x - offset_x * sizeGrid, startPosition.y, startPosition.z - offset_z * sizeGrid);
                    GameObject unit      = enemyUnit.unit;
                    if (unit != null)
                    {
                        unitGroup.AddUnit(spawnNew(position, unit));
                        yield return(new WaitForSeconds(levelData.spawnDelay));
                    }
                }
            }
        }
        else
        {
            //for each position in the grid
            for (int x = 0; x < levelGridSize; x++)
            {
                for (int z = 0; z < levelGridSize; z++)
                {
                    //get the 3d position and the unit for that position
                    Vector3    position = new Vector3(startPosition.x - ((float)x * sizeGrid), startPosition.y, startPosition.z - ((float)z * sizeGrid));
                    GameObject unit     = levelData.levels[levelIndex].units[currentPosition].unit;

                    if (unit != null)
                    {
                        //if there is a unit/character, spawn it and wait a moment for the spawn effect
                        spawnNew(position, unit);
                        yield return(new WaitForSeconds(levelData.spawnDelay));
                    }

                    //increase the current position index
                    currentPosition++;
                }
            }
        }
    }
예제 #4
0
    public void UpdateInit()
    {
        GameObject[][] tanks = BattleFactory.CreateBattleUnits(InstancePlayer.instance.battle,
                                                               InstancePlayer.instance.battle.dataMap);
        _unitGroup.AddUnit(tanks);

        BattleFactory.CreateBackground(InstancePlayer.instance.battle.mission.asset);



        _gameEntering.Start();

        SwitchState(STATE.ENTERING);
    }
예제 #5
0
파일: Unit.cs 프로젝트: mikkpr/LD40
    public void OnBeatEnd(bool success)
    {
        if (health <= 0)
        {
            // This unit is already dismissed
            return;
        }

        // Time window for unit key presses ended
        if (success)
        {
            // This unit is successful
            if (group == null)
            {
                // Not in the army yet
                if (candidateGroup != null)
                {
                    // Join the army
                    candidateGroup.AddUnit(this);
                    group = candidateGroup;
                    SoundManager.instance.addMusicLayer();
                }
            }
            else
            {
                // We are in the army
                // Keep up the good work
            }

            // Play success animation
            if (soldierAnimators != null)
            {
                foreach (Animator a in soldierAnimators)
                {
                    a.SetTrigger("Cheer");
                }
            }
        }
        else
        {
            LoseHealth();
        }

        if (bannerManAnimator != null)
        {
            bannerManAnimator.SetBool("Alert", false);
        }
    }
예제 #6
0
    private void SpawnUnit()
    {
        if (UnitResource != null)
        {
            if (unitGroup.AddUnit())
            {
                RespawnTimer = DefaultRespawnTime;
                if (!singleFree)
                {
                    baseController.GetGameResources().SubtractResources(RespawnCost);
                }
                else
                {
                    singleFree = false;
                }

                GameObject ant = Instantiate(Resources.Load(UnitResource) as GameObject);

                GameObject container = GameObject.Find("Ants");
                if (container == null)
                {
                    throw new Exception("The \"Ants\" container was not found. Please add a container to save the Hierarchy from clutter!");
                }
                else
                {
                    ant.transform.SetParent(container.transform);
                }

                ant.GetComponent <Ant>().unitGroupID = GroupId;
                ant.GetComponent <Ant>().TeamID      = TeamId;

                ant.GetComponent <NavMeshAgent>().Warp(transform.position);
                ant.GetComponent <NavMeshAgent>().enabled = true;
            }
        }
        else
        {
            throw new Exception($"The {GetType()} has no UnitResource set!");
        }
    }
    public void ProcessAction(ActionSystem ctx)
    {
        Unit[] targetUnits = new Unit[targets.Length];
        for (int i = 0; i < targets.Length; i++)
        {
            targetUnits[i] = UnitManager.INSTANCE.unitLookup[targets[i]];
        }
        bool      needsNewGroup = false;
        UnitGroup group         = targetUnits[0].associatedPathfindingGroup;

        for (int i = 1; i < targetUnits.Length; i++)
        {
            if (group != targetUnits[i].associatedPathfindingGroup)
            {
                needsNewGroup = true;
            }
        }

        if (group != null)
        {
            needsNewGroup = (targets.Length != group.associatedUnits.Count);
        }
        else
        {
            needsNewGroup = true;
        }
        if (needsNewGroup)
        {
            group = PathfindingManager.INSTANCE.formGroup();
            foreach (Unit u in targetUnits)
            {
                group.AddUnit(u);
            }
        }
        group.targetPosition = targetPosition;
        group.UpdatePathfinding();
    }
예제 #8
0
    // places new unit within nearby group if one exists, aggregating multiple should it bridge different groups.
    private void IntegrateUnit(ResUnit unit)
    {
        Debug.Log("INTEGRATING");
        VectorHex posHex = unit.posHex;

        Debug.Log("ID: " + unit.owner.playerID);
        List <UnitGroup> neighborGroups = grid.GetPosNeighborGroups(posHex, distinguishPlayers: true, playerQueried: unit.owner.playerID, ignoreOwnGroup: true, invertPlayerSelection: false);

        // if there are no neighbors
        if (neighborGroups.Count < 1)
        {
            UnitGroup newGroup = new UnitGroup(unit.owner);
            newGroup.AddUnit(unit);
            allGroups.Add(newGroup);
        }
        else if (neighborGroups.Count > 1)
        {
            UnitGroup superGroup = neighborGroups[0];
            for (int i = 1; i < neighborGroups.Count; i++)
            {
                superGroup.AddUnits(neighborGroups[i].units);
                if (allGroups.Contains(neighborGroups[i]))
                {
                    allGroups.Remove(neighborGroups[i]);
                }
            }
            superGroup.AddUnit(unit);
        }
        else
        {
            neighborGroups[0].AddUnit(unit);
        }

        grid.PlaceUnit(unit);
        allUnits.Add(unit);
    }
예제 #9
0
 /// <summary>
 /// Increases this towers unit count by one.
 /// </summary>
 public void IncStationedUnits()
 {
     stationedGroup.AddUnit();
 }
예제 #10
0
 private void ChangeGroup(ResUnit changingUnit, UnitGroup newGroup)
 {
     changingUnit.group.RemoveUnit(changingUnit);
     newGroup.AddUnit(changingUnit);
 }