autohide cursor

This commit is contained in:
ntr committed 2022-06-05 21:19:18 +10:00
1 parent 9861d652e7
commit 7ec6ede19a
10 files changed
+89 -20

No files matched your search

+3 -1
View File
@@ -1754,7 +1754,7 @@ Canvas:
m_GameObject: {fileID: 5305278010342315831}
m_Enabled: 1
serializedVersion: 3
m_RenderMode: 1
m_RenderMode: 0
m_Camera: {fileID: 0}
m_PlaneDistance: 100
m_PixelPerfect: 0
@@ -1820,6 +1820,8 @@ MonoBehaviour:
m_EditorClassIdentifier:
currentVis: {fileID: 5305278009821670017}
vfxMenu: {fileID: 0}
mouseHideTimeSeconds: 3
mouseHideThreshold: 3
--- !u!1 &6466943970290633308
GameObject:
m_ObjectHideFlags: 0
+3 -3
View File
@@ -142,7 +142,7 @@ Material:
- _AlphaToMaskInspectorValue: 0
- _Anisotropy: 0
- _BlendMode: 0
- _Brightness: 3.9499998
- _Brightness: 3.1000001
- _CoatMask: 0
- _CullMode: 2
- _CullModeForward: 2
@@ -235,7 +235,7 @@ Material:
- _UVEmissive: 0
- _UseEmissiveIntensity: 0
- _UseShadowThreshold: 0
- _Wildness: 5.721429
- _Wildness: 4.921429
- _Wow: 4
- _ZTestDepthEqualForOpaque: 3
- _ZTestGBuffer: 4
@@ -243,7 +243,7 @@ Material:
- _ZWrite: 1
- _Zing: 0
- _Zip: 0.5
- _Zoom: -0.2628572
- _Zoom: -0.54285717
m_Colors:
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
- _BaseColorMap_MipInfo: {r: 0, g: 0, b: 0, a: 0}
+3 -3
View File
@@ -820,11 +820,11 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 6299956056252612629, guid: 31660dba95ae9a9408051002a1e4c382, type: 3}
propertyPath: m_SizeDelta.x
value: 219
value: 64
objectReference: {fileID: 0}
- target: {fileID: 6299956056252612629, guid: 31660dba95ae9a9408051002a1e4c382, type: 3}
propertyPath: m_SizeDelta.y
value: 60
value: 64
objectReference: {fileID: 0}
- target: {fileID: 7200639167805561534, guid: 31660dba95ae9a9408051002a1e4c382, type: 3}
propertyPath: m_RootOrder
@@ -833,7 +833,7 @@ PrefabInstance:
- target: {fileID: 7817393215567595311, guid: 31660dba95ae9a9408051002a1e4c382, type: 3}
propertyPath: m_Texture
value:
objectReference: {fileID: 2800000, guid: 9c39ce62ca6b36f45af28ac4bb70d702, type: 3}
objectReference: {fileID: 2800000, guid: bcf19558d625cc1459278eea869f67c1, type: 3}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 31660dba95ae9a9408051002a1e4c382, type: 3}
--- !u!1 &667181310
+2 -2
View File
@@ -211,8 +211,8 @@ Material:
- _SpecularAAScreenSpaceVariance: 0.1
- _SpecularAAThreshold: 0.2
- _SpecularOcclusionMode: 1
- _SphereSize: 0.94285715
- _SphereStretch: 0.5928571
- _SphereSize: 0.9785714
- _SphereStretch: 0.6
- _SrcBlend: 1
- _StencilRef: 0
- _StencilRefDepth: 8
@@ -152,10 +152,14 @@ Shader "FullScreen/GeneDrive"
// camera coordinates
float2 uv = guv;
float3 eye = float3(sin(time * 0.1) * 5.0, cos(time * 0.1) * 5.0 + 0.5, 1.0);
float tau = 6.283185307179586;
float3 eye = float3(0.0, 0.0, 0.0);
// float3 at = float3(sin(time * 0.1) * tau, cos(time * 0.1) * tau + 0.5, sin(time * 0.1) + 0.2 * tau);
float3 at = float3(sin(time * 0.1) * tau, cos(time * 0.1) * tau + 0.5, sin(time * 0.1) + 0.2 * tau);
// float3 eye = float3(5.0, 5.0, 1.0);
float3 at = float3(0.0, 0.0, 0.0);
// float3 at = float3(0.0, 0.0, 0.0);
float3 z = normalize(at-eye);
float3 x = normalize(cross(z, float3(0.0,1.0,0.0)));
float3 y = cross(x, z);
+26
View File
@@ -0,0 +1,26 @@
using UnityEngine;
using System.Collections;
public class CursorHide : MonoBehaviour {
public float hideAfterSeconds = 3f;
public float thresholdInPixels = 3f;
float _lastTime;
Vector3 _lastMousePos;
void Start () {
_lastTime = Time.timeSinceLevelLoad;
_lastMousePos = Input.mousePosition;
}
void Update () {
Vector2 dx = Input.mousePosition - _lastMousePos;
bool move = (dx.sqrMagnitude > (thresholdInPixels * thresholdInPixels));
_lastMousePos = Input.mousePosition;
if (move)
_lastTime = Time.timeSinceLevelLoad;
Cursor.visible = (Time.timeSinceLevelLoad - _lastTime) < hideAfterSeconds;
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7e3f63f71f856934f8bb5743688a4732
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+27
View File
@@ -18,6 +18,11 @@ public class Loader : MonoBehaviour {
private KeyCode PrevButton = KeyCode.Backspace;
private KeyCode MenuButton = KeyCode.Escape;
public float mouseHideTimeSeconds = 3f;
public float mouseHideThreshold = 3f;
float mouseLastMoveTime;
Vector3 mouseLastMovePos;
void Awake() {
ToggleMenu(menuVisible);
}
@@ -26,6 +31,11 @@ public class Loader : MonoBehaviour {
scene = SceneManager.GetActiveScene();
currentVis.text = scene.name;
// Debug.Log("Active Scene name is: " + scene.name + "\nActive Scene index: " + scene.buildIndex);
// cursor visibility
mouseLastMoveTime = Time.timeSinceLevelLoad;
mouseLastMovePos = Input.mousePosition;
}
void Update() {
@@ -40,6 +50,8 @@ public class Loader : MonoBehaviour {
if (Input.GetKeyDown(MenuButton)) {
ToggleMenu(!menuVisible);
}
CheckMouseVisibility();
}
void VfxMenuVisible(bool v) {
@@ -58,6 +70,21 @@ public class Loader : MonoBehaviour {
menuVisible = visible;
}
void CheckMouseVisibility() {
if (menuVisible) {
Vector2 dx = Input.mousePosition - mouseLastMovePos;
bool move = (dx.sqrMagnitude > (mouseHideThreshold * mouseHideThreshold));
mouseLastMovePos = Input.mousePosition;
if (move)
mouseLastMoveTime = Time.timeSinceLevelLoad;
Cursor.visible = (Time.timeSinceLevelLoad - mouseLastMoveTime) < mouseHideTimeSeconds;
} else {
Cursor.visible = false;
}
}
public void NextScene() {
int current = scene.buildIndex;
int next = (current + 1) % (SceneManager.sceneCountInBuildSettings);