-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
188 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System; | ||
using System.Reflection; | ||
using MelonLoader; | ||
|
||
namespace LabratEyeTracking | ||
{ | ||
public static class ConfigHelper | ||
{ | ||
public static Config LoadedConfig; | ||
private static readonly string myCategory = "LabratEyeTracking"; | ||
|
||
private static MelonPreferences_Category category; | ||
|
||
public static bool DoesEntryExist(string key) => MelonPreferences.HasEntry(category.Identifier, key); | ||
|
||
private static void CreateEntryInConfig<T>(string key, string description, T defaultValue) => | ||
MelonPreferences.CreateEntry(category.Identifier, key, defaultValue, key, description); | ||
|
||
private static T GetEntryInConfig<T>(string key) => | ||
MelonPreferences.GetEntry<T>(category.Identifier, key).Value; | ||
|
||
private static void CreateConfig() | ||
{ | ||
category = MelonPreferences.CreateCategory(myCategory); | ||
LogHelper.Debug("Created Config!"); | ||
} | ||
|
||
public static Config LoadConfig() | ||
{ | ||
CreateConfig(); | ||
Config newConfig = new Config(); | ||
foreach (FieldInfo field in newConfig.GetType().GetFields()) | ||
{ | ||
// Try and get it's method | ||
MethodInfo reload = | ||
field.FieldType.GetMethod("ReloadValues", BindingFlags.Public | BindingFlags.Instance); | ||
object fieldValue = field.GetValue(newConfig); | ||
if (reload != null) | ||
reload.Invoke(fieldValue, null); | ||
else | ||
LogHelper.Warn("Could not find ReloadValues method for Field " + field.Name); | ||
} | ||
|
||
LoadedConfig = newConfig; | ||
LogHelper.Debug("Loaded Config!"); | ||
return newConfig; | ||
} | ||
|
||
public class Config | ||
{ | ||
public ConfigValue<int> sdkType = new ConfigValue<int>("sdkType", | ||
() => CreateEntryInConfig("sdkType", "Select the runtime used for Eye Tracking.", 0), | ||
() => GetEntryInConfig<int>("sdkType")); | ||
} | ||
|
||
public class ConfigValue<T> | ||
{ | ||
public string Key { get; } | ||
public T Value { get; set; } | ||
private Func<T> GetEntry; | ||
|
||
public ConfigValue(string Key, Action CreateEntry, Func<T> GetEntry) | ||
{ | ||
this.Key = Key; | ||
if (!DoesEntryExist(Key)) | ||
{ | ||
CreateEntry.Invoke(); | ||
LogHelper.Debug($"Created entry {Key}"); | ||
} | ||
this.GetEntry = GetEntry; | ||
GetEntry.Invoke(); | ||
} | ||
|
||
public T ReloadValues() | ||
{ | ||
T value = GetEntry.Invoke(); | ||
Value = value; | ||
LogHelper.Debug($"Reloaded Config Value {Key} and got Value {value}"); | ||
return value; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using UnityEngine; | ||
|
||
namespace LabratEyeTracking | ||
{ | ||
public class EyeDriver : MonoBehaviour | ||
{ | ||
private bool set = false; | ||
private Transform playerHead; | ||
|
||
private void OnEnable() | ||
{ | ||
if(gameObject.GetComponent<Collider>() != null) | ||
Destroy(gameObject.GetComponent<Collider>()); | ||
} | ||
|
||
private void FixedUpdate() | ||
{ | ||
if (playerHead != null) | ||
{ | ||
Vector3 origin = playerHead.position + UniversalEyeData.CombinedEye.origin; | ||
Vector3 direction = playerHead.forward + UniversalEyeData.CombinedEye.direction; | ||
RaycastHit hit; | ||
if (Physics.Raycast(origin, direction, out hit, Mathf.Infinity)) | ||
{ | ||
Debug.DrawRay(origin, direction * hit.distance, Color.yellow); | ||
transform.position = hit.transform.position; | ||
} | ||
} | ||
else | ||
{ | ||
playerHead = GameHelper.FindPlayerModel().transform.Find("SteamVRObjects").Find("VRCamera"); | ||
if (!set && playerHead != null) | ||
{ | ||
set = true; | ||
playerHead.position = Vector3.zero; | ||
playerHead.rotation = new Quaternion(0, 0, 0, 0); | ||
LogHelper.Debug("Found Player Head!"); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using BepInEx.Logging; | ||
using UnityEngine; | ||
using Logger = BepInEx.Logging.Logger; | ||
using MelonLoader; | ||
|
||
namespace LabratEyeTracking | ||
{ | ||
public class LogHelper | ||
{ | ||
private static readonly ManualLogSource _logger = Logger.CreateLogSource("LabratEyeTracking"); | ||
private static readonly MelonLogger.Instance _logger = new MelonLogger.Instance("LabratEyeTracking"); | ||
|
||
public static void Debug(object message) => _logger.Log(LogLevel.Info, "[LabratEyeTracking] (DEBUG): " + message); | ||
public static void Warn(object message) => _logger.LogWarning("[LabratEyeTracking] (WARN): " + message); | ||
public static void Error(object message) => _logger.LogError("[LabratEyeTracking] (ERROR): " + message); | ||
public static void Critical(object message) => _logger.LogError("[LabratEyeTracking] (CRITICAL): " + message); | ||
public static void Debug(object message) => _logger.Msg(message); | ||
public static void Warn(object message) => _logger.Warning(message); | ||
public static void Error(object message) => _logger.Error(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
LabratEyeTracking/LabratEyeTracking/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using MelonLoader; | ||
using LabratEyeTracking; | ||
|
||
[assembly: MelonInfo(typeof(MainMod), "LabratEyeTracking", "1.3.0", "200Tigersbloxed")] | ||
[assembly: MelonGame("Bezbro Games", "SCP Labrat")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.