public class XUICwjTest : Xui
{
Transform tmpLab;
List<Transform> copyList = new List<Transform>();
public Color fromColor = new Color(0f, 1f, 0f, 1f);
public Color toColor = new Color(0f, 86/255f, 0f, 1f);
public int AddPosY = 50;
public float waittime = 0.4f;
public Transform ParentTranform;
public override void OnInit()
{
tmpLab = XGetChild<Transform>("Tmp");
ParentTranform = this.GetComponent<UIPanel>().transform;
}
public static void FlyAwayTextList(Transform parentFom, List<string> txtList)
{
if (txtList.Count == 0)
return;
if (!XUIManager.Inst.IsOpen<XUICwjTest>())
XUIManager.Inst.OpenUI<XUICwjTest>();
XUIManager.Inst.CallUIMethod<XUICwjTest>("FlyAway", parentFom, txtList);
}
public void FlyAway(Transform parentFom, List<string> txtList)
{
ParentTranform = parentFom;
ClearCopyList();
StartCoroutine(CoShowMsg(txtList));
}
IEnumerator CoShowMsg(List<string> txtList)
{
for (int i = 0; i < txtList.Count; ++i )
{
Transform copyT = (Transform)Instantiate(tmpLab, tmpLab.transform.position, tmpLab.transform.rotation);
copyT.parent = ParentTranform;
copyT.localScale = new Vector3(1, 1, 1);
UILabel lb = copyT.GetComponent<UILabel>();
lb.text = txtList[i];
lb.color = fromColor;
copyT.gameObject.SetActive(true);
copyList.Add(copyT);
foreach (UIWidget widget in copyT.GetComponentsInChildren<UIWidget>())
{
widget.color = fromColor;
TweenPosition.Begin(widget.gameObject, waittime, copyT.transform.localPosition + new Vector3(0, AddPosY, 0));
TweenColor.Begin(widget.gameObject, waittime/2, toColor);
}
yield return new WaitForSeconds(waittime);
GameObject.Destroy(copyT.gameObject);
copyList.Remove(copyT);
}
}
public void ClearCopyList()
{
for (int i = 0; i < copyList.Count; ++i )
{
if(copyList[i] != null)
GameObject.Destroy(copyList[i].gameObject);
}
copyList.Clear();
StopAllCoroutines();
}
public override void OnClose()
{
ClearCopyList();
}
}