void OnchatBtnClick() { MusicManager.PlaySe("click"); parent = transform.parent; string id = GameFuncs.GetId(parent.transform); int indexs = 0; foreach (var dialog in Resources.LoadAll("Dialogs")) { if (dialog.name.Contains(id) && dialog.name.Contains("chat")) { indexs++; } } Globals.currentDialog = id + "_chat" + Random.Range(1, indexs + 1); GameFuncs.GoToScene("Chat"); }
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; } } }