|
|
@@ -5,16 +5,141 @@ using UnityEngine.UI;
|
|
|
|
|
|
public class DeviceView : MonoBehaviour
|
|
|
{
|
|
|
+ Transform scrollContent;
|
|
|
+ Transform itemPrefab;
|
|
|
+ GameObject bowOptions;
|
|
|
+ GameObject arrowOptions;
|
|
|
+ List<DeviceInfo> deviceList;
|
|
|
void Start()
|
|
|
{
|
|
|
- Transform t = this.transform.Find("ScrollView/Viewport/Content");
|
|
|
- for (int i = 0; i < t.childCount; i++)
|
|
|
+ scrollContent = this.transform.Find("ScrollView/Viewport/Content");
|
|
|
+ itemPrefab = scrollContent.GetChild(0);
|
|
|
+ itemPrefab.gameObject.SetActive(false);
|
|
|
+ bowOptions = this.transform.Find("ItemInfo/BowOptions").gameObject;
|
|
|
+ arrowOptions = this.transform.Find("ItemInfo/ArrowOptions").gameObject;
|
|
|
+ deviceList = DeviceMgr.ins.GetMyDeviceList();
|
|
|
+ //初始化设备列表-并默认点开第一个设备
|
|
|
+ foreach (DeviceInfo deviceInfo in deviceList)
|
|
|
{
|
|
|
- int k = i;
|
|
|
- t.GetChild(i).GetComponent<Button>().onClick.AddListener(delegate() {
|
|
|
- Debug.Log(k);
|
|
|
+ DeviceConfig deviceConfig = deviceInfo.config;
|
|
|
+ GameObject item = GameObject.Instantiate(itemPrefab.gameObject, scrollContent);
|
|
|
+ Image modelImage = item.transform.Find("ModelBG/Model").GetComponent<Image>();
|
|
|
+ modelImage.sprite = Resources.Load<Sprite>("Textures/Device/" + deviceConfig.model);
|
|
|
+ modelImage.SetNativeSize();
|
|
|
+ item.transform.Find("TextBG/Text").GetComponent<TextAutoLanguage>().SetText(deviceConfig.name);
|
|
|
+ item.gameObject.SetActive(true);
|
|
|
+ item.GetComponent<Button>().onClick.AddListener(delegate() {
|
|
|
+ AudioMgr.ins.PlayBtn();
|
|
|
+ SelectItem(deviceInfo);
|
|
|
});
|
|
|
}
|
|
|
+ SelectItem(deviceList[0]);
|
|
|
+ //初始化弓的校准按钮
|
|
|
+ Button[] bowOptionBtns = bowOptions.GetComponentsInChildren<Button>();
|
|
|
+ for (int i = 0; i < bowOptionBtns.Length; i++)
|
|
|
+ {
|
|
|
+ int optionID = i;
|
|
|
+ bowOptionBtns[i].onClick.AddListener(delegate() {
|
|
|
+ AudioMgr.ins.PlayBtn();
|
|
|
+ if (optionID == 0) {
|
|
|
+ DeviceCalibrateView.Create(DeviceCalibrateItem.Gyr);
|
|
|
+ } else if (optionID == 1) {
|
|
|
+ DeviceCalibrateView.Create(DeviceCalibrateItem.Mag);
|
|
|
+ } else if (optionID == 2) {
|
|
|
+ AimHandler.ins.DoIdentity();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //初始化箭的加速计按钮选项
|
|
|
+ Button[] arrowOptionBtns = arrowOptions.GetComponentsInChildren<Button>();
|
|
|
+ for (int i = 0; i < arrowOptionBtns.Length; i++)
|
|
|
+ {
|
|
|
+ int optionID = i;
|
|
|
+ arrowOptionBtns[i].onClick.AddListener(delegate() {
|
|
|
+ AudioMgr.ins.PlayBtn();
|
|
|
+ //select
|
|
|
+ float acc = 16;
|
|
|
+ if (optionID == 1) {
|
|
|
+ acc = 64;
|
|
|
+ }
|
|
|
+ SelectAccForArrow(acc);
|
|
|
+ //save
|
|
|
+ LoginMgr.myUserInfo.deviceAccValue = acc;
|
|
|
+ LoginMgr.myUserInfo.Save();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ SelectAccForArrow(LoginMgr.myUserInfo.deviceAccValue);
|
|
|
+ }
|
|
|
+
|
|
|
+ void SelectAccForArrow(float acc)
|
|
|
+ {
|
|
|
+ for (int i = 0; i < arrowOptions.transform.childCount; i++)
|
|
|
+ {
|
|
|
+ Transform t = arrowOptions.transform.GetChild(i);
|
|
|
+ t.GetComponent<Button>().enabled = true;
|
|
|
+ t.GetComponent<Image>().sprite = Resources.Load<Sprite>("Textures/Common/ButtonGray");
|
|
|
+ t.GetComponentInChildren<Text>().color = Color.gray;
|
|
|
+ }
|
|
|
+ Transform optionTransform;
|
|
|
+ Color outColor;
|
|
|
+ if (acc == 16)
|
|
|
+ {
|
|
|
+ optionTransform = arrowOptions.transform.GetChild(0);
|
|
|
+ optionTransform.GetComponent<Button>().enabled = false;
|
|
|
+ ColorUtility.TryParseHtmlString("#3D6B03", out outColor);
|
|
|
+ optionTransform.GetComponentInChildren<Text>().color = outColor;
|
|
|
+ optionTransform.GetComponent<Image>().sprite = Resources.Load<Sprite>("Textures/Common/ButtonGreen");
|
|
|
+ }
|
|
|
+ else if (acc == 64)
|
|
|
+ {
|
|
|
+ optionTransform = arrowOptions.transform.GetChild(1);
|
|
|
+ optionTransform.GetComponent<Button>().enabled = false;
|
|
|
+ ColorUtility.TryParseHtmlString("#B65A00", out outColor);
|
|
|
+ optionTransform.GetComponentInChildren<Text>().color = outColor;
|
|
|
+ optionTransform.GetComponent<Image>().sprite = Resources.Load<Sprite>("Textures/Common/ButtonYellow");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ DeviceInfo currentDeviceInfo;
|
|
|
+ void SelectItem(DeviceInfo deviceInfo)
|
|
|
+ {
|
|
|
+ currentDeviceInfo = deviceInfo;
|
|
|
+ Image modelImage = this.transform.Find("ItemShow/Model").GetComponent<Image>();
|
|
|
+ modelImage.sprite = Resources.Load<Sprite>("Textures/Device/" + deviceInfo.config.model);
|
|
|
+ modelImage.SetNativeSize();
|
|
|
+ this.transform.Find("ItemInfo/Name").GetComponent<TextAutoLanguage>().SetText(deviceInfo.config.name);
|
|
|
+ this.transform.Find("ItemInfo/Detail").GetComponent<TextAutoLanguage>().SetText(deviceInfo.config.detail);
|
|
|
+ Transform stars = this.transform.Find("ItemInfo/Stars");
|
|
|
+ Image starLight = stars.GetChild(0).GetComponent<Image>();
|
|
|
+ Image starDark = stars.GetChild(1).GetComponent<Image>();
|
|
|
+ starLight.gameObject.SetActive(false);
|
|
|
+ starDark.gameObject.SetActive(false);
|
|
|
+ for (int i = 1; i <= 5; i++) {
|
|
|
+ stars.GetChild(i + 2).GetComponent<Image>().sprite =
|
|
|
+ i <= deviceInfo.config.difficulty ? starLight.sprite : starDark.sprite;
|
|
|
+ }
|
|
|
+ bowOptions.SetActive(deviceInfo.config.type == 1);
|
|
|
+ arrowOptions.SetActive(deviceInfo.config.type == 2);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void LeftPointer()
|
|
|
+ {
|
|
|
+ AudioMgr.ins.PlayBtn();
|
|
|
+ int index = deviceList.IndexOf(currentDeviceInfo) - 1;
|
|
|
+ if (index < 0) {
|
|
|
+ index = deviceList.Count - 1;
|
|
|
+ }
|
|
|
+ SelectItem(deviceList[index]);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void RightPointer()
|
|
|
+ {
|
|
|
+ AudioMgr.ins.PlayBtn();
|
|
|
+ int index = deviceList.IndexOf(currentDeviceInfo) + 1;
|
|
|
+ if (index >= deviceList.Count) {
|
|
|
+ index = 0;
|
|
|
+ }
|
|
|
+ SelectItem(deviceList[index]);
|
|
|
}
|
|
|
|
|
|
public void Back() {
|