Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 private void OnChangeMap(ED_MapCom newMap)
 {
     if (currSelMap != null)
     {
         SaveMap(currSelMap);
     }
     currSelMap             = newMap;
     Selection.activeObject = currSelMap;
 }
Esempio n. 3
0
 public void Init(int uid, int id, string actorName, bool isMainActor, ED_MapCom mapCom)
 {
     this.UId       = uid;
     this.Id        = id;
     this.ActorName = actorName;
     IsMainActor    = isMainActor;
     this.mapCom    = mapCom;
     SetGoName();
 }
Esempio n. 4
0
        public static ED_MapCom CreateMapGo(string name)
        {
            GameObject mapGo  = AssetDatabase.LoadAssetAtPath <GameObject>(MapPrefabPath);
            GameObject newGo  = GameObject.Instantiate(mapGo);
            ED_MapCom  mapCom = newGo.GetComponent <ED_MapCom>();

            mapCom.mapId = int.Parse(name);
            newGo.name   = name;
            Selection.activeGameObject = newGo;
            return(mapCom);
        }
Esempio n. 5
0
        private void SaveMap(ED_MapCom map)
        {
            if (map == null)
            {
                return;
            }
            string mapPath = MapSetting.Setting.MapSearchPath + "/" + map.name + ".prefab";

            PrefabUtility.SaveAsPrefabAsset(map.gameObject, mapPath);
            GameObject.DestroyImmediate(map.gameObject);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
Esempio n. 6
0
        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));
            });
        }