| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using ShotSimulator.Tool;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class ZyeTest : MonoBehaviour
- {
- public GameObject obj_1;
- public GameObject obj_2;
- public GameObject obj_3;
- public GameObject obj_4;
- public GameObject obj_5;
- public GameObject obj_6;
- public Camera snipeCamera;
- public Image snipeImage;
- public RectTransform rect;
- private Ray ray;
- List<MonoTest> list = new List<MonoTest>();
- private void Awake()
- {
- Debug.Log(Screen.width + ":" + Screen.height);
- //rect = snipeImage.transform.parent.GetComponent<RectTransform>();
- //obj_1.transform.position = ExtraTool.GetWorldPositionWithResolutionPercent(0.4f, 0.75f, 10);
- //obj_2.transform.position = ExtraTool.GetWorldPositionWithResolutionPercent(0.3f, 0.5f, 10);
- //obj_3.transform.position = ExtraTool.GetWorldPositionWithResolutionPercent(0.4f, 0.25f, 10);
- //obj_4.transform.position = ExtraTool.GetWorldPositionWithResolutionPercent(0.6f, 0.75f, 10);
- //obj_5.transform.position = ExtraTool.GetWorldPositionWithResolutionPercent(0.7f, 0.5f, 10);
- //obj_6.transform.position = ExtraTool.GetWorldPositionWithResolutionPercent(0.6f, 0.25f, 10);
- }
- private void Update()
- {
- return;
- snipeImage.GetComponent<RectTransform>().anchoredPosition = ScreenPointToUILocalPoint(rect, Input.mousePosition);
- //obj.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 50));
- //snipeCamera.transform.LookAt(obj.transform);
- ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- if (Physics.Raycast(ray, out var hit, 100f))
- {
- if (Input.GetMouseButton(0))
- {
- Destroy(hit.transform.gameObject);
- }
- }
- }
- public static Vector2 ScreenPointToUILocalPoint(RectTransform parentRT, Vector2 screenPoint)
- {
- Vector2 localPos;
- Camera uiCamera = Camera.main;
- RectTransformUtility.ScreenPointToLocalPointInRectangle(parentRT, screenPoint, null, out localPos);
- // 转换后的 localPos 使用下面方法赋值
- // target 为需要使用的 UI RectTransform
- // parentRT 是 target.parent.GetComponent<RectTransform>()
- // 最后赋值 target.anchoredPosition = localPos;
- return localPos;
- }
- }
|