Hi, for my programm im programming a “clock like” behaviour. Meaning i
- order some pictures in a circle (works)
- if i click and drag on any item all items should rotate with the mouse (works)
But i get a weird bug. The first time i click and hold the mouse my images “jump” to different positions. if i hold the mouse down i can rotate my clock ust fine.
When i MouseUp and start dragin from the same image it works well. if i go to another image i get this “Jump” again.
If i increase the number of images in my clock the jumped items decrease.
For example. if i have 8 items in my clock the dragged image jumps 3 images(for example the number 5 would jump to number 2, and all images jump acordingly)
If i have 30 items and i drag the number 12, it jumps to number 11 and all other images accordingly.
So the clock itself keeps it numbers in the right position, it just has jump in all numbers when i start dragin a new number compared to last drag.
I checked alot of issues, the math, sine cosine … added some degrees changed some other values. It is not working.
Best idea on how to find the bug is by the different behaviours when i re-drag the same item or another one.
Lets say i have 8 images.
1-2-3-4-5-6-7-8
if i start draging number 3 my clock changes immediately to
6-7-8-1-2-3-4-5
Than i can drag it without problem. If i MouseUp and redrag on the 3 everything works as i want.
If i than drag on the number 2, all images jump 1 so the clock looks like
7-8-1-2-3-4-5-6
The more images i ahve in my clock the “smaller” this gap gets.
Well i think most understood the problem now. Here is the code where i think the problem is:
#############
public void SetLayoutHorizontal ()
{
Debug.Log ("LAYOUT");
for (var i =0; i < Rect.childCount; i++)
{
var PanelPrefab = Rect.GetChild (i) as RectTransform;
Transform ImageObject = PanelPrefab.GetComponentInChildren<Transform>().Find("Image");
if (PanelPrefab == null)
continue;
PanelPrefab.sizeDelta = CellSize;
PanelPrefab.anchoredPosition = new Vector2(radius * Mathf.Sin( CalculateCircleAngle(i) - deltaRadian),radius * Mathf.Cos(CalculateCircleAngle(i) - deltaRadian));
}
}
private float CalculateCircleAngle(int parts)
{
//parts == Number of parts the whole circle is to be cut into
return parts * (360/Rect.childCount) * (Mathf.PI/180);
}
public void OnDrag (PointerEventData eventData)
{
var diffX = eventData.position.x - _rect.rect.width/2;
var diffY = eventData.position.y - _rect.rect.height/2;
deltaRadian = Mathf.Atan2(diffY,diffX);
SetDirty();
}