public override void Build() { if (m_SerialId == 0) { if (Application.isPlaying) { TransformParam param = new TransformParam(); param.Position = transform.position; param.EulerAngles = transform.rotation.eulerAngles; param.Scale = transform.localScale; m_SerialId = GameEntry.Level.CreateLevelObject(Constant.Define.Portal, param); } else { #if UNITY_EDITOR GameObject portal = LevelComponent.CreateLevelEditorObject(MapHolderType.Portal); portal.transform.parent = transform; portal.transform.localPosition = Vector3.zero; portal.transform.localEulerAngles = Vector3.zero; portal.transform.localScale = Vector3.one; #endif } } }
public override void Build() { if (Width < m_DefaultWidth) { Width = m_DefaultWidth; } int count = Mathf.CeilToInt(Width / m_DefaultWidth); m_Size.x = count * m_DefaultWidth; m_Size.y = 4; m_Size.z = 1.5f; m_Body = transform.Find("Body"); if (m_Body == null) { m_Body = new GameObject("Body").transform; m_Body.parent = transform; m_Body.transform.localPosition = Vector3.zero; m_Body.localEulerAngles = Vector3.zero; } else { m_Body.DestroyChildren(); } float halfCount = count * 0.5f; for (int i = 0; i < count; i++) { if (Application.isPlaying) { TransformParam param = new TransformParam(); param.Position = transform.position; param.EulerAngles = transform.rotation.eulerAngles; param.Scale = transform.localScale; m_SerialId = GameEntry.Level.CreateLevelObject(Constant.Define.Barrier, param); } else { #if UNITY_EDITOR GameObject barrier = LevelComponent.CreateLevelEditorObject(MapHolderType.Barrier); barrier.transform.parent = transform; Vector3 localPosition = Vector3.right * (i - halfCount + 0.5f) * m_DefaultWidth; localPosition.z = m_Size.z * 0.5f; barrier.transform.localPosition = localPosition; barrier.transform.localEulerAngles = Vector3.zero; barrier.transform.localScale = Vector3.one; #endif } } m_Collider = gameObject.GetOrAddComponent <BoxCollider>(); m_Collider.size = m_Size; m_Collider.center = new Vector3(0, m_Size.y * 0.5f, m_Size.z * 0.5f); GlobalTools.SetLayer(gameObject, Constant.Layer.BarrerId); }
public override void OnInspectorGUI() { m_level = target as LevelComponent; if (Application.isPlaying) { RunTimeModeInspector(); } else { EditorModeInspector(); } }
public override void Build() { transform.DestroyChildren(); if (Application.isPlaying) { TransformParam param = new TransformParam(); param.Position = transform.position; param.EulerAngles = transform.rotation.eulerAngles; param.Scale = transform.localScale; m_SerialId = GameEntry.Level.CreateLevelObject(Id, param); } else { #if UNITY_EDITOR GameObject mine = LevelComponent.CreateLevelEditorObject(MapHolderType.MineGroup); mine.transform.SetParent(transform, false); mine.transform.localPosition = Vector3.zero; mine.transform.localScale = Vector3.one; mine.transform.localRotation = Quaternion.identity; #endif } }
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); }
private MapConfig Export() { LevelComponent pHandler = target as LevelComponent; MapConfig data = new MapConfig(); data.Id = pHandler.LevelID; data.MapName = pHandler.MapName; data.MapPath = pHandler.MapPath; List <LevelElement> pList = new List <LevelElement>(); for (int i = 0; i < pHandler.transform.childCount; i++) { Transform child = pHandler.transform.GetChild(i); LevelElement pElem = child.GetComponent <LevelElement>(); if (pElem) { pList.Add(pElem); } } for (int k = 0; k < pList.Count; k++) { string classType = pList[k].GetType().Name; LevelElement current = pList[k]; switch (classType) { case "HolderBorn": { HolderBorn pHolder = current as HolderBorn; if (pHolder != null) { for (int i = 0; i < pHolder.Elements.Count; i++) { LevelElement pElem = pHolder.Elements[i]; switch (pHolder.Elements[i].Camp) { case BattleCampType.Ally: data.Ally = pElem.Export() as MapBorn; break; case BattleCampType.Enemy: data.Enemy = pElem.Export() as MapBorn; break; case BattleCampType.Neutral: data.Neutral = pElem.Export() as MapBorn; break; } } } } break; case "HolderBarrier": { HolderBarrier pHolder = current as HolderBarrier; if (pHolder != null) { for (int i = 0; i < pHolder.Elements.Count; i++) { LevelElement pElem = pHolder.Elements[i]; data.Barriers.Add(pElem.Export() as MapBarrier); } } } break; case "HolderPortal": { HolderPortal pHolder = current as HolderPortal; if (pHolder != null) { for (int i = 0; i < pHolder.Elements.Count; i++) { LevelElement pElem = pHolder.Elements[i]; data.Portals.Add(pElem.Export() as MapPortal); } } } break; case "HolderRegion": { HolderRegion pHolder = current as HolderRegion; if (pHolder != null) { for (int i = 0; i < pHolder.Elements.Count; i++) { LevelElement pElem = pHolder.Elements[i]; data.Regions.Add(pElem.Export() as MapRegion); } } } break; case "HolderWaveSet": { HolderWaveSet pHolder = current as HolderWaveSet; if (pHolder != null) { for (int i = 0; i < pHolder.Elements.Count; i++) { LevelElement pElem = pHolder.Elements[i]; data.WaveSets.Add(pElem.Export() as MapWaveSet); } } } break; case "HolderMonsterGroup": { HolderMonsterGroup pHolder = current as HolderMonsterGroup; if (pHolder != null) { for (int i = 0; i < pHolder.Elements.Count; i++) { LevelElement pElem = pHolder.Elements[i]; data.MonsterGroups.Add(pElem.Export() as MapMonsterGroup); } } } break; case "HolderMineGroup": { HolderMineGroup pHolder = current as HolderMineGroup; if (pHolder != null) { for (int i = 0; i < pHolder.Elements.Count; i++) { LevelElement pElem = pHolder.Elements[i]; data.MineGroups.Add(pElem.Export() as MapMineGroup); } } } break; case "HolderNpc": { HolderNpc pHolder = current as HolderNpc; if (pHolder != null) { for (int i = 0; i < pHolder.Elements.Count; i++) { LevelElement pElem = pHolder.Elements[i]; data.Npcs.Add(pElem.Export() as MapNpc); } } } break; } } return(data); }