public void SetBoxingList(Hashtable list) { while (boxTable.transform.childCount > 0) { DestroyImmediate(boxTable.transform.GetChild(0).gameObject); } if (list != null) { boxViewTable = new Hashtable(); System.Collections.IDictionaryEnumerator enumerator = UserManager.Instance.RoleTable.GetEnumerator(); while (enumerator.MoveNext()) { //设置格子 roleTable BoxingViewData r = list[enumerator.Key] as BoxingViewData; if (r != null) { GameObject obj = Instantiate(boxPrefabe); obj.SetActive(true); BoxingView pop = obj.GetComponent <BoxingView>(); pop.InitData(r, true); obj.name = r.sort.ToString(); pop.transform.parent = boxTable.transform; pop.transform.position = Vector3.zero; pop.transform.localScale = Vector3.one; if (!boxViewTable.Contains(r.data.csv_id)) { boxViewTable.Add(r.data.csv_id, pop); } } } boxScrollView.ResetPosition(); boxTable.Reposition(); boxTable.repositionNow = true; } }
/// <summary> /// 重写父类的拖拽释放函数 /// </summary> protected override void OnDragDropRelease(GameObject surface) { if (surface != null) { BoxingView tar = surface.GetComponent <BoxingView>(); cur = this.GetComponent <BoxingView>(); //是否相同类型技能 bool flag = BoxingMgr.Instance.SwapBoxingList(ref cur, ref tar, sourceParent, oriPos); //最终调用父类的功能 if (flag) //回归原位 OnDragDropRelease 会导致不能 改parent { if (tag == Def.BoxingSave) { this.transform.localPosition = oriPos; } BoxingMgr.Instance.RefreshTable(); } } base.OnDragDropRelease(surface, sourceParent.transform, oriPos); if (tag == Def.BoxingSave) { this.transform.localPosition = oriPos; } }
//选中 public void SetBoxingFocus(BoxingView v) { if (pop != null && v != null && pop.curBoxView != v) { pop.curBoxView.SetFous(false); v.SetFous(true); pop.curBoxView = v; SetSelectBoxing(v); } }
//删除重置拳法表 public void RemoveBoxingList(BoxingView v1, BoxingView v2) { v2.RestItem(v1.data); pop.boxViewTable.Remove(v1); v1.gameObject.SetActive(false); NGUITools.Destroy(v1); pop.boxTable.Reposition(); pop.boxScrollView.ResetPosition(); pop.boxTable.repositionNow = true; }
/// <summary> /// 重写父类的拖拽开始函数 /// </summary> protected override void OnDragDropStart() { //当拖拽开始时存储原始的父对象 cur = this.GetComponent <BoxingView>(); this.sourceParent = this.transform.parent.gameObject; // if (tag == Def.BoxingSave) { oriPos = new Vector3(); oriPos.x = transform.localPosition.x; oriPos.y = transform.localPosition.y; oriPos.z = transform.localPosition.z; } if (cur != null && cur.data != null && cur.data.level > 0) { this.transform.parent = BoxingMgr.Instance.GetPop().movePanel.transform; base.OnDragDropStart(); } }
//选中显示 public void SetSelectBoxing(BoxingView view) { BoxingViewData v = view.data; Debug.Log(v.sort + "/" + v.data.csv_id); if (v.frag_num < 1) { v.frag_num = BagMgr.Instance.GetItemNumById(view.data.data.levelData.item_id); } int ind = view.data.data.levelData.g_csv_id; BoxingLevelData bld = null; if (v.level < Def.BoxLevelMax) { //查找背包有多少item ind++; bld = GameShared.Instance.GetBoxingLevelByIdCon(ind); if (v.frag_num >= bld.item_num) { v.fra_value = 1.0f; } else { float a = (float)v.frag_num / (float)bld.item_num; v.fra_value = a; } } else { bld = GameShared.Instance.GetBoxingLevelByIdCon(ind); v.fra_value = 1.0f; } pop.boxingIcon.RestItem(v); pop.SetBoxingInfo(v, GetAttr(v.data)); pop.curBoxView.SetFous(true); pop.SetFragNum(v.frag_num + "/" + bld.item_num); //CheckBtn(); }
//public bool BoxingCanSwap(BoxingView cur) //{ // bool flag = false; // if (cur != null && cur.data != null && cur.data.level > 0 && pop.curRoleView.data.id) // { // } // return flag; //} //设置技能 public bool SwapBoxingList(ref BoxingView v1, ref BoxingView v2, GameObject sourceParent, Vector3 oriPos) { bool flag = false;//是否回归原位 if (v1 != null && v1.data != null) { bool have = CheckHaveBoxing(v1.data); if (!have && v1.tag != Def.BoxingSave ) { UIWidget w = v1.GetComponent <UIWidget>(); Debug.Log(w.depth); // if (v2 != null && v1.data.data.levelData.skill_type == v2.type && v1.tag != Def.BoxingSave && v2.tag == Def.BoxingSave) { //移入装备技能 v2.RestItem(v1.data); flag = true; } else if (v2 != null && v2.tag == Def.BoxingSave)//从上面移入装备栏 但类型不对 { ToastManager.Instance.Show("不可以放这个类型"); } else { //在上面的表移动 flag = true; } } else if (!have)//不用和才可移入装备 { //交换两个 BoxingDragView dr = v1.GetComponent <BoxingDragView>(); if (v2 != null && v2.tag == Def.BoxingSave && dr != null) { //在装备技能中移动 if (v2.data == null) { v2.RestItem(v1.data); v1.RestEmpty(); } else { BoxingViewData temp = v2.data; v2.RestItem(v1.data); v1.RestItem(temp); } v1.gameObject.transform.localPosition = dr.oriPos; } //移除 else {//从一个移入一个空的 v1.RestEmpty(); v1.gameObject.transform.localPosition = dr.oriPos; } } else { //移除移入的不是下面的装备栏 if ((v2 == null || v2.tag != Def.BoxingSave) && v1.tag == Def.BoxingSave) { v1.RestEmpty(); flag = true; v1.gameObject.transform.localPosition = oriPos; } else if (v2 != null && v1.type == v2.type && v1.tag == Def.BoxingSave && v2.tag == Def.BoxingSave) //同类互换 { flag = true; v1.gameObject.transform.localPosition = oriPos; } else { //非同类互换 if (v1.tag == Def.BoxingSave && v2.tag == Def.BoxingSave && v1.type != v2.type) { flag = true; v1.gameObject.transform.localPosition = oriPos; ToastManager.Instance.Show("不可以放这个类型"); } else { //从上面移入装备栏 以存在 if ((v2.data == null || v1.data.data.csv_id != v2.data.data.csv_id) && !have) { v1.RestEmpty(); flag = true; v1.gameObject.transform.localPosition = oriPos; } } } } } else { } pop.boxTable.Reposition(); pop.boxTable.repositionNow = true; return(flag); }