/// <summary> /// enable swipe control /// </summary> void Awake() { if (!swipeCtrl) { swipeCtrl = gameObject.GetComponent <SwipeControl>(); //Find SwipeControl on same GameObject if none given } if (imgRect == new Rect(0, 0, 0, 0)) { //If no rect given, create default rect imgRect = new Rect(-(Screen.width * 0.8f) * 0.5f, -(Screen.width * 0.8f) * 0.5f, (Screen.width * 0.8f), (Screen.width * 0.8f)); } //Set up SwipeControl swipeCtrl.partWidth = img[0].width; swipeCtrl.maxValue = img.Length - 1; if (expandInputAreaToFullWidth) { swipeCtrl.SetMouseRect(new Rect(-Screen.width * 0.5f, imgRect.y, Screen.width, imgRect.height)); // Use image-height for the input-Rect, but full screen-width } else { swipeCtrl.SetMouseRect(imgRect); //Use the same Rect as the images for input } swipeCtrl.CalculateEdgeRectsFromMouseRect(imgRect); swipeCtrl.Setup(); //Determine center position of the Dots if (dotRelativeCenterPos == Vector2.zero) { dotRelativeCenterPos.y = imgRect.height * 0.5f + 14f; } dotRelativeCenterPos = new Vector2(0, imgRect.height * 0.6f); Debug.Log("ImageRect: " + imgRect.height); Debug.Log("dotX: " + imgRect.x); if (centerMatrixOnScreen) { matrixPosition.x += Mathf.Round(Screen.width * 0.5f); matrixPosition.y += Mathf.Round(Screen.height * 0.5f); } }
protected override void onStart() { base.onStart(); if (!swipeCtrl) { swipeCtrl = gameObject.GetComponent <SwipeControl> (); //Find SwipeControl on same GameObject if none given } ignoreTimeScale = true; var worldsCnt = 7; buttons = new Transform[worldsCnt]; for (int i = 0; i < worldsCnt; i++) { var ch = Instantiate(button); ch.parent = transform; ch.GetComponent <LevelButton> ().init(i + 1); ch.name = "button" + i; buttons [i] = ch; var p = new Vector3(dx * i, .4f, 0); ch.localPosition = p; var d = Instantiate(dot); d.parent = transform; d.name = "dot" + i; p = new Vector3(.4f * i - worldsCnt * .5f * .4f, -3f, 0); d.localPosition = p; } maxXPos = dx * worldsCnt; swipeSmoothFactor = 1f / worldsCnt; xDist = maxXPos - minXPos; //calculate distance between min and max swipeCtrl.SetMouseRect(new Rect(0, 0, Screen.width, Screen.height * .9f)); //entire screen swipeCtrl.maxValue = worldsCnt - 1; //max value swipeCtrl.currentValue = 0; //current value set to max, so it starts from the end swipeCtrl.startValue = 0; //Mathf.RoundToInt ((gameModel.skin-1) * 0.5f); //when Setup() is called it will animate from the end to the middle swipeCtrl.partWidth = Screen.width / 2; //how many pixels do you have to swipe to change the value by one? in this case we make it dependent on the screen-width and the maxValue, so swiping from one edge of the screen to the other will scroll through all values. swipeCtrl.Setup(); }
void Awake() { if (!swipeCtrl) { swipeCtrl = gameObject.GetComponent <SwipeControl>(); //Find SwipeControl on same GameObject if none given } if (centerMatrixOnScreen) { matrixPosition.x += Mathf.Round(Screen.width * 0.5f); matrixPosition.y += Mathf.Round(Screen.height * 0.5f); } if (myRect == new Rect(0, 0, 0, 0)) //If no rect given, create default rect { myRect = new Rect(-img[1].width * 0.5f, -img[1].height * 0.5f, img[1].width, img[1].height); } //Set up SwipeControl swipeCtrl.partWidth = img[1].width; swipeCtrl.maxValue = img.Length - 1; swipeCtrl.SetMouseRect(myRect); swipeCtrl.Setup(); }