You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.9 KiB
72 lines
1.9 KiB
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<GameObject> PowerListAll=new List<GameObject>(); |
|
public static event Func<long,List<GameObject>, List<GameObject>> 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<GameObject>(); |
|
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<PowerItemToggle>().Set(power); |
|
} |
|
} |
|
// Update is called once per frame |
|
void Update () { |
|
|
|
} |
|
}
|
|
|