void Start() { Instacne = this; hitScreenData = GetComponent <P3dHitScreen>(); //hitScreenData.enabled = false; allTextures = new List <Texture>(); for (int i = 1; i <= numOfTextures; i++) { allTextures.Add(Resources.Load("Textures/texture0" + i) as Texture); GameObject GO = Instantiate(textureButtonPrefab, textureParent); GO.GetComponent <RawImage>().texture = Resources.Load("Textures/old/texture0" + i) as Texture; TextureHolderScript THS = GO.GetComponent <TextureHolderScript>(); THS.heldTexture = allTextures[i - 1]; } hasErased = false; ThickStrongNoShape(); }
void Update() { if (isInGame) { if (Input.touchCount == 0) { PainterManager.Instacne.hitScreenData.ClearHitCache(); PainterManager.Instacne.hitScreenData.ResetConnections(); PainterManager.Instacne.hitScreenData.ClearFingers(); PainterManager.Instacne.hitScreenData.enabled = false; textureScrollRect.enabled = true; timerForApplyTex = 0; timerForGetTex = 0; previouslyDetectedPiece = null; clickingTex = false; clickingGrad = false; chosenTex = false; chosenGrad = false; texture.gameObject.SetActive(false); gradTexture = null; paintableObject = null; paintableTexture = null; canPaint = true; currentTHS = null; DisconnectPaint3DTouches(); } if (Input.touchCount > 0 || Input.GetMouseButtonDown(0)) { if (AnimationManager.isFinishedAnimation) { DeactivateObjectsOnScreenTouch(); AnimationManager.isFinishedAnimation = false; } } if (Input.touchCount == 1 && canPaintShoe) { touch = Input.GetTouch(0); if (!PainterManager.Instacne.hitScreenData.enabled) { Invoke("EnableHitScreen", 0.15f); } if (touch.phase == TouchPhase.Stationary) { if (clickingTex && !chosenTex) { timerForGetTex += Time.deltaTime; if (timerForGetTex > 0.1f) { textureScrollRect.enabled = false; chosenTex = true; timerForApplyTex = 0; TextureHolderScript THS = currentTHS.transform.GetComponent <TextureHolderScript>(); texture.gameObject.SetActive(true); texture.texture = THS.heldTexture; Vector3 mousePos = Camera.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, 100)); mousePos.z = texture.transform.position.z; //Debug.DrawRay(Camera.transform.position, mousePos, Color.red); texture.transform.position = mousePos; texture.transform.localScale = new Vector3(1, 1, 1); } } if (clickingGrad && !chosenGrad) { timerForGetTex += Time.deltaTime; if (timerForGetTex > 0.1f) { //textureScrollRect.enabled = false; chosenGrad = true; timerForApplyTex = 0; //TextureHolderScript THS = currentTHS.transform.GetComponent<TextureHolderScript>(); //texture.gameObject.SetActive(true); //texture.texture = THS.heldTexture; Vector3 mousePos = Camera.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, 100)); mousePos.z = gradTexture.transform.position.z - 1; //Debug.DrawRay(Camera.transform.position, mousePos, Color.red); gradTexture.transform.position = mousePos; //texture.transform.position = mousePos; //texture.transform.localScale = new Vector3(1, 1, 1); } } } if (touch.phase == TouchPhase.Moved) { timerForGetTex = 0; timerForApplyTex = 0; if (chosenTex && !changingTexNow) { changingTexNow = true; Vector3 mousePos = Camera.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, 100)); mousePos.z = 75; texture.transform.position = mousePos; texture.transform.localScale = new Vector3(1, 1, 1); RaycastHit hit; Ray ray = Camera.ScreenPointToRay(touch.position); //Debug.DrawRay(Camera.transform.position, mousePos, Color.red); if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { if (hit.transform.CompareTag("ShoePiece") || hit.transform.CompareTag("ShoePieceNonPaintable")) { texture.transform.position = new Vector3(hit.point.x, hit.point.y, hit.point.z - 1); texture.transform.localScale = new Vector3(0.2f, 0.2f, 1); timerForApplyTex += Time.deltaTime; if (hit.transform.CompareTag("ShoePiece")) { paintableObject = hit.transform.GetComponent <P3dPaintable>(); paintableTexture = hit.transform.GetComponent <P3dPaintableTexture>(); } } } else { paintableObject = null; paintableTexture = null; timerForApplyTex = 0; //if (previouslyDetectedPiece) //{ // Renderer previouslyDetectedPieceRenderer = previouslyDetectedPiece.transform.GetComponent<Renderer>(); // previouslyDetectedPieceRenderer.material.SetTexture("_BaseMap", null); // previouslyDetectedPiece = null; //} } changingTexNow = false; } if (chosenGrad && !changingTexNow) { changingTexNow = true; Vector3 mousePos = Camera.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, 100)); mousePos.z = 74; gradTexture.transform.position = mousePos; gradTexture.transform.localScale = new Vector3(1, 1, 1); RaycastHit hit; Ray ray = Camera.ScreenPointToRay(touch.position); //Debug.DrawRay(Camera.transform.position, mousePos, Color.red); if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { if (hit.transform.CompareTag("ShoePiece") || hit.transform.CompareTag("ShoePieceNonPaintable")) { gradTexture.transform.position = new Vector3(hit.point.x, hit.point.y, hit.point.z - 1); gradTexture.transform.localScale = new Vector3(0.2f, 0.2f, 1); timerForApplyTex += Time.deltaTime; if (hit.transform.CompareTag("ShoePiece")) { paintableObject = hit.transform.GetComponent <P3dPaintable>(); paintableTexture = hit.transform.GetComponent <P3dPaintableTexture>(); } } } else { paintableObject = null; paintableTexture = null; timerForApplyTex = 0; } changingTexNow = false; } } if (touch.phase == TouchPhase.Ended) { DisconnectPaint3DTouches(); if (chosenTex) { StartCoroutine(ChangeTexOnPiece(touch)); } if (chosenGrad) { gradTexture.transform.localPosition = originalGradTexPos; gradTexture.transform.localScale = new Vector3(1, 1, 1); StartCoroutine(ChangeGradOnPiece(touch)); } } } if (Input.touchCount >= 2 && canPaintShoe) { PainterManager.Instacne.hitScreenData.enabled = false; canPaint = false; //PainterManager.Instacne.hitScreenData.enabled = false; //PainterManager.Instacne.hitScreenData.Paint() Touch touchOne = Input.GetTouch(0); Touch touchTwo = Input.GetTouch(1); if (touchOne.phase == TouchPhase.Moved) { if (toRotate.transform.eulerAngles.y < 320 && toRotate.transform.eulerAngles.y > 230) { float deltaX = touchOne.deltaPosition.x; float deltaY = touchOne.deltaPosition.y; ShoeRotationY = deltaX * Time.deltaTime * rotationSpeedModifier; ShoeRotationZ -= deltaY * Time.deltaTime * rotationSpeedModifier; } else { float deltaX = touchOne.deltaPosition.x; float deltaY = touchOne.deltaPosition.y; ShoeRotationY = deltaX * Time.deltaTime * rotationSpeedModifier; ShoeRotationZ += deltaY * Time.deltaTime * rotationSpeedModifier; } float rotateY = toRotate.transform.eulerAngles.y - ShoeRotationY; ShoeRotationZ = Mathf.Clamp(ShoeRotationZ, -13, 13); toRotate.transform.eulerAngles = new Vector3(0, rotateY, ShoeRotationZ); //toRotate.transform.rotation = Quaternion.Euler(new Vector3(0, rotateY, rotateZ)); } } } if (isSharingScreen) { if (Input.touchCount >= 2) { RotateSpecificScreen(); } } if (UIManager.Instance.isLastScreen && UIManager.Instance.disableOnTouch.Count <= 0) { if (Input.touchCount >= 2) { UIManager.Instance.lastScreenAssetsNoShoe.SetActive(false); UIManager.Instance.designAgainFromShareScreen.SetActive(true); RotateSpecificScreen(); } } }