예제 #1
0
        private static GameUnit ReincarnateUnitName(string nextEntName, GameUnit unit, int maxLvl)
        {
            var pos = unit.CurrentPos;
            var origName = unit.OriginalName;
            var owner = unit.Owner;

            var lvlText = origName[origName.Length - 1].ToString();
            int lvl;
            if (!int.TryParse(lvlText, out lvl))
            {
                Debug.LogError("ReincarnateUnitName: " + origName + ". Cant parse lvl");
                return null;
            }

            if (nextEntName.Length == 0) return null;
            if (lvl > maxLvl) lvl = maxLvl;
            nextEntName = nextEntName + lvl;

            var unitChunkNumber = unit.ChunkNumber;

            unit.KillSelf();

            var chunk = ChunkManager.GetChunkByNum(unitChunkNumber);
            var nUnit = chunk.SetupUnit(nextEntName, pos, owner);
            UnitEvents.OnEvolution(nUnit);
            return nUnit;
        }