private void InitLevelObject()
        {
            //触发区域
            for (int i = 0; i < Config.Regions.Count; i++)
            {
                MapRegion data = Config.Regions[i];
                if (data.StartActive)
                {
                    LevelElement pHolder = GetHolder(MapHolderType.Region);
                    GameObject   go      = pHolder.gameObject.AddChild();
                    LevelRegion  pRegion = go.AddComponent <LevelRegion>();
                    pRegion.Import(data, false);
                    pRegion.Init();
                }
            }

            //障碍物
            for (int i = 0; i < Config.Barriers.Count; i++)
            {
                MapBarrier   data     = Config.Barriers[i];
                LevelElement pHolder  = GetHolder(MapHolderType.Barrier);
                GameObject   go       = pHolder.gameObject.AddChild();
                LevelBarrier pBarrier = go.AddComponent <LevelBarrier>();
                pBarrier.Import(data, false);
                pBarrier.Init();
            }

            //传送门
            for (int i = 0; i < Config.Portals.Count; i++)
            {
                MapPortal    data    = Config.Portals[i];
                LevelElement pHolder = GetHolder(MapHolderType.Portal);
                GameObject   go      = pHolder.gameObject.AddChild();
                LevelPortal  pPortal = go.AddComponent <LevelPortal>();
                pPortal.Import(data, false);
                pPortal.Init();
            }
        }
Example #2
0
        private void Import()
        {
            LevelComponent levelCom = target as LevelComponent;

            levelCom.transform.DestroyChildren();
            levelCom.InitHolder();
            string    fsPath = AssetUtility.GetLevelConfigAsset(levelCom.LevelID.ToString());
            MapConfig data   = new MapConfig();

            data.EditorLoad(fsPath);

            levelCom.MapName = data.MapName;

            for (int i = 0; i < data.Regions.Count; i++)
            {
                LevelElement pHolder = levelCom.GetHolder(MapHolderType.Region);
                GameObject   go      = pHolder.gameObject.AddChild();
                LevelRegion  pRegion = go.AddComponent <LevelRegion>();
                pRegion.Import(data.Regions[i], true);
            }

            for (int i = 0; i < data.Barriers.Count; i++)
            {
                LevelElement pHolder  = levelCom.GetHolder(MapHolderType.Barrier);
                GameObject   go       = pHolder.gameObject.AddChild();
                LevelBarrier pBarrier = go.AddComponent <LevelBarrier>();
                pBarrier.Import(data.Barriers[i], true);
            }


            for (int i = 0; i < data.WaveSets.Count; i++)
            {
                LevelElement pHolder  = levelCom.GetHolder(MapHolderType.WaveSet);
                GameObject   go       = pHolder.gameObject.AddChild();
                LevelWaveSet pWaveSet = go.AddComponent <LevelWaveSet>();
                pWaveSet.Import(data.WaveSets[i], true);
            }

            for (int i = 0; i < data.MonsterGroups.Count; i++)
            {
                LevelElement      pHolder = levelCom.GetHolder(MapHolderType.MonsterGroup);
                GameObject        go      = pHolder.gameObject.AddChild();
                LevelMonsterGroup pGroup  = go.AddComponent <LevelMonsterGroup>();
                pGroup.Import(data.MonsterGroups[i], true);
            }

            for (int i = 0; i < data.MineGroups.Count; i++)
            {
                LevelElement   pHolder = levelCom.GetHolder(MapHolderType.MineGroup);
                GameObject     go      = pHolder.gameObject.AddChild();
                LevelMineGroup pGroup  = go.AddComponent <LevelMineGroup>();
                pGroup.Import(data.MineGroups[i], true);
            }

            for (int i = 0; i < data.Portals.Count; i++)
            {
                LevelElement pHolder = levelCom.GetHolder(MapHolderType.Portal);
                GameObject   go      = pHolder.gameObject.AddChild();
                LevelPortal  pPortal = go.AddComponent <LevelPortal>();
                pPortal.Import(data.Portals[i], true);
            }

            for (int i = 0; i < data.Npcs.Count; i++)
            {
                LevelElement pHolder = levelCom.GetHolder(MapHolderType.Npc);
                GameObject   go      = pHolder.gameObject.AddChild();
                LevelNpc     pNpc    = go.AddComponent <LevelNpc>();
                pNpc.Import(data.Npcs[i], true);
            }

            {
                LevelElement pHolder = levelCom.GetHolder(MapHolderType.Born);
                if (data.Ally != null)
                {
                    GameObject gA     = pHolder.gameObject.AddChild();
                    LevelBorn  pBornA = gA.AddComponent <LevelBorn>();
                    pBornA.Import(data.Ally, true);
                }
                if (data.Enemy != null)
                {
                    GameObject gB     = pHolder.gameObject.AddChild();
                    LevelBorn  pBornB = gB.AddComponent <LevelBorn>();
                    pBornB.Import(data.Enemy, true);
                }
                if (data.Neutral != null)
                {
                    GameObject gC     = pHolder.gameObject.AddChild();
                    LevelBorn  pBornC = gC.AddComponent <LevelBorn>();
                    pBornC.Import(data.Neutral, true);
                }
            }

            Debug.Log("导入关卡数据:" + fsPath);
        }