//close ans start next level public void NextLv() { LevelManager.instance.StartNextLevel(); merchantObj.SetActive(false); //destory all unpicked loot Loot[] unpickedLoot = FindObjectsOfType <Loot>(); for (int i = 0; i < unpickedLoot.Length; i++) { Destroy(unpickedLoot[i].gameObject); } RPGCore.SetDictionaryValue("talk", LevelManager.instance.current_lv.ToString()); //TODO:effect }
//參數設定 public void ReadArgs(ref string args) { if (args == "") { return; } //跳脫字元 args = RPGCore.Put_Back_EscChar(args); //自定義變數 args = RPGCore.ReadCustomVariables(args); //title foreach (Match match in GetMatch(args, RPGCore.REGEX_ARGS_TITLE)) { title.text = match.Groups["title"].Value; } //by foreach (Match match in GetMatch(args, RPGCore.REGEX_ARGS_BY)) { //找到說話的物件,計算位置,將UI放置在該物件旁 (UI座標) GameObject talk_by = GameObject.Find(match.Groups["by"].Value); if (talk_by != null) { Vector3 target_top_pos = talk_by.transform.position; //在物件上方 Renderer rend = talk_by.GetComponent <Renderer>(); if (rend != null) { target_top_pos.y += rend.bounds.size.y * 1.5f; } else { target_top_pos.y += 2.5f; } Vector2 ui_pos = Camera.main.WorldToScreenPoint(target_top_pos); //ui_pos.y+=100; Wrapper.transform.position = ui_pos; } else { Debug.LogError("talk by not found."); } } #region //img foreach (Match match in GetMatch(args, RPGCore.REGEX_ARGS_IMG)) { SetPortraitImg(match.Groups["side"].Value, match.Groups["imgPath"].Value); } //animation foreach (Match match in GetMatch(args, RPGCore.REGEX_ARGS_ANIMATION)) { GameObject target = GameObject.Find((match.Groups["objectName"].Value)); if (target != null) { Animator animator = target.GetComponent <Animator>(); if (animator != null) { animator.Play((match.Groups["clipName"].Value)); } else { Debug.LogError("<animation arg error> animator not found"); } } } //audio foreach (Match match in GetMatch(args, RPGCore.REGEX_ARGS_AUDIO)) { string operation = (match.Groups["operation"].Value); GameObject target = GameObject.Find((match.Groups["objectName"].Value)); if (target != null) { AudioSource audioSource = target.GetComponent <AudioSource>(); if (audioSource != null) { if (operation == "play") { audioSource.Play(); } else if (operation == "pause") { audioSource.Pause(); } else if (operation == "stop") { audioSource.Stop(); } } else { Debug.LogError("<audio arg error> audioSource not found"); } } } //set foreach (Match match in GetMatch(args, RPGCore.REGEX_ARGS_SET)) { Debug.Log("SET"); string _key = Regex.Replace(match.Groups["key"].Value, @"['""]", "");; string _value = match.Groups["value"].Value; string _operator = match.Groups["operator"].Value; //optional string _value2 = match.Groups["value2"].Value; //optional //判斷value是字典key或值 bool v1_is_key = Regex.IsMatch(_value, @"['""].*?['""]"); bool v2_is_key = Regex.IsMatch(_value2, @"['""].*?['""]"); string v1 = _value, v2 = _value2; if (v1_is_key) { v1 = RPGCore.GetDictValue(Regex.Replace(_value, @"['""]", "")); } if (v2_is_key) { v2 = RPGCore.GetDictValue(Regex.Replace(_value2, @"['""]", "")); } //先做運算 if (_operator != "") { int v1_num = int.Parse(v1); int v2_num = int.Parse(v2); if (_operator == "+") { RPGCore.SetDictionaryValue(_key, (v1_num + v2_num).ToString()); } if (_operator == "-") { RPGCore.SetDictionaryValue(_key, (v1_num - v2_num).ToString()); } if (_operator == "*") { RPGCore.SetDictionaryValue(_key, (v1_num * v2_num).ToString()); } if (_operator == "/") { RPGCore.SetDictionaryValue(_key, (v1_num / v2_num).ToString()); } } else { //不做運算直接給值 RPGCore.SetDictionaryValue(_key, v1); } } //其他 (可刪除,或去補齊方法cs檔): 用括號的參數改用統一regex拆解 foreach (Match match in GetMatch(args, RPGCore.REGEX_FUNC_PARA)) { //方法名稱 string functionName = match.Groups["func"].Value; Debug.Log(functionName); string[] paras = match.Groups["para"].Value.Split(','); //enable /disable if (functionName == "enable") { foreach (string objName in paras) { GameObject target = temp_preparedList.Find(x => x.name.Equals(objName)); if (target != null) { target.SetActive(true); } } } if (functionName == "disable") { foreach (string objName in paras) { GameObject target = temp_preparedList.Find(x => x.name.Equals(objName)); if (target != null) { target.SetActive(false); } } } //**************** YOUR OWN SCRIPT FUNCTION ***************************** //Effect 特效 if (functionName == "effect") { foreach (string effect_name in paras) { if (effect_name == "shake") { //Effecter.cs StartCoroutine(Effecter.Shake(Wrapper, 5, 10, 0.25f)); Debug.Log("Do SHAKE"); } } } //changeScene(scenetoLoad ) 換場景 if (functionName == "changeScene") { //load場景 string scene_to_load = paras[0]; SceneManager.LoadScene(scene_to_load); } } #endregion }
//參數設定 public void ReadArgs(ref string args) { if (args == "") { return; } //跳脫字元 args = RPGCore.Put_Back_EscChar(args); //自定義變數 args = RPGCore.ReadCustomVariables(args); //title foreach (Match match in GetMatch(args, RPGCore.REGEX_ARGS_TITLE)) { title.text = match.Groups["title"].Value; } //by foreach (Match match in GetMatch(args, RPGCore.REGEX_ARGS_BY)) { //找到說話的物件,計算位置,將UI放置在該物件旁 (UI座標) GameObject talk_by = GameObject.Find(match.Groups["by"].Value); if (talk_by != null) { Vector3 target_top_pos = talk_by.transform.position; //在物件上方 Renderer rend = talk_by.GetComponent <Renderer>(); if (rend != null) { target_top_pos.y += rend.bounds.size.y * 1.5f; } else { target_top_pos.y += 2.5f; } Vector2 ui_pos = Camera.main.WorldToScreenPoint(target_top_pos); //ui_pos.y+=100; Wrapper.transform.position = ui_pos; } else { Debug.LogError("talk by not found."); } } #region //img foreach (Match match in GetMatch(args, RPGCore.REGEX_ARGS_IMG)) { SetPortraitImg(match.Groups["side"].Value, match.Groups["imgPath"].Value); } //animation foreach (Match match in GetMatch(args, RPGCore.REGEX_ARGS_ANIMATION)) { GameObject target = GameObject.Find((match.Groups["objectName"].Value)); if (target != null) { Animator animator = target.GetComponent <Animator>(); if (animator != null) { animator.Play((match.Groups["clipName"].Value)); } else { Debug.LogError("<animation arg error> animator not found"); } } } //audio foreach (Match match in GetMatch(args, RPGCore.REGEX_ARGS_AUDIO)) { string operation = (match.Groups["operation"].Value); GameObject target = GameObject.Find((match.Groups["objectName"].Value)); if (target != null) { AudioSource audioSource = target.GetComponent <AudioSource>(); if (audioSource != null) { if (operation == "play") { audioSource.Play(); } else if (operation == "pause") { audioSource.Pause(); } else if (operation == "stop") { audioSource.Stop(); } } else { Debug.LogError("<audio arg error> audioSource not found"); } } } //set foreach (Match match in GetMatch(args, RPGCore.REGEX_ARGS_SET)) { Debug.Log("SET"); string _key = Regex.Replace(match.Groups["key"].Value, @"['""]", "");; string _value = match.Groups["value"].Value; string _operator = match.Groups["operator"].Value; //optional string _value2 = match.Groups["value2"].Value; //optional //判斷value是字典key或值 bool v1_is_key = Regex.IsMatch(_value, @"['""].*?['""]"); bool v2_is_key = Regex.IsMatch(_value2, @"['""].*?['""]"); string v1 = _value, v2 = _value2; if (v1_is_key) { v1 = RPGCore.GetDictValue(Regex.Replace(_value, @"['""]", "")); } if (v2_is_key) { v2 = RPGCore.GetDictValue(Regex.Replace(_value2, @"['""]", "")); } //先做運算 if (_operator != "") { int v1_num = int.Parse(v1); int v2_num = int.Parse(v2); if (_operator == "+") { RPGCore.SetDictionaryValue(_key, (v1_num + v2_num).ToString()); } if (_operator == "-") { RPGCore.SetDictionaryValue(_key, (v1_num - v2_num).ToString()); } if (_operator == "*") { RPGCore.SetDictionaryValue(_key, (v1_num * v2_num).ToString()); } if (_operator == "/") { RPGCore.SetDictionaryValue(_key, (v1_num / v2_num).ToString()); } } else { //不做運算直接給值 RPGCore.SetDictionaryValue(_key, v1); } } //Init foreach (Match match in GetMatch(args, RPGCore.REGEX_ARGS_INIT)) { Debug.Log("Init"); string _key = Regex.Replace(match.Groups["key"].Value, @"['""]", "");; string _value = match.Groups["value"].Value; string _operator = match.Groups["operator"].Value; //optional string _value2 = match.Groups["value2"].Value; //optional //判斷value是字典key或值 bool v1_is_key = Regex.IsMatch(_value, @"['""].*?['""]"); bool v2_is_key = Regex.IsMatch(_value2, @"['""].*?['""]"); string v1 = _value, v2 = _value2; bool key_is_inDict = false; RPGCore.GetDictValue(_key, out key_is_inDict); //已經在字典裡就不用設值 if (key_is_inDict) { return; } if (v1_is_key) { v1 = RPGCore.GetDictValue(Regex.Replace(_value, @"['""]", "")); } if (v2_is_key) { v2 = RPGCore.GetDictValue(Regex.Replace(_value2, @"['""]", "")); } //先做運算 if (_operator != "") { int v1_num = int.Parse(v1); int v2_num = int.Parse(v2); if (_operator == "+") { RPGCore.SetDictionaryValue(_key, (v1_num + v2_num).ToString()); } if (_operator == "-") { RPGCore.SetDictionaryValue(_key, (v1_num - v2_num).ToString()); } if (_operator == "*") { RPGCore.SetDictionaryValue(_key, (v1_num * v2_num).ToString()); } if (_operator == "/") { RPGCore.SetDictionaryValue(_key, (v1_num / v2_num).ToString()); } } else { //不做運算直接給值 RPGCore.SetDictionaryValue(_key, v1); } } //其他 (可刪除,或去補齊方法cs檔): 用括號的參數改用統一regex拆解 foreach (Match match in GetMatch(args, RPGCore.REGEX_FUNC_PARA)) { //方法名稱 string functionName = match.Groups["func"].Value; Debug.Log(functionName); string[] paras = match.Groups["para"].Value.Split(','); //enable /disable if (functionName == "enable") { foreach (string objName in paras) { GameObject target = temp_preparedList.Find(x => x.name.Equals(objName)); if (target != null) { target.SetActive(true); } } } if (functionName == "disable") { foreach (string objName in paras) { GameObject target = temp_preparedList.Find(x => x.name.Equals(objName)); if (target != null) { target.SetActive(false); } } } //**************** YOUR OWN SCRIPT FUNCTION ***************************** //Effect 特效 if (functionName == "effect") { foreach (string effect_name in paras) { if (effect_name == "shake") { //Effecter.cs //StartCoroutine(Effecter.Shake(Wrapper, 5, 10, 0.25f)); Debug.Log("Do SHAKE"); } } } //changeScene(scenetoLoad ) 換場景 if (functionName == "changeScene") { //load場景 string scene_to_load = paras[0]; SceneManager.LoadScene(scene_to_load); } if (functionName == "price") { string _item = paras[0].Trim(); Merchant merchant = FindObjectOfType <Merchant>(); if (_item.Equals("wep")) { RPGCore.SetDictionaryValue("temp_wep_cost", merchant.selling_weapon.cost.ToString()); } else if (_item.Equals("ammo")) { RPGCore.SetDictionaryValue("temp_ammo_cost", merchant.selling_ammo.cost.ToString()); } } //buy(item) if (functionName == "buy") { string bought_item = paras[0]; Debug.Log("BUY " + bought_item); if (bought_item.Equals("hp")) { int _cost = int.Parse(RPGCore.temp_StoryRecord["temp_hp_cost"]); if (ScoreManager.instance.UsePoint(_cost)) { FindObjectOfType <PlayerControl>().Heal(100); } else { RPGCore.temp_StoryRecord["temp_buy_res"] = "0"; } } else if (bought_item.Equals("weapon")) { Debug.Log("BUY weapon"); if (!FindObjectOfType <Merchant>().BuyWeapon()) { RPGCore.temp_StoryRecord["temp_buy_res"] = "0"; } } else if (bought_item.Equals("ammo")) { if (!FindObjectOfType <Merchant>().BuyAmmo()) { RPGCore.temp_StoryRecord["temp_buy_res"] = "0"; } } else if (bought_item.Equals("nextlv")) { FindObjectOfType <Merchant>().NextLv(); } else if (bought_item.Equals("money")) { //int _cost = int.Parse(RPGCore.temp_StoryRecord["temp_money_cost"]); BlackScreenEffect bke = FindObjectOfType <BlackScreenEffect>(); bke.SetMagnitude(bke.mask_magnitude * 2); ScoreManager.instance.AddScore(500); } } } #endregion }