This commit is contained in:
huyulong 2024-11-25 23:55:04 +08:00
commit 211e72cc58
4 changed files with 145 additions and 5 deletions

View File

@ -1333,6 +1333,7 @@ GameObject:
- component: {fileID: 278122028}
- component: {fileID: 278122027}
- component: {fileID: 278122026}
- component: {fileID: 278122030}
m_Layer: 5
m_Name: Canvas
m_TagString: Untagged
@ -1424,6 +1425,22 @@ RectTransform:
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!114 &278122030
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 278122025}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a9c4729dd6c76ce438ab89f953186816, type: 3}
m_Name:
m_EditorClassIdentifier:
m_cam: {fileID: 2127085744}
mainScene: {fileID: 1769459763}
minX: -5315
maxX: 0
--- !u!1 &278944241
GameObject:
m_ObjectHideFlags: 0
@ -1676,7 +1693,7 @@ RectTransform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 332514049}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
@ -1705,6 +1722,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: fa9fccadda7b7ac43b24c43fa954dcce, type: 3}
m_Name:
m_EditorClassIdentifier:
mainPanel: {fileID: 0}
BTN_0: {fileID: 1937427102}
BTN_1: {fileID: 1906759230}
BTN_2: {fileID: 934652041}
@ -7286,7 +7304,7 @@ RectTransform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1769459763}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
@ -9200,7 +9218,7 @@ Camera:
field of view: 60
orthographic: 0
orthographic size: 5
m_Depth: -1
m_Depth: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
@ -9223,7 +9241,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2127085742}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 1, z: -10}
m_LocalPosition: {x: 654, y: 1235, z: -2436.0815}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []

View File

@ -7,7 +7,9 @@ using UnityEngine.UI;
//md FUCK everthing
//史山,别学
public class mainBTN : MonoBehaviour
{
{
public GameObject mainPanel;
public GameObject BTN_0;
public GameObject BTN_1;
public GameObject BTN_2;

View File

@ -0,0 +1,109 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class sceneContorl : MonoBehaviour
{
public Camera m_cam;
public GameObject mainScene;
private bool m_fingerDown = false;
// 手指的起始位置
private Vector2 m_oneFingerDragStartPos;
// UI元素的 RectTransform
private RectTransform mainSceneRectTransform;
// 灵敏度系数
private float sensitivity = 0.5f; // 可以根据需要调整此值
// 滑动限制的最小值和最大值
public float minX = -500f; // 最小x值
public float maxX = 500f; // 最大x值
// Start is called before the first frame update
void Start()
{
mainSceneRectTransform = mainScene.GetComponent<RectTransform>();
}
// Update is called once per frame
void Update()
{
#if UNITY_EDITOR || UNITY_STANDALONE
// 桌面端:鼠标按下时
if (Input.GetMouseButtonDown(0))
{
m_fingerDown = true;
m_oneFingerDragStartPos = Input.mousePosition; // 获取鼠标按下的起始位置
}
// 桌面端:鼠标松开时
if (Input.GetMouseButtonUp(0))
{
m_fingerDown = false;
}
// 处理鼠标拖动
if (m_fingerDown)
{
HandleFingerDragMove(Input.mousePosition);
}
#else
// 移动端:单指滑动
if (Input.touchCount == 1)
{
Touch touch = Input.touches[0];
// 手指刚触碰屏幕时
if (touch.phase == TouchPhase.Began)
{
m_fingerDown = true;
m_oneFingerDragStartPos = touch.position; // 获取手指按下的起始位置
}
// 手指在屏幕上滑动时
else if (touch.phase == TouchPhase.Moved)
{
HandleFingerDragMove(touch.position); // 处理手指拖动
}
}
else
{
m_fingerDown = false;
}
#endif
}
/// <summary>
/// 单指滑动
/// </summary>
private void HandleFingerDragMove(Vector2 fingerPos)
{
// 计算当前帧的滑动增量(交换顺序,保证滑动方向一致)
Vector3 moveDelta = fingerPos - m_oneFingerDragStartPos; // 当前触摸位置 - 起始位置
Vector3 newPos = mainSceneRectTransform.anchoredPosition;
// 根据滑动增量计算新的x轴位置并限制在指定范围内
newPos.x = newPos.x + (moveDelta.x * sensitivity);
// 限制x轴位置在 minX 和 maxX 之间
newPos.x = Mathf.Clamp(newPos.x, minX, maxX);
mainSceneRectTransform.anchoredPosition = newPos; // 设置新的锚点位置
// 更新起始位置,用于计算下一帧的增量
m_oneFingerDragStartPos = fingerPos;
}
/// <summary>
/// 屏幕坐标换算成3D坐标
/// </summary>
/// <param name="screenPos">屏幕坐标</param>
/// <returns></returns>
Vector3 GetWorldPos(Vector2 screenPos)
{
return m_cam.ScreenToWorldPoint(new Vector3(screenPos.x, screenPos.y, Mathf.Abs(m_cam.transform.position.z)));
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a9c4729dd6c76ce438ab89f953186816
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: