private List <ActorModel> CollectMapDefaultActors(GameObject mapGo) { defaultActorUid = -100; if (mapGo == null) { Debug.LogError("地图导出失败,没有地图预制体" + name); return(null); } List <ActorModel> actors = new List <ActorModel>(); Transform actorRoot = mapGo.transform.Find("DefaultActor"); if (actorRoot != null) { for (int i = 0; i < actorRoot.childCount; i++) { Transform actor = actorRoot.GetChild(i).transform; ActorCnf actorModel = ED_MapCom.GetActorCnf(actor.name); if (actorModel != null) { ActorModel actorData = new ActorModel(); actorData.uid = defaultActorUid--; actorData.id = actorModel.id; actorData.pos = ED_ActorCom.HandlePos(transform.position); actorData.roate = ED_ActorCom.HandlePos(transform.localEulerAngles); actorData.scale = ED_ActorCom.HandlePos(transform.localScale); actorData.isActive = gameObject.activeSelf; actors.Add(actorData); } } } return(actors); }
public ED_ActorCom CreateActor(ActorCnf actorData) { ED_MapAreaCom areaCom = GetArea(); if (areaCom == null) { Debug.LogError("创建地图失败,没有区域!!!!"); return(null); } if (startUid > endUid) { Debug.LogError("此地图Uid已用完!!!!"); return(null); } ED_ActorCom actorCom = MapEditorDef.CreateActorGo(); actorCom.Init(CalcActorUid(), actorData.id, actorData.name, actorData.isPlayer, this); //预制体 if (actorData.prefab != null) { GameObject actorPrefab = (GameObject)PrefabUtility.InstantiatePrefab(actorData.prefab.GetObj()); MapEditorHelper.SetParent(actorPrefab.gameObject, actorCom.gameObject); } areaCom.AddActor(actorCom); return(actorCom); }
public override object ExportData() { ActorPointModel pointData = new ActorPointModel(); pointData.runAnimName = runAnimName; pointData.waitTime = waitTime; pointData.waitAnimName = waitAnimName; pointData.waitExParam = waitExParam; pointData.point = ED_ActorCom.HandlePos(transform.position); return(pointData); }
public override object ExportData() { UpdateRect(); AreaModel areaModel = new AreaModel(); areaModel.pos = transform.localPosition; areaModel.rect = areaRect; areaModel.areaPrefab = AreaEnv.name; //演员 ED_ActorCom[] actorComs = ActorRoot.GetComponentsInChildren <ED_ActorCom>(true); if (actorComs != null) { for (int i = 0; i < actorComs.Length; i++) { ED_ActorCom tActorCom = actorComs[i]; areaModel.actors.Add((ActorModel)tActorCom.ExportData()); } } //地图默认演员 List <ActorModel> mapActors = CollectMapDefaultActors(tmpAreaEnv); if (mapActors != null && mapActors.Count > 0) { foreach (ActorModel actorData in mapActors) { areaModel.actors.Add(actorData); } } //触发区域 ED_MapTriggerCom[] triggerComs = TriggerRoot.GetComponentsInChildren <ED_MapTriggerCom>(true); if (triggerComs != null) { for (int i = 0; i < triggerComs.Length; i++) { ED_MapTriggerCom tTriggerCom = triggerComs[i]; areaModel.triggers.Add(i + 1, (MapTriggerModel)tTriggerCom.ExportData()); } } return(areaModel); }
private void CheckUid() { if (mapCom == null) { return; } List <ED_ActorCom> actorComs = mapCom.GetActors(); for (int i = 0; i < actorComs.Count; i++) { ED_ActorCom actorCom = actorComs[i]; if (!actorCom.Equals(this)) { if (actorCom.UId == UId) { UId = mapCom.CalcActorUid(); } } } }
private void Update() { UpdateRect(); ED_ActorCom[] actors = GetActors(); if (actors != null || actors.Length > 0) { for (int i = 0; i < actors.Length; i++) { ED_ActorCom actorCom = actors[i]; actorCom.transform.position = ClampPos(actorCom.transform.position); } } ED_MapTriggerCom[] triggers = GetTriggers(); if (triggers != null || triggers.Length > 0) { for (int i = 0; i < triggers.Length; i++) { ED_MapTriggerCom triggerCom = triggers[i]; triggerCom.transform.position = ClampPos(triggerCom.transform.position); } } }
private void OnGUI() { if (!ContextDataCache.TryGetContextData <GUIStyle>("BigLabel", out var bigLabel)) { bigLabel.value = new GUIStyle(GUI.skin.label); bigLabel.value.fontSize = 18; bigLabel.value.fontStyle = FontStyle.Bold; bigLabel.value.alignment = TextAnchor.MiddleLeft; bigLabel.value.stretchWidth = true; } //工具栏 GUILayoutExtension.HorizontalGroup(() => { string selMap = currSelMap == null ? "Null" : currSelMap.mapId.ToString(); GUILayout.Label($"当前地图:{selMap}", bigLabel.value); if (GUILayout.Button("加载地图", GUILayout.Width(BtnWidth), GUILayout.Height(BtnHeight))) { List <string> mapNames = new List <string>(); for (int i = 0; i < maps.Count; i++) { mapNames.Add(maps[i].mapId.ToString()); } MiscHelper.Menu(mapNames, (string selMap) => { ED_MapCom mapAsset = GetMap(int.Parse(selMap)); GameObject mapGo = (GameObject)PrefabUtility.InstantiatePrefab(mapAsset.gameObject); OnChangeMap(mapGo.GetComponent <ED_MapCom>()); }); } if (currSelMap != null) { if (GUILayout.Button("保存地图", GUILayout.Width(BtnWidth), GUILayout.Height(BtnHeight))) { SaveMap(currSelMap); Refresh(); } } if (GUILayout.Button("新建地图", GUILayout.Width(BtnWidth), GUILayout.Height(BtnHeight))) { MiscHelper.Input("输入地图Id", (string x) => { if (GetMap(int.Parse(x)) != null) { Debug.LogError($"地图Id重复>>>>{x}"); return; } SaveMap(currSelMap); ED_MapCom mapCom = MapEditorDef.CreateMapGo(x); mapCom.SetUid(GetMapStartUid()); OnChangeMap(mapCom); }); } if (GUILayout.Button("导出所有配置", GUILayout.Width(BtnWidth), GUILayout.Height(BtnHeight))) { ED_MapCom.ActorCnfs = MapEditorWindow.ActorCnfs; List <ED_MapCom> maps = MapSetting.GetAllMaps(); for (int i = 0; i < maps.Count; i++) { GameObject mapGo = GameObject.Instantiate(maps[i].gameObject); ED_MapCom eD_MapCom = mapGo.GetComponent <ED_MapCom>(); MapModel model = eD_MapCom.ExportData(); string filePath = MapSetting.GetMapModelSavePath(model.mapId.ToString()); IOHelper.WriteText(JsonMapper.ToJson(model), filePath); DestroyImmediate(eD_MapCom.gameObject); Debug.Log($"地图配置生成成功>>>>{filePath}"); } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } }, GUILayout.Height(50)); GUILayoutExtension.HorizontalGroup(() => { //演员分组列表 GUILayoutExtension.VerticalGroup(() => { GUILayout.Label("演员列表", bigLabel.value); for (int i = 0; i < ActorCnfs.Count; i++) { if (GUILayout.Button($"{ActorCnfs[i].name}-{ActorCnfs[i].id}", GUILayout.Width(100), GUILayout.Height(BtnHeight))) { ED_ActorCom actorCom = currSelMap.CreateActor(ActorCnfs[i]); Selection.activeObject = actorCom; } } }, GUILayout.Width(50)); }); }
public void AddActor(ED_ActorCom actorCom) { MapEditorHelper.SetParent(actorCom.gameObject, ActorRoot.gameObject); }