public void OnShow() { //data ServantData data = ServantManager.getInstace().getData(); UIList list = transform.Find("Group_ServantSelect/ScrollView/Viewport/Content").GetComponent <UIList>(); list.DrawList(data.nameToServant.Count, (index, listItem) => { Servant servant = data.nameToServant[index]; listItem.transform.Find("UIButton").GetComponent <Button>().onClick.AddListener(() => { GameObject uiDialogShop = UIManager.getInstace().ShowDialog("DlgShop"); uiDialogShop.GetComponent <DlgShop>().OnShow(servant.servantEName); }); listItem.transform.Find("UIText").GetComponent <Text>().text = servant.servantEName; }); }
static Global() { GameObject go = GameObject.Find("DontDestroyOnLoad"); DontDestroyOnLoad(go); Instace = go.AddComponent <Global>(); //Init Managers //uimanager always is the last one managers = new List <IManager>(); managers.Add(AudioManager.getInstace()); managers.Add(ResourceManager.getInstace()); managers.Add(ConfigManager.getInstace()); managers.Add(ServantManager.getInstace()); managers.Add(UIManager.getInstace()); foreach (var manager in managers) { manager.Init(); } }
public void OnShow(string servantEName) { //animation needUpdate = false; //data servant = ServantManager.getInstace().getData().getServant(servantEName); data = servant.voiceData; List <ServantVoice> voices = data.getServantVoice(); servantStage = 1; currMode = 1; currTheme = 0; //ui reinit RectTran_ServantImage.anchorMin = initAnchor; RectTran_ServantImage.anchorMax = initAnchor; Image_ServantImage.sprite = servant.getDefaultExpression(servantStage); Transform_ServantExpression.localPosition = servant.expressionLocation1; SetExpression(Image_ServantExpression, null); //刑部姬戴帽子 造型 stage1 x-2.1 y103 // stage2 x-3.55 y102.1 // -2.09 109.9 servantWord_Narrow.gameObject.SetActive(false); servantWord_Wide.gameObject.SetActive(false); //右边的界面的显隐也要控制 //bg and bgm Group_Bg.GetComponent <Image>().sprite = ResourceManager.getInstace().getBGSprite(servant.BGSprite); BGMPlayer = Group_Bg.GetComponent <AudioSource>(); BGMPlayer.clip = ResourceManager.getInstace().getBGM(servant.BGM); BGMPlayer.Play(); //playVoice action PlayVoice = voice => { //模仿对话界面 如果当前正在播放语音 那么关闭语音。如果没有播放语音则播放 //想这两种对话框 其实应该提取出来 作为一个view的 不应该绑定在具体哪一个界面上 if (isPlayingVoice()) { ForceCloseVoice(); return; } VoicePlayer = AudioManager.getInstace().Play2DSound(servantEName, voice.getVoiceId(), () => { if (currMode != 2) { servantWord_Narrow.gameObject.SetActive(true); Text_Speaker_Narrow.text = voice.getServantName(); Text_Content_Narrow.text = voice.getVoiceContent(); } else { servantWord_Wide.gameObject.SetActive(true); Text_Speaker_Wide.text = voice.getServantName(); Text_Content_Wide.text = voice.getVoiceContent(); } }, () => { SetExpression(Image_ServantExpression, null); if (currMode != 2) { servantWord_Narrow.gameObject.SetActive(false); } else { servantWord_Wide.gameObject.SetActive(false); } } ); Dictionary <float, string> timeToExpression = voice.getTimeToExpression(); foreach (KeyValuePair <float, string> entry in timeToExpression) { if (entry.Key >= VoicePlayer.length - 0.1f || entry.Key <= 0) { continue; } IEnumerator expressionCoroutine = ShowExpression(entry.Key, entry.Value); StartCoroutine(expressionCoroutine); } // IEnumerator expressionEndCoroutine = ShowExpression(VoicePlayer.length, null); // StartCoroutine(expressionEndCoroutine); }; Button_ServantImage.onClick.RemoveAllListeners(); Button_ServantImage.onClick.AddListener(() => { int index = UnityEngine.Random.Range(0, voices.Count); ServantVoice voice = voices[index]; // ServantVoice voice; // while (true) // { // voice = voices[index]; // if (voice.getVoiceType() == 2 || voice.getVoiceType() == 3) // { // break; // } // } PlayVoice.Invoke(voice); }); //右边 Transform Tran_DropdownVoiceType = Group_ServantVoice.Find("Dropdown_VoiceType"); Transform Tran_Content = Group_ServantVoice.Find("ScrollView/Viewport/Content"); Dropdown dropDown = Tran_DropdownVoiceType.GetComponent <Dropdown>(); dropDown.ClearOptions(); List <Dropdown.OptionData> temp = new List <Dropdown.OptionData>(); // foreach (int type in Enum.GetValues(typeof(CommonEnum.VoiceType))) // { // // } temp.Add(new Dropdown.OptionData("战斗")); temp.Add(new Dropdown.OptionData("召唤与强化")); temp.Add(new Dropdown.OptionData("个人空间")); temp.Add(new Dropdown.OptionData("活动")); dropDown.options = temp; dropDown.onValueChanged.AddListener(index => { List <ServantVoice> typeVoices = data.getVoicesByType(index); Tran_Content.GetComponent <UIList>().DrawList(typeVoices.Count, (btnindex, obj) => { ServantVoice voice = typeVoices[btnindex]; obj.GetComponent <UIItem>().DrawItem(voice.getVoiceTitle(), () => { PlayVoice.Invoke(voice); }); }); }); dropDown.value = 4; dropDown.value = 3; }