Skip to content

Commit

Permalink
Fixed browser parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Vito217 committed Oct 22, 2020
1 parent 91b2f60 commit d4df5c8
Show file tree
Hide file tree
Showing 25 changed files with 443 additions and 202 deletions.
2 changes: 1 addition & 1 deletion Assets/Resources/Prefabs/3.0/Players/HTCVivePlayer.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Transform:
m_GameObject: {fileID: 8569552642144684878}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: -0.05, z: 0.01}
m_LocalScale: {x: 0.0325, y: 0.0325, z: 0.0325}
m_LocalScale: {x: 0.03, y: 0.03, z: 0.03}
m_Children: []
m_Father: {fileID: 7141709304274196013}
m_RootOrder: 0
Expand Down
8 changes: 7 additions & 1 deletion Assets/Resources/Prefabs/3.0/UI/Keyboards.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,13 @@ PrefabInstance:
propertyPath: m_Name
value: Punchkeyboard
objectReference: {fileID: 0}
m_RemovedComponents: []
- target: {fileID: 108504188608708260, guid: d85aeebb7d9d19b46b11a1e3a7635f5c,
type: 3}
propertyPath: AlterateKeyCapChar
value: =
objectReference: {fileID: 0}
m_RemovedComponents:
- {fileID: 108504188608708413, guid: d85aeebb7d9d19b46b11a1e3a7635f5c, type: 3}
m_SourcePrefab: {fileID: 100100000, guid: d85aeebb7d9d19b46b11a1e3a7635f5c, type: 3}
--- !u!4 &1301352057777476581 stripped
Transform:
Expand Down
354 changes: 197 additions & 157 deletions Assets/Scripts/Keyboard/Key.cs
Original file line number Diff line number Diff line change
@@ -1,158 +1,198 @@
using System.Collections;
using UnityEngine;
using UnityEngine.UI;

public class Key : MonoBehaviour
{
public delegate void OnKeyPressed();
public static OnKeyPressed keyPressed;
public string KeyCapChar;
public string AlterateKeyCapChar;
public Rigidbody Rigidbody;
public bool KeyPressed = false;
public Color PressedKeycapColor;
public Color KeycapColor;
public Color InitialKeycapColor;

protected Transform initialPosition;
private KeycodeAdder keycodeAdder;
private Text keyCapText;
private Vector3 initialLocalPosition;
private Quaternion initialLocalRotation;
private Vector3 constrainedPosition;
private Quaternion constrainedRotation;
private bool uppercaseSwitch = true;
private bool symbolSwitch = false;
private bool checkForButton = true;
private const float DistanceToBePressed = 0.01f;
private const float KeyBounceBackMultiplier = 1500f;
private KeySoundController keySoundController;
private float currentDistance = -1;

void Start()
{
keycodeAdder = this.gameObject.GetComponent<KeycodeAdder> ();

keyCapText = this.gameObject.GetComponentInChildren<Text> ();
KeycapColor = this.gameObject.GetComponent<Renderer> ().material.color;
InitialKeycapColor = KeycapColor;

initialPosition = new GameObject(string.Format("[{0}] initialPosition", this.gameObject.name)).transform;
initialPosition.parent = this.transform.parent;
initialPosition.localPosition = Vector3.zero;
initialPosition.localRotation = Quaternion.identity;

if(Rigidbody == null)
{
Rigidbody = GetComponent<Rigidbody>();
}

initialLocalPosition = this.transform.localPosition;
initialLocalRotation = this.transform.localRotation;

constrainedPosition = initialLocalPosition;
constrainedRotation = initialLocalRotation;

keySoundController = transform.parent.parent.parent.parent.parent
.gameObject.GetComponent<KeySoundController> ();

SwitchKeycapCharCase ();
}

void FixedUpdate()
{
ConstrainPosition ();
currentDistance = Vector3.Distance(this.transform.position, initialPosition.position);

Vector3 PositionDelta = initialPosition.position - this.transform.position;
this.Rigidbody.velocity = PositionDelta * KeyBounceBackMultiplier * Time.deltaTime;
}

void Update()
{
if (checkForButton)
{
if (currentDistance > DistanceToBePressed)
{
KeyPressed = true;
keyPressed ();
if (symbolSwitch)
{
keycodeAdder.SimulateAlternateKeyPress ();
}
else
{
keycodeAdder.SimulateKeyPress ();
}
keySoundController.StartKeySound (this.gameObject.transform);
checkForButton = false;
}
} else if (!checkForButton)
{
if (currentDistance < DistanceToBePressed)
{
KeyPressed = false;
checkForButton = true;
}
}

ChangeKeyColorOnPress ();
}

void LateUpdate()
{
ConstrainPosition ();
}

void ChangeKeyColorOnPress()
{
if (KeyPressed)
{
gameObject.GetComponent<Renderer> ().material.color = PressedKeycapColor;
}
else
{
gameObject.GetComponent<Renderer> ().material.color = KeycapColor;
}
}

void ConstrainPosition()
{
constrainedPosition.y = this.transform.localPosition.y;
if (this.transform.localPosition.y > initialLocalPosition.y)
{
constrainedPosition.y = initialLocalPosition.y;
}
this.transform.localPosition = constrainedPosition;
this.transform.localRotation = constrainedRotation;
}

public void SwitchKeycapCharCase()
{
if (uppercaseSwitch)
{
keyCapText.text = KeyCapChar.ToLower ();
uppercaseSwitch = false;
}
else
{
keyCapText.text = KeyCapChar.ToUpper ();
uppercaseSwitch = true;
}
}

public void SwitchToSymbols()
{
if (!symbolSwitch)
{
keyCapText.text = AlterateKeyCapChar;
symbolSwitch = true;
}
else
{
keyCapText.text = KeyCapChar;
keyCapText.text = KeyCapChar.ToLower ();
symbolSwitch = false;
}
}
using System;
using System.Collections;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using UnityEngine;
using UnityEngine.UI;
using WindowsInput;

public class Key : MonoBehaviour
{
public delegate void OnKeyPressed();
public static OnKeyPressed keyPressed;
public string KeyCapChar;
public string AlterateKeyCapChar;
public Rigidbody Rigidbody;
public bool KeyPressed = false;
public Color PressedKeycapColor;
public Color KeycapColor;
public Color InitialKeycapColor;

protected Transform initialPosition;
private KeycodeAdder keycodeAdder;
private Text keyCapText;
private Vector3 initialLocalPosition;
private Quaternion initialLocalRotation;
private Vector3 constrainedPosition;
private Quaternion constrainedRotation;
private bool uppercaseSwitch = true;
private bool symbolSwitch = false;
private bool checkForButton = true;
private const float DistanceToBePressed = 0.01f;
private const float KeyBounceBackMultiplier = 1500f;
private KeySoundController keySoundController;
private float currentDistance = -1;

void Start()
{
keycodeAdder = this.gameObject.GetComponent<KeycodeAdder> ();

keyCapText = this.gameObject.GetComponentInChildren<Text> ();
KeycapColor = this.gameObject.GetComponent<Renderer> ().material.color;
InitialKeycapColor = KeycapColor;

initialPosition = new GameObject(string.Format("[{0}] initialPosition", this.gameObject.name)).transform;
initialPosition.parent = this.transform.parent;
initialPosition.localPosition = Vector3.zero;
initialPosition.localRotation = Quaternion.identity;

if(Rigidbody == null)
{
Rigidbody = GetComponent<Rigidbody>();
}

initialLocalPosition = this.transform.localPosition;
initialLocalRotation = this.transform.localRotation;

constrainedPosition = initialLocalPosition;
constrainedRotation = initialLocalRotation;

keySoundController = transform.root.Find("Keyboards/Punchkeyboard")
.gameObject.GetComponent<KeySoundController> ();

SwitchKeycapCharCase ();
}

void FixedUpdate()
{
ConstrainPosition ();
currentDistance = Vector3.Distance(this.transform.position, initialPosition.position);

Vector3 PositionDelta = initialPosition.position - this.transform.position;
this.Rigidbody.velocity = PositionDelta * KeyBounceBackMultiplier * Time.deltaTime;
}

void Update()
{
if (checkForButton)
{
if (currentDistance > DistanceToBePressed)
{
KeyPressed = true;
keyPressed ();
if (symbolSwitch)
{
if (name.Contains("Space") ||
name.Contains("Backspace") ||
name.Contains("Return") ||
name.Contains("Shift") ||
name.Contains("Symbol"))

keycodeAdder.SimulateAlternateKeyPress();

else

WriteStringToTarget();
}
else
{
if (name.Contains("Space") ||
name.Contains("Backspace") ||
name.Contains("Return") ||
name.Contains("Shift") ||
name.Contains("Symbol"))

keycodeAdder.SimulateKeyPress();

else

WriteStringToTarget();

}
keySoundController.StartKeySound (this.gameObject.transform);
checkForButton = false;
}
} else if (!checkForButton)
{
if (currentDistance < DistanceToBePressed)
{
KeyPressed = false;
checkForButton = true;
}
}

ChangeKeyColorOnPress ();
}

void LateUpdate()
{
ConstrainPosition ();
}

void ChangeKeyColorOnPress()
{
if (KeyPressed)
{
gameObject.GetComponent<Renderer> ().material.color = PressedKeycapColor;
}
else
{
gameObject.GetComponent<Renderer> ().material.color = KeycapColor;
}
}

void ConstrainPosition()
{
constrainedPosition.y = this.transform.localPosition.y;
if (this.transform.localPosition.y > initialLocalPosition.y)
{
constrainedPosition.y = initialLocalPosition.y;
}
this.transform.localPosition = constrainedPosition;
this.transform.localRotation = constrainedRotation;
}

public void SwitchKeycapCharCase()
{
if (uppercaseSwitch)
{
keyCapText.text = KeyCapChar.ToLower ();
uppercaseSwitch = false;
}
else
{
keyCapText.text = KeyCapChar.ToUpper ();
uppercaseSwitch = true;
}
}

public void SwitchToSymbols()
{
if (!symbolSwitch)
{
keyCapText.text = AlterateKeyCapChar;
symbolSwitch = true;
}
else
{
keyCapText.text = KeyCapChar;
keyCapText.text = KeyCapChar.ToLower ();
symbolSwitch = false;
}
}

private void WriteStringToTarget()
{
InitializeBehaviour window =
transform.root.gameObject.GetComponent<InitializeBehaviour>();
if (!window.loadingWheel.activeSelf)
{
int lcp = window.lastCaretPosition;
window.keyboardTarget.ActivateInputField();
window.keyboardTarget.text =
window.keyboardTarget.text.Insert(lcp, keyCapText.text);
window.keyboardTarget.caretPosition = lcp + 1;
}
}
}
Loading

0 comments on commit d4df5c8

Please sign in to comment.