Skip to content

Commit fd5681d

Browse files
committed
better led perfomance
1 parent 73fb326 commit fd5681d

File tree

2 files changed

+193
-9
lines changed

2 files changed

+193
-9
lines changed

Assets/Scenes/WACVR.unity

+153
Original file line numberDiff line numberDiff line change
@@ -10972,6 +10972,9 @@ GameObject:
1097210972
- component: {fileID: 1483037935}
1097310973
- component: {fileID: 1483037933}
1097410974
- component: {fileID: 1483037940}
10975+
- component: {fileID: 1483037942}
10976+
- component: {fileID: 1483037943}
10977+
- component: {fileID: 1483037941}
1097510978
m_Layer: 5
1097610979
m_Name: ConfigCanvas
1097710980
m_TagString: Untagged
@@ -11114,6 +11117,156 @@ MonoBehaviour:
1111411117
m_Name:
1111511118
m_EditorClassIdentifier:
1111611119
Camera: {fileID: 1326126835}
11120+
--- !u!114 &1483037941
11121+
MonoBehaviour:
11122+
m_ObjectHideFlags: 0
11123+
m_CorrespondingSourceObject: {fileID: 0}
11124+
m_PrefabInstance: {fileID: 0}
11125+
m_PrefabAsset: {fileID: 0}
11126+
m_GameObject: {fileID: 1483037931}
11127+
m_Enabled: 1
11128+
m_EditorHideFlags: 0
11129+
m_Script: {fileID: 11500000, guid: 0ad34abafad169848a38072baa96cdb2, type: 3}
11130+
m_Name:
11131+
m_EditorClassIdentifier:
11132+
m_InteractionManager: {fileID: 1730787728}
11133+
m_Colliders:
11134+
- {fileID: 1483037943}
11135+
m_InteractionLayerMask:
11136+
serializedVersion: 2
11137+
m_Bits: 4294967295
11138+
m_InteractionLayers:
11139+
m_Bits: 1
11140+
m_DistanceCalculationMode: 1
11141+
m_SelectMode: 0
11142+
m_CustomReticle: {fileID: 0}
11143+
m_FirstHoverEntered:
11144+
m_PersistentCalls:
11145+
m_Calls: []
11146+
m_LastHoverExited:
11147+
m_PersistentCalls:
11148+
m_Calls: []
11149+
m_HoverEntered:
11150+
m_PersistentCalls:
11151+
m_Calls: []
11152+
m_HoverExited:
11153+
m_PersistentCalls:
11154+
m_Calls: []
11155+
m_FirstSelectEntered:
11156+
m_PersistentCalls:
11157+
m_Calls: []
11158+
m_LastSelectExited:
11159+
m_PersistentCalls:
11160+
m_Calls: []
11161+
m_SelectEntered:
11162+
m_PersistentCalls:
11163+
m_Calls: []
11164+
m_SelectExited:
11165+
m_PersistentCalls:
11166+
m_Calls: []
11167+
m_Activated:
11168+
m_PersistentCalls:
11169+
m_Calls: []
11170+
m_Deactivated:
11171+
m_PersistentCalls:
11172+
m_Calls: []
11173+
m_OnFirstHoverEntered:
11174+
m_PersistentCalls:
11175+
m_Calls: []
11176+
m_OnLastHoverExited:
11177+
m_PersistentCalls:
11178+
m_Calls: []
11179+
m_OnHoverEntered:
11180+
m_PersistentCalls:
11181+
m_Calls: []
11182+
m_OnHoverExited:
11183+
m_PersistentCalls:
11184+
m_Calls: []
11185+
m_OnSelectEntered:
11186+
m_PersistentCalls:
11187+
m_Calls: []
11188+
m_OnSelectExited:
11189+
m_PersistentCalls:
11190+
m_Calls: []
11191+
m_OnSelectCanceled:
11192+
m_PersistentCalls:
11193+
m_Calls: []
11194+
m_OnActivate:
11195+
m_PersistentCalls:
11196+
m_Calls: []
11197+
m_OnDeactivate:
11198+
m_PersistentCalls:
11199+
m_Calls: []
11200+
m_AttachTransform: {fileID: 0}
11201+
m_UseDynamicAttach: 1
11202+
m_MatchAttachPosition: 1
11203+
m_MatchAttachRotation: 1
11204+
m_SnapToColliderVolume: 1
11205+
m_AttachEaseInTime: 0.15
11206+
m_MovementType: 2
11207+
m_VelocityDamping: 1
11208+
m_VelocityScale: 1
11209+
m_AngularVelocityDamping: 1
11210+
m_AngularVelocityScale: 1
11211+
m_TrackPosition: 1
11212+
m_SmoothPosition: 0
11213+
m_SmoothPositionAmount: 5
11214+
m_TightenPosition: 0.5
11215+
m_TrackRotation: 1
11216+
m_SmoothRotation: 0
11217+
m_SmoothRotationAmount: 5
11218+
m_TightenRotation: 0.5
11219+
m_ThrowOnDetach: 0
11220+
m_ThrowSmoothingDuration: 0.25
11221+
m_ThrowSmoothingCurve:
11222+
serializedVersion: 2
11223+
m_Curve:
11224+
- serializedVersion: 3
11225+
time: 1
11226+
value: 1
11227+
inSlope: 0
11228+
outSlope: 0
11229+
tangentMode: 0
11230+
weightedMode: 0
11231+
inWeight: 0
11232+
outWeight: 0
11233+
m_PreInfinity: 2
11234+
m_PostInfinity: 2
11235+
m_RotationOrder: 4
11236+
m_ThrowVelocityScale: 1.5
11237+
m_ThrowAngularVelocityScale: 1
11238+
m_ForceGravityOnDetach: 0
11239+
m_RetainTransformParent: 0
11240+
m_AttachPointCompatibilityMode: 0
11241+
--- !u!54 &1483037942
11242+
Rigidbody:
11243+
m_ObjectHideFlags: 0
11244+
m_CorrespondingSourceObject: {fileID: 0}
11245+
m_PrefabInstance: {fileID: 0}
11246+
m_PrefabAsset: {fileID: 0}
11247+
m_GameObject: {fileID: 1483037931}
11248+
serializedVersion: 2
11249+
m_Mass: 1
11250+
m_Drag: 0
11251+
m_AngularDrag: 0.05
11252+
m_UseGravity: 1
11253+
m_IsKinematic: 1
11254+
m_Interpolate: 0
11255+
m_Constraints: 0
11256+
m_CollisionDetection: 0
11257+
--- !u!65 &1483037943
11258+
BoxCollider:
11259+
m_ObjectHideFlags: 0
11260+
m_CorrespondingSourceObject: {fileID: 0}
11261+
m_PrefabInstance: {fileID: 0}
11262+
m_PrefabAsset: {fileID: 0}
11263+
m_GameObject: {fileID: 1483037931}
11264+
m_Material: {fileID: 0}
11265+
m_IsTrigger: 0
11266+
m_Enabled: 1
11267+
serializedVersion: 2
11268+
m_Size: {x: 1, y: 1, z: 1}
11269+
m_Center: {x: 0, y: 0, z: 0}
1111711270
--- !u!1 &1494369262
1111811271
GameObject:
1111911272
m_ObjectHideFlags: 0

Assets/Script/LightManager/LightManager.cs

+40-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using UnityEngine.UI;
44
using UnityEngine;
5+
using System;
56

67
public class LightManager : MonoBehaviour
78
{
@@ -11,7 +12,9 @@ public class LightManager : MonoBehaviour
1112
private bool isIPCIdle = true;
1213
[SerializeField]
1314
private bool useIPCLighting = true;
14-
static Texture2D RGBColor2D;
15+
//static Texture2D RGBColor2D;
16+
static byte[] RGBAColors;
17+
static byte[][] Colors;
1518

1619
private IEnumerator[] coroutines = new IEnumerator[240];
1720
public float FadeDuration = 0.5f;
@@ -41,7 +44,7 @@ private void Start()
4144

4245
if (useIPCLighting)
4346
{
44-
RGBColor2D = new Texture2D(480, 1, TextureFormat.RGBA32, false);
47+
//RGBColor2D = new Texture2D(480, 1, TextureFormat.RGBA32, false);
4548
//RGBColor2D.filterMode = FilterMode.Point; //for debugging
4649
//GetComponent<Renderer>().material.mainTexture = RGBColor2D; //for debugging
4750
}
@@ -56,7 +59,10 @@ private void Update()
5659

5760
if (IPCManager.sharedBuffer != null)
5861
{
59-
GetTextureFromBytes(IPCManager.GetLightData());
62+
//GetTextureFromBytes(IPCManager.GetLightData());
63+
RGBAColors = IPCManager.GetLightData();
64+
Colors = SplitByteArray(RGBAColors, 4);
65+
CheckIPCState(RGBAColors);
6066
if (isIPCIdle)
6167
return;
6268
UpdateLED();
@@ -87,10 +93,19 @@ private void UpdateLED()
8793
{
8894
for (int ii = 0; ii < 4; ii++)
8995
{
90-
Materials[119 - i - ii * 30].SetColor("_EmissionColor", RGBColor2D.GetPixel(index * 2, 0));
91-
Materials[119 - i - ii * 30].SetColor("_EmissionColor2", RGBColor2D.GetPixel(index * 2 + 1, 0));
92-
Materials[210 + i - ii * 30].SetColor("_EmissionColor", RGBColor2D.GetPixel((index + 120) * 2, 0));
93-
Materials[210 + i - ii * 30].SetColor("_EmissionColor2", RGBColor2D.GetPixel((index + 120) * 2 + 1, 0));
96+
97+
Materials[119 - i - ii * 30].SetColor("_EmissionColor",
98+
new Color32(Colors[index * 2][0], Colors[index * 2][1], Colors[index * 2][2], 255));
99+
Materials[119 - i - ii * 30].SetColor("_EmissionColor2",
100+
new Color32(Colors[index * 2 + 1][0], Colors[index * 2 + 1][1], Colors[index * 2 + 1][2], 255));
101+
Materials[210 + i - ii * 30].SetColor("_EmissionColor",
102+
new Color32(Colors[(index + 120) * 2][0], Colors[(index + 120) * 2][1], Colors[(index + 120) * 2][2], 255));
103+
Materials[210 + i - ii * 30].SetColor("_EmissionColor2",
104+
new Color32(Colors[(index + 120) * 2 + 1][0], Colors[(index + 120) * 2 + 1][1], Colors[(index + 120) * 2 + 1][2], 255));
105+
// Materials[119 - i - ii * 30].SetColor("_EmissionColor", RGBColor2D.GetPixel(index * 2, 0));
106+
// Materials[119 - i - ii * 30].SetColor("_EmissionColor2", RGBColor2D.GetPixel(index * 2 + 1, 0));
107+
// Materials[210 + i - ii * 30].SetColor("_EmissionColor", RGBColor2D.GetPixel((index + 120) * 2, 0));
108+
// Materials[210 + i - ii * 30].SetColor("_EmissionColor2", RGBColor2D.GetPixel((index + 120) * 2 + 1, 0));
94109
index++;
95110
}
96111
}
@@ -104,8 +119,8 @@ void GetTextureFromBytes(byte[] bytes)
104119
return;
105120
var newbytes = new byte[1920];
106121
newbytes = bytes;
107-
RGBColor2D.LoadRawTextureData(newbytes);
108-
RGBColor2D.Apply();
122+
//RGBColor2D.LoadRawTextureData(newbytes);
123+
//RGBColor2D.Apply();
109124

110125
}
111126
public void UpdateFadeLight(int Area, bool State)
@@ -137,4 +152,20 @@ public IEnumerator FadeOut(int Area, Material mat)
137152
yield return null;
138153
}
139154
}
155+
public static byte[][] SplitByteArray(byte[] byteArray, int chunkSize)
156+
{
157+
int numChunks = (byteArray.Length + chunkSize - 1) / chunkSize;
158+
byte[][] result = new byte[numChunks][];
159+
for (int i = 0; i < numChunks; i++)
160+
{
161+
int offset = i * chunkSize;
162+
int chunkLength = Math.Min(chunkSize, byteArray.Length - offset);
163+
byte[] chunk = new byte[chunkLength];
164+
Buffer.BlockCopy(byteArray, offset, chunk, 0, chunkLength);
165+
result[i] = chunk;
166+
}
167+
return result;
168+
}
169+
170+
140171
}

0 commit comments

Comments
 (0)