HUGE CHANGES !!!!Add Assembly definitions for code!!!!

This commit is contained in:
xpeng
2022-07-26 15:36:43 +02:00
parent 642f28b29c
commit 54c392fb39
43 changed files with 152 additions and 0 deletions
@@ -0,0 +1,18 @@
{
"name": "ControlPanel",
"rootNamespace": "",
"references": [
"GUID:6055be8ebefd69e48b49212b09b47b2f",
"GUID:75469ad4d38634e559750d17036d5f7c",
"GUID:80de51a1f88203a4cb129a5922de311f"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 5436500ab54595849b4b0dda68b4f629
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,87 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using System.IO;
using UnityEngine.Networking;
using System.Runtime.InteropServices;
using System;
public class HeightAdjuster : MonoBehaviour
{
[SerializeField]
private double height = 0; // meters
[SerializeField]
private double upperLimit = 10; // meters
[SerializeField]
private double lowerLimit = -10; // meters
[Space]
[SerializeField]
private double adjustSpeed = 0.1; // meters per second
[Header("Components")]
[SerializeField]
private PanelButton incrementButton;
[SerializeField]
private PanelButton decrementButton;
[SerializeField]
private PanelButton resetButton;
[SerializeField]
private TextMeshPro counterTxt;
[SerializeField]
private Transform XROrigin;
private bool incrementing = false;
private bool decrementing = false;
void Start()
{
if (JsonConfiguration.HasKey("Height")) height = JsonConfiguration.GetDouble("Height");
else SaveHeight();
incrementButton.ButtonPressed += StartIncrementing;
incrementButton.ButtonReleased += StopIncrementing;
decrementButton.ButtonPressed += StartDecrementing;
decrementButton.ButtonReleased += StopDecrementing;
resetButton.ButtonPressed += ResetHeight;
}
void Update()
{
if (incrementing) height += Time.deltaTime * adjustSpeed;
if (decrementing) height -= Time.deltaTime * adjustSpeed;
if (height > upperLimit) height = upperLimit;
if (height < lowerLimit) height = lowerLimit;
counterTxt.text = String.Format("{0:F2}m", height);
XROrigin.position = new Vector3(XROrigin.position.x, (float) -height, XROrigin.position.z);
}
private void StartIncrementing() { incrementing = true; }
private void StartDecrementing() { decrementing = true; }
private void StopIncrementing()
{
incrementing = false;
SaveHeight();
}
private void StopDecrementing()
{
decrementing = false;
SaveHeight();
}
private void ResetHeight()
{
height = 0;
SaveHeight();
}
private void SaveHeight() {
JsonConfiguration.SetDouble("Height", height);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 46aeec2d43d72c84a808e47673b6177f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class LocomotionStatus : MonoBehaviour
{
private TextMeshPro text;
// Start is called before the first frame update
void Start()
{
text = GetComponent<TextMeshPro>();
UpdateText(LocomotionToggle.IsEnabled);
}
public void UpdateText(bool status)
{
text.text = "LOCOMOTION: " + (status ? "ENABLED" : "DISABLED");
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 351fc1d968d436d44b431f42a0570812
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,88 @@
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
[RequireComponent(typeof(AudioSource))]
public class LocomotionToggle : MonoBehaviour
{
[System.Serializable]
public class LocomotionToggleEvent : UnityEvent<bool> { }
public static bool IsEnabled
{
get { return _state; }
}
private static bool _state = true;
private float timer = 0;
private bool actionDone = false;
private bool leftHeld = false;
private bool rightHeld = false;
public LocomotionToggleEvent locoEvent;
private AudioClip soundOn;
private AudioClip soundOff;
private AudioSource audioSrc;
[Header("Settings")]
[SerializeField]
private float holdTime;
[Header("References")]
[SerializeField]
private GameObject locomotionController;
[SerializeField]
private InputActionProperty leftHandAction;
[SerializeField]
private InputActionProperty rightHandAction;
private void Start()
{
if (locoEvent == null)
locoEvent = new LocomotionToggleEvent();
audioSrc = GetComponent<AudioSource>();
soundOn = Resources.Load<AudioClip>("Audio/loco on");
soundOff = Resources.Load<AudioClip>("Audio/loco off");
leftHandAction.action.Enable();
rightHandAction.action.Enable();
leftHandAction.action.started +=
(InputAction.CallbackContext _) => leftHeld = true;
leftHandAction.action.canceled +=
(InputAction.CallbackContext _) => leftHeld = false;
rightHandAction.action.started +=
(InputAction.CallbackContext _) => rightHeld = true;
rightHandAction.action.canceled +=
(InputAction.CallbackContext _) => rightHeld = false;
locomotionController.SetActive(_state);
}
private void Update()
{
if (leftHeld && rightHeld)
{
timer += Time.unscaledDeltaTime;
if (timer >= holdTime && !actionDone)
{
_state = !_state;
locoEvent.Invoke(_state);
locomotionController.SetActive(_state);
actionDone = true;
audioSrc.clip = _state ? soundOn : soundOff;
audioSrc.Play();
}
}
else
{
timer = 0;
actionDone = false;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e28739818e0aced4fbf1afd49f82dcff
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+95
View File
@@ -0,0 +1,95 @@
using System;
using System.Runtime.InteropServices;
using UnityEngine;
using WindowsInput.Native;
public class PanelButton : MonoBehaviour
{
[DllImport("user32.dll")]
public static extern uint MapVirtualKey(uint uCode, uint uMapType);
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);
public event Action ButtonPressed;
public event Action ButtonReleased;
public VirtualKeyCode key;
public VirtualKeyCode key2;
public bool isToggle;
public bool doesBeep;
public bool isOn;
private int _insideColliderCount = 0;
private Renderer cr;
//public GameObject camera; // just generating warnings lmao
public AudioSource audioSrc;
void Start()
{
cr = GetComponent<Renderer>();
if (isToggle)
{
// initialize toggle state
ButtonPress();
ButtonRelease();
}
}
private void OnTriggerEnter(Collider other)
{
_insideColliderCount += 1;
ButtonPress();
if (doesBeep)
audioSrc?.Play();
}
private void OnTriggerExit(Collider other)
{
_insideColliderCount = Mathf.Clamp(_insideColliderCount - 1, 0, _insideColliderCount);
if (_insideColliderCount == 0)
{
ButtonRelease();
}
}
private void ButtonPress()
{
ButtonPressed?.Invoke();
if (isToggle)
{
if (!isOn)
{
cr.material.color = Color.green;
keybd_event(System.Convert.ToByte(key2), (byte)MapVirtualKey((uint)key2, 0), 2, UIntPtr.Zero);
keybd_event(System.Convert.ToByte(key), (byte)MapVirtualKey((uint)key, 0), 0, UIntPtr.Zero);
isOn = true;
}
else
{
cr.material.color = Color.red;
keybd_event(System.Convert.ToByte(key), (byte)MapVirtualKey((uint)key, 0), 2, UIntPtr.Zero);
keybd_event(System.Convert.ToByte(key2), (byte)MapVirtualKey((uint)key2, 0), 0, UIntPtr.Zero);
isOn = false;
}
}
else
{
cr.material.color = Color.white;
keybd_event(System.Convert.ToByte(key), (byte)MapVirtualKey((uint)key, 0), 0, UIntPtr.Zero);
}
}
private void ButtonRelease()
{
ButtonReleased?.Invoke();
keybd_event(System.Convert.ToByte(key), (byte)MapVirtualKey((uint)key, 0), 2, UIntPtr.Zero);
keybd_event(System.Convert.ToByte(key2), (byte)MapVirtualKey((uint)key2, 0), 2, UIntPtr.Zero);
if (!isToggle)
cr.material.color = Color.gray;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 259f9860c17d7be48be056658ffa3d1e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,91 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof(AudioSource))]
public class PanelHiderButton : MonoBehaviour
{
private int colliderCount = 0;
private bool isLocked = false;
private float timer = 0f;
private bool actionTaken = false;
private Renderer r;
[Header("Settings")]
[SerializeField]
private float holdTime = 1f;
[Header("Components")]
[SerializeField]
private RawImage statusImg;
[SerializeField]
private Image timerRing;
[SerializeField]
private List<GameObject> panelButtons;
[Header("Assets")]
[SerializeField]
private Texture lockImg;
[SerializeField]
private Texture unlockImg;
[SerializeField]
private AudioClip lockSound;
[SerializeField]
private AudioClip unlockSound;
private AudioSource audioSrc;
private void Start()
{
audioSrc = GetComponent<AudioSource>();
r = GetComponent<Renderer>();
statusImg.texture = isLocked ? lockImg : unlockImg;
audioSrc.clip = lockSound;
}
private void OnTriggerEnter(Collider _)
{
r.material.color = Color.white;
++colliderCount;
}
private void OnTriggerExit(Collider _)
{
r.material.color = Color.gray;
colliderCount = Mathf.Clamp(colliderCount - 1, 0, colliderCount);
}
private void Update()
{
if (colliderCount >= 1)
{
timer += Time.unscaledDeltaTime;
float ratio = Mathf.Clamp(timer, 0, holdTime) / holdTime;
timerRing.fillAmount = Mathf.Pow(ratio, 3f);
if (ratio >= 1 && !actionTaken)
{
isLocked = !isLocked;
foreach (var btn in panelButtons)
{
btn.SetActive(!isLocked);
}
actionTaken = true;
timerRing.color = Color.cyan;
statusImg.texture = isLocked ? lockImg : unlockImg;
audioSrc.clip = isLocked ? lockSound : unlockSound;
audioSrc.Play();
}
}
else
{
timer = 0;
timerRing.fillAmount = 0;
timerRing.color = Color.white;
actionTaken = false;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b5ce728dbf8b0e54e880d703d5c18eba
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,37 @@
using System;
using System.Runtime.InteropServices;
using UnityEngine;
using WindowsInput.Native;
public class PanelThirdPersonButton : MonoBehaviour
{
public bool isTP;
private Renderer cr;
public GameObject tpCamera;
public AudioSource audioSrc;
void Start()
{
cr = GetComponent<Renderer>();
if (JsonConfiguration.HasKey("ThirdPerson")) SetTP(JsonConfiguration.GetBoolean("ThirdPerson"));
else SetTP(isTP);
}
private void OnTriggerEnter(Collider other)
{
audioSrc.Play();
isTP = !isTP;
SetTP(isTP);
}
private void SetTP(bool state)
{
isTP = state;
cr.material.color = state ? Color.green : Color.red;
tpCamera?.SetActive(state);
JsonConfiguration.SetBoolean("ThirdPerson", state);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 447b0e47a465da145b212861d2c70c27
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,136 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using System.IO;
using UnityEngine.Networking;
using System.Runtime.InteropServices;
using System;
public class SkyboxSwitcher : MonoBehaviour
{
private string skyboxPath;
public List<Texture2D> textures = new List<Texture2D>();
public List<System.IntPtr> ptrs = new List<System.IntPtr>();
[SerializeField]
private List<Material> skyboxes;
[SerializeField]
private int currentSkyboxIndex = 0;
[Header("Components")]
[SerializeField]
private PanelButton incrementBtn;
[SerializeField]
private PanelButton decrementBtn;
[SerializeField]
private TextMeshPro counterTxt;
void Start()
{
if (JsonConfiguration.HasKey("Skybox")) currentSkyboxIndex = JsonConfiguration.GetInt("Skybox");
else SaveSkyboxIndex();
incrementBtn.ButtonPressed += IncrementEvent;
decrementBtn.ButtonPressed += DecrementEvent;
skyboxes.Insert(0, RenderSettings.skybox); // add ubiquitous default skybox (should be current)
// check StreamingAssets folder for additional skybox textures
skyboxPath = Path.Combine(Application.streamingAssetsPath, "SkyboxTextures");
StartCoroutine(AddSkyboxes());
SetSkybox();
}
IEnumerator AddSkyboxes()
{
var skyboxDir = new DirectoryInfo(skyboxPath);
List<FileInfo> imageFiles = new List<FileInfo>();
imageFiles.AddRange(skyboxDir.GetFiles("*.png"));
imageFiles.AddRange(skyboxDir.GetFiles("*.jpg"));
imageFiles.AddRange(skyboxDir.GetFiles("*.jpeg"));
//List<FileInfo> hdrFiles = new List<FileInfo>();
//hdrFiles.AddRange(skyboxDir.GetFiles("*.hdr"));
//hdrFiles.AddRange(skyboxDir.GetFiles("*.hdri"));
//hdrFiles.AddRange(skyboxDir.GetFiles("*.exr"));
foreach (var file in imageFiles) // Typical image files
{
var uwr = UnityWebRequestTexture.GetTexture(file.ToString());
yield return uwr.SendWebRequest();
if (uwr.result == UnityWebRequest.Result.ConnectionError)
{
Debug.LogWarning($"Couldn't load skybox texture at {uwr.uri}.");
}
else
{
var skyboxMat = new Material(Shader.Find("Skybox/Panoramic"));
skyboxMat.SetFloat("_Rotation", 45f);
var texture = DownloadHandlerTexture.GetContent(uwr);
if (texture != null)
{
skyboxMat.SetTexture("_MainTex", texture);
skyboxes.Add(skyboxMat);
}
}
}
SetSkybox();
//foreach (var file in hdrFiles) // HDR files -- no way to use by scripting?
//{
// var uwr = UnityWebRequest.Get(file.ToString());
// yield return uwr.SendWebRequest();
// if (uwr.result == UnityWebRequest.Result.ConnectionError)
// {
// Debug.Log($"Had trouble loading file {uwr.uri}.");
// }
// else
// {
// byte[] data = uwr.downloadHandler.data;
// if (data != null)
// {
// GCHandle pinnedArray = GCHandle.Alloc(data, GCHandleType.Pinned);
// IntPtr pointer = pinnedArray.AddrOfPinnedObject();
// var cubemap = Cubemap.CreateExternalTexture(2200, TextureFormat.DXT5, false, pointer);
// var skyboxMat = new Material(Shader.Find("Skybox/Panoramic"));
// skyboxMat.SetTexture("_Tex", cubemap);
// skyboxes.Add(skyboxMat);
// pinnedArray.Free();
// }
// // FIXME: convert Texture2D to Cubemap
// //textures.Add(texture);
// //ptrs.Add(texture.GetNativeTexturePtr());
// //texture = textures[textures.Count - 1];
// //var cubemap = Cubemap.CreateExternalTexture(texture.width, texture.format, false, texture.GetNativeTexturePtr());
// //skyboxMat.SetTexture("_Tex", cubemap);
// }
//}
}
private void IncrementEvent()
{
currentSkyboxIndex = (currentSkyboxIndex + 1) % skyboxes.Count;
SetSkybox();
}
private void DecrementEvent()
{
if (--currentSkyboxIndex < 0)
currentSkyboxIndex = skyboxes.Count - 1;
SetSkybox();
}
private void SetSkybox()
{
counterTxt.text = (currentSkyboxIndex + 1).ToString();
if (currentSkyboxIndex < skyboxes.Count && skyboxes[currentSkyboxIndex] != null)
RenderSettings.skybox = skyboxes[currentSkyboxIndex];
SaveSkyboxIndex();
}
private void SaveSkyboxIndex()
{
JsonConfiguration.SetInt("Skybox", currentSkyboxIndex);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d9d7372274e9214429d55ed4ef283584
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: