private void Start() { scrollRect = GameObject.Find("VirtualJoystick").GetComponent <MyScrollRect>(); jumpButton = GameObject.Find("StartNJump").GetComponent <MyJumpButton>(); rgb = this.GetComponent <Rigidbody2D>(); startPosition = transform.position; }
// Start is called before the first frame update void Start() { m_scrollRect = gameObject.GetComponentInParent <MyScrollRect>(); m_UIRectTrans = gameObject.GetComponent <RectTransform>(); m_scrollRect.contentValues = m_UIRectTrans; m_scrollbarHorizontal = m_scrollRect.transform.GetChild(1).gameObject.GetComponent <Scrollbar>(); m_scrollbarVerticalTopDown = m_scrollRect.transform.GetChild(2).gameObject.GetComponent <Scrollbar>(); m_localPosition = m_UIRectTrans.localPosition; m_position = m_UIRectTrans.position; m_horiValue = m_scrollbarHorizontal.value; m_vertiValue = m_scrollbarVerticalTopDown.value; }
public void Awake() { scroRect = transform.gameObject.AddComponent <MyScrollRect>(); scroRect.horizontal = false; scroRect.OnScrollDraged = OnScrollDraged; RectTransform baseRect = scroRect.GetComponent <RectTransform>(); GameObject viewport = new GameObject("viewport"); RectTransform viewtrans = viewport.AddComponent <RectTransform>(); viewtrans.SetParent(transform, false); viewtrans.pivot = Vector2.up; viewtrans.anchorMin = Vector2.zero; viewtrans.anchorMax = Vector2.one; viewtrans.anchoredPosition3D = Vector3.zero; viewtrans.sizeDelta = Vector2.zero; viewport.AddComponent <CanvasRenderer>(); viewport.AddComponent <Image>().raycastTarget = false; viewport.AddComponent <Mask>().showMaskGraphic = false; contenttrans = new GameObject("content").AddComponent <RectTransform>(); contenttrans.SetParent(viewtrans, false); contenttrans.pivot = Vector2.up; contenttrans.anchorMin = Vector2.up; contenttrans.anchorMax = Vector2.up; contenttrans.anchoredPosition3D = Vector3.zero; contenttrans.sizeDelta = Vector2.zero; content = contenttrans.gameObject.AddComponent <SchemeImageContent>(); content.scrollRect = scroRect; contentRect = content.contentTrans; scroRect.content = contentRect; // 设置布局 SetData(420, 672, 30, 70, 6, 2, 20, refreshDis, content.itemPrefab); // 测试 数据 ItemData[] data = new ItemData[20]; Display(data); }
void Start() { scrollRect = scroRect.GetComponent <MyScrollRect>(); }