hide ui and add zoom cam

This commit is contained in:
VDH
2026-04-06 15:47:21 +07:00
parent 6461e9878b
commit a4931995d0
5 changed files with 239 additions and 42 deletions
@@ -12,8 +12,8 @@ GameObject:
- component: {fileID: 2923694103221183510}
- component: {fileID: 864878593467321995}
- component: {fileID: 3005089224860696078}
- component: {fileID: 9220823260634167621}
- component: {fileID: 6720462472486200866}
- component: {fileID: 9220823260634167621}
m_Layer: 0
m_Name: FreeLook Camera
m_TagString: Untagged
@@ -171,6 +171,36 @@ MonoBehaviour:
Time: 0
Smoothing: 0
IgnoreY: 0
--- !u!114 &6720462472486200866
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5860545600847923144}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ca7de3aefa901374ba29464584a3109a, type: 3}
m_Name:
m_EditorClassIdentifier:
CameraRadius: 0.4
Decollision:
Enabled: 0
ObstacleLayers:
serializedVersion: 2
m_Bits: 1
UseFollowTarget:
Enabled: 0
YOffset: 0
Damping: 0.5
SmoothingTime: 0
TerrainResolution:
Enabled: 1
TerrainLayers:
serializedVersion: 2
m_Bits: 200
MaximumRaycast: 5
Damping: 0.25
--- !u!114 &9220823260634167621
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -229,33 +259,3 @@ MonoBehaviour:
DecelTime: 0
PlayerIndex: -1
AutoEnableInputs: 0
--- !u!114 &6720462472486200866
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5860545600847923144}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ca7de3aefa901374ba29464584a3109a, type: 3}
m_Name:
m_EditorClassIdentifier:
CameraRadius: 0.4
Decollision:
Enabled: 0
ObstacleLayers:
serializedVersion: 2
m_Bits: 1
UseFollowTarget:
Enabled: 0
YOffset: 0
Damping: 0.5
SmoothingTime: 0
TerrainResolution:
Enabled: 1
TerrainLayers:
serializedVersion: 2
m_Bits: 200
MaximumRaycast: 5
Damping: 0.25
@@ -111,6 +111,22 @@ PrefabInstance:
serializedVersion: 3
m_TransformParent: {fileID: 6641252726352799703}
m_Modifications:
- target: {fileID: 129645434728095412, guid: 76408ccdbeb4c654291462fcff24a8c5, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 129645434728095412, guid: 76408ccdbeb4c654291462fcff24a8c5, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 129645434728095412, guid: 76408ccdbeb4c654291462fcff24a8c5, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 129645434728095412, guid: 76408ccdbeb4c654291462fcff24a8c5, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 1464374634028484465, guid: 76408ccdbeb4c654291462fcff24a8c5, type: 3}
propertyPath: m_text
value:
@@ -175,6 +191,22 @@ PrefabInstance:
propertyPath: m_AnchoredPosition.y
value: 28.228401
objectReference: {fileID: 0}
- target: {fileID: 3951120581356990872, guid: 76408ccdbeb4c654291462fcff24a8c5, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3951120581356990872, guid: 76408ccdbeb4c654291462fcff24a8c5, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3951120581356990872, guid: 76408ccdbeb4c654291462fcff24a8c5, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3951120581356990872, guid: 76408ccdbeb4c654291462fcff24a8c5, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3984476637502251390, guid: 76408ccdbeb4c654291462fcff24a8c5, type: 3}
propertyPath: m_fontSize
value: 17
@@ -383,6 +415,42 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7087492923537698131, guid: 76408ccdbeb4c654291462fcff24a8c5, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7087492923537698131, guid: 76408ccdbeb4c654291462fcff24a8c5, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7087492923537698131, guid: 76408ccdbeb4c654291462fcff24a8c5, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7087492923537698131, guid: 76408ccdbeb4c654291462fcff24a8c5, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7708887638066944733, guid: 76408ccdbeb4c654291462fcff24a8c5, type: 3}
propertyPath: m_SizeDelta.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7924665791547601326, guid: 76408ccdbeb4c654291462fcff24a8c5, type: 3}
propertyPath: m_AnchorMax.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7924665791547601326, guid: 76408ccdbeb4c654291462fcff24a8c5, type: 3}
propertyPath: m_AnchorMin.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7924665791547601326, guid: 76408ccdbeb4c654291462fcff24a8c5, type: 3}
propertyPath: m_AnchoredPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 7924665791547601326, guid: 76408ccdbeb4c654291462fcff24a8c5, type: 3}
propertyPath: m_AnchoredPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8086917028654197348, guid: 76408ccdbeb4c654291462fcff24a8c5, type: 3}
propertyPath: m_Type
value: 3
@@ -486,9 +554,14 @@ MonoBehaviour:
expText: {fileID: 9091953190536401803}
nameText: {fileID: 6716045574192280964}
levelText: {fileID: 3632374887765724611}
spText: {fileID: 0}
healthImage: {fileID: 4133230328392276113}
manaImage: {fileID: 246901321761552071}
expImage: {fileID: 7351517459147011958}
apImage: {fileID: 0}
apToggles: []
buffIconPrefab: {fileID: 0}
m_btnOpenCharacter: {fileID: 0}
neededExp: 0
--- !u!114 &1313768687643874887 stripped
MonoBehaviour:
@@ -1,7 +1,6 @@
using Unity.Cinemachine;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Serialization;
namespace BrewMonster
{
@@ -16,6 +15,18 @@ namespace BrewMonster
[SerializeField] private float verticalRotationPerScreen = 500f;
[SerializeField, HideInInspector] private bool _migratedDeadZoneToNormalized;
[Header("Zoom (orbit scale)")]
[Tooltip("RadialAxis scales camera distance: effective distance = Orbital Follow Radius × this value.")]
[SerializeField] private bool enableZoom = true;
[SerializeField] private float orbitScaleMin = 0.5f;
[SerializeField] private float orbitScaleMax = 2f;
[SerializeField] private float defaultOrbitScale = 1f;
[SerializeField] private float zoomSensitivityScroll = 0.15f;
[SerializeField] private float zoomSensitivityPinch = 0.004f;
private float _lastPinchDistance;
private bool _pinchZoomActive;
public CinemachineOrbitalFollow Orbital { get => orbital;}
void OnEnable()
@@ -24,6 +35,11 @@ namespace BrewMonster
MigrateLegacyDeadZone();
}
private void Start()
{
SyncRadialAxisRange();
}
public void OnDrag(PointerEventData eventData)
{
if (!fingerDown || orbital == null)
@@ -57,6 +73,88 @@ namespace BrewMonster
private void OnValidate()
{
MigrateLegacyDeadZone();
orbitScaleMin = Mathf.Max(0.01f, orbitScaleMin);
orbitScaleMax = Mathf.Max(orbitScaleMin, orbitScaleMax);
defaultOrbitScale = Mathf.Clamp(defaultOrbitScale, orbitScaleMin, orbitScaleMax);
SyncRadialAxisRange();
}
/// <summary> Keeps Cinemachine RadialAxis range in sync with serialized min/max. </summary>
private void SyncRadialAxisRange()
{
if (orbital == null)
{
return;
}
float min = Mathf.Min(orbitScaleMin, orbitScaleMax);
float max = Mathf.Max(orbitScaleMin, orbitScaleMax);
var radial = orbital.RadialAxis;
var range = radial.Range;
range.x = min;
range.y = max;
radial.Range = range;
radial.Value = radial.ClampValue(radial.Value);
orbital.RadialAxis = radial;
}
private void ResetFollowCameraAxes()
{
if (orbital == null)
{
return;
}
orbital.HorizontalAxis.Value = 208;
orbital.VerticalAxis.Value = -268;
SyncRadialAxisRange();
var radial = orbital.RadialAxis;
radial.Value = radial.ClampValue(defaultOrbitScale);
orbital.RadialAxis = radial;
}
private void ApplyRadialZoomDelta(float delta)
{
if (!enableZoom || orbital == null || Mathf.Abs(delta) < 1e-6f)
{
return;
}
var radial = orbital.RadialAxis;
radial.Value = radial.ClampValue(radial.Value + delta);
orbital.RadialAxis = radial;
}
private void UpdatePinchZoom()
{
if (!enableZoom || orbital == null)
{
_pinchZoomActive = false;
return;
}
if (Input.touchCount == 2)
{
Touch t0 = Input.GetTouch(0);
Touch t1 = Input.GetTouch(1);
float dist = Vector2.Distance(t0.position, t1.position);
if (!_pinchZoomActive)
{
_pinchZoomActive = true;
_lastPinchDistance = dist;
}
else
{
float delta = dist - _lastPinchDistance;
_lastPinchDistance = dist;
// Pinch outward increases distance → larger scale
ApplyRadialZoomDelta(delta * zoomSensitivityPinch);
}
}
else
{
_pinchZoomActive = false;
}
}
private void MigrateLegacyDeadZone()
@@ -86,24 +184,33 @@ namespace BrewMonster
{
_cinemachineCamera.Follow = CECGameRun.Instance.GetHostPlayer().PointCam;
_cinemachineCamera.ForceCameraPosition(CECGameRun.Instance.GetHostPlayer().PointCam.position, Quaternion.identity);
orbital.HorizontalAxis.Value = 208;
orbital.VerticalAxis.Value = -268;
ResetFollowCameraAxes();
}
else
{
_cinemachineCamera.Follow = CECGameRun.Instance.GetHostPlayer().transform;
_cinemachineCamera.ForceCameraPosition(CECGameRun.Instance.GetHostPlayer().ObjectPosition, Quaternion.identity);
orbital.HorizontalAxis.Value = 208;
orbital.VerticalAxis.Value = -268;
ResetFollowCameraAxes();
}
}
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBGL
if (enableZoom && orbital != null)
{
float scroll = Input.mouseScrollDelta.y;
if (Mathf.Abs(scroll) > Mathf.Epsilon)
{
ApplyRadialZoomDelta(scroll * zoomSensitivityScroll);
}
}
#endif
UpdatePinchZoom();
}
public void UpdateFollowObject(Transform followObject)
{
_cinemachineCamera.Follow = followObject;
_cinemachineCamera.ForceCameraPosition(followObject.position, Quaternion.identity);
orbital.HorizontalAxis.Value = 208;
orbital.VerticalAxis.Value = -268;
ResetFollowCameraAxes();
}
}
}
+4 -4
View File
@@ -8087,7 +8087,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!224 &8029283128219612690
RectTransform:
m_ObjectHideFlags: 0
@@ -8104,9 +8104,9 @@ RectTransform:
- {fileID: 3703262150164293383}
m_Father: {fileID: 3016923604946316301}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 83.16, y: -292.4765}
m_SizeDelta: {x: 166.32, y: 130.2924}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &5150156580756960231
@@ -0,0 +1,17 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &1
MonoBehaviour:
m_ObjectHideFlags: 53
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8dd9412a94724634791c4076fdf86e3b, type: 3}
m_Name:
m_EditorClassIdentifier:
disableBuildValidation: 0
assetPreviewLoadTime: 20
customUnitDefinitions: []