Example #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();
        }
 // Update is called once per frame
 void Update()
 {
     if (canRespond)
     {
         if (Input.GetKeyDown(KeyCode.Alpha1))
         {
             score    += current.score1;
             lastTime  = Time.time;
             responded = true;
             current   = Talk.GetDialogDefinition(current.next1);
         }
         if (Input.GetKeyDown(KeyCode.Alpha2))
         {
             score    += current.score2;
             lastTime  = Time.time;
             responded = true;
             current   = Talk.GetDialogDefinition(current.next2);
         }
         if (Input.GetKeyDown(KeyCode.Alpha3))
         {
             score    += current.score3;
             lastTime  = Time.time;
             responded = true;
             current   = Talk.GetDialogDefinition(current.next3);
         }
         if (Input.GetKeyDown(KeyCode.Alpha4))
         {
             score    += current.score4;
             lastTime  = Time.time;
             responded = true;
             current   = Talk.GetDialogDefinition(current.next4);
         }
         if (responded)
         {
             canRespond = false;
             responded  = false;
             prompt.GetComponent <TextMesh>().text  = current.prompt;
             option1.GetComponent <TextMesh>().text = "1) " + current.option1;
             option2.GetComponent <TextMesh>().text = "2) " + current.option2;
             option3.GetComponent <TextMesh>().text = "3) " + current.option3;
             option4.GetComponent <TextMesh>().text = "4) " + current.option4;
         }
         currentScore.text = "Score: " + score.ToString();
     }
     if (Time.time - lastTime > 3)
     {
         canRespond = true;
     }
 }
 // Use this for initialization
 void Start()
 {
     currentScore.text = "Score: " + score.ToString();
     current           = Talk.GetDialogDefinition(_cat);
     prompt            = transform.Find("Prompt").gameObject;
     option1           = transform.Find("Option1").gameObject;
     option2           = transform.Find("Option2").gameObject;
     option3           = transform.Find("Option3").gameObject;
     option4           = transform.Find("Option4").gameObject;
     prompt.GetComponent <TextMesh>().text  = current.prompt;
     option1.GetComponent <TextMesh>().text = "1) " + current.option1;
     option2.GetComponent <TextMesh>().text = "2) " + current.option2;
     option3.GetComponent <TextMesh>().text = "3) " + current.option3;
     option4.GetComponent <TextMesh>().text = "4) " + current.option4;
     score      = 0;
     canRespond = false;
     responded  = false;
     lastTime   = Time.time;
 }
 public MessageAnwer_OpenDialog(string buttonLabel, DialogDef dialog)
 {
     Dialog   = dialog;
     labelInt = buttonLabel;
 }
 public CommAction_OpenDialogWithFaction(DialogDef def) => Dialog = def;