using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using AX.MessageSystem; using Newtonsoft.Json; using System.IO; public class RoleSelectPanel : MonoBehaviour { public string roleName; public Button okButton; private GameObject prefab; public Transform parent; // Use this for initialization void Start() { okButton.onClick.AddListener(OkFun); prefab = Resources.Load("UI/RoleItem") as GameObject; DrawUI(); } // Update is called once per frame void Update() { } private void DrawUI() { string json = null; string path = Path.Combine(Application.streamingAssetsPath, "Roles.json"); if (File.Exists(path)) { json = File.ReadAllText(path); } var data = JsonConvert.DeserializeObject>(json); if (data!=null) { foreach (var role in data) { GameObject item = Instantiate(prefab, parent) as GameObject; item.GetComponent().group = parent.GetComponent(); item.GetComponent().SetItem(role); } } } private void OkFun() { if (string.IsNullOrEmpty(roleName)) { ResourceLoadWindow.Instance.LoadTextHintWindow("请先选择角色类型", 2f); } else { MessageDispatcher.SendMessage("RoleSelected", (object)roleName); gameObject.SetActive(false); } } }