add dithering back, only zoom when right clicking
This commit is contained in:
@@ -935,6 +935,118 @@ Transform:
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1757155171}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &907193628
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 907193632}
|
||||
- component: {fileID: 907193631}
|
||||
- component: {fileID: 907193630}
|
||||
- component: {fileID: 907193629}
|
||||
m_Layer: 6
|
||||
m_Name: Cube
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!65 &907193629
|
||||
BoxCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 907193628}
|
||||
m_Material: {fileID: 0}
|
||||
m_IncludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_ExcludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_LayerOverridePriority: 0
|
||||
m_IsTrigger: 0
|
||||
m_ProvidesContacts: 0
|
||||
m_Enabled: 1
|
||||
serializedVersion: 3
|
||||
m_Size: {x: 1, y: 1, z: 1}
|
||||
m_Center: {x: 0, y: 0, z: 0}
|
||||
--- !u!23 &907193630
|
||||
MeshRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 907193628}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 1
|
||||
m_ReceiveShadows: 1
|
||||
m_DynamicOccludee: 1
|
||||
m_StaticShadowCaster: 0
|
||||
m_MotionVectors: 1
|
||||
m_LightProbeUsage: 1
|
||||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 2
|
||||
m_RayTraceProcedural: 0
|
||||
m_RayTracingAccelStructBuildFlagsOverride: 0
|
||||
m_RayTracingAccelStructBuildFlags: 1
|
||||
m_SmallMeshCulling: 1
|
||||
m_ForceMeshLod: -1
|
||||
m_MeshLodSelectionBias: 0
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 2100000, guid: 78be8f8bd251f244ab82d30f189c8824, type: 2}
|
||||
m_StaticBatchInfo:
|
||||
firstSubMesh: 0
|
||||
subMeshCount: 0
|
||||
m_StaticBatchRoot: {fileID: 0}
|
||||
m_ProbeAnchor: {fileID: 0}
|
||||
m_LightProbeVolumeOverride: {fileID: 0}
|
||||
m_ScaleInLightmap: 1
|
||||
m_ReceiveGI: 1
|
||||
m_PreserveUVs: 0
|
||||
m_IgnoreNormalsForChartDetection: 0
|
||||
m_ImportantGI: 0
|
||||
m_StitchLightmapSeams: 1
|
||||
m_SelectedEditorRenderState: 3
|
||||
m_MinimumChartSize: 4
|
||||
m_AutoUVMaxDistance: 0.5
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_GlobalIlluminationMeshLod: 0
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 0
|
||||
m_MaskInteraction: 0
|
||||
m_AdditionalVertexStreams: {fileID: 0}
|
||||
--- !u!33 &907193631
|
||||
MeshFilter:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 907193628}
|
||||
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!4 &907193632
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 907193628}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 14.41, y: 36.27, z: -1.91}
|
||||
m_LocalScale: {x: 6.073, y: 5.7034, z: 0.72736}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1001 &1073270999
|
||||
PrefabInstance:
|
||||
m_ObjectHideFlags: 0
|
||||
@@ -1095,7 +1207,7 @@ PrefabInstance:
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 5478143440182735446, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
|
||||
propertyPath: obstructionMask.m_Bits
|
||||
value: 12
|
||||
value: 64
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 5526037850913171920, guid: 0fd9b22e9158e474a96c42de5ee0d85f, type: 3}
|
||||
propertyPath: m_LocalPosition.x
|
||||
@@ -11234,3 +11346,4 @@ SceneRoots:
|
||||
- {fileID: 273139142}
|
||||
- {fileID: 1073270999}
|
||||
- {fileID: 2107450398}
|
||||
- {fileID: 907193632}
|
||||
|
||||
@@ -34,6 +34,17 @@ public class CameraController : MonoBehaviour
|
||||
[SerializeField] private float collisionOffset = 0.1f;
|
||||
[SerializeField] private float positionSmoothness = 15f;
|
||||
|
||||
[Header("Occlusion Settings")]
|
||||
[SerializeField] private LayerMask obstructionMask;
|
||||
[SerializeField] private float fadedAlpha = 0.25f;
|
||||
[SerializeField] private float fadeSpeed = 5f;
|
||||
|
||||
private Dictionary<Renderer, float> currentAlpha =
|
||||
new Dictionary<Renderer, float>();
|
||||
|
||||
private Dictionary<Renderer, float> targetAlpha =
|
||||
new Dictionary<Renderer, float>();
|
||||
|
||||
private float yaw;
|
||||
private float pitch = 20f;
|
||||
private float targetDistance;
|
||||
@@ -82,6 +93,8 @@ private void LateUpdate()
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateOcclusion();
|
||||
UpdateFade();
|
||||
HandleRotation();
|
||||
HandleZoom();
|
||||
UpdateCameraPosition();
|
||||
@@ -95,11 +108,9 @@ private void HandleRotation()
|
||||
UnityEngine.Cursor.lockState = CursorLockMode.None;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityEngine.Cursor.visible = false;
|
||||
UnityEngine.Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
|
||||
UnityEngine.Cursor.visible = false;
|
||||
UnityEngine.Cursor.lockState = CursorLockMode.Locked;
|
||||
|
||||
yaw += Input.GetAxis("Mouse X") * rotationSpeed * Time.deltaTime;
|
||||
pitch -= Input.GetAxis("Mouse Y") * rotationSpeed * Time.deltaTime;
|
||||
@@ -109,6 +120,11 @@ private void HandleRotation()
|
||||
|
||||
private void HandleZoom()
|
||||
{
|
||||
if (!Input.GetMouseButton(1))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float scrollInput = Input.GetAxis("Mouse ScrollWheel");
|
||||
|
||||
targetDistance -= scrollInput * zoomSpeed;
|
||||
@@ -137,269 +153,11 @@ private void UpdateCameraPosition()
|
||||
|
||||
MainCamera.transform.position = Vector3.SmoothDamp(MainCamera.transform.position, finalPosition, ref currentVelocity, 1f / positionSmoothness);
|
||||
|
||||
MainCamera.transform.rotation = Quaternion.LookRotation(targetPosition - MainCamera.transform.position, Vector3.up); }
|
||||
|
||||
/*public float camTargetRotation { get; private set; } = 0;
|
||||
public CameraControlMode CamControlMode { get; private set; } = CameraControlMode.SnapRotate;
|
||||
public Camera MainCamera;
|
||||
|
||||
private bool isCamRotating = false;
|
||||
|
||||
[Header("Rotation")]
|
||||
public float mouseSensitivity = 200f;
|
||||
public float minPitch = -30f;
|
||||
public float maxPitch = 60f;
|
||||
public float distance = 5f;
|
||||
private float yaw;
|
||||
private float pitch;
|
||||
|
||||
[Header("Zoom")]
|
||||
public float followSpeed = 10f;
|
||||
public float maxDistance = 6f;
|
||||
public float minDistance = 1f;
|
||||
public float zoomSpeed = 5f;
|
||||
public float heightOffset = -0.5f;
|
||||
private float currentDistance;
|
||||
private float distanceVelocity;
|
||||
|
||||
[Header("Collision")]
|
||||
public float collisionRadius = 0.3f;
|
||||
public float collisionOffset = 0.2f;
|
||||
public LayerMask collisionMask;
|
||||
|
||||
[Header("Occlusion Settings")]
|
||||
public LayerMask obstructionMask;
|
||||
public float fadedAlpha = 0.25f;
|
||||
public float fadeSpeed = 5f;
|
||||
|
||||
private Dictionary<Renderer, float> currentAlpha =
|
||||
new Dictionary<Renderer, float>();
|
||||
|
||||
private Dictionary<Renderer, float> targetAlpha =
|
||||
new Dictionary<Renderer, float>();
|
||||
|
||||
public Transform playerCamHome;
|
||||
Transform dougBody;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
UpdateOcclusion();
|
||||
UpdateFade();
|
||||
|
||||
if (Input.GetMouseButton(1))
|
||||
{
|
||||
HandleFreeCamRotation();
|
||||
}
|
||||
else
|
||||
{
|
||||
CamAvoidCollisions();
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
Vector3 angles = playerCamHome.transform.eulerAngles;
|
||||
|
||||
yaw = angles.y;
|
||||
pitch = angles.x;
|
||||
currentDistance = distance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Trigger cam rotation
|
||||
/// </summary>
|
||||
public void RotateCam()
|
||||
{
|
||||
if (!isCamRotating)
|
||||
{
|
||||
float currentY = playerCamHome.transform.rotation.eulerAngles.y;
|
||||
camTargetRotation = currentY + 90f;
|
||||
isCamRotating = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set cam rotation immediately
|
||||
/// </summary>
|
||||
void SnapToRotation(float rotation)
|
||||
{
|
||||
if (CamControlMode == CameraControlMode.SnapRotate)
|
||||
{
|
||||
playerCamHome.RotateAround(
|
||||
transform.position,
|
||||
Vector3.up,
|
||||
rotation
|
||||
);
|
||||
|
||||
camTargetRotation = rotation;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move cam to desired rotation (every frame)
|
||||
/// </summary>
|
||||
void HandleSnapCamRotation()
|
||||
{
|
||||
float currentY = playerCamHome.transform.rotation.eulerAngles.y;
|
||||
float step = 200 * Time.deltaTime;
|
||||
float newY = Mathf.MoveTowardsAngle(currentY, camTargetRotation, step);
|
||||
|
||||
playerCamHome.RotateAround(
|
||||
transform.position,
|
||||
Vector3.up,
|
||||
newY - currentY
|
||||
);
|
||||
|
||||
if (Mathf.Abs(Mathf.DeltaAngle(newY, camTargetRotation)) < 0.01f)
|
||||
{
|
||||
isCamRotating = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move cam to desired free rotation (every frame)
|
||||
/// </summary>
|
||||
void HandleFreeCamRotation()
|
||||
{
|
||||
if (dougBody == null)
|
||||
{
|
||||
if (GameManager.Instance.PlayerController.DougBody != null)
|
||||
dougBody = GameManager.Instance.PlayerController.DougBody.transform;
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 target = new Vector3(dougBody.position.x, dougBody.position.y + heightOffset, dougBody.position.z);
|
||||
|
||||
// Mouse Input
|
||||
float mouseX = Input.GetAxis("Mouse X");
|
||||
float mouseY = Input.GetAxis("Mouse Y");
|
||||
|
||||
yaw += mouseX * mouseSensitivity * Time.deltaTime;
|
||||
pitch -= mouseY * mouseSensitivity * Time.deltaTime;
|
||||
|
||||
pitch = Mathf.Clamp(pitch, minPitch, maxPitch);
|
||||
|
||||
// Rotation
|
||||
Quaternion rotation = Quaternion.Euler(pitch, yaw, 0);
|
||||
|
||||
// Zoom
|
||||
float scroll = Input.GetAxis("Mouse ScrollWheel");
|
||||
|
||||
if (Mathf.Abs(scroll) > 0.0001f)
|
||||
{
|
||||
distance -= scroll * zoomSpeed;
|
||||
distance = Mathf.Clamp(distance, minDistance, maxDistance);
|
||||
}
|
||||
|
||||
currentDistance = Mathf.SmoothDamp(
|
||||
currentDistance,
|
||||
distance,
|
||||
ref distanceVelocity,
|
||||
0.05f);
|
||||
|
||||
float adjustedDistance = currentDistance;
|
||||
|
||||
Vector3 desiredDirection =
|
||||
rotation * Vector3.back;
|
||||
|
||||
// Camera obstruction handling
|
||||
if (Physics.SphereCast(
|
||||
target,
|
||||
collisionRadius,
|
||||
desiredDirection,
|
||||
out RaycastHit hit,
|
||||
currentDistance,
|
||||
collisionMask,
|
||||
QueryTriggerInteraction.Ignore))
|
||||
{
|
||||
adjustedDistance =
|
||||
Mathf.Max(
|
||||
hit.distance - collisionOffset,
|
||||
minDistance);
|
||||
}
|
||||
|
||||
// Desired Position
|
||||
Vector3 offset = rotation * Vector3.forward * -adjustedDistance;
|
||||
Vector3 desiredPosition = target + offset;
|
||||
|
||||
if (desiredPosition.y < dougBody.position.y)
|
||||
{
|
||||
desiredPosition.y = dougBody.position.y;
|
||||
}
|
||||
|
||||
// Smooth Follow
|
||||
playerCamHome.transform.position = Vector3.Lerp(
|
||||
playerCamHome.transform.position,
|
||||
desiredPosition,
|
||||
followSpeed * Time.deltaTime
|
||||
);
|
||||
|
||||
// Look at player
|
||||
playerCamHome.transform.LookAt(target + Vector3.up);
|
||||
}
|
||||
|
||||
void CamAvoidCollisions()
|
||||
{
|
||||
if (dougBody == null)
|
||||
{
|
||||
if (GameManager.Instance.PlayerController.DougBody != null)
|
||||
dougBody = GameManager.Instance.PlayerController.DougBody.transform;
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 target = new Vector3(dougBody.position.x, dougBody.position.y + heightOffset, dougBody.position.z);
|
||||
Quaternion rotation = Quaternion.Euler(pitch, yaw, 0);
|
||||
Vector3 desiredDirection = rotation * Vector3.back;
|
||||
|
||||
float adjustedDistance = currentDistance;
|
||||
|
||||
if (Physics.SphereCast(
|
||||
target,
|
||||
collisionRadius,
|
||||
desiredDirection,
|
||||
out RaycastHit hit,
|
||||
currentDistance,
|
||||
collisionMask,
|
||||
QueryTriggerInteraction.Ignore))
|
||||
{
|
||||
adjustedDistance =
|
||||
Mathf.Max(
|
||||
hit.distance - collisionOffset,
|
||||
minDistance);
|
||||
}
|
||||
|
||||
// Desired Position
|
||||
Vector3 offset = rotation * Vector3.forward * -adjustedDistance;
|
||||
Vector3 desiredPosition = target + offset;
|
||||
|
||||
if (desiredPosition.y < dougBody.position.y)
|
||||
{
|
||||
desiredPosition.y = dougBody.position.y;
|
||||
}
|
||||
|
||||
// Smooth Follow
|
||||
playerCamHome.transform.position = Vector3.Lerp(
|
||||
playerCamHome.transform.position,
|
||||
desiredPosition,
|
||||
followSpeed * Time.deltaTime
|
||||
);
|
||||
|
||||
// Look at player
|
||||
playerCamHome.transform.LookAt(target + Vector3.up);
|
||||
MainCamera.transform.rotation = Quaternion.LookRotation(targetPosition - MainCamera.transform.position, Vector3.up);
|
||||
}
|
||||
|
||||
void UpdateOcclusion()
|
||||
{
|
||||
if (dougBody == null)
|
||||
{
|
||||
if (GameManager.Instance.PlayerController.DougBody != null)
|
||||
dougBody = GameManager.Instance.PlayerController.DougBody.transform;
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset all renderers to visible
|
||||
foreach (Renderer r in new List<Renderer>(targetAlpha.Keys))
|
||||
{
|
||||
@@ -407,12 +165,12 @@ void UpdateOcclusion()
|
||||
}
|
||||
|
||||
Vector3 dir =
|
||||
MainCamera.transform.position - dougBody.position;
|
||||
MainCamera.transform.position - target.position;
|
||||
|
||||
float dist = dir.magnitude;
|
||||
|
||||
RaycastHit[] hits = Physics.RaycastAll(
|
||||
dougBody.position,
|
||||
target.position,
|
||||
dir.normalized,
|
||||
dist,
|
||||
obstructionMask,
|
||||
@@ -473,7 +231,7 @@ void UpdateFade()
|
||||
targetAlpha.Remove(r);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
public enum CameraControlMode
|
||||
|
||||
@@ -24,7 +24,7 @@ TagManager:
|
||||
- CameraObstructions
|
||||
- Water
|
||||
- UI
|
||||
-
|
||||
- Dither
|
||||
-
|
||||
-
|
||||
-
|
||||
|
||||
Reference in New Issue
Block a user