Import assets from store
This commit is contained in:
1 parent
a05f2e47a2
commit
376e52e323
875 files changed
+128037
No files matched your search
@@ -0,0 +1,154 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace CharacterMovement
|
||||
{
|
||||
public static class InputSystemKeyCodeUtility
|
||||
{
|
||||
public static bool WasPressedThisFrame(KeyCode keyCode)
|
||||
{
|
||||
Keyboard keyboard = Keyboard.current;
|
||||
if (keyboard == null || !TryConvert(keyCode, out Key key))
|
||||
return false;
|
||||
|
||||
return keyboard[key].wasPressedThisFrame;
|
||||
}
|
||||
|
||||
private static bool TryConvert(KeyCode keyCode, out Key key)
|
||||
{
|
||||
key = keyCode switch
|
||||
{
|
||||
KeyCode.A => Key.A,
|
||||
KeyCode.B => Key.B,
|
||||
KeyCode.C => Key.C,
|
||||
KeyCode.D => Key.D,
|
||||
KeyCode.E => Key.E,
|
||||
KeyCode.F => Key.F,
|
||||
KeyCode.G => Key.G,
|
||||
KeyCode.H => Key.H,
|
||||
KeyCode.I => Key.I,
|
||||
KeyCode.J => Key.J,
|
||||
KeyCode.K => Key.K,
|
||||
KeyCode.L => Key.L,
|
||||
KeyCode.M => Key.M,
|
||||
KeyCode.N => Key.N,
|
||||
KeyCode.O => Key.O,
|
||||
KeyCode.P => Key.P,
|
||||
KeyCode.Q => Key.Q,
|
||||
KeyCode.R => Key.R,
|
||||
KeyCode.S => Key.S,
|
||||
KeyCode.T => Key.T,
|
||||
KeyCode.U => Key.U,
|
||||
KeyCode.V => Key.V,
|
||||
KeyCode.W => Key.W,
|
||||
KeyCode.X => Key.X,
|
||||
KeyCode.Y => Key.Y,
|
||||
KeyCode.Z => Key.Z,
|
||||
KeyCode.Alpha0 => Key.Digit0,
|
||||
KeyCode.Alpha1 => Key.Digit1,
|
||||
KeyCode.Alpha2 => Key.Digit2,
|
||||
KeyCode.Alpha3 => Key.Digit3,
|
||||
KeyCode.Alpha4 => Key.Digit4,
|
||||
KeyCode.Alpha5 => Key.Digit5,
|
||||
KeyCode.Alpha6 => Key.Digit6,
|
||||
KeyCode.Alpha7 => Key.Digit7,
|
||||
KeyCode.Alpha8 => Key.Digit8,
|
||||
KeyCode.Alpha9 => Key.Digit9,
|
||||
KeyCode.F1 => Key.F1,
|
||||
KeyCode.F2 => Key.F2,
|
||||
KeyCode.F3 => Key.F3,
|
||||
KeyCode.F4 => Key.F4,
|
||||
KeyCode.F5 => Key.F5,
|
||||
KeyCode.F6 => Key.F6,
|
||||
KeyCode.F7 => Key.F7,
|
||||
KeyCode.F8 => Key.F8,
|
||||
KeyCode.F9 => Key.F9,
|
||||
KeyCode.F10 => Key.F10,
|
||||
KeyCode.F11 => Key.F11,
|
||||
KeyCode.F12 => Key.F12,
|
||||
KeyCode.Escape => Key.Escape,
|
||||
KeyCode.Tab => Key.Tab,
|
||||
KeyCode.Space => Key.Space,
|
||||
KeyCode.Return => Key.Enter,
|
||||
KeyCode.Backspace => Key.Backspace,
|
||||
KeyCode.Delete => Key.Delete,
|
||||
KeyCode.Insert => Key.Insert,
|
||||
KeyCode.Home => Key.Home,
|
||||
KeyCode.End => Key.End,
|
||||
KeyCode.PageUp => Key.PageUp,
|
||||
KeyCode.PageDown => Key.PageDown,
|
||||
KeyCode.UpArrow => Key.UpArrow,
|
||||
KeyCode.DownArrow => Key.DownArrow,
|
||||
KeyCode.LeftArrow => Key.LeftArrow,
|
||||
KeyCode.RightArrow => Key.RightArrow,
|
||||
KeyCode.LeftShift => Key.LeftShift,
|
||||
KeyCode.RightShift => Key.RightShift,
|
||||
KeyCode.LeftControl => Key.LeftCtrl,
|
||||
KeyCode.RightControl => Key.RightCtrl,
|
||||
KeyCode.LeftAlt => Key.LeftAlt,
|
||||
KeyCode.RightAlt => Key.RightAlt,
|
||||
KeyCode.BackQuote => Key.Backquote,
|
||||
KeyCode.Minus => Key.Minus,
|
||||
KeyCode.Equals => Key.Equals,
|
||||
KeyCode.LeftBracket => Key.LeftBracket,
|
||||
KeyCode.RightBracket => Key.RightBracket,
|
||||
KeyCode.Backslash => Key.Backslash,
|
||||
KeyCode.Semicolon => Key.Semicolon,
|
||||
KeyCode.Quote => Key.Quote,
|
||||
KeyCode.Comma => Key.Comma,
|
||||
KeyCode.Period => Key.Period,
|
||||
KeyCode.Slash => Key.Slash,
|
||||
_ => Key.None
|
||||
};
|
||||
|
||||
return key != Key.None;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SceneReferenceResolver
|
||||
{
|
||||
public static T FindComponentInSameScene<T>(Component owner) where T : Component
|
||||
{
|
||||
if (!owner)
|
||||
return null;
|
||||
|
||||
Scene scene = owner.gameObject.scene;
|
||||
if (!scene.IsValid() || !scene.isLoaded)
|
||||
return null;
|
||||
|
||||
GameObject[] roots = scene.GetRootGameObjects();
|
||||
for (int i = 0; i < roots.Length; i++)
|
||||
{
|
||||
T component = roots[i].GetComponentInChildren<T>(true);
|
||||
if (component)
|
||||
return component;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Camera FindMainCameraInSameScene(Component owner)
|
||||
{
|
||||
if (!owner)
|
||||
return null;
|
||||
|
||||
Scene scene = owner.gameObject.scene;
|
||||
if (!scene.IsValid() || !scene.isLoaded)
|
||||
return null;
|
||||
|
||||
GameObject[] roots = scene.GetRootGameObjects();
|
||||
for (int i = 0; i < roots.Length; i++)
|
||||
{
|
||||
Camera[] cameras = roots[i].GetComponentsInChildren<Camera>(true);
|
||||
for (int j = 0; j < cameras.Length; j++)
|
||||
{
|
||||
if (cameras[j] && cameras[j].CompareTag("MainCamera"))
|
||||
return cameras[j];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c93a8738026148d7bdc9e6e5f0c7473b
|
||||
timeCreated: 1781733150
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 367142
|
||||
packageName: "MotionCore \u2013 Physics Character Controller"
|
||||
packageVersion: 1.2
|
||||
assetPath: Assets/Character Controller/Core/Scripts/Utility/SceneReferenceResolver.cs
|
||||
uploadId: 997018
|
||||
Reference in new issue
Block a user