Skip to content

Commit 6b98855

Browse files
committed
Added some more scripts
Added Camera Facing Billboard Added Vr Emulate Controller
1 parent a33fd94 commit 6b98855

32 files changed

Lines changed: 430 additions & 17 deletions
126 KB
Binary file not shown.
126 KB
Binary file not shown.
126 KB
Binary file not shown.

Testie/Assets/Visual.unity

65.4 KB
Binary file not shown.

Testie/Assets/Visual.unity.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Testie/Assets/seyahdoo/controlls/MouseLookSimple.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
1-
using System.Collections;
2-
using System.Collections.Generic;
1+
///Author: seyahdoo(Seyyid Ahmed Doğan)
2+
///github: github.com/seyahdoo
3+
///email : contact@seyahdoo.com
4+
///
5+
///see my other reusable unity codes at
6+
///https://github.com/seyahdoo/Unity-Code-Repo
7+
8+
///Changelog:
9+
///XX.XX.XXXX -> Created by seyahdoo
10+
11+
///usage:
12+
///Attach to any camera
13+
14+
///Dependancies:
15+
///None
16+
317
using UnityEngine;
418

519
namespace seyahdoo.controlls
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
///Author: seyahdoo(Seyyid Ahmed Doğan)
2+
///github: github.com/seyahdoo
3+
///email : contact@seyahdoo.com
4+
///
5+
///see my other reusable unity codes at
6+
///https://github.com/seyahdoo/Unity-Code-Repo
7+
8+
///Changelog:
9+
///XX.XX.XXXX -> Copied from internet
10+
///30.07.2017 -> Edited to emulate Vr Camera Controller
11+
12+
///usage:
13+
///Attach to any camera
14+
15+
///Dependancies:
16+
///None
17+
18+
using UnityEngine;
19+
20+
namespace seyahdoo.controlls
21+
{
22+
23+
public class VrEmulateController : MonoBehaviour
24+
{
25+
26+
Transform cam;
27+
28+
void Awake()
29+
{
30+
cam = Camera.main.transform;
31+
Input.gyro.enabled = true;
32+
//oldRot = Input.gyro.attitude;
33+
}
34+
35+
//Quaternion oldRot;
36+
//
37+
//void Update()
38+
//{
39+
//
40+
// Quaternion rot = Input.gyro.attitude;
41+
// //rot.Rotate(0f, 0f, 180f, Space.Self); // Swap "handedness" of quaternion from gyro.
42+
// //rot.Rotate(90f, 180f, 0f, Space.World); // Rotate to make sense as a camera pointing out the back of your device.
43+
//
44+
//
45+
//
46+
// Vector3 mov = Input.gyro.attitude.eulerAngles - oldRot.eulerAngles;
47+
// cam.eulerAngles += mov;
48+
//
49+
//
50+
//
51+
// oldRot = Input.gyro.attitude;
52+
//}
53+
54+
private float initialYAngle = 0f;
55+
private float appliedGyroYAngle = 0f;
56+
public float calibrationYAngle = 0f;
57+
58+
void Start()
59+
{
60+
initialYAngle = cam.eulerAngles.y;
61+
}
62+
63+
void Update()
64+
{
65+
ApplyGyroRotation();
66+
ApplyCalibration();
67+
}
68+
69+
70+
public void CalibrateYAngle()
71+
{
72+
calibrationYAngle = appliedGyroYAngle - initialYAngle; // Offsets the y angle in case it wasn't 0 at edit time.
73+
}
74+
75+
void ApplyGyroRotation()
76+
{
77+
cam.rotation = Input.gyro.attitude;
78+
cam.Rotate(0f, 0f, 180f, Space.Self); // Swap "handedness" of quaternion from gyro.
79+
cam.Rotate(90f, 180f, 0f, Space.World); // Rotate to make sense as a camera pointing out the back of your device.
80+
appliedGyroYAngle = cam.eulerAngles.y; // Save the angle around y axis for use in calibration.
81+
}
82+
83+
void ApplyCalibration()
84+
{
85+
cam.Rotate(0f, -calibrationYAngle, 0f, Space.World); // Rotates y angle back however much it deviated when calibrationYAngle was saved.
86+
}
87+
88+
89+
}
90+
91+
}

Testie/Assets/seyahdoo/controlls/VrEmulateController.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Testie/Assets/seyahdoo/crosshair/Crosshair.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ public static void SetupCrosshair(Camera camera)
5151
Debug.LogError(typeof(Crosshair).Name + " -> SetupCrosshair(Camera) -> camera cant be null");
5252
else
5353
SetupCrosshair(camera.gameObject);
54-
54+
5555
}
56-
56+
5757
/// <summary>
5858
/// Call this if you are not sure crosshair is not setted up
5959
/// </summary>
@@ -96,10 +96,10 @@ void Update()
9696
RaycastHit hit;
9797

9898
//if i found something
99-
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit,float.MaxValue,layerMask))
99+
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, float.MaxValue, layerMask))
100100
{
101101
//did i found a new thing?
102-
if(_lastCollider != hit.collider)
102+
if (_lastCollider != hit.collider)
103103
{
104104
//i should focus to that
105105
focusToCollider(hit.collider);
@@ -108,7 +108,12 @@ void Update()
108108
else
109109
{
110110
//im not hitting anything, i should focus to nothing
111-
focusToCollider(null);
111+
//unless im already focused to nothing
112+
if (_lastCollider != null)
113+
{
114+
focusToCollider(null);
115+
}
116+
112117
}
113118
}
114119

@@ -122,14 +127,14 @@ void focusToCollider(Collider collider)
122127
if (_target)
123128
{
124129
///Dont bug me about its being obsolete! i maid it!
125-
#pragma warning disable 612, 618
130+
#pragma warning disable 612, 618
126131
_target.setFocus(false);
127-
#pragma warning restore 612, 618
132+
#pragma warning restore 612, 618
128133

129134
_target = null;
130135
}
131136

132-
//im not hitting anything
137+
//if im not hitting anything, will be null
133138
_lastCollider = collider;
134139

135140
//if im not looking to nothingness
@@ -142,9 +147,9 @@ void focusToCollider(Collider collider)
142147
if (_target)
143148
{
144149
///Dont bug me about its being obsolete! i maid it!
145-
#pragma warning disable 612, 618
150+
#pragma warning disable 612, 618
146151
_target.setFocus(true);
147-
#pragma warning restore 612, 618
152+
#pragma warning restore 612, 618
148153
}
149154
}
150155

Testie/Assets/seyahdoo/crosshair/Target.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ virtual protected void Update()
136136
}
137137
else
138138
{
139-
justnotfocused = false;
139+
justnotfocused = true;
140140
}
141141

142142
}

0 commit comments

Comments
 (0)