make ipc config functional
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ConfigBehavior : MonoBehaviour
|
||||
{
|
||||
public static ConfigBehavior instance;
|
||||
void Awake()
|
||||
{
|
||||
instance = this;
|
||||
}
|
||||
public static void SaveFile()
|
||||
{
|
||||
instance.StopCoroutine(ConfigManager.SaveFileWait());
|
||||
instance.StartCoroutine(ConfigManager.SaveFileWait());
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f08f3c86e1b0ac4090e2ae9c18b8201
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -14,6 +14,9 @@ public class ConfigManager : MonoBehaviour
|
||||
private static bool hasInitialized = false;
|
||||
Config oldConfig;
|
||||
public static event Action onConfigChanged;
|
||||
private static float saverTimer = 0;
|
||||
private static bool isSavingConfig = false;
|
||||
private float saverDelay = 1.5f;
|
||||
void Awake()
|
||||
{
|
||||
onConfigChanged += EnsureInitialization;
|
||||
@@ -26,10 +29,6 @@ public class ConfigManager : MonoBehaviour
|
||||
UpdateConfigPanel();
|
||||
AddListenerToWidget();
|
||||
onConfigChanged?.Invoke();
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
public static void EnsureInitialization()
|
||||
{
|
||||
@@ -60,16 +59,30 @@ public class ConfigManager : MonoBehaviour
|
||||
}
|
||||
public static void SaveFile()
|
||||
{
|
||||
if (ConfigBehavior.instance != null)
|
||||
ConfigBehavior.SaveFile();
|
||||
isSavingConfig = true;
|
||||
saverTimer = 0;
|
||||
Debug.Log("Saving config file");
|
||||
}
|
||||
public static IEnumerator SaveFileWait()
|
||||
public void saveFileWait()
|
||||
{
|
||||
yield return new WaitForSeconds(1.5f);
|
||||
File.WriteAllText(GetFileName(), JsonConvert.SerializeObject(config, Formatting.Indented));
|
||||
Debug.Log("Config file saved");
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (isSavingConfig)
|
||||
{
|
||||
saverTimer += Time.deltaTime;
|
||||
if (saverTimer >= saverDelay)
|
||||
{
|
||||
isSavingConfig = false;
|
||||
saverTimer = 0;
|
||||
saveFileWait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private TMP_Dropdown CaptureModeDropdown;
|
||||
private TMP_Dropdown CaptureFPSDropdown;
|
||||
private Toggle CaptureDesktopToggle;
|
||||
|
||||
@@ -9,9 +9,9 @@ public class LightManager : MonoBehaviour
|
||||
public List<GameObject> Lights = new List<GameObject>();
|
||||
List<Material> Materials = new List<Material>();
|
||||
[SerializeField]
|
||||
public bool isIPCIdle = true;
|
||||
private bool isIPCIdle = true;
|
||||
[SerializeField]
|
||||
public bool useIPCLighting = true;
|
||||
private bool useIPCLighting = true;
|
||||
static Texture2D RGBColor2D;
|
||||
|
||||
private IEnumerator[] coroutines = new IEnumerator[240];
|
||||
@@ -36,7 +36,11 @@ public class LightManager : MonoBehaviour
|
||||
private void Update()
|
||||
{
|
||||
if (!useIPCLighting)
|
||||
{
|
||||
isIPCIdle = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (IPCManager.sharedBuffer != null)
|
||||
{
|
||||
GetTextureFromBytes(IPCManager.GetLightData());
|
||||
@@ -80,9 +84,9 @@ public class LightManager : MonoBehaviour
|
||||
RGBColor2D.LoadRawTextureData(bytes);
|
||||
RGBColor2D.Apply();
|
||||
}
|
||||
public void UpdateLightFade(int Area, bool State)
|
||||
public void UpdateFadeLight(int Area, bool State)
|
||||
{
|
||||
if(!isIPCIdle || useIPCLighting)
|
||||
if(!isIPCIdle | useIPCLighting)
|
||||
return;
|
||||
|
||||
Area -= 1;
|
||||
|
||||
@@ -20,7 +20,7 @@ public class ColliderToTouch : MonoBehaviour
|
||||
_insideColliderCount += 1;
|
||||
TouchManager.SetTouch(Area, true);
|
||||
touchDidChange?.Invoke();
|
||||
LightManager.UpdateLightFade(Area, true);
|
||||
LightManager.UpdateFadeLight(Area, true);
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collider other)
|
||||
@@ -31,7 +31,7 @@ public class ColliderToTouch : MonoBehaviour
|
||||
{
|
||||
TouchManager.SetTouch(Area, false);
|
||||
touchDidChange?.Invoke();
|
||||
LightManager.UpdateLightFade(Area, false);
|
||||
LightManager.UpdateFadeLight(Area, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:476196b3fd6829e45b839eb138f356ed",
|
||||
"GUID:4b68ab8531bd5864db8bb4af74c61824"
|
||||
"GUID:4b68ab8531bd5864db8bb4af74c61824",
|
||||
"GUID:80de51a1f88203a4cb129a5922de311f"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
||||
@@ -7,7 +7,6 @@ using System.Linq;
|
||||
using UnityEngine;
|
||||
public class TouchManager : MonoBehaviour
|
||||
{
|
||||
|
||||
const byte CMD_GET_SYNC_BOARD_VER = 0xa0;
|
||||
const byte CMD_NEXT_READ = 0x72;
|
||||
const byte CMD_GET_UNIT_BOARD_VER = 0xa8;
|
||||
@@ -36,10 +35,11 @@ public class TouchManager : MonoBehaviour
|
||||
byte[] SettingData_201 = new byte[3] {201, 0, 73};
|
||||
static byte[] TouchPackL = new byte[36];
|
||||
static byte[] TouchPackR = new byte[36];
|
||||
public static bool[] TouchPackAll = new bool[240];
|
||||
static bool[] TouchPackAll = new bool[240];
|
||||
bool StartUp = false;
|
||||
void Start()
|
||||
{
|
||||
ConfigManager.EnsureInitialization();
|
||||
try
|
||||
{
|
||||
ComL.Open();
|
||||
@@ -49,7 +49,7 @@ public class TouchManager : MonoBehaviour
|
||||
{
|
||||
Console.WriteLine($"Failed to Open Serial Ports: {ex}");
|
||||
}
|
||||
//Debug.Log("Touch Serial Initializing..");
|
||||
Debug.Log("Touch Serial Initializing..");
|
||||
//Send touch update periodically to keep "read" alive
|
||||
_touchQueue = Queue.Synchronized(new Queue());
|
||||
_touchThread = new Thread(TouchThreadLoop);
|
||||
@@ -85,8 +85,8 @@ public class TouchManager : 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();
|
||||
}
|
||||
@@ -101,6 +101,8 @@ public class TouchManager : MonoBehaviour
|
||||
// Debug.Log("Sending Right");
|
||||
SendTouch(ComR, TouchPackR);
|
||||
}
|
||||
if (ConfigManager.config.useIPCTouch)
|
||||
IPCManager.SetTouchData(TouchPackAll); //send touch data to IPC
|
||||
}
|
||||
|
||||
IEnumerator TouchTest(bool State) //this is a touch test code
|
||||
@@ -223,30 +225,29 @@ public class TouchManager : MonoBehaviour
|
||||
Pack[34] = 0;
|
||||
return Pack;
|
||||
}
|
||||
void SendTouch(SerialPort Serial, byte[] Pack) //Send touch data
|
||||
void SendTouch(SerialPort Serial, byte[] Pack) //Send touch data to serial
|
||||
{
|
||||
if (StartUp)
|
||||
Serial.Write(GetTouchPack(Pack), 0, 36);
|
||||
}
|
||||
public static void SetTouch(int Area, bool State) //set touch data 0-239
|
||||
public static void SetTouch(int Area, bool State) //set touch data 1-240
|
||||
{
|
||||
Area -= 1;
|
||||
if (Area < 120)
|
||||
Area -= 1; //0-239
|
||||
if (Area < 120) //right side
|
||||
{
|
||||
TouchPackAll[Area + 120] = State;
|
||||
TouchPackAll[Area + 120] = State; //save R touch for IPC
|
||||
|
||||
Area += Area / 5 * 3 + 7;
|
||||
ByteHelper.SetBit(TouchPackR, Area, State);
|
||||
}
|
||||
else if (Area >= 120)
|
||||
else if (Area >= 120) //left side
|
||||
{
|
||||
TouchPackAll[Area - 120] = State;
|
||||
TouchPackAll[Area - 120] = State; //save L touch for IPC
|
||||
|
||||
Area -= 120;
|
||||
Area += Area / 5 * 3 + 7;
|
||||
ByteHelper.SetBit(TouchPackL, Area, State);
|
||||
}
|
||||
IPCManager.SetTouchData(TouchPackAll);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user