海淀天下城电子沙盘单机版
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.
 
 
 
 

61 lines
1.6 KiB

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<List<string>>(json);
if (data!=null)
{
foreach (var role in data)
{
GameObject item = Instantiate(prefab, parent) as GameObject;
item.GetComponent<Toggle>().group = parent.GetComponent<ToggleGroup>();
item.GetComponent<RoleItem>().SetItem(role);
}
}
}
private void OkFun()
{
if (string.IsNullOrEmpty(roleName))
{
ResourceLoadWindow.Instance.LoadTextHintWindow("请先选择角色类型", 2f);
}
else
{
MessageDispatcher.SendMessage("RoleSelected", (object)roleName);
gameObject.SetActive(false);
}
}
}