IEnumerator IShowUI() { yield return(new WaitForSeconds(6)); canvas.SetActive(true); UIManager.ChangeText("waveText", "Battle " + BattleGlobals.currentWave.ToString() + "/" + BattleGlobals.waves.ToString()); //Set set = GameFuncs.FindHiden("setParent"); heroPanel = GameFuncs.FindHiden("heroPanelParent"); skillPanel = GameFuncs.FindHiden("skillPanelParent"); Button setBtn = UIManager.GetButton("setBtn"); setBtn.onClick.AddListener(OnsetBtnClick); //create state(image,hp,mp,cp) for (int i = 0; i < BattleGlobals.selectHeroes.Count; i++) { string hid = BattleGlobals.selectHeroes[i]; string id = "h" + i; GameObject heroObj = BattleFuncs.FindObj(id); Hero hero = heroObj.GetComponent <Hero>(); Transform states = GameObject.Find("States").transform; GameObject state = Instantiate((GameObject)GameFuncs.GetResource("Prefabs/state")); state.transform.SetParent(states); state.transform.Find("Image").GetComponent <Image>().sprite = Resources.Load <Sprite>("Character/Image/" + hid + "_001"); Slider hpSlider = state.transform.Find("hpSlider").GetComponent <Slider>(); Slider mpSlider = state.transform.Find("mpSlider").GetComponent <Slider>(); Slider cpSlider = state.transform.Find("cpSlider").GetComponent <Slider>(); hpSlider.value = (float)hero.currentHp / hero.infos[0]; mpSlider.value = (float)hero.currentMp / hero.infos[1]; cpSlider.value = (float)hero.cp / 100; Text hpText = state.transform.Find("hpText").GetComponent <Text>(); Text mpText = state.transform.Find("mpText").GetComponent <Text>(); Text cpText = state.transform.Find("cpText").GetComponent <Text>(); hpText.text = hero.currentHp.ToString() + "/" + hero.infos[0].ToString(); mpText.text = hero.currentMp.ToString() + "/" + hero.infos[1].ToString(); cpText.text = hero.cp.ToString() + "/100"; hero.hpSlider = hpSlider; hero.mpSlider = mpSlider; hero.cpSlider = cpSlider; hero.hpText = hpText; hero.mpText = mpText; hero.cpText = cpText; } //create heads bar = canvas.transform.Find("Bar"); start = bar.Find("start"); end = bar.Find("end"); CreateHeads(); StartCoroutine(IStartBattle()); }
public virtual void Magic(string sid, Entity other = null) { Skill s = GameFuncs.GetSkill(sid); Hero h = BattleGlobals.currentObj.GetComponent <Hero>(); GameObject effect = Instantiate((GameObject)GameFuncs.GetResource("Effect/" + sid)); Destroy(effect, 2); BattleCamera.Shake(); int cost = s.isCp ? s.cost : s.cost / 5; float ats = s.isCp ? h.infos[4] : (h.infos[2] + h.infos[4]) / 2; float value = cost * ats; if (s.isAoe) { if (BattleGlobals.currentObj.tag == "Hero") { effect.transform.position = Battle.mone.position; List <string> temp = new List <string>(); foreach (string lm in BattleGlobals.liveMonsters) { temp.Add(lm); } for (int i = 0; i < temp.Count; i++) { string es = temp[i]; Enemy en = BattleFuncs.FindObj(es).GetComponent <Enemy>(); en.GetHurt(value, GetRestrict(en, ref value)); } } else if (BattleGlobals.currentObj.tag == "Enemy") { List <string> temp = BattleGlobals.liveHeroes; for (int i = 0; i < temp.Count; i++) { string hs = temp[i]; Hero he = BattleFuncs.FindObj(hs).GetComponent <Hero>(); he.GetHurt(value, GetRestrict(he, ref value)); } } } else { effect.transform.position = other.gameObject.transform.position; other.GetHurt(value, GetRestrict(other, ref value)); } BattleGlobals.currentSid = ""; Invoke("SetTurnOver", 2); }
public static void CreateHeads() { heads.Clear(); foreach (Transform head in bar) { if (!head.gameObject.name.Contains("start") && !head.gameObject.name.Contains("end")) { Destroy(head.gameObject); } } //create new heads for (int i = 0; i < BattleGlobals.liveHeroes.Count; i++) { string id = BattleFuncs.FindObj(BattleGlobals.liveHeroes[i]).GetComponent <Entity>().id; heads.Add(CreateHead(id, true, i)); } for (int i = 0; i < BattleGlobals.monsters[BattleGlobals.currentWave - 1].Count; i++) { string id = BattleGlobals.monsters[BattleGlobals.currentWave - 1][i]; heads.Add(CreateHead(id, false, i)); } }
public void EnterNextWave() { if (BattleGlobals.liveMonsters.Count <= 0)//这波敌人死亡 { BattleGlobals.isStop = true; if (BattleGlobals.currentWave < BattleGlobals.waves)//进入下一波 { BattleGlobals.currentObj = null; BattleGlobals.otherObjs.Clear(); foreach (Transform mp in GameObject.Find("mpoints").transform) { foreach (Transform m in mp) { Destroy(m.gameObject); } } //wave ui BattleGlobals.currentWave++; UIManager.ChangeText("waveText", "Battle " + BattleGlobals.currentWave.ToString() + "/" + BattleGlobals.waves.ToString()); //create monsters Battle.currentMonsters = BattleGlobals.monsters[BattleGlobals.currentWave - 1]; Battle.CreateCurrentEnemy(); BattleUI.CreateHeads(); //is boss if (BattleGlobals.currentWave == BattleGlobals.waves) { BattleGlobals.isStop = true; BattleUI.canvas.SetActive(false); //boss(play boss bgm;hp slider;camera anim) MusicManager.PlayBgm("boss"); BattleCamera.PlayAnim("_boss"); StartCoroutine(DelayToInvoke.DelayToInvokeDo(WaitNotStop, 6)); } else { StartCoroutine(DelayToInvoke.DelayToInvokeDo(WaitNotStop, 0.2f)); } } else//win { BattleGlobals.isOver = true; BattleUI.HideUI(); //if current hero else random(live heroes) -> set win bool true GameObject winObj = null; Hero winHero = null; if (BattleGlobals.currentObj.tag == "Hero") { winObj = BattleGlobals.currentObj; } else { winObj = BattleFuncs.FindObj (BattleGlobals.liveHeroes[Random.Range(0, BattleGlobals.liveHeroes.Count - 1)]); } //camera string winIndex = winObj.transform.parent.gameObject.name [winObj.transform.parent.gameObject.name.Length - 1].ToString(); BattleCamera.SetAnimStop(); BattleCamera.PlayAnim("h" + winIndex); winHero = BattleGlobals.currentObj.GetComponent <Hero>(); winHero.Win(); //show win ui(every select heroes exp++;date(attribute) ++;click->return select map) StartCoroutine(DelayToInvoke.DelayToInvokeDo(WaitShowWin, 4f)); } } if (BattleGlobals.liveHeroes.Count <= 0)//英雄全部死亡,失败 { BattleGlobals.isOver = true; BattleGlobals.isStop = true; BattleUI.HideUI(); //show lose ui(click->return select map) BattleUI.ShowLosePanel(); } }
// Update is called once per frame void Update() { if (!BattleGlobals.isStop && !BattleCamera.anim.isPlaying) { BattleGlobals.canEnterNext = true; BattleGlobals.currentObj = null; BattleGlobals.otherObjs.Clear(); //heads move by speed foreach (GameObject head in heads) { string id = head.name; Entity e = BattleFuncs.FindObj(id).GetComponent <Entity>(); //move head.transform.Translate(Vector3.right * e.infos[5]); head.transform.position = new Vector2(Mathf.Clamp( head.transform.position.x, start.position.x, end.position.x), head.transform.position.y); //turn if (Vector2.Distance(head.transform.position, end.position) <= 1) { BattleGlobals.currentObj = null; BattleGlobals.otherObjs.Clear(); BattleGlobals.isStop = true; BattleGlobals.currentObj = BattleFuncs.FindObj(id); if (BattleGlobals.currentObj.tag == "Enemy") { if (true) { BattleGlobals.isNearAttack = true; //近战 } if (BattleGlobals.liveHeroes.Count > 0) { GameObject ranHero = BattleFuncs.FindObj(BattleGlobals.liveHeroes [Random.Range(0, BattleGlobals.liveHeroes.Count)]); BattleGlobals.otherObjs.Clear(); BattleGlobals.otherObjs.Add(ranHero); } } else if (BattleGlobals.currentObj.tag == "Hero") { if (!BattleGlobals.isOver) { BattleCamera.SetIsStop(); //active hero ui heroPanel.SetActive(true); //Bind heroPanelBtns Button atkBtn = UIManager.GetButton("atkBtn"); Button skillBtn = UIManager.GetButton("skillBtn"); Button defBtn = UIManager.GetButton("defBtn"); atkBtn.onClick.AddListener(OnatkBtnClick); skillBtn.onClick.AddListener(OnskillBtnClick); defBtn.onClick.AddListener(OndefBtnClick); } } head.transform.position = start.position; } } if (heroPanel.activeInHierarchy) { BattleGlobals.isStop = true; } } else//停止时获得当前对象 { if (heroPanel != null && heroPanel.activeInHierarchy && !BattleCamera.anim.isPlaying) { foreach (GameObject head in heads) { string id = head.name; if (!id.Contains("m")) { if (Vector2.Distance(head.transform.position, start.position) <= 1) { BattleGlobals.currentObj = null; BattleGlobals.otherObjs.Clear(); BattleGlobals.currentObj = BattleFuncs.FindObj(id); } } else { BattleFuncs.FindObj(id).GetComponent <Animator>().SetBool("run", false); } } } } }