123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- using BeinLab.Util;
- using ShadowStudio.Model;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using XRTool.Util;
- using XRTool.WorldUI;
- public class ContentIconList : MonoBehaviour
- {
- private List<GameObject> IconViewList;
- //private List<ArtInfo> ArtInfoList;
- public GameObject IconItem;
- private RectTransform contentRect;
- public ArtType artType;
- private int rightnum;
- private int leftnum;
- //private void CreateSuccess(ArtContainer container)
- //{
- // for (int i = 0; i < IconViewList.Count; i++)
- // {
- // IconItem Item = IconViewList[i].transform.GetComponent<IconItem>();
- // if (Item.info.ArtId == container.GetGoodsInfo().art_id)
- // {
- // Item.CreateSuccess(container);
- // }
- // }
- //}
- private void Start()
- {
- IconViewList = new List<GameObject>();
- contentRect = transform.GetComponent<RectTransform>();
- if (ArtInfoMgr.Instance != null && ArtInfoMgr.Instance.IsInit)
- {
- //Init();
- }
- else
- {
- ArtInfoMgr.Instance.InitComplete += () =>
- {
- //Init();
- };
- }
- }
- public void Init()
- {
- var ArtInfoList = ArtInfoMgr.Instance.GetArtInfoList(artType);
- //UnityLog.Instance.LogError("artType"+ artType+ "count:"+ArtInfoList.Count);
- OnItemCreat(ArtInfoList.Count);
- for (int i = 0; i < IconViewList.Count; i++)
- {
- IconItem Item = IconViewList[i].transform.GetComponent<IconItem>();
- Item.Init(ArtInfoList[i]);
- }
- //ArtInfoList.Clear();
- //ArtInfoList = null;
- }
- void Update()
- {
- //CheckContent();
- }
- void CheckContent()
- {
- if (contentRect.anchoredPosition3D.x > 0)
- {
- contentRect.anchoredPosition3D = Vector3.zero;
- }
- for (int i = 0; i < IconViewList.Count; i++)
- {
- RectTransform rectTransform;
- rectTransform = IconViewList[i].transform.GetComponent<RectTransform>();
- float num1 = Mathf.Abs(contentRect.anchoredPosition3D.x);
- if (rectTransform.anchoredPosition3D.x > 0)
- {
- //rectTransform.anchoredPosition3D = new Vector3(0, 0, 0);
- }
- if (rectTransform.anchoredPosition3D.x < num1 || rectTransform.anchoredPosition3D.x > 200 + num1)
- {
- IconViewList[i].transform.GetChild(0).gameObject.SetActive(false);
- }
- else
- {
- IconViewList[i].transform.GetChild(0).gameObject.SetActive(true);
- }
- }
- }
- //void Checkright()
- //{
- // float num = 80 + contentRect.anchoredPosition3D.x;
- // if (num > 0)
- // {
- // if (num >= 40)
- // {
- // leftnum = -1;
- // rightnum = 6;
- // }
- // else
- // {
- // leftnum = 0;
- // rightnum = 7;
- // }
- // }
- // else
- // {
- // float num1 = num / 80;
- // float num2 = Mathf.Abs(num1);
- // int leftnumTemp = Mathf.CeilToInt(num2);
- // Debug.Log(leftnumTemp+"AAA");
- // Debug.Log(num2+"BBB");
- // if (leftnumTemp > num2 + 0.5)
- // {
- // leftnum = leftnumTemp - 1;
- // }
- // else
- // {
- // leftnum = leftnumTemp;
- // }
- // rightnum = 7 + leftnum;
- // Debug.Log(leftnum);
- // Debug.Log(rightnum);
- // }
- // for (int i = 0; i < IconChildList.Count; i++)
- // {
- // if (i <= leftnum || i >= rightnum)
- // {
- // IconChildList[i].SetActive(false);
- // }
- // else
- // {
- // IconChildList[i].SetActive(true);
- // }
- // }
- //}
- public void OnItemCreat(int _count)
- {
- if (_count > 0)
- {
- //IconItem.SetActive(true); //第一个item实例已经放在列表第一个位置,直接激活
- //IconViewList.Add(IconItem);
- int i = 0;
- while (i <= _count - 1)
- {
- GameObject obj = GameObject.Instantiate(IconItem) as GameObject;
- obj.transform.SetParent(transform); //设置为 Content 的子对象
- IconViewList.Add(obj);
- RectTransform t = IconViewList[i].GetComponent<RectTransform>(); //获取前一个 item 的位置
- //当前 item 位置放在在前一个 item 下方
- obj.GetComponent<RectTransform>().localPosition =
- new Vector3(t.localPosition.x, t.localPosition.y - t.rect.height, t.localPosition.z);
- obj.GetComponent<RectTransform>().localEulerAngles = new Vector3(0, 0, 0);
- obj.GetComponent<RectTransform>().localScale = new Vector3(1, 1, 1);
- i++;
- }
- //根据当前 item 个数更新 Content 高度
- transform.GetComponent<RectTransform>().sizeDelta =
- new Vector2(transform.GetComponent<RectTransform>().sizeDelta.x, 30);
- }
- }
- }
|