protected override void ItemChildGameObject(GameObject obj = null) { view.GetComponent <UDragScroll>().scroRect = ScroRect; SchemeManifestItemFunc func = obj.GetComponent <SchemeManifestItemFunc>(); func.OnChange = ItemIndexChange; }
protected override void Update() { if (isDown == false || moved == true || dragActive == true) { return; } if (Time.time - beginTime > longPressDelay) { scroRect.vertical = false; dragActive = true; itemStartPos = tranRect.anchoredPosition; dragToItem = null; viewDragActivePos = viewRect.position; } }
public void ItemIndexChange(int from, int to) { if (itemDic.ContainsKey(from) == false || itemDic.ContainsKey(to) == false) { Debug.LogWarning("ItemIndexChange Wrong :index " + from + " or " + to + " 不存在!"); return; } SchemeManifestItemFunc funcFrom = itemDic[from] as SchemeManifestItemFunc; SchemeManifestItemFunc funcTo = itemDic[to] as SchemeManifestItemFunc; funcFrom.index = to; funcTo.index = from; itemDic[from] = funcTo; itemDic[to] = funcFrom; ItemData fromdata = this.msgs[from]; ItemData todata = this.msgs[to]; this.msgs[from] = todata; this.msgs[to] = fromdata; RefreshDisplay(); }
private void SetDraggedPosition(PointerEventData data) { if (offset == data.position - inputStartPos) { return; } offset = data.position - inputStartPos; tranRect.anchoredPosition = itemStartPos + GetPos(offset); Vector2 org = new Vector2(tranRect.position.x + 1.8f, tranRect.position.y - 1.3f); count = Physics2D.OverlapPointNonAlloc(org, coll); if (count == 0) { return; } bool hasOldFunc = false; for (int i = 0; i < count; i++) { if (coll[i].transform.parent == null) { continue; } if (coll[i].transform.parent == this.transform) { continue; } if (dragToItem != null && dragToItem.transform == coll[i].transform.parent) { hasOldFunc = true; break; } SchemeManifestItemFunc func = coll[i].transform.parent.GetComponent <SchemeManifestItemFunc>(); if (func == null) { continue; } if (dragToItem != null) { dragToItem.goBack(dragToItem.viewRect); } dragToItem = func; dragToItem.GoToWorldPos(dragToItem.viewRect, viewDragActivePos); func.transform.SetSiblingIndex(50); return; } if (hasOldFunc == false) { if (dragToItem != null) { dragToItem.goBack(dragToItem.viewRect); dragToItem = null; } } }
public override void RefreshDisplay(List <ItemData> data = null, bool restPos = false, bool isChange = false) { //base.RefreshDisplay(); foreach (UGUIItemFunction item in itemDic.Values) { item.gameObject.SetActive(false); skinList.Push(item.gameObject); } itemDic.Clear(); if (restPos == true) { ResetPostion(); } if (data != null) { this.Msgs = data; } if (data != null || isChange) { SetContentSize(this.Msgs.Count + 2); } int index = 0; if (specialskin == null) { specialskin = GetInstance(); GameObject addManifest = specialskin.transform.FindChild("view/AddManifest").gameObject; addManifest.SetActive(true); GameObject manifestImage = specialskin.transform.FindChild("view/ManifestImage").gameObject; manifestImage.SetActive(false); BoxCollider2D coll = specialskin.GetComponentInChildren <BoxCollider2D>(); coll.enabled = false; GameObject text = specialskin.transform.FindChild("view/Text").gameObject; text.SetActive(false); coll.gameObject.SetActive(false); }//skinClone specialskin.transform.SetParent(ContentRectTrans); specialskin.transform.localPosition = GetLoaclPosByIndex(index); specialskin.transform.localScale = Vector3.one; specialskin.GetComponent <RectTransform>().SetSiblingIndex(index); SchemeManifestItemFunc itemfunc = specialskin.GetComponent <SchemeManifestItemFunc>(); itemfunc.scroRect = ScroRect; itemfunc.data = specialitem; itemfunc.index = index; ItemAddListion(itemfunc); ItemChildGameObject(specialskin); for (int i = 0; i < this.Msgs.Count; i++) { if ((i < CurrentIndex - UpperLimitIndex) && (CurrentIndex > LowerLimitIndex) && !isChange) { return; } skinClone = GetInstance(); skinClone.transform.SetParent(ContentRectTrans); skinClone.transform.localPosition = GetLoaclPosByIndex(i + AddItemPerfab); skinClone.transform.localScale = Vector3.one; skinClone.GetComponent <RectTransform>().SetSiblingIndex(i + AddItemPerfab); SchemeManifestItemFunc func = skinClone.GetComponent <SchemeManifestItemFunc>(); func.scroRect = ScroRect; func.data = this.Msgs[i]; func.index = i + AddItemPerfab; itemDic.Add(i + AddItemPerfab, func); ItemAddListion(func); ItemChildGameObject(skinClone); } }