赞
踩
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Assertions.Comparers;
-
- public class RotateAndZoom : MonoBehaviour
- {
- public int id;
- public bool isMain;
-
- public static RotateAndZoom _instance;
-
- private Quaternion startQuaternion;
- private Vector3 startScale;
- private Vector3 startPos;
- private Vector3 centerPos;
-
- private Touch frisTouch;
- private Touch secondTouch;
-
- private bool autoRotate;
- private bool isRecover;
- [HideInInspector]
- public float coolTime;
-
- private bool isCenter;
-
- private float waitTime;
- private float recoverTime;
- private float centerTime;
- private bool isTouch;
-
- private bool isCool;
-
- void Awake()
- {
- _instance = this;
- }
-
- void Start()
- {
- isCool = true;
- centerPos = new Vector3(0,0,-1);
- startQuaternion = transform.rotation;
- startScale = transform.localScale;
- startPos = transform.position;
- autoRotate = true;
- }
-
- void Update()
- {
- AutoRoattionAndRecover();
-
- if (Input.touchCount < 0)
- return;
-
- if (isTouch)
- {
- if (Input.touchCount > 0)
- {
- Touch touch = Input.GetTouch(0);
- Vector2 deltaPos = touch.deltaPosition;
-
- transform.Rotate(Vector3.down*deltaPos.x*2, Space.World);
- transform.Rotate(Vector3.right*deltaPos.y*2, Space.World);
- }
-
- if (Input.touchCount > 0)
- {
- Touch newTouch1 = Input.GetTouch(0);
- Touch newTouch2 = Input.GetTouch(1);
-
- if (newTouch2.phase == TouchPhase.Began)
- {
- frisTouch = newTouch1;
- secondTouch = newTouch2;
- return;
- }
-
-
- float startDistance = Vector2.Distance(frisTouch.position, secondTouch.position);
- float newDistance = Vector2.Distance(newTouch1.position, newTouch2.position);
-
- float offset = newDistance - startDistance;
-
-
- float scaleFactor = offset/100f;
- Vector3 localScale = transform.localScale;
- Vector3 scale = new Vector3(localScale.x + scaleFactor, localScale.y + scaleFactor,
- localScale.z + scaleFactor);
-
- if (scale.x > 0.3f && scale.y > 0.3f && scale.z > 0.3f)
- {
- transform.localScale = scale;
- }
-
- float scale1 = Mathf.Clamp(transform.localScale.x, 3f, 4.5f);
- transform.localScale = Vector3.one*scale1;
- ;
- frisTouch = newTouch1;
- secondTouch = newTouch2;
- }
- }
-
- if (isMain && !isRecover)
- {
- if (Input.touchCount > 0)
- {
- if (Input.GetTouch(0).phase == TouchPhase.Began || Input.GetTouch(0).phase == TouchPhase.Moved)
- {
- coolTime = 0;
- }
- }
-
- if (isCool)
- isCenter = true;
-
- autoRotate = false;
- waitTime += Time.deltaTime;
- if (waitTime >= 2)
- {
- isTouch = true;
- }
- coolTime += Time.deltaTime;
- if (coolTime >= 3)
- {
- coolTime = 0;
- isRecover = true;
- isTouch = false;
- waitTime = 0;
- isMain = false;
- isCenter = false;
- }
- }
-
-
- }
-
- void AutoRoattionAndRecover()
- {
- if (autoRotate)
- transform.RotateAround(transform.position, Vector3.up, 30 * Time.deltaTime);
-
- if (isRecover)
- {
- transform.position = Vector3.Lerp(transform.position, startPos, 2*Time.deltaTime);
- transform.rotation = Quaternion.Lerp(transform.rotation, startQuaternion, 2*Time.deltaTime);
- transform.localScale = Vector3.Lerp(transform.localScale, startScale, 2*Time.deltaTime);
-
- recoverTime += Time.deltaTime;
- if (recoverTime >= 2)
- {
- recoverTime = 0;
- autoRotate = true;
- isRecover = false;
- isCool = true;
- }
- }
-
- if (isCenter)
- {
- transform.position = Vector3.Lerp(transform.position, centerPos, 2*Time.deltaTime);
- transform.localScale = Vector3.Lerp(transform.localScale, Vector3.one*2.8f, 2*Time.deltaTime);
- centerTime += Time.deltaTime;
- if (centerTime >= 2)
- {
- centerTime = 0;
- isCool = false;
- isCenter = false;
- }
- }
-
- }
- }
- using System.Collections;
- using System.Collections.Generic;
- using System.Security.Policy;
- using UnityEngine;
- using UnityEngine.UI;
-
- public class GameManager : MonoBehaviour
- {
- public static GameManager _instance;
-
- public Transform[] spawnTargetpos;
- public GameObject targetGo;
- public Transform parent;
- public Text getText;
- [HideInInspector]
- public List<GameObject> goList = new List<GameObject>();
- private int touchIndex = -1;
- private bool isStop;
- private RaycastHit hitInfor;
-
- private RotateAndZoom touchGo_RotateZoom ;
-
- void Awake()
- {
- _instance = this;
- }
-
- void Start()
- {
- isStop = true;
- }
-
-
- void Update()
- {
-
- if (Input.touchCount > 0)
- {
- if (Input.GetTouch(0).phase == TouchPhase.Began)
- {
- LoopAddGameObject();
-
- touchIndex++;
- GameObject go = GameObject.Instantiate(targetGo) as GameObject;
- go.transform.position = spawnTargetpos[touchIndex].position;
- RotateAndZoom rotateAndZoom = go.GetComponent<RotateAndZoom>();
- rotateAndZoom.id = touchIndex;
- goList.Add(go);
-
- Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
- Physics.Raycast(ray, out hitInfor, 100);
-
- if (!hitInfor.collider)
- {
-
- }
- else
- {
- touchGo_RotateZoom = hitInfor.collider.gameObject.GetComponent<RotateAndZoom>();
- touchGo_RotateZoom.isMain = true;
- touchGo_RotateZoom.coolTime = 0;
- HeadOtherCollider(touchGo_RotateZoom.id);
- getText.text = touchGo_RotateZoom.id.ToString();
- }
- }
- }
-
- CheckTouchObjectState();
- }
-
- void HeadOtherCollider(int id)
- {
- for (int i = 0; i < goList.Count; i++)
- {
- RotateAndZoom rotateAndZoom = goList[i].GetComponent<RotateAndZoom>();
- if (rotateAndZoom.id == id)
- {
- Collider collider = rotateAndZoom.GetComponent<Collider>();
- //MeshRenderer renderer = rotateAndZoom.GetComponent<MeshRenderer>();
- collider.enabled = true;
- //renderer.material.color = Color.red;
- }
- else
- {
- Collider collider = rotateAndZoom.GetComponent<Collider>();
- //MeshRenderer renderer = rotateAndZoom.GetComponent<MeshRenderer>();
- collider.enabled = false;
- //renderer.material.color = Color.blue;
- }
- }
- }
-
-
- void CheckTouchObjectState()
- {
- if (touchGo_RotateZoom == null)
- {
- return;
- }
-
- if (!touchGo_RotateZoom.isMain)
- {
- for (int i = 0; i < goList.Count; i++)
- {
- Collider collider = goList[i].GetComponent<Collider>();
- //MeshRenderer renderer = goList[i].GetComponent<MeshRenderer>();
- collider.enabled = true;
- //renderer.material.color = Color.blue;
- }
- }
- }
-
-
- void LoopAddGameObject()
- {
- if (goList.Count > 10)
- {
- print(touchIndex);
- for (int i = 0; i < goList.Count; i++)
- {
- RotateAndZoom rotateAndZoom1 = goList[i].GetComponent<RotateAndZoom>();
-
- if (rotateAndZoom1.id == touchIndex - 10)
- {
- MeshRenderer[] renderers = rotateAndZoom1.GetComponentsInChildren<MeshRenderer>();
- for (int j = 0; j < renderers.Length; j++)
- {
- renderers[i].enabled = false;
- }
- goList.Remove(rotateAndZoom1.gameObject);
- GameObject.Destroy(rotateAndZoom1.gameObject, 0.5f);
- }
-
- }
- }
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。