コード例 #1
0
        // Token: 0x0600035C RID: 860 RVA: 0x0001B1C8 File Offset: 0x000193C8
        internal static Unit9 AddUnit(Unit unit)
        {
            Unit9 result;

            try
            {
                if (EntityManager9.ignoredUnits.Contains(unit.Name))
                {
                    result = null;
                }
                else
                {
                    Unit9 unit2 = EntityManager9.GetUnitFast(unit.Handle);
                    if (unit2 != null)
                    {
                        result = unit2;
                    }
                    else
                    {
                        Hero hero;
                        Type type2;
                        if ((hero = (unit as Hero)) != null)
                        {
                            if (hero.HeroId == HeroId.npc_dota_hero_base || hero.Inventory == null)
                            {
                                EntityManager9.DelayedAdd(hero);
                                return(null);
                            }
                            Type type;
                            if (EntityManager9.heroTypes.TryGetValue(hero.HeroId, out type))
                            {
                                unit2 = (Hero9)Activator.CreateInstance(type, new object[]
                                {
                                    hero
                                });
                            }
                            else
                            {
                                unit2 = new Hero9(hero);
                            }
                            if (!unit2.IsIllusion && unit2.Handle == ObjectManager.LocalHero.Handle)
                            {
                                EntityManager9.Owner.SetHero(unit2);
                            }
                        }
                        else if (EntityManager9.unitTypes.TryGetValue(unit.Name, out type2))
                        {
                            unit2 = (Unit9)Activator.CreateInstance(type2, new object[]
                            {
                                unit
                            });
                        }
                        else
                        {
                            unit2 = new Unit9(unit);
                        }
                        EntityManager9.units[unit2.Handle] = unit2;
                        Unit unit3;
                        if ((unit3 = (unit2.BaseOwner as Unit)) != null && unit3.IsValid)
                        {
                            try
                            {
                                unit2.Owner = EntityManager9.AddUnit(unit3);
                            }
                            catch (Exception exception)
                            {
                                Logger.Error(exception, "Set unit owner");
                            }
                        }
                        EntityManager9.UnitMonitor.CheckModifiers(unit2);
                        EntityManager9.EventHandler <Unit9> eventHandler = EntityManager9.unitAdded;
                        if (eventHandler != null)
                        {
                            eventHandler(unit2);
                        }
                        result = unit2;
                    }
                }
            }
            catch (Exception exception2)
            {
                Logger.Error(exception2, unit, null);
                result = null;
            }
            return(result);
        }