public static int makeBits(params int[] values) { int num_args = values.Length; int value = 0; int b0 = 0; for (int i = num_args; i > 1; i = i - 2) { int b = values[i - 2]; int v = values[i - 1]; int v2 = bits(v, 0, b); if (v != v2) { if (KSDebug.enableLog) { KSDebug.LogError("makebits value out of bit range : " + v); } return(0); } v = v << b0; value = value + v; b0 = b0 + b; } return(value); }
//设置选中 public void SetSelected(int index, bool animation = false) { if (index < 0 || index >= maxCount) { if (KSDebug.enableLog) { KSDebug.LogError("SetSelected index = " + index + " out of rang!!!!"); } return; } this.selectedIndex = -1; this.lastRoundTableRotationRadian = -1; float targetRadian = -index * eachRadian; targetRadian = FliterRotationRadian(targetRadian); if (animation) { if (status == TableStatus.Idle) { SetStatus(TableStatus.Fling); } flingToTargetRandian = targetRadian; } else { roundTableRotationRadian = targetRadian; UpdateLayout(); } }
public static IEnumerator LoadImage(Image image, string path) { //string path = @"file://" + Application.dataPath + @"/Resources/Army/" + name + ".png"; using (WWW www = new WWW(path)) { yield return(www); if (www.isDone && www.error == null) { Texture2D texture = www.texture; Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); image.sprite = sprite; //image.sprite = Sprite.Create(www.texture, new Rect(0, 0, 512f, 512f), new Vector2(0.5f, 0.5f)); } else { KSDebug.LogError(www.error); } } }
public void OnEndDrag(PointerEventData eventData) { if (passTouchToFallback) { fallbackTouchObject.OnEndDrag(eventData); return; } if (status != TableStatus.Touch) { return; } SetStatus(TableStatus.Fling); flingVelocityCalculate.addPoint(eventData.position, Time.deltaTime); Vector2 velocity = flingVelocityCalculate.computeCurrentVelocity(); if (KSDebug.enableLog) { KSDebug.Log("fling velocity = " + velocity.ToString()); } flingVelocityCalculate.Reset(); float targetRadian; if (isGearScrollMode) { //齿轮滚动模式 targetRadian = FliterRotationRadian(roundTableRotationRadian + GearFlingVelocity2RotationRadian(velocity)); } else { //惯性滚动模式 //松手后要滚动的距离 float xf = velocity.x == 0 ? 1 : velocity.x / Mathf.Abs(velocity.x); float yf = velocity.y == 0 ? 1 : velocity.y / Mathf.Abs(velocity.y); float xs = xf * Mathf.Pow(velocity.x, 2) / (2 * flingResistance); float ys = yf * Mathf.Pow(velocity.y, 2) / (2 * flingResistance); targetRadian = roundTableRotationRadian + TouchDelat2RotationRadian(xs, ys); targetRadian = FliterRotationRadian(targetRadian); } //停靠到最进的一个弧度上 float maxNearRandian; float minNearRandian; if (targetRadian >= 0) { minNearRandian = ((int)(targetRadian / eachRadian)) * eachRadian; maxNearRandian = minNearRandian + eachRadian; } else { maxNearRandian = ((int)(targetRadian / eachRadian)) * eachRadian; minNearRandian = maxNearRandian - eachRadian; } float toRandian; if (maxNearRandian >= maxRotationRadian) {//达到顺时针的边界 toRandian = minNearRandian; } else if (minNearRandian <= minRotationRadian) {//达到逆时针边界 toRandian = maxNearRandian; } else { toRandian = Mathf.Abs(targetRadian - maxNearRandian) > Mathf.Abs(minNearRandian - targetRadian) ? minNearRandian : maxNearRandian; } if (Mathf.Abs(toRandian - roundTableRotationRadian) < 0.01) { roundTableRotationRadian = toRandian; SetStatus(TableStatus.Idle); } else { //记录fling目标,在后续update中进行动画滚动 flingToTargetRandian = toRandian; } }