Skip to content

Commit

Permalink
GUI ON/OFFの追加、YOTOGIモードで掴みOFFを追加、MyKeyInputサンプルのキー入力周りを強化
Browse files Browse the repository at this point in the history
  • Loading branch information
nekopanda committed Feb 5, 2017
1 parent c70726a commit e36cb65
Show file tree
Hide file tree
Showing 8 changed files with 270 additions and 62 deletions.
86 changes: 83 additions & 3 deletions CM3D2.VRMenu.MyKeyInput/CM3D2.VRMenu.MyKeyInput.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
Expand All @@ -13,7 +14,7 @@ namespace CM3D2.VRMenu.MyKeyInput
PluginFilter("CM3D2VRx64"),
PluginFilter("CM3D2OHVRx64"),
PluginName("VRMenuMyKeyInput"),
PluginVersion("0.0.2.2")
PluginVersion("0.0.3.0")
]
public class VRMenuMyKeyInput : PluginBase
{
Expand All @@ -39,19 +40,98 @@ private void Start()
// Console.WriteLine("[VRMenuMyKeyInput] メニューをインストールしました");
}

// keycodeについて
// アルファベットは大文字で指定
// 数字はそのまま
// ファンクションキーはGetFKeyで変換(1~24まで)
// その他のキーはKEYに定義されてる

private int GetFKey(int num)
{
return 0x70 + (num - 1);
}

private enum KEY
{
BACKSPACE = 0x08,
TAB = 0x09,
ENTER = 0x0D,
SHIFT = 0x10,
CTRL = 0x11,
ALT = 0x12,
PAUSE = 0x13,
CAPSLOCK = 0x14,
ESC = 0x1B,
SPACE = 0x20,
PAGEUP = 0x21,
PAGEDOWN = 0x22,
END = 0x23,
HOME = 0x24,
LEFT = 0x25, // ←
UP = 0x26, // ↑
RIGHT = 0x27, // →
DOWN = 0x28, // ↓
PRINTSCREEN = 0x2C,
INSERT = 0x2D,
DELETE = 0x2E,

// 以下日本語キーボード用
COLON = 0xBA, // :
SEMICOLON = 0xBB, // ;
COMMA = 0xBC, // ,
MINUS = 0xBD, // -
PERIOD = 0xBE, // .
SLASH = 0xBF, // /
AT = 0xC0, // @

LEFT_KAKKO = 0xDB, // [
YEN = 0xDC, // \
RIGHT_KAKKO = 0xDD,// [
HAT = 0xDE, // ^
BACK_SLASH = 0xE2, // \
}

[DllImport("user32.dll")]
public static extern uint keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);

private void KeyInput(int keycode)
{
StartCoroutine(KeyInputCo(keycode, 0, 0));
}

// 2つ同時押し
private void KeyInput(int keycode1, int keycode2)
{
StartCoroutine(KeyInputCo(keycode1, keycode2, 0));
}

// 3つ同時押し
private void KeyInput(int keycode1, int keycode2, int keycode3)
{
StartCoroutine(KeyInputCo(keycode1, keycode2, keycode3));
}

private IEnumerator KeyInputCo(int keycode1, int keycode2, int keycode3)
{
uint KEYEVENTF_KEYUP = 2;
keybd_event((byte)keycode, 0, 0, (UIntPtr)0);
keybd_event((byte)keycode, 0, KEYEVENTF_KEYUP, (UIntPtr)0);
keybd_event((byte)keycode1, 0, 0, (UIntPtr)0);
yield return null;
if(keycode2 != 0)
{
keybd_event((byte)keycode2, 0, 0, (UIntPtr)0);
yield return null;
if (keycode3 != 0)
{
keybd_event((byte)keycode3, 0, 0, (UIntPtr)0);
yield return null;
keybd_event((byte)keycode3, 0, KEYEVENTF_KEYUP, (UIntPtr)0);
yield return null;
}
keybd_event((byte)keycode2, 0, KEYEVENTF_KEYUP, (UIntPtr)0);
yield return null;
}
keybd_event((byte)keycode1, 0, KEYEVENTF_KEYUP, (UIntPtr)0);
yield break;
}

private object createVibeYourMaidController()
Expand Down
4 changes: 2 additions & 2 deletions CM3D2.VRMenu.MyKeyInput/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を
// 既定値にすることができます:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.2.2")]
[assembly: AssemblyFileVersion("0.0.2.2")]
[assembly: AssemblyVersion("0.0.3.0")]
[assembly: AssemblyFileVersion("0.0.3.0")]
37 changes: 25 additions & 12 deletions CM3D2.VRMenu.Plugin/GUIQuad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ private void OnGUI()
}
}

private static readonly Vector3 ColliderScale = new Vector3(1, 1, 0.07f);

private GameObject ovr_screen;

private RenderTexture rtIMGUI;
Expand All @@ -34,7 +36,7 @@ private void OnGUI()

private bool IsCursorUnlocked = false;

private bool visible_;
private bool visible_ = true;
public bool Visible {
get {
return visible_;
Expand Down Expand Up @@ -64,7 +66,7 @@ public static GUIQuad Create()
go.name = "VRMenu GUIQuad";
go.GetComponent<MeshCollider>().enabled = false;
BoxCollider collider = go.AddComponent<BoxCollider>();
collider.size = new Vector3(1, 1, 0.07f);
collider.size = ColliderScale;
// raycast使わないけど一応・・・
go.layer = LayerMask.NameToLayer("Ignore Raycast");
instance_ = go.AddComponent<GUIQuad>();
Expand Down Expand Up @@ -102,6 +104,11 @@ public void UpdateGuiQuadScale()
gameObject.transform.localScale = new Vector3(x, y, 1);
}

public void ToggleUI()
{
Visible = !Visible;
}

#region IMGUIをrtIMGUIにレンダリング

private RenderTexture prevRenderTexture;
Expand Down Expand Up @@ -160,7 +167,7 @@ private void Update()
rtOVRUI = ovr_screen.GetComponentInChildren<MeshRenderer>().material.mainTexture as RenderTexture;
uiMaterial.SetTexture("_SecondTex", rtOVRUI);

switchVisiblity(visible_);
//switchVisiblity(visible_);
}
}
if(rtOVRUI != null)
Expand All @@ -176,12 +183,6 @@ private void Update()
{
rtIMGUI.Create();
}

if(gameObject.activeSelf == ovr_screen.activeSelf)
{
// 整合性を取る
ovr_screen.SetActive(!gameObject.activeSelf);
}
}
}

Expand All @@ -202,6 +203,11 @@ private void updateScreenSize()

public void MoveCursorTo(int x, int y)
{
if(gameObject.activeSelf == false)
{
return;
}

if(WinAPI.WindowHandle == IntPtr.Zero)
{
return;
Expand Down Expand Up @@ -269,10 +275,17 @@ public Vector4 IMGUIVirtualScreenRect {

private void switchVisiblity(bool visilbe)
{
if (ovr_screen != null)
if(visilbe)
{
Log.Debug("Enabled GUIQuad");
gameObject.GetComponent<BoxCollider>().size = ColliderScale;
gameObject.GetComponent<MeshRenderer>().enabled = true;
}
else
{
gameObject.SetActive(visilbe);
ovr_screen.SetActive(!visilbe);
Log.Debug("Disabled GUIQuad");
gameObject.GetComponent<BoxCollider>().size = new Vector3(0.0001f, 0.0001f, 0.0001f);
gameObject.GetComponent<MeshRenderer>().enabled = false;
}
}
}
Expand Down
13 changes: 3 additions & 10 deletions CM3D2.VRMenu.Plugin/PluginMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ class YotogiCommandTool : VRMenuPage, IVRControllerMode
{
private static string[] EmptyString = new string[0];

public bool IsDiableGripByTrigger { get { return false; } }
public bool IsDiableGripByGrip { get { return false; } }
public bool IsDiableGripByTrigger { get { return VRMenuPlugin.Instance.Config.DisableButtonsInYotogiMode; } }
public bool IsDiableGripByGrip { get { return VRMenuPlugin.Instance.Config.DisableButtonsInYotogiMode; } }

public bool IsEnabled {
get {
Expand Down Expand Up @@ -513,16 +513,9 @@ public void OnActivated(Controller controller)
state = VRMenuPlugin.Instance.Controllers[(int)controller].gameObject.AddComponent<State>();
stateList[(int)controller] = state;
}
state.SetInputActive(true);
}
public void OnDeactivated(Controller controller)
{
State state = stateList[(int)controller];
if (state != null)
{
state.SetInputActive(false);
}
}
{ }
public void OnTouchPadState(Controller controller, bool enable)
{
State state = stateList[(int)controller];
Expand Down
4 changes: 2 additions & 2 deletions CM3D2.VRMenu.Plugin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を
// 既定値にすることができます:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.2.2")]
[assembly: AssemblyFileVersion("0.0.2.2")]
[assembly: AssemblyVersion("0.0.3.0")]
[assembly: AssemblyFileVersion("0.0.3.0")]
31 changes: 23 additions & 8 deletions CM3D2.VRMenu.Plugin/VRMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ public override void OnButtonClicked(VRMenu menu, Controller controller) { }
protected List<IMenuButton> buttons = new List<IMenuButton>();
protected IMenuButton[] enabledButtons = null;
private ButtonHelper buttonHelper = new ButtonHelper();
private VRMenu[] parentMenu = new VRMenu[(int)Controller.Max];

public string Name { get; set; }

Expand All @@ -286,8 +287,6 @@ public bool Enabled

public int Metric { get; set; }

public VRMenu ParentMenu { get; protected set; }

protected bool IsNeedUpdate;

public VRMenu()
Expand All @@ -296,6 +295,16 @@ public VRMenu()
ToggleState = new bool[0];
}

public VRMenu GetParent(Controller controller)
{
return parentMenu[(int)controller];
}

protected void SetParent(Controller controller, VRMenu parent)
{
parentMenu[(int)controller] = parent;
}

public void Reset()
{
IsNeedUpdate = true;
Expand Down Expand Up @@ -409,7 +418,7 @@ public void SetMenu(VRMenu parentMenu, int buttonIndex)
// 親メニューから選択されたとき
public void OnButtonClicked(VRMenu menu, Controller controllerId)
{
ParentMenu = menu;
SetParent(controllerId, menu);

var controller = VRMenuPlugin.Instance.Controllers[(int)controllerId];
if (IsSystemMenu(controller))
Expand All @@ -426,25 +435,31 @@ public void OnButtonClicked(VRMenu menu, Controller controllerId)
private bool IsSystemMenu(VRMenuController controller)
{
VRMenu menu = this;
while(menu.ParentMenu != null)
while(true)
{
menu = menu.ParentMenu;
var parent = menu.GetParent(controller.ControllerId);
if(parent == null)
{
break;
}
menu = parent;
}
return menu == controller.Mode.SystemMenuTop;
}

public void BackMenu(VRMenuController controller)
{
if(ParentMenu != null)
var parent = GetParent(controller.ControllerId);
if (parent != null)
{
if (IsSystemMenu(controller))
{
controller.Menu.SetSystemMenu(ParentMenu);
controller.Menu.SetSystemMenu(parent);
}
else
{
controller.Menu.SetUserMenuVisiblity(this, false);
controller.Menu.SetUserMenuVisiblity(ParentMenu, true);
controller.Menu.SetUserMenuVisiblity(parent, true);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions CM3D2.VRMenu.Plugin/VRMenuController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,6 @@ private void Start()
guiQuad.transform.position = head.TransformPoint(new Vector3(0, 0, 0.3f));
guiQuad.transform.rotation = Quaternion.LookRotation(head.forward);

guiQuad.Visible = true;

//printCollisionMatrix();
}
else
Expand Down Expand Up @@ -676,6 +674,8 @@ public void ResetGUIPosition()
guiQuad.transform.position = transform.TransformPoint(new Vector3(0, 0, 0.2f));
// 60度上を向かせる
guiQuad.transform.rotation = Quaternion.LookRotation(transform.forward) * Quaternion.Euler(60,0,0);
// 非表示になっていたら表示する
guiQuad.Visible = true;
}
}

Expand Down
Loading

0 comments on commit e36cb65

Please sign in to comment.