Improve Touch Delay
Reduce Touch Overhead by only sending input state once a second to keep the game reading alive, on top of whenever a change in the state happens. Also add a small cube to the scene to use for debugging touch in editor when needed
This commit is contained in:
parent
8b3c03af3d
commit
9c0f3dd989
@ -666,6 +666,120 @@ Transform:
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 6
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &88826006
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 88826011}
|
||||
- component: {fileID: 88826010}
|
||||
- component: {fileID: 88826009}
|
||||
- component: {fileID: 88826008}
|
||||
- component: {fileID: 88826007}
|
||||
m_Layer: 0
|
||||
m_Name: TouchTester
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 0
|
||||
--- !u!54 &88826007
|
||||
Rigidbody:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 88826006}
|
||||
serializedVersion: 2
|
||||
m_Mass: 1
|
||||
m_Drag: 0
|
||||
m_AngularDrag: 0.05
|
||||
m_UseGravity: 0
|
||||
m_IsKinematic: 1
|
||||
m_Interpolate: 0
|
||||
m_Constraints: 0
|
||||
m_CollisionDetection: 0
|
||||
--- !u!65 &88826008
|
||||
BoxCollider:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 88826006}
|
||||
m_Material: {fileID: 0}
|
||||
m_IsTrigger: 1
|
||||
m_Enabled: 1
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 1, y: 1, z: 1}
|
||||
m_Center: {x: 0, y: 0, z: 0}
|
||||
--- !u!23 &88826009
|
||||
MeshRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 88826006}
|
||||
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_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, 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_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 0
|
||||
m_AdditionalVertexStreams: {fileID: 0}
|
||||
--- !u!33 &88826010
|
||||
MeshFilter:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 88826006}
|
||||
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!4 &88826011
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 88826006}
|
||||
m_LocalRotation: {x: -0, y: 1, z: -0, w: 0}
|
||||
m_LocalPosition: {x: 0.0421, y: 1.0341, z: -0.055}
|
||||
m_LocalScale: {x: 0.1, y: 0.1, z: 0.1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 5
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &90706079
|
||||
@ -1152,7 +1266,7 @@ Transform:
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 9
|
||||
m_RootOrder: 10
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &125821350
|
||||
MonoBehaviour:
|
||||
@ -4599,7 +4713,7 @@ Transform:
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 6
|
||||
m_RootOrder: 7
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &881068519
|
||||
MonoBehaviour:
|
||||
@ -8109,7 +8223,7 @@ Transform:
|
||||
- {fileID: 113329740}
|
||||
- {fileID: 655176480}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 8
|
||||
m_RootOrder: 9
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &1686740784
|
||||
MonoBehaviour:
|
||||
@ -8709,7 +8823,7 @@ Transform:
|
||||
m_Children:
|
||||
- {fileID: 1688695918}
|
||||
m_Father: {fileID: 0}
|
||||
m_RootOrder: 7
|
||||
m_RootOrder: 8
|
||||
m_LocalEulerAnglesHint: {x: 6.924, y: 15.724, z: 0}
|
||||
--- !u!114 &1746567233
|
||||
MonoBehaviour:
|
||||
|
@ -9,6 +9,7 @@ public class ColliderToSerial : MonoBehaviour
|
||||
{
|
||||
private Renderer cr;
|
||||
private int _insideColliderCount = 0;
|
||||
public static event Action touchDidChange;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
@ -19,6 +20,7 @@ public class ColliderToSerial : MonoBehaviour
|
||||
{
|
||||
_insideColliderCount += 1;
|
||||
Serial.SetTouch(Convert.ToInt32(gameObject.name), true);
|
||||
touchDidChange?.Invoke();
|
||||
cr.material.color = new Color(1f, 1f, 1f, 1f);
|
||||
}
|
||||
|
||||
@ -26,10 +28,12 @@ public class ColliderToSerial : MonoBehaviour
|
||||
{
|
||||
_insideColliderCount -= 1;
|
||||
_insideColliderCount = Mathf.Max(0, _insideColliderCount);
|
||||
cr.material.color = new Color(0f, 0f, 0f, 0f);
|
||||
|
||||
if (_insideColliderCount == 0)
|
||||
{
|
||||
Serial.SetTouch(Convert.ToInt32(gameObject.name), false);
|
||||
touchDidChange?.Invoke();
|
||||
cr.material.color = new Color(0f, 0f, 0f, 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
using UnityEngine;
|
||||
using System.IO.Ports;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Ports;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
public class Serial : MonoBehaviour
|
||||
{
|
||||
|
||||
@ -42,6 +42,10 @@ public class Serial : MonoBehaviour
|
||||
SetSettingData_201();
|
||||
SetSettingData_162();
|
||||
SetSettingData_148();
|
||||
//Send touch update periodically to keep "read" alive
|
||||
InvokeRepeating("SendTouchState", 0, 1);
|
||||
//Send touch updates whenever actual state changes to achieve desired update frequency without overloading
|
||||
ColliderToSerial.touchDidChange += SendTouchState;
|
||||
}
|
||||
|
||||
void Update()
|
||||
@ -50,14 +54,23 @@ public class Serial : MonoBehaviour
|
||||
ReadHead(ComL, 0);
|
||||
if (ComR.IsOpen)
|
||||
ReadHead(ComR, 1);
|
||||
if (Input.GetKeyDown(KeyCode.M)) //this is a touch test code
|
||||
StartCoroutine(TouchTest(true));
|
||||
// if (Input.GetKeyDown(KeyCode.M)) //this is a touch test code
|
||||
// StartCoroutine(TouchTest(true));
|
||||
if (Input.GetKeyDown(KeyCode.M) && StartUp)
|
||||
SendTouchState();
|
||||
}
|
||||
|
||||
private void FixedUpdate() {
|
||||
private void SendTouchState()
|
||||
{
|
||||
Debug.Log("Sending Touch State");
|
||||
Debug.Log("Sending Left");
|
||||
SendTouch(ComL, TouchPackL);
|
||||
Debug.Log("Sending Right");
|
||||
SendTouch(ComR, TouchPackR);
|
||||
}
|
||||
private void FixedUpdate() {
|
||||
//SendTouchState();
|
||||
}
|
||||
|
||||
IEnumerator TouchTest(bool State) //this is a touch test code
|
||||
{
|
||||
@ -181,7 +194,13 @@ public class Serial : MonoBehaviour
|
||||
void SendTouch(SerialPort Serial, byte[] Pack) //Send touch data
|
||||
{
|
||||
if (StartUp)
|
||||
Serial.Write(GetTouchPack(Pack), 0, 36);
|
||||
{
|
||||
// Debug.Log($"Pack {string.Join(" ", Pack)}");
|
||||
var output = GetTouchPack(Pack);
|
||||
// Debug.Log($"Output {string.Join(" ", output)}");
|
||||
Serial.Write(output, 0, 36);
|
||||
}
|
||||
|
||||
}
|
||||
public static void SetTouch(int Area, bool State) //set touch data 0-239
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user