static void OngetsBtnClick() { MusicManager.PlaySe("click"); gets.SetActive(true); summonGets = GameObject.Find("summonGets"); for (int i = 0; i < Random.Range(0, 11); i++) { Item item = Globals.itemList[Random.Range(0, Globals.itemList.Count)]; bool isGetItem = false; for (int j = 0; j < Globals.items.Count; j++) { if (Globals.items[j].itemId == item.itemId) { isGetItem = true; Globals.items[j].count++; break; } } if (!isGetItem) { Globals.items.Add(item); } GameObject summonGet = GameObject.Instantiate( (GameObject)GameFuncs.GetResource("Prefabs/summonGet"), summonGets.transform); string imagePath = "Icons/" + item.imagePath; summonGet.transform.Find("Image").GetComponent <Image>().sprite = Resources.Load <Sprite>(imagePath); } }
public static void CreateCurrentEnemy() { //Create Enemy for (int i = 0; i < currentMonsters.Count; i++) { //create enemy Enemy e = (Enemy)GameFuncs.GetEntity(currentMonsters[i]); GameObject monster = null; if (currentMonsters.Count > 1) { monster = Instantiate((GameObject)GameFuncs.GetResource ("Prefabs/" + currentMonsters[i]), mpoints[i]); } else { monster = Instantiate((GameObject)GameFuncs.GetResource ("Prefabs/" + currentMonsters[i]), mone); } monster.name = "m" + i; Enemy en = monster.AddComponent <Enemy>(); monster.AddComponent <OnEnemy>(); GameFuncs.CopyEntity(en, currentMonsters[i]); en.anim = monster.GetComponent <Animator>(); en.battleId = monster.name; BattleGlobals.liveMonsters.Add(monster.name); //enemys'ui Transform canvas = monster.transform.Find("Canvas"); canvas.Find("name").GetComponent <Text>().text = e.ename; Image ele = canvas.Find("ele/Image").GetComponent <Image>(); ele.sprite = Resources.Load <Sprite>("Icons/" + e.ele); Slider hpSlider = canvas.Find("hp").GetComponent <Slider>(); hpSlider.value = (float)e.currentHp / e.infos[0]; en.hpSlider = hpSlider; } }
// Use this for initialization void Start() { itemPre = (GameObject)GameFuncs.GetResource("Prefabs/item"); items = GameObject.Find("Items"); panel = GameObject.Find("Panel"); //Create Items for (int i = 0; i < Globals.items.Count; i++) { int j = i / 6; Item it = Globals.items[i]; string iname = it.iname; string imagePath = "Icons/" + it.imagePath; int count = it.count; string info = it.info; GameObject item = GameObject.Instantiate(itemPre); item.transform.SetParent(items.transform); itemList.Add(item); //values item.transform.Find("Image").GetComponent <Image>().sprite = Resources.Load <Sprite>(imagePath); item.transform.Find("Text").GetComponent <Text>().text = count.ToString(); //Set info GameObject infoObj = item.transform.Find("info").gameObject; infoObj.name = i.ToString(); infoObj.transform.SetParent(panel.transform); infoObj.GetComponent <RectTransform>().position = new Vector2( item.GetComponent <RectTransform>().position.x + 245.4f + 135 * i, item.GetComponent <RectTransform>().position.y + 524 - 135 * j); infos.Add(infoObj); //Bind Btn item.GetComponent <Button>().onClick.AddListener(() => { OnitemClick(item, "<color=yellow>" + iname + "</color>\n" + info, infoObj); }); } }
public virtual void GetHurt(float value, int restrict = 0) { //create damage in Canvas MusicManager.PlaySe("hit"); Transform canvas = transform.Find("Canvas"); GameObject damage = Instantiate((GameObject)GameFuncs.GetResource("Prefabs/damage"), canvas); Text dt = damage.GetComponent <Text>(); dt.text = "-" + (int)value; switch (restrict) { case 1: dt.color = Color.yellow; break; case -1: dt.color = Color.blue; break; default: dt.color = Color.white; break; } currentHp -= Mathf.RoundToInt(value); if (currentHp <= 0) { currentHp = 0; //Die Die(); } hpSlider.value = (float)currentHp / infos[0]; }
public static void CreateCharacter(Transform point, string modelPath) { GameObject selectCharacter = GameFuncs.FindHiden("selectCharacterParent"); //Instantiate Model GameObject pre = (GameObject)GameFuncs.GetResource(modelPath); GameObject obj = GameObject.Instantiate(pre); obj.transform.position = point.transform.position; //MusicManager.PlaySe("click"); if (point.name == "point1") { obj.transform.SetParent(point.transform); } else if (point.name == "point2") { obj.transform.Rotate(Vector3.up * 90); obj.transform.SetParent(point.transform); } obj.AddComponent <OnModel>(); //Destroy selectCharacter Transform grid = selectCharacter.transform.Find("grid"); foreach (Transform child in grid) { Destroy(child.gameObject); } //Active False selectCharacter.SetActive(false); }
/// <summary> /// change image's sprite /// </summary> /// <param name="name"></param> /// <param name="path"></param> public static void ChangeRawImage(string name, string path) { RawImage image = GetRawImage(name); Texture2D texture = (Texture2D)GameFuncs.GetResource(path); image.texture = texture; }
public void CreateOptions(int count) { GameObject optionPre = GameFuncs.GetResource("Prefabs/option") as GameObject; for (int i = 0; i < count; i++) { GameObject optionObj = GameObject.Instantiate(optionPre); optionObj.transform.SetParent(options.transform); } }
public static void PlayBgm(string bgm) { AudioSource audio = GameObject.Find("bgm").GetComponent <AudioSource>(); audio.loop = true; AudioClip ac = (AudioClip)GameFuncs.GetResource("Music/Bgm/" + bgm); audio.clip = ac; audio.Play(); SetVolume(); }
public static void PlayVoice(string voice) { AudioSource audio = GameObject.Find("voice").GetComponent <AudioSource>(); audio.loop = false; AudioClip ac = (AudioClip)GameFuncs.GetResource("Music/Voice/" + voice); audio.clip = ac; audio.Play(); SetVolume(); }
// Use this for initialization void Start() { summonGetPre = (GameObject)GameFuncs.GetResource("Prefabs/summonGet"); gets = GameFuncs.FindHiden("GetsParent"); oneBtn = UIManager.GetButton("oneBtn"); tenBtn = UIManager.GetButton("tenBtn"); oneBtn.onClick.AddListener(OnoneBtnClick); tenBtn.onClick.AddListener(OntenBtnClick); UIManager.ChangeText("goldText", Globals.player.gold.ToString()); UIManager.ChangeText("diaText", Globals.player.dia.ToString()); }
void OndressBtnClick(string modelPath) { MusicManager.PlaySe("click"); Transform point = GameObject.Find("point").transform; if (point.childCount > 0) { Destroy(point.GetChild(0).gameObject); } GameObject hero = Instantiate((GameObject)GameFuncs.GetResource(modelPath), point); hero.AddComponent <OnHeroInfoModel>(); }
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()); }
void OnchangeHeadBtnClick() { if (!changeHeadImage.activeInHierarchy) { changeHeadImage.SetActive(true); headImageGrid = changeHeadImage.transform.Find("headImages/headImageGrid"); //create headImage string path = "0"; foreach (var item in Resources.LoadAll <Sprite>("HeadImage")) { GameObject headImage = Instantiate((GameObject)GameFuncs.GetResource("Prefabs/HeadImage")); headImage.transform.SetParent(headImageGrid); headImage.transform.Find("Image").GetComponent <Image>().sprite = item; Toggle t = headImage.GetComponent <Toggle>(); t.onValueChanged.AddListener((bool isOn) => { if (t.isOn) { path = headImage.transform.Find("Image").GetComponent <Image>().sprite.name; } }); t.group = headImageGrid.GetComponent <ToggleGroup>(); if (Globals.player.headImagePath == item.name) { t.isOn = true; } } UIManager.GetButton("okHeadImageBtn").onClick.AddListener(() => { Globals.player.headImagePath = path; UIManager.ChangeImage("headImage", "HeadImage/" + path); foreach (Transform hi in headImageGrid) { Destroy(hi.gameObject); } changeHeadImage.SetActive(false); if (changeName.activeInHierarchy) { changeName.SetActive(false); } if (changeSex.activeInHierarchy) { changeSex.SetActive(false); } if (headMenu.activeInHierarchy) { headMenu.SetActive(false); } }); } }
//timer to auto slide // Use this for initialization void Start() { switch (SceneManager.GetActiveScene().name) { case "Main": num = 4; boardImages = Resources.LoadAll <Sprite>("Background"); boardTexts = new string[] { "Battle", "Heroes", "Room", "Summon" }; break; case "Summon": num = 3; boardImages = Resources.LoadAll <Sprite>("Summon"); boardTexts = new string[num]; break; default: break; } boardBtns = transform.Find("boardBtns"); sr = GetComponent <ScrollRect>(); boardToggles = transform.Find("boardToggles"); width = boardBtns.GetComponent <RectTransform>().sizeDelta.x; height = boardBtns.GetComponent <RectTransform>().sizeDelta.y; posX = width / 2; boardBtns.GetComponent <RectTransform>().anchoredPosition = new Vector2(posX * (num - 1), 0); boardBtns.GetComponent <RectTransform>().sizeDelta = new Vector2(width * num, boardBtns.GetComponent <RectTransform>().rect.height); //instantiate btns and toggles for (int i = 0; i < num; i++) { //btns GameObject boardBtn = Instantiate((GameObject)GameFuncs.GetResource("Prefabs/boardBtn")); boardBtn.GetComponent <RectTransform>().sizeDelta = new Vector2(width, height); boardBtn.transform.SetParent(boardBtns); boardBtn.GetComponent <Image>().sprite = boardImages[i]; boardBtn.GetComponentInChildren <Text>().text = boardTexts[i]; boardBtn.GetComponent <Button>().onClick.AddListener(() => { OnboardBtnClick(boardBtn.GetComponentInChildren <Text>().text); }); //toggles GameObject boardToggle = Instantiate((GameObject)GameFuncs.GetResource("Prefabs/boardToggle")); boardToggle.transform.SetParent(boardToggles); Toggle bt = boardToggle.GetComponent <Toggle>(); bt.group = boardToggles.GetComponent <ToggleGroup>(); if (i == 0) { bt.isOn = true; } bt.onValueChanged.AddListener((bool isOn) => { OnboardToggleClick(isOn, bt); }); toggles[i] = bt; } }
public static void LoadDialogs(string path) { Globals.dialogs = new List <Dialog>(); Globals.dialogs.Clear(); string context = GameFuncs.GetResource("Dialogs/" + path).ToString(); string[] dialogs = context.Split('#'); for (int i = 0; i < dialogs.Length; i++) { string d = dialogs[i]; Dialog dialog = new Dialog(d); Globals.dialogs.Add(dialog); } }
// Use this for initialization void Start() { BattleFuncs.ResetBattle(); BattleGlobals.monsters = JsonFuncs.LoadEnemys(BattleGlobals.placeName); MusicManager.PlayBgm("battle"); MusicManager.SetVolume(); //Load Infos string place = BattleGlobals.placeName; BattleGlobals.currentWave = 1; currentMonsters = BattleGlobals.monsters[BattleGlobals.currentWave - 1]; RenderSettings.skybox = (Material)GameFuncs.GetResource("SkyBox/" + place); GameFuncs.FindHiden(place + "Parent").SetActive(true); //Load Transforms BattleGlobals.hpoints = GameObject.Find("hpoints").transform; BattleGlobals.mpoints = GameObject.Find("mpoints").transform; foreach (Transform t in BattleGlobals.hpoints) { hpoints.Add(t); } foreach (Transform t in BattleGlobals.mpoints) { if (!t.gameObject.name.Contains("one")) { mpoints.Add(t); } else { mone = t; } } //Create Hero for (int i = 0; i < BattleGlobals.selectHeroes.Count; i++) { //create hero GameObject hero = Instantiate((GameObject)GameFuncs.GetResource ("Prefabs/" + BattleGlobals.selectHeroes[i]), hpoints[i]); Hero h = hero.AddComponent <Hero>(); GameFuncs.CopyHero(h, BattleGlobals.selectHeroes[i]); h.anim = hero.GetComponent <Animator>(); h.currentMp = h.infos[1]; h.cp = 100; hero.name = "h" + i; h.battleId = hero.name; BattleGlobals.liveHeroes.Add(hero.name); } CreateCurrentEnemy(); }
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 GameObject CreateHead(string id, bool isHero, int index) { Sprite sprite = Resources.Load <Sprite>("Character/Portrait/" + id); GameObject head = Instantiate((GameObject)GameFuncs.GetResource("Prefabs/head"), bar); head.transform.Find("Image").GetComponent <Image>().sprite = sprite; if (isHero) { head.name = "h" + index; } else { head.name = "m" + index; } return(head); }
void OnskillBtnClick() { MusicManager.PlaySe("click"); //show skill panel skillPanel.SetActive(true); Transform panel = skillPanel.transform; Button closeSkillBtn = UIManager.GetButton("closeSkillBtn"); closeSkillBtn.onClick.AddListener(() => { OncloseSkillBtn(panel); }); Button okSkillBtn = UIManager.GetButton("okSkillBtn"); okSkillBtn.onClick.AddListener(() => { OnokSkillBtn(panel); }); //create skill list Hero currentHero = BattleGlobals.currentObj.GetComponent <Hero>(); List <Skill> skills = currentHero.skills; for (int i = 0; i < skills.Count; i++) { Skill s = skills[i]; if (s.ele == currentHero.ele) { Transform grid = panel.Find("list/grid"); Text infoText = panel.Find("infoText").GetComponent <Text>(); GameObject skill = Instantiate((GameObject)GameFuncs.GetResource("Prefabs/skill")); skill.transform.SetParent(grid); skill.transform.Find("ele").GetComponent <Image>().sprite = Resources.Load <Sprite>("Icons/" + s.ele); skill.transform.Find("name").GetComponent <Text>().text = s.sname; if (s.isCp) { skill.transform.Find("cost").GetComponent <Text>().text = s.cost.ToString() + "cp"; } else { skill.transform.Find("cost").GetComponent <Text>().text = s.cost.ToString() + "mp"; } Toggle st = skill.GetComponent <Toggle>(); st.group = grid.GetComponent <ToggleGroup>(); string info = s.info + "\n" + (s.isAoe ? "群体" : "单体"); st.onValueChanged.AddListener((bool isOn) => { OnskillToggleClick(st, isOn, infoText, s, grid); }); } } for (int i = skills.Count; i < panel.Find("list/grid").childCount; i++) { Destroy(panel.Find("list/grid").GetChild(i).gameObject); } }
// Use this for initialization void Start() { GameObject storyBtnPre = (GameObject)GameFuncs.GetResource("Prefabs/storyBtn"); Button closeStoryBtn = UIManager.GetButton("closeStoryBtn"); Transform storyList = transform.Find("storyList"); storyGrid = storyList.Find("storyGrid"); closeStoryBtn.onClick.AddListener(OncloseStoryBtnClick); //Load StoryBtns for (int i = 0; i < RoomGlobals.storyInfos.Count; i++) { StoryInfo si = RoomGlobals.storyInfos[i]; string path = si.storyPath; string id = path.Substring(0, 3); if (id == RoomGlobals.currentId) { storyCount++; GameObject story = GameObject.Instantiate(storyBtnPre); story.transform.SetParent(storyGrid); storys.Add(story); story.transform.Find("Text").GetComponent <Text>().text = si.storyName; story.GetComponent <Button>().onClick.AddListener(() => { OnstoryBtnClick(path); }); //for i<lv,if(si.storyName[last]<=lv) interactable=true; story.GetComponent <Button>().interactable = !si.isLocked; for (int j = 0; j < RoomGlobals.loveDic[RoomGlobals.currentId].lv; j++) { if (int.Parse(si.storyName[si.storyName.Length - 1].ToString()) <= RoomGlobals.loveDic[RoomGlobals.currentId].lv) { story.GetComponent <Button>().interactable = true; } } } } for (int i = 0; i < storyGrid.childCount; i++) { if (i >= storyCount) { Destroy(storyGrid.GetChild(i).gameObject); } } }
// Use this for initialization void Start() { heroPre = (GameObject)GameFuncs.GetResource("Prefabs/hero"); Transform selectGrid = GameObject.Find("selectGrid").transform; Transform heroes = GameObject.Find("heroes").transform; //Load selectToggles selectToggles = selectGrid.GetComponentsInChildren <Toggle>(false); foreach (Toggle t in selectToggles) { t.onValueChanged.AddListener((bool isOn) => { OnselectToggleClick(t, isOn); }); } currentToggle = selectToggles[0]; //Load eleToggles Toggle[] eleToggles = heroes.GetComponentsInChildren <Toggle>(false); foreach (Toggle t in eleToggles) { t.onValueChanged.AddListener((bool isOn) => { OneleToggleClick(t, isOn); }); } //Show All Heroes foreach (Toggle t in eleToggles) { string eleName = t.gameObject.name.Replace("Toggle", ""); string panelParentName = eleName + "PanelParent"; GameObject panel = GameFuncs.FindHiden(panelParentName); Transform grid = panel.transform.Find(eleName + "Grid"); ShowHeroes(eleName, grid); grids.Add(grid); } UIManager.ChangeText("energyText", Globals.player.energy.ToString() + "/" + Globals.player.maxEnergy); UIManager.ChangeSlider("energySlider", (float)Globals.player.energy / Globals.player.maxEnergy); Button goBtn = UIManager.GetButton("goBtn"); goBtn.onClick.AddListener(OngoBtnClick); Button backBtn = UIManager.GetButton("backBtn"); backBtn.onClick.AddListener(() => { GameFuncs.GoToScene("SelectBattleMap"); }); }
void OnpointBtn(string btnName) { MusicManager.PlaySe("click"); GameObject point = GameObject.Find(btnName.Replace("Btn", "")); if (point.transform.childCount == 0)//Add Chracter(Select UI->Instantiate) { if (!selectCharacter.activeInHierarchy) { selectCharacter.SetActive(true); //Create Characters Transform grid = selectCharacter.transform.Find("grid"); for (int i = 0; i < Globals.heroes.Count; i++) { if (!RoomFuncs.FindModel(Globals.heroes[i].id)) { GameObject character_roomSelect = GameObject.Instantiate( (GameObject)GameFuncs.GetResource("Prefabs/character_roomSelect"), grid); string modelPath = "Prefabs/" + Globals.heroes[i].id; string imagePath = "Character/Portrait/" + Globals.heroes[i].id; Image image = character_roomSelect.transform.Find("Image").GetComponent <Image>(); image.sprite = Resources.Load <Sprite>(imagePath); Button character_roomSelectBtn = character_roomSelect.GetComponent <Button>(); character_roomSelectBtn.onClick.AddListener(() => { Oncharacter_roomSelectBtnClick(point.transform, modelPath, btnName); }); } } } else { Transform grid = selectCharacter.transform.Find("grid"); foreach (Transform child in grid) { Destroy(child.gameObject); } selectCharacter.SetActive(false); } } }
// Use this for initialization void Start() { Button closeGiftBtn = UIManager.GetButton("closeGiftBtn"); Transform giftList = transform.Find("giftList"); giftGrid = giftList.Find("giftGrid"); Button giftBtn = UIManager.GetButton("giftBtn"); closeGiftBtn.onClick.AddListener(OncloseGiftBtnClick); giftBtn.onClick.AddListener(OngiftBtn); //Load Gifts GameObject giftPre = (GameObject)GameFuncs.GetResource("Prefabs/gift"); for (int i = 0; i < Globals.items.Count; i++) { int j = i / 3; Item it = Globals.items[i]; if (it.itag == 1)//is gift { giftCount++; string imagePath = "Icons/" + it.imagePath; int count = it.count; GameObject item = GameObject.Instantiate(giftPre); item.transform.SetParent(giftGrid.transform); giftsList.Add(item); //values item.transform.Find("Image").GetComponent <Image>().sprite = Resources.Load <Sprite>(imagePath); item.transform.Find("Text").GetComponent <Text>().text = count.ToString(); item.GetComponent <Toggle>().group = giftGrid.GetComponent <ToggleGroup>(); } } for (int i = 0; i < giftGrid.childCount; i++) { if (i >= giftCount) { Destroy(giftGrid.GetChild(i).gameObject); } } }
void Start() { heroPre = (GameObject)GameFuncs.GetResource("Prefabs/hero"); //Load eleToggles Toggle[] toggles = GameObject.FindObjectsOfType <Toggle>(); foreach (Toggle t in toggles) { t.onValueChanged.AddListener((bool isOn) => { OneleToggleClick(t, isOn); }); } //Items int upItemCount = 0; int breakItemCount = 0; for (int i = 0; i < Globals.items.Count; i++) { if (Globals.items[i].itemId == "001")//合成剂 { upItemCount = Globals.items[i].count; } if (Globals.items[i].itemId == "003")//突破晶石 { breakItemCount = Globals.items[i].count; } } UIManager.ChangeText("upItemText", upItemCount.ToString()); UIManager.ChangeText("breakItemText", breakItemCount.ToString()); UIManager.ChangeText("goldText", Globals.player.gold.ToString()); HeroGlobals.upItemCount = upItemCount; HeroGlobals.breakItemCount = breakItemCount; //Show All Heroes foreach (Toggle t in toggles) { string eleName = t.gameObject.name.Replace("Toggle", ""); string panelParentName = eleName + "PanelParent"; GameObject panel = GameFuncs.FindHiden(panelParentName); Transform grid = panel.transform.Find(eleName + "Grid"); ShowHeroes(eleName, grid); } }
void CreateSkill(Skill s) { GameObject skill = Instantiate((GameObject)GameFuncs.GetResource("Prefabs/skill")); skill.transform.SetParent(skillGrid); skill.transform.Find("ele").GetComponent <Image>().sprite = Resources.Load <Sprite>("Icons/" + s.ele); skill.transform.Find("name").GetComponent <Text>().text = s.sname; if (s.isCp) { skill.transform.Find("cost").GetComponent <Text>().text = s.cost.ToString() + "cp"; } else { skill.transform.Find("cost").GetComponent <Text>().text = s.cost.ToString() + "mp"; } Toggle st = skill.GetComponent <Toggle>(); st.group = skillGrid.GetComponent <ToggleGroup>(); string info = s.info + "\n" + (s.isAoe ? "群体" : "单体"); st.onValueChanged.AddListener((bool isOn) => { OnskillToggleClick(st, isOn, infoText, info, skillGrid); }); }
public static void ShowWinPanel() { //BattleGlobals.selectHeroes.Clear(); //foreach (Transform t in Battle.hpoints) //{ // foreach (Transform h in t) // { // string hid = h.gameObject.name.Substring(0, 3); // BattleGlobals.selectHeroes.Add(hid); // } //} winPanel.SetActive(true); tip.SetActive(true); getsBtn.SetActive(true); Transform win = winPanel.transform; winPanel.GetComponent <Button>().onClick.AddListener(() => { GameFuncs.GoToSceneAsync("Main"); }); Transform grid = win.Find("winGrid"); //gets getsBtn.GetComponent <Button>().onClick.AddListener(OngetsBtnClick); //create heroWin for (int i = 0; i < Globals.heroes.Count; i++) { string id = Globals.heroes[i].id; if (BattleGlobals.selectHeroes.Contains(id)) { Hero h = Globals.heroes[i]; GameObject winHero = Instantiate((GameObject)GameFuncs.GetResource("Prefabs/heroWin")); winHero.transform.SetParent(grid); winHero.GetComponent <Image>().sprite = Resources.Load <Sprite>("Character/Portrait/" + id); winHero.transform.Find("name").GetComponent <Text>().text = h.ename; Slider expSlider = winHero.transform.Find("expSlider").GetComponent <Slider>(); Text lvText = winHero.transform.Find("lvImage/lvText").GetComponent <Text>(); Slider loveSlider = winHero.transform.Find("loveSlider").GetComponent <Slider>(); //exp h.exps[1] += 10; if (h.exps[1] >= h.exps[2])//lv up { h.exps[0]++; for (int j = 0; j < h.infos.Length; j++) { h.infos[j] += (h.exps[0] - 1) * 10; } h.exps[1] -= h.exps[2]; h.exps[2] += (h.exps[0] - 1) * 100; //add skill foreach (Skill s in Globals.skillList) { if (!s.isCp && s.ele == h.ele && s.lv <= h.exps[0])//学会 { h.skills.Add(s); h.skills.Sort(); } } } expSlider.value = (float)h.exps[1] / h.exps[2]; lvText.text = h.exps[0].ToString(); //love h.li.love++; if (h.li.love >= h.li.maxLove) { h.li.lv++; h.li.love -= h.li.maxLove; } loveSlider.value = (float)h.li.love / h.li.maxLove; loveSlider.transform.Find("loveText").GetComponent <Text>().text = h.li.love.ToString() + "/" + h.li.maxLove.ToString(); loveSlider.transform.Find("Icon/lvText").GetComponent <Text>().text = h.li.lv.ToString(); } } BattleGlobals.selectHeroes.Clear(); }
// Use this for initialization void Start() { //Load Hero string id = HeroGlobals.currentid; for (int i = 0; i < Globals.heroes.Count; i++) { if (Globals.heroes[i].id == id) { currentHero = Globals.heroes[i]; } } Transform point = GameObject.Find("point").transform; GameObject hero = Instantiate((GameObject)GameFuncs.GetResource("Prefabs/" + id), point); hero.AddComponent <OnHeroInfoModel>(); hero.GetComponent <Rigidbody>().useGravity = false; //Load Toggle Toggle[] toggles = GameObject.FindObjectsOfType <Toggle>(); foreach (Toggle t in toggles) { t.onValueChanged.AddListener((bool isOn) => { OninfoToggleClick(t, isOn); }); } foreach (Toggle t in toggles) { string infoName = t.gameObject.name.Replace("Toggle", ""); string panelParentName = infoName + "PanelParent"; panel = GameFuncs.FindHiden(panelParentName).transform; //Load All if (infoName == "all") { ShowAll(panel); //Bind Btns Button upBtn = UIManager.GetButton("upBtn"); Button breakBtn = UIManager.GetButton("breakBtn"); upBtn.onClick.AddListener(() => { MusicManager.PlaySe("click"); if (Globals.player.gold >= 100) { if (HeroGlobals.upItemCount > 0) { //values currentHero.exps[1] += 10; HeroGlobals.upItemCount--; Globals.player.gold -= 100; for (int i = 0; i < Globals.items.Count; i++) { if (Globals.items[i].itemId == "001")//合成剂 { Globals.items[i].count = HeroGlobals.upItemCount; } } if (currentHero.exps[1] >= currentHero.exps[2])//lv up { currentHero.exps[0]++; for (int i = 0; i < currentHero.infos.Length; i++) { currentHero.infos[i] += (currentHero.exps[0] - 1) * 1; } currentHero.exps[1] -= currentHero.exps[2]; currentHero.exps[2] += (currentHero.exps[0] - 1) * 100; } ShowAll(panel); } else { GameFuncs.CreateMsg("合成剂不足!"); } } else { GameFuncs.CreateMsg("金币不足!"); } }); breakBtn.onClick.AddListener(() => { MusicManager.PlaySe("click"); if (Globals.player.gold >= 1000) { if (HeroGlobals.breakItemCount > 0) { //values currentHero.exps[0]++; for (int i = 0; i < currentHero.infos.Length; i++) { currentHero.infos[i] += (currentHero.exps[0] - 1) * 1; } HeroGlobals.breakItemCount--; for (int i = 0; i < Globals.items.Count; i++) { if (Globals.items[i].itemId == "003")//突破晶石 { Globals.items[i].count = HeroGlobals.breakItemCount; } } Globals.player.gold -= 1000; currentHero.exps[1] = 0; currentHero.exps[2] += (currentHero.exps[0] - 1) * 100; //add skill foreach (Skill s in Globals.skillList) { if (!currentHero.skills.Contains(s)) { if (!s.isCp && s.ele == currentHero.ele && s.lv <= currentHero.exps[0]) //学会 { currentHero.skills.Add(s); currentHero.skills.Sort(); GameFuncs.CreateMsg("学会[" + s.sname + "]技能!"); CreateSkill(s); } } } ShowAll(panel); } else { GameFuncs.CreateMsg("突破晶石不足!"); } } else { GameFuncs.CreateMsg("金币不足!"); } }); } //Load Skill else if (infoName == "skill") { skillGrid = panel.Find("list/grid"); infoText = panel.Find("infoText").GetComponent <Text>(); List <Skill> skills = currentHero.skills; skills.Sort(); //skills.Add(currentHero.superSkill); for (int i = 0; i < skills.Count; i++) { Skill s = skills[i]; CreateSkill(s); } } //Load Dresses else if (infoName == "dress") { Image image = panel.Find("Image").GetComponent <Image>(); Text text = panel.Find("Text").GetComponent <Text>(); Button imageBtn = panel.Find("Image").GetComponent <Button>(); Button nextBtn = panel.Find("nextBtn").GetComponent <Button>(); nextBtn.interactable = dressIndex < currentHero.dresses.Count - 1 ? true : false; Button preBtn = panel.Find("preBtn").GetComponent <Button>(); preBtn.interactable = dressIndex > 0 ? true : false; nextBtn.onClick.AddListener(() => { MusicManager.PlaySe("click"); if (dressIndex < currentHero.dresses.Count - 1) { dressIndex++; } }); nextBtn.onClick.AddListener(() => { MusicManager.PlaySe("click"); if (dressIndex > 0) { dressIndex--; } }); image.sprite = Resources.Load <Sprite>("Character/Portrait/" + currentHero.dresses[0].imagePath); text.text = currentHero.dresses[0].dname; imageBtn.onClick.AddListener(() => { OndressBtnClick("Prefabs/" + currentHero.dresses[0].modelPath); }); } } Button setHeadBtn = UIManager.GetButton("setHeadBtn");//弹出对话框 setHeadBtn.onClick.AddListener(() => { MusicManager.PlaySe("click"); GameFuncs.CreateMsg("设为首席成功!"); Globals.player.characterId = currentHero.id; }); Button backBtn = UIManager.GetButton("backBtn"); backBtn.onClick.AddListener(() => { GameFuncs.GoToScene("Heroes"); }); }
void OnchangeBtnClick() { MusicManager.PlaySe("click"); if (selectCharacter.activeInHierarchy == false) { selectCharacter.SetActive(true); grid = selectCharacter.transform.Find("grid"); UIManager.GetButton("closeChangeBtn").onClick.AddListener(() => { MusicManager.PlaySe("click"); foreach (Transform t in grid) { Destroy(t.gameObject); } selectCharacter.SetActive(false); }); //Create Characters foreach (Transform child in grid) { Destroy(child.gameObject); } for (int i = 0; i < Globals.heroes.Count; i++) { if (!RoomFuncs.FindModel(Globals.heroes[i].id) && (RoomGlobals.point1.transform.childCount == 0 || RoomGlobals.point2.transform.childCount == 0)) //替换没有在房间内的 { bool canCreate = true; foreach (Transform child in grid) { if (child.Find("Image").GetComponent <Image>().sprite.name.Contains(Globals.heroes[i].id)) { canCreate = false; break; } } if (canCreate) { GameObject character_roomSelect = GameObject.Instantiate( (GameObject)GameFuncs.GetResource("Prefabs/character_roomSelect"), grid); string modelPath = "Prefabs/" + Globals.heroes[i].id; string imagePath = "Character/Portrait/" + Globals.heroes[i].id; Image image = character_roomSelect.transform.Find("Image").GetComponent <Image>(); image.sprite = Resources.Load <Sprite>(imagePath); Button character_roomSelectBtn = character_roomSelect.GetComponent <Button>(); character_roomSelectBtn.onClick.AddListener(() => { Oncharacter_roomSelectBtnClick(parent, modelPath); }); if (RoomGlobals.roomInfos.ContainsKey(parent.gameObject.name)) { RoomGlobals.roomInfos[parent.gameObject.name] = modelPath; } if (!RoomGlobals.loveDic.ContainsKey(Globals.heroes[i].id)) { RoomGlobals.loveDic.Add(Globals.heroes[i].id, new LoveInfo(1, 0)); } } } else if (RoomFuncs.FindModel(Globals.heroes[i].id) && (RoomGlobals.point1.transform.childCount > 0 && RoomGlobals.point2.transform.childCount > 0))//交换在房间内的 { parent = GameFuncs.GetParent(RoomGlobals.currentId, GameObject.Find("Points").transform); string id = ""; //对方的id Transform p = null; //对方的point string modelPath1 = "Prefabs/" + GameFuncs.GetId(parent.transform); if (parent.name == "point1") { id = GameFuncs.GetId(RoomGlobals.point2.transform); p = RoomGlobals.point2.transform; } else if (parent.name == "point2") { id = GameFuncs.GetId(RoomGlobals.point1.transform); p = RoomGlobals.point1.transform; } GameObject character_roomSelect = GameObject.Instantiate( (GameObject)GameFuncs.GetResource("Prefabs/character_roomSelect"), grid); string modelPath2 = "Prefabs/" + id; string imagePath = "Character/Portrait/" + id; Image image = character_roomSelect.transform.Find("Image").GetComponent <Image>(); image.sprite = Resources.Load <Sprite>(imagePath); Button character_roomSelectBtn = character_roomSelect.GetComponent <Button>(); character_roomSelectBtn.onClick.AddListener(() => { OnExchangeCharacter(parent, modelPath1, p, modelPath2); }); if (RoomGlobals.roomInfos.ContainsKey(p.gameObject.name)) { RoomGlobals.roomInfos[p.gameObject.name] = modelPath1; } if (RoomGlobals.roomInfos.ContainsKey(parent.gameObject.name)) { RoomGlobals.roomInfos[parent.gameObject.name] = modelPath2; } } } //如果是自身或重复就销毁 if (RoomGlobals.isDestroy) { for (int i = 0; i < grid.childCount; i++) { if (i >= Globals.heroes.Count - 1) { Destroy(grid.GetChild(i).gameObject); } } RoomGlobals.isDestroy = false; } } }