void Start() { canChangeItem = true; int count = listEnhanceItems.Count; dFactor = (Mathf.RoundToInt((1f / count) * 10000f)) * 0.0001f; mCenterIndex = count / 2; //This is for any number of item if (count % 2 == 0) //this is for when number is 6,8,10,... then mid would be 2,3,4,.... { mCenterIndex = count / 2 - 1; } int index = 0; for (int i = count - 1; i >= 0; i--) { listEnhanceItems[i].CurveOffSetIndex = i; listEnhanceItems[i].CenterOffSet = dFactor * (mCenterIndex - index); listEnhanceItems[i].SetSelectState(false); GameObject obj = listEnhanceItems[i].gameObject; if (inputType == InputSystemType.NGUIAndWorldInput) { #region hidden cause not using NGUI /// DragEnhanceView script = obj.GetComponent<DragEnhanceView>(); ////if (script != null) //// script.SetScrollView(this); #endregion } else { UDragEnhanceView script = obj.GetComponent <UDragEnhanceView>(); if (script != null) { script.SetScrollView(this); } } index++; } // set the center item with startCenterIndex if (startCenterIndex < 0 || startCenterIndex >= count) { Debug.LogError("## startCenterIndex < 0 || startCenterIndex >= listEnhanceItems.Count out of index ##"); startCenterIndex = mCenterIndex; } // sorted items listSortedItems = new List <EnhanceItem>(listEnhanceItems.ToArray()); totalHorizontalWidth = cellWidth * count; curCenterItem = listEnhanceItems[startCenterIndex]; curHorizontalValue = 0.5f - curCenterItem.CenterOffSet; LerpTweenToTarget(0f, curHorizontalValue, false); #region hidden cause not using NGUI // // enable the drag actions // //// EnableDrag(true); #endregion }
void Start() { startCenterIndex = saveDate.startCenterPos; Debug.Log("开始位置。。。。。。。。。。。。" + startCenterIndex); canChangeItem = true; for (int i = 0; i < transform.childCount; i++) { listEnhanceItems.Add(transform.GetChild(i).GetComponent <EnhanceItem>()); } int count = listEnhanceItems.Count; dFactor = (Mathf.RoundToInt((1f / count) * 10000f)) * 0.0001f; mCenterIndex = count / 2; if (count % 2 == 0) { mCenterIndex = count / 2 - 1; } int index = 0; for (int i = count - 1; i >= 0; i--) { listEnhanceItems[i].CurveOffSetIndex = i; listEnhanceItems[i].CenterOffSet = dFactor * (mCenterIndex - index); listEnhanceItems[i].SetSelectState(false); GameObject obj = listEnhanceItems[i].gameObject; if (inputType == InputSystemType.UGUIInput) { UDragEnhanceView script = obj.GetComponent <UDragEnhanceView>(); if (script != null) { script.SetScrollView(this); } } index++; } // set the center item with startCenterIndex if (startCenterIndex < 0 || startCenterIndex >= count) { Debug.LogError("## startCenterIndex < 0 || startCenterIndex >= listEnhanceItems.Count out of index ##"); startCenterIndex = mCenterIndex; } // sorted items listSortedItems = new List <EnhanceItem>(listEnhanceItems.ToArray()); totalHorizontalWidth = cellWidth * count;//间距变化 curCenterItem = listEnhanceItems[startCenterIndex]; curHorizontalValue = 0.5f - curCenterItem.CenterOffSet; LerpTweenToTarget(0f, curHorizontalValue, false); }
public void allstart() { createcure(); canChangeItem = true; int count = listEnhanceItems.Count; dFactor = (Mathf.RoundToInt((1f / count) * 10000f)) * 0.0001f; mCenterIndex = count / 2; if (count % 2 == 0) { mCenterIndex = count / 2 - 1; } int index = 0; for (int i = count - 1; i >= 0; i--) { listEnhanceItems[i].CurveOffSetIndex = i; listEnhanceItems[i].CenterOffSet = dFactor * (mCenterIndex - index); listEnhanceItems[i].SetSelectState(false); GameObject obj = listEnhanceItems[i].gameObject; UDragEnhanceView script = obj.GetComponent <UDragEnhanceView>(); if (script != null) { script.SetScrollView(this); } index++; } // set the center item with startCenterIndex if (startCenterIndex < 0 || startCenterIndex >= count) { Logger.LogError("## startCenterIndex < 0 || startCenterIndex >= listEnhanceItems.Count out of index ##"); startCenterIndex = mCenterIndex; } // sorted items listSortedItems = new List <EnhanceItem>(listEnhanceItems.ToArray()); totalHorizontalWidth = cellWidth * count; curCenterItem = listEnhanceItems[startCenterIndex]; curHorizontalValue = 0.5f - curCenterItem.CenterOffSet; LerpTweenToTarget(0f, curHorizontalValue, false); // // enable the drag actions // EnableDrag(true); }
//当插入了所有子项后 public void Reload(System.Action <Chapter> c = null) { OnSelect = c; listEnhanceItems.Clear(); for (int i = 0; i < transform.childCount; i++) { EnhanceItem item = transform.GetChild(i).GetComponent <EnhanceItem>(); if (item != null && item.transform != itemPrefab.transform) { listEnhanceItems.Add(item); } } canChangeItem = true; //是否可以改变目标 int count = listEnhanceItems.Count; //滚动目标数量 dFactor = (Mathf.RoundToInt((1f / count) * 10000f)) * 0.0001f; //保留四位小数 //中心id赋值 mCenterIndex = count / 2; if (count % 2 == 0) { mCenterIndex = count / 2 - 1; } int index = 0; //反序遍历滚动视图中的目标列表 for (int i = count - 1; i >= 0; i--) { //初始化视图中的项 listEnhanceItems[i].CurveOffSetIndex = i; listEnhanceItems[i].CenterOffSet = dFactor * (mCenterIndex - index); //设置曲线中心偏移 listEnhanceItems[i].SetSelectState(false); //设置未选中状态 listEnhanceItems[i].SetScrollView(this); GameObject obj = listEnhanceItems[i].gameObject; UDragEnhanceView script = obj.GetComponent <UDragEnhanceView>(); if (script != null) { script.SetScrollView(this);//设置滚动视图 } index++; } // set the center item with startCenterIndex // 根据传入的初始被选中项id设置被选中物体(该物体在中心高亮提高显示) if (startCenterIndex < 0 || startCenterIndex >= count)//初始id合法性判断 { Debug.LogError("## startCenterIndex < 0 || startCenterIndex >= listEnhanceItems.Count out of index ##"); startCenterIndex = mCenterIndex; } // sorted items //对项目排序 listSortedItems = new List <EnhanceItem>(listEnhanceItems.ToArray()); //设置总宽度 totalHorizontalWidth = cellWidth * count; //设置当前中心项 curCenterItem = listEnhanceItems[startCenterIndex]; //设置当前水平值 curHorizontalValue = 0.5f - curCenterItem.CenterOffSet; //插值渐变到目标值 LerpTweenToTarget(0f, curHorizontalValue, false); }
public void initialize() { // Clear(); listSortedItems.Clear(); TextuerName = TextuerPropModel.GetInstance(); InstantiateTextuer(TextuerName.TEYP); canChangeItem = true; int count = listEnhanceItems.Count; dFactor = (Mathf.RoundToInt((1f / count) * 10000f)) * 0.0001f; mCenterIndex = count / 2; if (count % 2 == 0) { mCenterIndex = count / 2 - 1; } int index = 0; for (int i = count - 1; i >= 0; i--) { listEnhanceItems[i].CurveOffSetIndex = i; listEnhanceItems[i].CenterOffSet = dFactor * (mCenterIndex - index); //listEnhanceItems[i].SetSelectState(false); GameObject obj = listEnhanceItems[i].gameObject; if (inputType == InputSystemType.NGUIAndWorldInput) { DragEnhanceView script = obj.GetComponent <DragEnhanceView>(); if (script != null) { script.SetScrollView(this); } } else { UDragEnhanceView script = obj.GetComponent <UDragEnhanceView>(); if (script != null) { script.SetScrollView(this); } } index++; } // set the center item with startCenterIndex if (startCenterIndex < 0 || startCenterIndex >= count) { Debug.LogError("## startCenterIndex < 0 || startCenterIndex >= listEnhanceItems.Count out of index ##"); startCenterIndex = mCenterIndex; } // sorted items listSortedItems = new List <EnhanceItem>(listEnhanceItems.ToArray()); totalHorizontalWidth = cellWidth * count * cellWidthDeviant; curCenterItem = listEnhanceItems[startCenterIndex]; curHorizontalValue = 0.5f - curCenterItem.CenterOffSet; LerpTweenToTarget(0f, curHorizontalValue, false); // // enable the drag actions // EnableDrag(true); UITexture ME1 = Resources.Load <UITexture>("Prefabs/fuzi1"); //curCenterItem.GetComponent<UITexture>().mainTexture = Resources.Load<Texture>("Texture/centre" + curCenterItem.CurveOffSetIndex); fish1 = Instantiate(ME1, new Vector3(0, -1, 0), this.transform.rotation) as UITexture; fish1.mainTexture = Resources.Load <Texture>("song/" + TextuerName.listTextuerProp[curCenterItem.Number].textureSong); fish1.depth = 99; fish1.transform.parent = transform; fish1.transform.localScale = new Vector3(1, 1, 1); fish1.transform.localPosition = new Vector3(0, -1, 0); setAct(RS.getCurrentTextuer); setAct2(SO.GetComponent <StopOperation>().StopCallbackFunction); depthFactor = listEnhanceItems.Count; if (act != null) { act(curCenterItem.Number); } if (act2 != null) { act2(curCenterItem.Number); } SO.GetComponent <glrc>().chushihua(); }