예제 #1
0
        //This function is a total mess and needs some polish and refactoring - but it works just well enough :D
        //This works like a hobbled together foreach loop, going backwards in selected.
        IEnumerator SetupLine(GameObject node, bool firstloop)
        {
            float randomizedTiming = Random.Range(0.2f, 0.3f);

            if (firstloop)
            {
                yield return(new WaitUntil(() => firstloop == true));
            }
            else
            {
                yield return(new WaitForSeconds(randomizedTiming));
            }


            if (selected.Count > 0)
            {
                GameObject troop     = selected[selected.Count - 1];
                Waypoint   oldHome   = new GetClosestWaypoint().search(troop.transform.position);
                Waypoint   newHome   = node.GetComponent <Waypoint>();
                Unit       troopInfo = troop.GetComponent <UnitCore>().thisunit;
                troop.GetComponent <Outline>().enabled     = false;
                troop.GetComponent <UnitCore>().isSelected = false;

                if (oldHome != newHome)
                {
                    if (troopInfo.faction == "Player")
                    {
                        oldHome.AllyRemove(troop);
                        newHome.AllyAdd(troop);
                        troop.GetComponent <Movement>().MoveTo(newHome, "Right", newHome.Allies.Count, true);
                    }

                    if (troopInfo.faction == "Enemy")
                    {
                        oldHome.EnemyRemove(troop);
                        newHome.EnemyAdd(troop);
                        troop.GetComponent <Movement>().MoveTo(newHome, "Left", newHome.Enemies.Count, true);
                    }
                }
                if (selected.Count == 1)
                {
                    selected.RemoveAt(selected.Count - 1);
                }
                else
                {
                    selected.RemoveAt(selected.Count - 1);
                    StartCoroutine(SetupLine(node, false));
                }
            }
        }