using AX.MessageSystem; using AX.Network.Protocols; using AX.NetworkSystem; using AX.Serialization; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class PowerScroll : MonoBehaviour { public GameObject PowerItemPre; public Transform PowerContent; private static List PowerListAll=new List(); public static event Func, List> GetPower; // Use this for initialization void Awake () { if (PowerItemPre==null) { PowerItemPre = Resources.Load("HandOver/PowerItemToggle") as GameObject; } if (PowerContent == null) { PowerContent = transform.Find("Viewport/Content"); } } void OnEnable() { getAllPower(); CreateItems(); NetworkMessageDispatcher.AddListener("HAND_OVER_SYNC", Reset); } void OnDisable() { NetworkMessageDispatcher.RemoveListener("HAND_OVER_SYNC", Reset); } void Reset(BinaryMessage message) { StartCoroutine(UpdatePowers()); } IEnumerator UpdatePowers() { yield return new WaitForSeconds(0.1f); getAllPower(); CreateItems(); } void getAllPower() { PowerListAll = new List(); if (GetPower != null) { PowerListAll = GetPower(CurrentUserInfo.mySelf.Id,PowerListAll); } } void CreateItems() { for(int i = 0; i < PowerContent.childCount; i++) { Destroy(PowerContent.GetChild(i).gameObject); } foreach(GameObject power in PowerListAll) { GameObject powerItem = Instantiate(PowerItemPre, PowerContent); powerItem.GetComponent().Set(power); } } // Update is called once per frame void Update () { } }