Merge branch 'master' of github.com:teamfisk/VstyleR
This commit is contained in:
@@ -552,4 +552,45 @@ public class BezierCurve : MonoBehaviour {
|
|||||||
distance -= totalLength;
|
distance -= totalLength;
|
||||||
return GetPoint(firstPoint, secondPoint, distance / curveLength);
|
return GetPoint(firstPoint, secondPoint, distance / curveLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vector3 GetUniformPointAtDistance(float distance) {
|
||||||
|
|
||||||
|
if (distance <= 0) {
|
||||||
|
return points[0].position;
|
||||||
|
} else if (distance >= length) {
|
||||||
|
return points[points.Length - 1].position;
|
||||||
|
}
|
||||||
|
|
||||||
|
float segmentLength = length / 2;
|
||||||
|
|
||||||
|
float totalLength = 0;
|
||||||
|
for (int i = 0; i < points.Length - 1; i++) {
|
||||||
|
var p1 = points[i];
|
||||||
|
var p2 = points[i + 1];
|
||||||
|
|
||||||
|
if (p1 == null) {
|
||||||
|
p1 = points[points.Length - 1];
|
||||||
|
p2 = points[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
var curveLength = ApproximateLength(p1, p2, resolution);
|
||||||
|
if (totalLength + curveLength < distance) {
|
||||||
|
totalLength += curveLength;
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
var curveDistance = distance - totalLength;
|
||||||
|
var segmentIndex = (float)Math.Floor(curveDistance / segmentLength);
|
||||||
|
var segmentStart = segmentIndex * segmentLength;
|
||||||
|
var segmentEnd = (segmentIndex + 1) * segmentLength;
|
||||||
|
var segmentDistance = curveDistance - segmentStart;
|
||||||
|
|
||||||
|
Vector3 s1 = GetPoint(p1, p2, segmentStart / curveLength);
|
||||||
|
Vector3 s2 = GetPoint(p1, p2, segmentEnd / curveLength);
|
||||||
|
|
||||||
|
return GetLinearPoint(s1, s2, segmentDistance / segmentLength);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Vector3.zero;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -5,7 +5,25 @@ public class RightController : MonoBehaviour {
|
|||||||
public GameObject banana;
|
public GameObject banana;
|
||||||
public GameObject viveController;
|
public GameObject viveController;
|
||||||
|
|
||||||
// Use this for initialization
|
SteamVR_TrackedController trackedController;
|
||||||
|
WarehouseColumn warehouse;
|
||||||
|
|
||||||
|
WarehouseRow whRow = null;
|
||||||
|
Vector3? whScrollStartPos = null;
|
||||||
|
float whScrollDistance;
|
||||||
|
float whBaseOffset = 0.0f;
|
||||||
|
float whScrollOffset = 0.0f;
|
||||||
|
float whRowBaseOffset = 0.0f;
|
||||||
|
float whRowScrollOffset = 0.0f;
|
||||||
|
|
||||||
|
void Awake() {
|
||||||
|
trackedController = GetComponent<SteamVR_TrackedController>();
|
||||||
|
trackedController.TriggerClicked += triggerClicked;
|
||||||
|
trackedController.TriggerUnclicked += triggerUnclicked;
|
||||||
|
|
||||||
|
warehouse = GameObject.Find("Warehouse/Shelves/Column").GetComponent<WarehouseColumn>();
|
||||||
|
}
|
||||||
|
|
||||||
void Start () {
|
void Start () {
|
||||||
GetComponent<ViewFrustrumTrigger>().LeaveView += toggleBanana;
|
GetComponent<ViewFrustrumTrigger>().LeaveView += toggleBanana;
|
||||||
}
|
}
|
||||||
@@ -15,7 +33,51 @@ public class RightController : MonoBehaviour {
|
|||||||
viveController.SetActive(!viveController.activeSelf);
|
viveController.SetActive(!viveController.activeSelf);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
|
||||||
void Update () {
|
void Update () {
|
||||||
|
|
||||||
|
// Warehouse scroll
|
||||||
|
if (whScrollStartPos != null) {
|
||||||
|
Vector3 curPos = transform.position + (transform.forward * whScrollDistance);
|
||||||
|
|
||||||
|
whScrollOffset = (curPos - whScrollStartPos).Value.y;
|
||||||
|
whRowScrollOffset = (curPos - whScrollStartPos).Value.x;
|
||||||
|
|
||||||
|
warehouse.Offset = whBaseOffset + (-whScrollOffset);
|
||||||
|
whRow.Offset = whRowBaseOffset + whRowScrollOffset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
RaycastHit raycast() {
|
||||||
|
var ray = new Ray(transform.position, transform.forward);
|
||||||
|
RaycastHit hit;
|
||||||
|
bool bHit = Physics.Raycast(ray, out hit);
|
||||||
|
return hit;
|
||||||
|
}
|
||||||
|
|
||||||
|
void triggerClicked(object sender, ClickedEventArgs e) {
|
||||||
|
var ray = new Ray(transform.position, transform.forward);
|
||||||
|
RaycastHit result;
|
||||||
|
bool hit = Physics.Raycast(ray, out result);
|
||||||
|
|
||||||
|
if (!hit) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var item = result.transform.GetComponent<WarehouseItem>();
|
||||||
|
if (!item) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
whScrollStartPos = result.point;
|
||||||
|
whScrollDistance = result.distance;
|
||||||
|
whRow = item.GetComponentInParent<WarehouseRow>();
|
||||||
|
whBaseOffset = warehouse.Offset;
|
||||||
|
whRowBaseOffset = whRow.Offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
void triggerUnclicked(object sender, ClickedEventArgs e) {
|
||||||
|
if (whScrollStartPos != null) {
|
||||||
|
whScrollStartPos = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -8,7 +8,7 @@ public class WarehouseColumn : MonoBehaviour {
|
|||||||
private BezierCurve curve;
|
private BezierCurve curve;
|
||||||
private Transform rows;
|
private Transform rows;
|
||||||
|
|
||||||
private float offset = 0.0f;
|
public float Offset { get; set; }
|
||||||
|
|
||||||
void Awake() {
|
void Awake() {
|
||||||
curve = transform.Find("Curve").GetComponent<BezierCurve>();
|
curve = transform.Find("Curve").GetComponent<BezierCurve>();
|
||||||
@@ -21,12 +21,12 @@ public class WarehouseColumn : MonoBehaviour {
|
|||||||
|
|
||||||
void Update() {
|
void Update() {
|
||||||
if (Application.isPlaying) {
|
if (Application.isPlaying) {
|
||||||
offset += Time.deltaTime;
|
//offset += Time.deltaTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Transform row in rows) {
|
foreach (Transform row in rows) {
|
||||||
var i = row.GetSiblingIndex();
|
var i = row.GetSiblingIndex();
|
||||||
var distance = (float)i / (rows.childCount) * curve.length + offset;
|
var distance = (float)i / (rows.childCount) * curve.length + Offset;
|
||||||
distance = Mathf.Repeat(distance, curve.length);
|
distance = Mathf.Repeat(distance, curve.length);
|
||||||
var pos = curve.GetPointAtDistance(distance);
|
var pos = curve.GetPointAtDistance(distance);
|
||||||
row.position = pos;
|
row.position = pos;
|
||||||
|
|||||||
Executable
+15
@@ -0,0 +1,15 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
public class WarehouseItem : MonoBehaviour {
|
||||||
|
|
||||||
|
// Use this for initialization
|
||||||
|
void Start () {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update () {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable
+12
@@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 126df0f3c4fc8434386b7cb4484e88fb
|
||||||
|
timeCreated: 1464039271
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -7,11 +7,11 @@ using UnityEditor;
|
|||||||
public class WarehouseRow : MonoBehaviour {
|
public class WarehouseRow : MonoBehaviour {
|
||||||
public string Category;
|
public string Category;
|
||||||
|
|
||||||
|
public float Offset { get; set; }
|
||||||
|
|
||||||
BezierCurve curve;
|
BezierCurve curve;
|
||||||
Transform furniture;
|
Transform furniture;
|
||||||
|
|
||||||
float offset = 0;
|
|
||||||
|
|
||||||
void Awake() {
|
void Awake() {
|
||||||
curve = transform.Find("Curve").GetComponent<BezierCurve>();
|
curve = transform.Find("Curve").GetComponent<BezierCurve>();
|
||||||
furniture = transform.Find("Furniture");
|
furniture = transform.Find("Furniture");
|
||||||
@@ -43,7 +43,7 @@ public class WarehouseRow : MonoBehaviour {
|
|||||||
|
|
||||||
foreach (Transform t in furniture) {
|
foreach (Transform t in furniture) {
|
||||||
var i = t.GetSiblingIndex();
|
var i = t.GetSiblingIndex();
|
||||||
var distance = (float)i / (furniture.childCount) * curve.length + offset;
|
var distance = (float)i / (furniture.childCount) * curve.length + Offset;
|
||||||
distance = Mathf.Repeat(distance, curve.length);
|
distance = Mathf.Repeat(distance, curve.length);
|
||||||
var pos = curve.GetPointAtDistance(distance);
|
var pos = curve.GetPointAtDistance(distance);
|
||||||
t.position = pos;
|
t.position = pos;
|
||||||
|
|||||||
Reference in New Issue
Block a user