// On Drag End /// <summary> /// 拖拽结束 /// </summary> public void OnDragEnhanceViewEnd() { // 查找关闭项以居中 int closestIndex = 0; float value = (curHorizontalValue - (int)curHorizontalValue);//得到当前水平值得小数部分 float min = float.MaxValue; float tmp = 0.5f * (curHorizontalValue < 0 ? -1 : 1); //遍历滚动项目列表 for (int i = 0; i < listEnhanceItems.Count; i++) { //得到项目和中心的距离 float dis = Mathf.Abs(Mathf.Abs(value) - Mathf.Abs((tmp - listEnhanceItems[i].CenterOffSet))); //距离最小i的赋值给关闭id if (dis < min) { closestIndex = i; min = dis; } } originHorizontalValue = curHorizontalValue;//缓存初始水平值 //设置目标水平值 float target = ((int)curHorizontalValue + (tmp - listEnhanceItems[closestIndex].CenterOffSet)); preCenterItem = curCenterItem; //缓存上一个选中项 curCenterItem = listEnhanceItems[closestIndex]; //缓存当前选中项 //有渐变过程的移动 LerpTweenToTarget(originHorizontalValue, target, true); canChangeItem = false;//设置状态为不可改变目标 }
// On Drag End public void OnDragEnhanceViewEnd() { // find closed item to be centered int closestIndex = 0; float value = (curHorizontalValue - (int)curHorizontalValue); float min = float.MaxValue; float tmp = 0.5f * (curHorizontalValue < 0 ? -1 : 1); for (int i = 0; i < listEnhanceItems.Count; i++) { float dis = Mathf.Abs(Mathf.Abs(value) - Mathf.Abs((tmp - listEnhanceItems[i].CenterOffSet))); if (dis < min) { closestIndex = i; min = dis; } } originHorizontalValue = curHorizontalValue; float target = ((int)curHorizontalValue + (tmp - listEnhanceItems[closestIndex].CenterOffSet)); preCenterItem = curCenterItem; curCenterItem = listEnhanceItems[closestIndex]; LerpTweenToTarget(originHorizontalValue, target, true); canChangeItem = false; }
// On Drag End public void OnDragEnhanceViewEnd()//结束拖拽 { int closestIndex = 0; float value = (curHorizontalValue - (int)curHorizontalValue); float min = float.MaxValue; float tmp = 0.5f * (curHorizontalValue < 0 ? -1 : 1); for (int i = 0; i < listEnhanceItems.Count; i++) { float dis = Mathf.Abs(Mathf.Abs(value) - Mathf.Abs((tmp - listEnhanceItems[i].CenterOffSet))); if (dis < min) { closestIndex = i; min = dis; } } originHorizontalValue = curHorizontalValue; float target = ((int)curHorizontalValue + (tmp - listEnhanceItems[closestIndex].CenterOffSet)); preCenterItem = curCenterItem; curCenterItem = listEnhanceItems[closestIndex]; LerpTweenToTarget(originHorizontalValue, target, true); canChangeItem = false; if (this.name != "areaScrollView") { Music_Control.effect_music.Play(); } else { buYuMusicContral.instant.allYinXiao[23].Play(); } }
private void InstantiateTextuer(String _teyp) { for (int i = 0; i < TextuerName.listTextuerProp.Count; i++) { if (TextuerName.listTextuerProp[i].TEYP == _teyp) { //获取对应纹理 Texture tex = Resources.Load <Texture>("song/" + TextuerName.listTextuerProp[i].textureroll); MyNGUIEnhanceItem ME = Resources.Load <MyNGUIEnhanceItem>("Prefabs/fuzi3"); MyNGUIEnhanceItem fish = Instantiate(ME, this.transform.position, this.transform.rotation) as MyNGUIEnhanceItem; //设置主纹理 fish.GetComponent <UITexture>().mainTexture = tex; // fish.GetComponent<UITexture>().MakePixelPerfect(); //设置层级 fish.transform.parent = transform; fish.Set_mTrs(); EnhanceItem go = fish.GetComponent <EnhanceItem>(); go.Number = TextuerName.listTextuerProp[i].number - 1; //添加到listEnhanceItems中 listEnhanceItems.Add(go); } } }
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 }
private int GetMoveCurveFactorCount(EnhanceItem preCenterItem, EnhanceItem newCenterItem) { SortEnhanceItem(); int factorCount = Mathf.Abs(newCenterItem.RealIndex) - Mathf.Abs(preCenterItem.RealIndex); return(Mathf.Abs(factorCount)); }
//核心滚动函数 /// <summary> /// 设置横向轴参数,根据缩放曲线和位移曲线更新缩放和位置 /// </summary> internal void SetHorizontalTargetItemIndex(int itemIndex) { if (isInChange) { return; } EnhanceItem item = scrollViewItems[itemIndex];//___________________________________________________________新场景中根据这个来判断 if (centerItem == item) { return; } Debug.Log("item = " + item.name); if (item.name == "Texture01") { Debug.Log("YES"); } // _________________________________________________________________________________________ float dvalue = centerItem == null ? 0 : GetCurveTimeDValue(centerItem, item); // 更改target数值,平滑移动,设负数倒着转 horizontalTargetValue += -dvalue; beginScroll(horizontalValue, horizontalTargetValue); }
//_____________________________________________________________________________________________ void Update() { // 动作识别部分代码 // —————————————————————————————————————————————————————————————————————— if (!isInChange) { touch(); return; } currentDuration += Time.deltaTime; float percent = currentDuration / duration; horizontalValue = Mathf.Lerp(originHorizontalValue, horizontalTargetValue, percent); UpdateEnhanceScrollView(horizontalValue); SortDepth(); if (currentDuration > duration) { centerItem = textureTargets[textureTargets.Count - 1].gameObject.GetComponent <EnhanceItem>(); centerItem.SetSelectColor(true); isInChange = false; } }
/// <summary> /// 计算偏移量因子 /// </summary> /// <param name="preCenterItem">上一个选中项</param> /// <param name="newCenterItem">新的选中项</param> /// <returns></returns> private int GetMoveCurveFactorCount(EnhanceItem preCenterItem, EnhanceItem newCenterItem) { //排序滚动视图 SortEnhanceItem(); //新的真实索引 - 上一个真实索引 int factorCount = Mathf.Abs(newCenterItem.RealIndex) - Mathf.Abs(preCenterItem.RealIndex); //返回绝对值 return(Mathf.Abs(factorCount)); }
public void UpdateEnhanceScrollView(float fValue) { for (int i = 0; i < scrollViewItems.Count; i++) { EnhanceItem itemScript = scrollViewItems[i]; float xValue = GetXPosValue(fValue, dHorizontalValues[itemScript.scrollViewItemIndex]); float scaleValue = GetScaleValue(fValue, dHorizontalValues[itemScript.scrollViewItemIndex]); itemScript.UpdateScrollViewItems(xValue, yPositionValue, scaleValue); } }
/// <summary> /// 更新水平滚动 /// </summary> /// <param name="fValue"></param> private void UpdateEnhanceScrollView(float fValue) { for (int i = 0; i < scrollViewItems.Count; i++) { EnhanceItem itemScript = scrollViewItems[i]; float xValue = GetXPosValue(fValue, itemScript.dValueTime); float scaleValue = GetScaleValue(fValue, itemScript.dValueTime); itemScript.UpdateScrollViewItems(xValue, yPositionValue, scaleValue); } }
/// /// Update EnhanceItem state with curve fTime value /// public void UpdateEnhanceScrollView(float fValue) { for (int i = 0; i < listEnhanceItems.Count; i++) { EnhanceItem itemScript = listEnhanceItems[i]; float xValue = GetXPosValue(fValue, itemScript.CenterOffSet); float scaleValue = GetScaleValue(fValue, itemScript.CenterOffSet); float depthCurveValue = depthCurve.Evaluate(fValue + itemScript.CenterOffSet); itemScript.UpdateScrollViewItems(xValue, depthCurveValue, depthFactor, listEnhanceItems.Count, yFixedPositionValue, scaleValue); } }
// __________________________________________________________________ /// <summary> /// 获取移动后的项目索引 /// </summary> /// <param name="item">当前项目</param> /// <param name="count">移动位数,负数表示倒移</param> /// <returns></returns> private int GetMoveIndex(EnhanceItem item, int count) { EnhanceItem curItem = item; for (int i = 0; i < Mathf.Abs(count); i++) { curItem = count > 0 ? curItem.back : curItem.front; } return(curItem.scrollViewItemIndex); }
/// <summary> /// 设置横向轴参数,根据缩放曲线和位移曲线更新缩放和位置 /// </summary> public void SetHorizontalTargetItemIndex(int itemIndex) { if (!canChangeItem) { return; } EnhanceItem item = scrollViewItems[itemIndex]; if (centerItem == item) { return; } canChangeItem = false; preCenterItem = centerItem; centerItem = item; // 判断点击的是左侧还是右侧计算ScrollView中心需要移动的value float centerXValue = positionCurve.Evaluate(0.5f) * posCurveFactor; bool isRight = false; if (item.transform.localPosition.x > centerXValue) { isRight = true; } // 差值,计算横向值 int moveIndexCount = GetMoveCurveFactorCount(item.transform.localPosition.x); if (moveIndexCount == -1) { Debug.LogWarning("*****Move Index count is invalid."); moveIndexCount = 1; } float dvalue = 0.0f; if (isRight) { dvalue = -dFactor * moveIndexCount; } else { dvalue = dFactor * moveIndexCount; } // 更改target数值,平滑移动 horizontalTargetValue += dvalue; currentDuration = 0.0f; originHorizontalValue = horizontalValue; }
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); }
/// <summary> /// 根据曲线fTime值更新所有滚动项状态 /// </summary> /// <param name="fValue"></param> public void UpdateEnhanceScrollView(float fValue) { //遍历所有的滚动项 for (int i = 0; i < listEnhanceItems.Count; i++) { EnhanceItem itemScript = listEnhanceItems[i]; //获取x坐标值 float xValue = GetXPosValue(fValue, itemScript.CenterOffSet); //获取缩放值 float scaleValue = GetScaleValue(fValue, itemScript.CenterOffSet); //通过层深曲线获得层深值(中间大,两边小) float depthCurveValue = depthCurve.Evaluate(fValue + itemScript.CenterOffSet); //更新项目状态 itemScript.UpdateScrollViewItems(xValue, depthCurveValue, listEnhanceItems.Count, yFixedPositionValue, scaleValue); } }
public void SetHorizontalTargetItemIndex(EnhanceItem selectItem) { if (!canChangeItem) { return; } if (curCenterItem == selectItem) { return; } canChangeItem = false; preCenterItem = curCenterItem; curCenterItem = selectItem; // calculate the direction of moving float centerXValue = positionCurve.Evaluate(0.5f) * totalHorizontalWidth; bool isRight = false; if (selectItem.transform.localPosition.x > centerXValue) { isRight = true; } // calculate the offset * dFactor int moveIndexCount = GetMoveCurveFactorCount(preCenterItem, selectItem); float dvalue = 0.0f; if (isRight) { TimerManager.Destroy("rotate"); TimerManager.AddTimerRepeat("rotate", 0, RotateTrans, isRight); dvalue = -dFactor * moveIndexCount; } else { TimerManager.Destroy("rotate"); TimerManager.AddTimerRepeat("rotate", 0, RotateTrans, isRight); gearRotate.Rotate(30 * Vector3.forward); dvalue = dFactor * moveIndexCount; } float originValue = curHorizontalValue; LerpTweenToTarget(originValue, curHorizontalValue + dvalue, true); }
public void SetHorizontalTargetItemIndex(EnhanceItem selectItem) { if (!canChangeItem) { return; } if (curCenterItem == selectItem) { return; } if (curCenterItem == null) { curCenterItem = listEnhanceItems[startCenterIndex]; } canChangeItem = false; preCenterItem = curCenterItem; curCenterItem = selectItem; // calculate the direction of moving float centerXValue = positionCurve.Evaluate(0.5f) * totalHorizontalWidth; bool isRight = false; if (selectItem.transform.localPosition.x > centerXValue) { isRight = true; } // calculate the offset * dFactor int moveIndexCount = GetMoveCurveFactorCount(preCenterItem, selectItem); float dvalue = 0.0f; if (isRight) { dvalue = -dFactor * moveIndexCount; } else { dvalue = dFactor * moveIndexCount; } float originValue = curHorizontalValue; LerpTweenToTarget(originValue, curHorizontalValue + dvalue, true); }
void Update() { if (!isInit) { return; } currentDuration += Time.deltaTime; SortDepth(); if (currentDuration > duration) { currentDuration = duration; //if (centerItem != null) //{ // centerItem.SetSelectColor(true); //} if (centerItem == null) { var obj = transform.GetChild(transform.childCount - 1); if (obj != null) { centerItem = obj.GetComponent <EnhanceItem>(); } if (centerItem != null) { centerItem.SetSelectColor(true); } } else { centerItem.SetSelectColor(true); } if (preCenterItem != null) { preCenterItem.SetSelectColor(false); } canChangeItem = true; } float percent = currentDuration / duration; horizontalValue = Mathf.Lerp(originHorizontalValue, horizontalTargetValue, percent); UpdateEnhanceScrollView(horizontalValue); }
/// <summary> /// 设置水平目标项目id /// </summary> /// <param name="selectItem"></param> public void SetHorizontalTargetItemIndex(EnhanceItem selectItem) { if (!canChangeItem)//当前不允许改变选中目标,直接返回 { return; } if (curCenterItem == selectItem)//选中项为发生变化,直接放回 { return; } canChangeItem = false; //设置flag为不允许改变选中目标 preCenterItem = curCenterItem; //缓存上一个选中的项目 curCenterItem = selectItem; //缓存当前选中的目标 // 计算运动的方向 float centerXValue = positionCurve.Evaluate(0.5f) * totalHorizontalWidth; //得到中心x坐标 bool isRight = false; if (selectItem.transform.localPosition.x > centerXValue)//选中项的x坐标大于中心坐标时,目标在右方 { isRight = true; } // 计算偏移量因子 int moveIndexCount = GetMoveCurveFactorCount(preCenterItem, selectItem); // 得到运动距离 float dvalue = 0.0f; if (isRight)//目标在右方为负 { dvalue = -dFactor * moveIndexCount; } else { dvalue = dFactor * moveIndexCount; } float originValue = curHorizontalValue; //插值渐变运算 LerpTweenToTarget(originValue, curHorizontalValue + dvalue, true); }
void OnTriggerStay(Collider collider) { time += Time.deltaTime; Debug.Log(time); if (time >= 3) { centreitem = GameObject.Find("EnhanceScrollViewController").GetComponent <EnhancelScrollView>().centerItem; Debug.Log("__________________________________________________" + centreitem); //添加数据 //fileLoad.getEnhance ().Add (centreitem.ToString()); Application.LoadLevel("controller_sence"); //Debug.Log("enter "+time+" s next sence"); } }
void Start() { if ((scrollViewItems.Count % 2) == 0) { Debug.LogError("item count is invaild,please set odd count! just support odd count."); } if (moveHorizontalValues == null) { moveHorizontalValues = new float[scrollViewItems.Count]; } if (dHorizontalValues == null) { dHorizontalValues = new float[scrollViewItems.Count]; } if (textureTargets == null) { textureTargets = new List <RawImage>(); } int centerIndex = scrollViewItems.Count / 2; for (int i = 0; i < scrollViewItems.Count; i++) { scrollViewItems[i].scrollViewItemIndex = i; RawImage tmpTexture = scrollViewItems[i].gameObject.GetComponent <RawImage>(); textureTargets.Add(tmpTexture); scrollViewItems[i].parent = this; dHorizontalValues[i] = dFactor * (centerIndex - i); dHorizontalValues[centerIndex] = 0.0f; moveHorizontalValues[i] = 0.5f - dHorizontalValues[i]; scrollViewItems[i].SetSelectColor(false); } centerItem = scrollViewItems[centerIndex]; canChangeItem = true; canPlay = true; Debug.LogError("====start======"); }
/// /// Update EnhanceItem state with curve fTime value /// public void UpdateEnhanceScrollView(float fValue) { for (int i = 0; i < listEnhanceItems.Count; i++) { EnhanceItem itemScript = listEnhanceItems[i]; float xValue; if (this.name == "areaScrollView") { xValue = GetXPosValue(fValue, itemScript.CenterOffSet) - 250 * listEnhanceItems.Count;//X轴位置变化 } else { xValue = GetXPosValue(fValue, itemScript.CenterOffSet) - 200 * listEnhanceItems.Count;//X轴位置变化 } float scaleValue = GetScaleValue(fValue, itemScript.CenterOffSet); float depthCurveValue = depthCurve.Evaluate(fValue + itemScript.CenterOffSet); itemScript.UpdateScrollViewItems(xValue, depthCurveValue, depthFactor, listEnhanceItems.Count, yFixedPositionValue, scaleValue); } }
private void InitItem() { print("开始"); List <EnhanceItem> list = new List <EnhanceItem>(); for (int i = 0; i < 10; ++i) { GameObject item = GameObject.Instantiate(mItem); item.name = "item" + i.ToString(); item.SetActive(true); item.transform.SetParent(mContent, false); item.transform.GetComponent <Image>().sprite = Resources.Load <Sprite>("Image" + (i + 1).ToString()); EnhanceItem enitem = item.GetComponent <EnhanceItem>(); enitem.scrollViewItemIndex = i; item.GetComponent <RectTransform>().SetSiblingIndex(i); list.Add(enitem); } enhanceScroll.InitScrollViewData(list); }
//当插入了所有子项后 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 SetHorizontalTargetItemIndex(EnhanceItem selectItem) { if (!canChangeItem) return; if (curCenterItem == selectItem) return; canChangeItem = false; preCenterItem = curCenterItem; curCenterItem = selectItem; // calculate the direction of moving float centerXValue = positionCurve.Evaluate(0.5f) * totalHorizontalWidth; bool isRight = false; if (selectItem.transform.localPosition.x > centerXValue) isRight = true; // calculate the offset * dFactor int moveIndexCount = GetMoveCurveFactorCount(preCenterItem, selectItem); float dvalue = 0.0f; if (isRight) { dvalue = -dFactor * moveIndexCount; } else { dvalue = dFactor * moveIndexCount; } float originValue = curHorizontalValue; LerpTweenToTarget(originValue, curHorizontalValue + dvalue, true); }
// sort item with X so we can know how much distance we need to move the timeLine(curve time line) static public int SortPosition(EnhanceItem a, EnhanceItem b) { return a.transform.localPosition.x.CompareTo(b.transform.localPosition.x); }
private int GetMoveCurveFactorCount(EnhanceItem preCenterItem, EnhanceItem newCenterItem) { SortEnhanceItem(); int factorCount = Mathf.Abs(newCenterItem.RealIndex) - Mathf.Abs(preCenterItem.RealIndex); return Mathf.Abs(factorCount); }
void Start() { 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; curCenterItem = listEnhanceItems[startCenterIndex]; curHorizontalValue = 0.5f - curCenterItem.CenterOffSet; LerpTweenToTarget(0f, curHorizontalValue, false); // // enable the drag actions // EnableDrag(true); }
// sort item with X so we can know how much distance we need to move the timeLine(curve time line) static public int SortPosition(EnhanceItem a, EnhanceItem b) { return(a.transform.localPosition.x.CompareTo(b.transform.localPosition.x)); }
// 获取项目A到项目B之间最小的时间差值(圆形角度计算,1=360度) private float GetCurveTimeDValue(EnhanceItem itemA, EnhanceItem itemB) { return(Round((Mathf.DeltaAngle(itemA.angla, itemB.angla)) / 360f, curACC)); }
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(); }