public void GridLayoutBackGround() { for (int i = 0; i < BackGroundManager.Instance.backGroundFrame.Length; i++) { GameObject backgroundFrame = (GameObject)Instantiate(BackGroundManager.Instance.backGroundFrame[i], transform); GameObject background = backgroundFrame.transform.GetChild(0).gameObject; backgroundFrame.tag = "BackGround"; BackGround backgroundData = background.GetComponent <BackGround>(); GameObject lockImage = background.transform.GetChild(0).gameObject; GameObject unlockImage = background.transform.GetChild(1).gameObject; if (i == 0) { backgroundData.Unlock(true); } if (i == BackGroundManager.Instance.CurrentBackGroundIndex) { CurrentSelectBackgr = background; background.GetComponent <OnClickBackGround>().ChangeOutLine(); } if (backgroundData.isFree || backgroundData.IsUnlocked) { lockImage.SetActive(false); unlockImage.SetActive(false); } else { if (CoinManager.Instance.Coins >= backgroundData.price) { lockImage.SetActive(false); unlockImage.SetActive(true); } else { lockImage.SetActive(true); unlockImage.SetActive(false); } } backgroundData.backGroundSequenceNumber = i; } }
// Update is called once per frame void Update() { #region Scrolling // Do the scrolling stuff if (Input.GetMouseButtonDown(0)) // first touch { startPos = Input.mousePosition; startTime = Time.time; hasMoved = false; } else if (Input.GetMouseButton(0)) // touch stays { endPos = Input.mousePosition; endTime = Time.time; float deltaX = Mathf.Abs(startPos.x - endPos.x); //float deltaY = Mathf.Abs(startPos.y - endPos.y); if (deltaX >= swipeThresholdX) { hasMoved = true; if (isCurrentbackGroundRotating) { StopRotateCurrentbackGround(true); } float speed = deltaX / (endTime - startTime); Vector3 dir = (startPos.x - endPos.x < 0) ? Vector3.right : Vector3.left; Vector3 moveVector = dir * (speed / 10) * scrollSpeedFactor * Time.fixedDeltaTime; currentAngle -= moveVector.x * backGroundAngleSpace / 5; if (currentAngle > Mathf.PI * 2) { currentAngle -= Mathf.PI * 2; } else if (currentAngle < 0) { currentAngle += Mathf.PI * 2; } // Move and scale the children for (int i = 0; i < listbackGround.Count; i++) { switch (scrollerStyle) { case ScrollerStyle.Line: MoveAndScale(listbackGround[i].transform, moveVector); break; case ScrollerStyle.Circle: MoveAndScaleCircleVer(listbackGround[i].transform, moveVector, i); break; default: break; } } // Update for next step startPos = endPos; startTime = endTime; } } if (Input.GetMouseButtonUp(0)) { if (hasMoved) { // Store the last currentbackGround lastCurrentbackGround = currentbackGround; // Update current backGround to the one nearest to center point switch (scrollerStyle) { case ScrollerStyle.Line: currentbackGround = FindbackGroundNearestToCenter(); // Snap float snapDistance = transform.InverseTransformPoint(centerPoint).x - currentbackGround.transform.localPosition.x; StartCoroutine(SnapAndRotate(snapDistance)); break; case ScrollerStyle.Circle: currentbackGround = FindbackGroundNearestToCenterCircleVer(); StartCoroutine(SnapAndRotateCircleVer()); break; default: break; } } } #endregion // Update UI totalCoins.text = CoinManager.Instance.Coins.ToString(); BackGround charData = currentbackGround.GetComponent <BackGround>(); if (!charData.isFree) { priceText.gameObject.SetActive(true); priceText.text = charData.price.ToString(); } else { priceText.gameObject.SetActive(false); } if (currentbackGround != lastCurrentbackGround) { if (charData.IsUnlocked) { unlockButton.gameObject.SetActive(false); lockButton.gameObject.SetActive(false); selectButon.gameObject.SetActive(true); } else { selectButon.gameObject.SetActive(false); if (CoinManager.Instance.Coins >= charData.price) { unlockButton.gameObject.SetActive(true); lockButton.gameObject.SetActive(false); } else { unlockButton.gameObject.SetActive(false); lockButton.gameObject.SetActive(true); } } } }
// Use this for initialization void Start() { //PlayerPrefs.DeleteAll(); lockColor.a = 0; // need this for later setting material colors to work int currentbackGroundIndex = BackGroundManager.Instance.CurrentBackGroundIndex; currentbackGroundIndex = Mathf.Clamp(currentbackGroundIndex, 0, BackGroundManager.Instance.backGrounds.Length - 1); centerPoint = transform.TransformPoint(centerPoint); switch (scrollerStyle) { case ScrollerStyle.Line: BackGroundScrollerCamera.GetComponent <Camera>().orthographic = true; break; case ScrollerStyle.Circle: BackGroundScrollerCamera.GetComponent <Camera>().orthographic = false; break; default: break; } backGroundAngleSpace = Mathf.PI * 2 / BackGroundManager.Instance.backGrounds.Length; currentAngle = currentbackGroundIndex * backGroundAngleSpace; for (int i = 0; i < BackGroundManager.Instance.backGrounds.Length; i++) { int deltaIndex = i - currentbackGroundIndex; GameObject backGround = (GameObject)Instantiate(BackGroundManager.Instance.backGrounds[i], centerPoint, Quaternion.Euler(0, 0, 0)); backGround.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f); BackGround charData = backGround.GetComponent <BackGround>(); charData.backGroundSequenceNumber = i; listbackGround.Add(backGround); backGround.transform.localScale = originalScale; //backGround.transform.position = centerPoint + new Vector3(deltaIndex * backGroundSpace, 0, 0); // Set color based on locking status //Renderer charRdr = backGround.GetComponentInChildren<Renderer>(); //if (charData.IsUnlocked) // charRdr.material.SetColor("_Color", Color.white); //else // charRdr.material.SetColor("_Color", lockColor); // Set as child of this object backGround.transform.parent = transform; switch (scrollerStyle) { case ScrollerStyle.Line: backGround.transform.localPosition += new Vector3(deltaIndex * BackGroundSpace, 0, 0); break; case ScrollerStyle.Circle: backGround.transform.localPosition = transform.InverseTransformPoint(centerPoint) + new Vector3(Mathf.Sin(-currentAngle + i * backGroundAngleSpace), 0, -Mathf.Cos(-currentAngle + i * backGroundAngleSpace)) * BackGroundScrollerRadius; break; default: break; } // Set layer for camera culling backGround.gameObject.layer = LayerMask.NameToLayer("BackGroundSelectionUI"); //GameObject child = backGround.gameObject.transform.GetChild(0).gameObject; //child.transform.GetChild(0).gameObject.layer = LayerMask.NameToLayer("BackGroundSelectionUI"); //if (backGround.gameObject.transform.childCount > 0) //{ // for (int j = 0; j < backGround.gameObject.transform.childCount; j++) // backGround.gameObject.transform.GetChild(j).gameObject.layer = LayerMask.NameToLayer("BackGroundSelectionUI"); //} } // Highlight current backGround currentbackGround = listbackGround[currentbackGroundIndex]; switch (scrollerStyle) { case ScrollerStyle.Line: currentbackGround.transform.localScale = maxScale * originalScale; currentbackGround.transform.localPosition += moveForwardAmount * Vector3.forward; break; case ScrollerStyle.Circle: currentbackGround.transform.localScale = maxScale * originalScale; break; default: break; } lastCurrentbackGround = null; StartRotateCurrentbackGround(); }
protected override void Awake() { backgroundData = gameObject.GetComponent <BackGround>(); }