@@ -49,6 +49,9 @@ public class LocomotionToggle : MonoBehaviour
|
||||
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 +=
|
||||
|
||||
@@ -11,6 +11,9 @@ public class PanelButton : MonoBehaviour
|
||||
[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;
|
||||
|
||||
@@ -62,6 +65,7 @@ public class PanelButton : MonoBehaviour
|
||||
|
||||
private void ButtonPress()
|
||||
{
|
||||
ButtonPressed?.Invoke();
|
||||
if (isToggle)
|
||||
{
|
||||
if (!isOn)
|
||||
@@ -89,6 +93,7 @@ public class PanelButton : MonoBehaviour
|
||||
|
||||
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)
|
||||
|
||||
@@ -2,12 +2,13 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class PanelLocker : MonoBehaviour
|
||||
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]
|
||||
@@ -35,17 +36,20 @@ public class PanelLocker : MonoBehaviour
|
||||
|
||||
private void Start()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
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; // should start at 0
|
||||
|
||||
[Header("Components")]
|
||||
[SerializeField]
|
||||
private PanelButton incrementBtn;
|
||||
[SerializeField]
|
||||
private PanelButton decrementBtn;
|
||||
[SerializeField]
|
||||
private TextMeshPro counterTxt;
|
||||
|
||||
void Start()
|
||||
{
|
||||
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.Log($"Had trouble loading file {uwr.uri}.");
|
||||
}
|
||||
else
|
||||
{
|
||||
var skyboxMat = new Material(Shader.Find("Skybox/Panoramic"));
|
||||
skyboxMat.SetFloat("_Rotation", 45f);
|
||||
var texture = DownloadHandlerTexture.GetContent(uwr);
|
||||
Debug.Log(uwr.uri);
|
||||
Debug.Log(texture);
|
||||
Debug.Log("////////////");
|
||||
if (texture != null)
|
||||
{
|
||||
skyboxMat.SetTexture("_MainTex", texture);
|
||||
skyboxes.Add(skyboxMat);
|
||||
}
|
||||
}
|
||||
}
|
||||
//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 (skyboxes[currentSkyboxIndex] != null)
|
||||
RenderSettings.skybox = skyboxes[currentSkyboxIndex];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9d7372274e9214429d55ed4ef283584
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user