private void ShowTalker(string talkerPic, string position) { //talkerPic = "person"; talkingPerson = position == "0" ? personLeft : personRight; if (talkingPerson != null && string.IsNullOrEmpty(talkerPic)) { talkingPerson.gameObject.SetActive(false); } else { talkingPerson = GetPerson(talkerPic, position); talkingPerson.Show(); } }
//todo 待优化 不要平凡创建销毁 private UIDialoguePerson GetPerson(string name, string position) { talkingPerson = position == "0" ? personLeft : personRight; if (talkingPerson != null) { if (talkingPerson.gameObject.name == name) { return(talkingPerson); } else { talkingPerson.gameObject.SetActive(false); } } List <GameObject> cacheList; personCache.TryGetValue(name, out cacheList); GameObject personGO = null; if (cacheList != null) { foreach (GameObject cache in cacheList) { if (!cache.activeSelf) { personGO = cache; break; } } } if (personGO == null) { GameObject go = March.Core.ResourceManager.ResourceManager.instance.Load <GameObject>(Configure.StoryDialogPerson, name); personGO = GameUtils.CreateGameObject(transform, go); if (!personCache.ContainsKey(name)) { personCache.Add(name, new List <GameObject>() { personGO }); } else { personCache[name].Add(personGO); } } personGO.transform.SetSiblingIndex(1); RectTransform rt = personGO.transform as RectTransform; UIDialoguePerson person = personGO.GetComponent <UIDialoguePerson>(); if (position == "0") { rt.pivot = new Vector2(0, 0); rt.anchorMin = new Vector2(0, 0); rt.anchorMax = new Vector2(0, 0); rt.anchoredPosition = new Vector2(-525, 0); rt.DOAnchorPosX(25, 0.5f).SetEase(Ease.OutCubic); //rt.anchoredPosition = new Vector2(25, 0); personLeft = person; } else { rt.pivot = new Vector2(1, 0); rt.anchorMin = new Vector2(1, 0); rt.anchorMax = new Vector2(1, 0); rt.anchoredPosition = new Vector2(525, 0); rt.DOAnchorPosX(-25, 0.5f).SetEase(Ease.OutCubic); //rt.anchoredPosition = new Vector2(-25, 0); personRight = person; } return(person); }
private void HideTalker(string position) { UIDialoguePerson person = position == "0" ? personLeft : personRight; person.Hide(); }