Beispiel #1
0
        public override void ExportGraph(List <InternalBaseGraphAsset> assets)
        {
            Dictionary <DialogType, List <DialogGraphAsset> > dialogGroupDict = new Dictionary <DialogType, List <DialogGraphAsset> >();

            for (int i = 0; i < assets.Count; i++)
            {
                if (assets[i] is DialogGraphAsset)
                {
                    DialogGraphAsset asset = assets[i] as DialogGraphAsset;
                    if (!dialogGroupDict.ContainsKey(asset.dialogType))
                    {
                        dialogGroupDict.Add(asset.dialogType, new List <DialogGraphAsset>());
                    }
                    dialogGroupDict[asset.dialogType].Add(asset);
                }
            }

            foreach (var item in dialogGroupDict)
            {
                TBDialogCnf cnfTab = new TBDialogCnf();

                List <DialogModel> dialogs = new List <DialogModel>();

                DialogType dialogType = item.Key;
                List <DialogGraphAsset> dialogAssets = item.Value;
                foreach (var dialogAsset in dialogAssets)
                {
                    BaseGraph graphData = dialogAsset.DeserializeGraph();
                    dialogs.AddRange(SerializeToDialogModel(graphData, dialogAsset));
                }

                for (int i = 0; i < dialogs.Count; i++)
                {
                    DialogModel tModel = dialogs[i];
                    if (cnfTab.ContainsKey(tModel.id))
                    {
                        Debug.LogError($"Dialog配置生成失败,重复的对话Id>>>>{tModel.id}");
                        return;
                    }
                    else
                    {
                        cnfTab.Add(tModel.id, tModel);
                    }
                }

                string filePath = DialogDef.GetDialogCnfPath(dialogType);
                IOHelper.WriteText(JsonMapper.ToJson(dialogs), filePath);
                Debug.Log($"对话生成成功》》》{filePath}");
            }

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
        public bool GetDialogModel(DialogType dialogType, int dialogId, out DialogModel model)
        {
            TBDialogCnf cnf = configDict[dialogType];

            foreach (var item in cnf)
            {
                if (item.Value.id == dialogId)
                {
                    model = item.Value;
                    return(true);
                }
            }
            DialogLocate.Log.LogError("获得对话配置失败>>>>", dialogId);
            model = default;
            return(false);
        }
 public void Init()
 {
     foreach (var item in Enum.GetValues(typeof(DialogType)))
     {
         string assetName = DialogDef.GetDialogCnfName((DialogType)item);
         string jsonStr   = LoadHelper.LoadString(assetName);
         if (string.IsNullOrEmpty(jsonStr))
         {
             DialogLocate.Log.LogError("没有对话类型的配置", item);
         }
         else
         {
             TBDialogCnf        cnf     = new TBDialogCnf();
             List <DialogModel> dialogs = JsonMapper.ToObject <List <DialogModel> >(jsonStr);
             for (int i = 0; i < dialogs.Count; i++)
             {
                 cnf.Add(dialogs[i].id, dialogs[i]);
             }
             configDict.Add((DialogType)item, cnf);
         }
     }
 }