first commit
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 459d76155d5c0d94ea6ece7fac829714
|
||||
folderAsset: yes
|
||||
timeCreated: 1505221813
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,56 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="Bezier.cs" company="Exit Games GmbH">
|
||||
// Part of: Photon Unity Networking Demos
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Original: http://catlikecoding.com/unity/tutorials/curves-and-splines/
|
||||
// Used in SlotRacer Demo
|
||||
// </summary>
|
||||
// <author>developer@exitgames.com</author>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace Photon.Pun.Demo.SlotRacer.Utils
|
||||
{
|
||||
public static class Bezier
|
||||
{
|
||||
public static Vector3 GetPoint(Vector3 p0, Vector3 p1, Vector3 p2, float t)
|
||||
{
|
||||
t = Mathf.Clamp01(t);
|
||||
float oneMinusT = 1f - t;
|
||||
return
|
||||
oneMinusT * oneMinusT * p0 +
|
||||
2f * oneMinusT * t * p1 +
|
||||
t * t * p2;
|
||||
}
|
||||
|
||||
public static Vector3 GetFirstDerivative(Vector3 p0, Vector3 p1, Vector3 p2, float t)
|
||||
{
|
||||
return
|
||||
2f * (1f - t) * (p1 - p0) +
|
||||
2f * t * (p2 - p1);
|
||||
}
|
||||
|
||||
public static Vector3 GetPoint(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t)
|
||||
{
|
||||
t = Mathf.Clamp01(t);
|
||||
float OneMinusT = 1f - t;
|
||||
return
|
||||
OneMinusT * OneMinusT * OneMinusT * p0 +
|
||||
3f * OneMinusT * OneMinusT * t * p1 +
|
||||
3f * OneMinusT * t * t * p2 +
|
||||
t * t * t * p3;
|
||||
}
|
||||
|
||||
public static Vector3 GetFirstDerivative(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t)
|
||||
{
|
||||
t = Mathf.Clamp01(t);
|
||||
float oneMinusT = 1f - t;
|
||||
return
|
||||
3f * oneMinusT * oneMinusT * (p1 - p0) +
|
||||
6f * oneMinusT * t * (p2 - p1) +
|
||||
3f * t * t * (p3 - p2);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b14b8c3e9cc04a13898e1e50c9f1024
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,19 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="BezierControlPointMode.cs" company="Exit Games GmbH">
|
||||
// Part of: Photon Unity Networking Demos
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Original: http://catlikecoding.com/unity/tutorials/curves-and-splines/
|
||||
// Used in SlotRacer Demo
|
||||
// </summary>
|
||||
// <author>developer@exitgames.com</author>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
namespace Photon.Pun.Demo.SlotRacer.Utils
|
||||
{
|
||||
public enum BezierControlPointMode {
|
||||
Free,
|
||||
Aligned,
|
||||
Mirrored
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c78ec24cea4e478bb35a5ce401fa7a6
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,45 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="BezierCurve.cs" company="Exit Games GmbH">
|
||||
// Part of: Photon Unity Networking Demos
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Original: http://catlikecoding.com/unity/tutorials/curves-and-splines/
|
||||
// Used in SlotRacer Demo
|
||||
// </summary>
|
||||
// <author>developer@exitgames.com</author>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace Photon.Pun.Demo.SlotRacer.Utils
|
||||
{
|
||||
public class BezierCurve : MonoBehaviour
|
||||
{
|
||||
public Vector3[] points;
|
||||
|
||||
public Vector3 GetPoint (float t)
|
||||
{
|
||||
return transform.TransformPoint(Bezier.GetPoint(points[0], points[1], points[2], points[3], t));
|
||||
}
|
||||
|
||||
public Vector3 GetVelocity (float t)
|
||||
{
|
||||
return transform.TransformPoint(Bezier.GetFirstDerivative(points[0], points[1], points[2], points[3], t)) - transform.position;
|
||||
}
|
||||
|
||||
public Vector3 GetDirection (float t)
|
||||
{
|
||||
return GetVelocity(t).normalized;
|
||||
}
|
||||
|
||||
public void Reset ()
|
||||
{
|
||||
points = new Vector3[] {
|
||||
new Vector3(1f, 0f, 0f),
|
||||
new Vector3(2f, 0f, 0f),
|
||||
new Vector3(3f, 0f, 0f),
|
||||
new Vector3(4f, 0f, 0f)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b7b6b4e22427e4efbb847bd026324e59
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,332 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="Bezier.cs" company="Exit Games GmbH">
|
||||
// Part of: Photon Unity Networking Demos
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Original: http://catlikecoding.com/unity/tutorials/curves-and-splines/
|
||||
// Used in SlotRacer Demo
|
||||
// </summary>
|
||||
// <author>developer@exitgames.com</author>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
using System;
|
||||
|
||||
namespace Photon.Pun.Demo.SlotRacer.Utils
|
||||
{
|
||||
public class BezierSpline : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Vector3[] points;
|
||||
|
||||
[SerializeField]
|
||||
private float[] lengths;
|
||||
|
||||
[SerializeField]
|
||||
private float[] lengthsTime;
|
||||
|
||||
public float TotalLength;
|
||||
|
||||
[SerializeField]
|
||||
private BezierControlPointMode[] modes;
|
||||
|
||||
[SerializeField]
|
||||
private bool loop;
|
||||
|
||||
public bool Loop
|
||||
{
|
||||
get {
|
||||
return loop;
|
||||
}
|
||||
set {
|
||||
loop = value;
|
||||
if (value == true) {
|
||||
modes[modes.Length - 1] = modes[0];
|
||||
SetControlPoint(0, points[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int ControlPointCount
|
||||
{
|
||||
get {
|
||||
return points.Length;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Awake()
|
||||
{
|
||||
this.ComputeLengths();
|
||||
|
||||
}
|
||||
public Vector3 GetControlPoint(int index)
|
||||
{
|
||||
return points[index];
|
||||
}
|
||||
|
||||
public void SetControlPoint(int index, Vector3 point)
|
||||
{
|
||||
if (index % 3 == 0)
|
||||
{
|
||||
Vector3 delta = point - points[index];
|
||||
if (loop)
|
||||
{
|
||||
if (index == 0)
|
||||
{
|
||||
points[1] += delta;
|
||||
points[points.Length - 2] += delta;
|
||||
points[points.Length - 1] = point;
|
||||
}
|
||||
else if (index == points.Length - 1)
|
||||
{
|
||||
points[0] = point;
|
||||
points[1] += delta;
|
||||
points[index - 1] += delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
points[index - 1] += delta;
|
||||
points[index + 1] += delta;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (index > 0)
|
||||
{
|
||||
points[index - 1] += delta;
|
||||
}
|
||||
if (index + 1 < points.Length)
|
||||
{
|
||||
points[index + 1] += delta;
|
||||
}
|
||||
}
|
||||
}
|
||||
points[index] = point;
|
||||
EnforceMode(index);
|
||||
}
|
||||
|
||||
public BezierControlPointMode GetControlPointMode(int index)
|
||||
{
|
||||
return modes[(index + 1) / 3];
|
||||
}
|
||||
|
||||
public void SetControlPointMode(int index, BezierControlPointMode mode)
|
||||
{
|
||||
int modeIndex = (index + 1) / 3;
|
||||
modes[modeIndex] = mode;
|
||||
if (loop)
|
||||
{
|
||||
if (modeIndex == 0) {
|
||||
modes[modes.Length - 1] = mode;
|
||||
}
|
||||
else if (modeIndex == modes.Length - 1) {
|
||||
modes[0] = mode;
|
||||
}
|
||||
}
|
||||
EnforceMode(index);
|
||||
}
|
||||
|
||||
private void EnforceMode(int index)
|
||||
{
|
||||
int modeIndex = (index + 1) / 3;
|
||||
BezierControlPointMode mode = modes[modeIndex];
|
||||
if (mode == BezierControlPointMode.Free || !loop && (modeIndex == 0 || modeIndex == modes.Length - 1))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int middleIndex = modeIndex * 3;
|
||||
int fixedIndex, enforcedIndex;
|
||||
if (index <= middleIndex)
|
||||
{
|
||||
fixedIndex = middleIndex - 1;
|
||||
if (fixedIndex < 0)
|
||||
{
|
||||
fixedIndex = points.Length - 2;
|
||||
}
|
||||
enforcedIndex = middleIndex + 1;
|
||||
if (enforcedIndex >= points.Length)
|
||||
{
|
||||
enforcedIndex = 1;
|
||||
}
|
||||
}else
|
||||
{
|
||||
fixedIndex = middleIndex + 1;
|
||||
if (fixedIndex >= points.Length)
|
||||
{
|
||||
fixedIndex = 1;
|
||||
}
|
||||
enforcedIndex = middleIndex - 1;
|
||||
if (enforcedIndex < 0)
|
||||
{
|
||||
enforcedIndex = points.Length - 2;
|
||||
}
|
||||
}
|
||||
|
||||
Vector3 middle = points[middleIndex];
|
||||
Vector3 enforcedTangent = middle - points[fixedIndex];
|
||||
if (mode == BezierControlPointMode.Aligned)
|
||||
{
|
||||
enforcedTangent = enforcedTangent.normalized * Vector3.Distance(middle, points[enforcedIndex]);
|
||||
}
|
||||
points[enforcedIndex] = middle + enforcedTangent;
|
||||
}
|
||||
|
||||
public int CurveCount
|
||||
{
|
||||
get {
|
||||
return (points.Length - 1) / 3;
|
||||
}
|
||||
}
|
||||
|
||||
public Vector3 GetPoint(float t)
|
||||
{
|
||||
int i;
|
||||
if (t >= 1f)
|
||||
{
|
||||
t = 1f;
|
||||
i = points.Length - 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
t = Mathf.Clamp01(t) * CurveCount;
|
||||
i = (int)t;
|
||||
t -= i;
|
||||
i *= 3;
|
||||
}
|
||||
return transform.TransformPoint(Bezier.GetPoint(points[i], points[i + 1], points[i + 2], points[i + 3], t));
|
||||
}
|
||||
|
||||
public Vector3 GetVelocity(float t)
|
||||
{
|
||||
int i;
|
||||
if (t >= 1f)
|
||||
{
|
||||
t = 1f;
|
||||
i = points.Length - 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
t = Mathf.Clamp01(t) * CurveCount;
|
||||
i = (int)t;
|
||||
t -= i;
|
||||
i *= 3;
|
||||
}
|
||||
return transform.TransformPoint(Bezier.GetFirstDerivative(points[i], points[i + 1], points[i + 2], points[i + 3], t)) - transform.position;
|
||||
}
|
||||
|
||||
public Vector3 GetDirection(float t)
|
||||
{
|
||||
return GetVelocity(t).normalized;
|
||||
}
|
||||
|
||||
public void AddCurve ()
|
||||
{
|
||||
Vector3 point = points[points.Length - 1];
|
||||
Array.Resize(ref points, points.Length + 3);
|
||||
point.x += 1f;
|
||||
points[points.Length - 3] = point;
|
||||
point.x += 1f;
|
||||
points[points.Length - 2] = point;
|
||||
point.x += 1f;
|
||||
points[points.Length - 1] = point;
|
||||
|
||||
Array.Resize(ref modes, modes.Length + 1);
|
||||
modes[modes.Length - 1] = modes[modes.Length - 2];
|
||||
EnforceMode(points.Length - 4);
|
||||
|
||||
if (loop)
|
||||
{
|
||||
points[points.Length - 1] = points[0];
|
||||
modes[modes.Length - 1] = modes[0];
|
||||
EnforceMode(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
points = new Vector3[] {
|
||||
new Vector3(1f, 0f, 0f),
|
||||
new Vector3(2f, 0f, 0f),
|
||||
new Vector3(3f, 0f, 0f),
|
||||
new Vector3(4f, 0f, 0f)
|
||||
};
|
||||
modes = new BezierControlPointMode[] {
|
||||
BezierControlPointMode.Free,
|
||||
BezierControlPointMode.Free
|
||||
};
|
||||
}
|
||||
|
||||
public void ComputeLengths()
|
||||
{
|
||||
int subDivisions = 100;
|
||||
|
||||
int totalSamples = points.Length * subDivisions;
|
||||
|
||||
// lets create lengths for each control point.
|
||||
this.lengths = new float[totalSamples];
|
||||
this.lengthsTime = new float[totalSamples];
|
||||
|
||||
float totalDistance = 0;
|
||||
float CurrentTime = 0f;
|
||||
|
||||
Vector3 pos;
|
||||
Vector3 lastPos = this.GetPoint (0f);
|
||||
// go from the first, to the second to last
|
||||
for (var i = 0; i < totalSamples - 1; i++)
|
||||
{
|
||||
CurrentTime = (1f * i) / totalSamples;
|
||||
pos = this.GetPoint (CurrentTime);
|
||||
|
||||
float _delta = (pos - lastPos).magnitude;
|
||||
|
||||
totalDistance += _delta ;
|
||||
this.lengths [i] = totalDistance;
|
||||
|
||||
this.lengthsTime [i] = CurrentTime;
|
||||
lastPos = pos;
|
||||
}
|
||||
|
||||
this.TotalLength = totalDistance;
|
||||
|
||||
}
|
||||
|
||||
public Vector3 GetPositionAtDistance(float distance,bool reverse = false)
|
||||
{
|
||||
if (reverse)
|
||||
{
|
||||
distance = this.TotalLength - distance;
|
||||
}
|
||||
|
||||
distance = Mathf.Repeat (distance, this.TotalLength);
|
||||
|
||||
// make sure that we are within the total distance of the points
|
||||
if(distance <= 0) return points[0];
|
||||
if(distance >= this.TotalLength) return points[points.Length - 1];
|
||||
|
||||
// lets find the first point that is below the distance
|
||||
// but, who's next point is above the distance
|
||||
var index = 0;
|
||||
while (index < lengths.Length -1 && lengths[index] < distance)
|
||||
index++;
|
||||
|
||||
// Debug.Log("Index ="+index);
|
||||
|
||||
// get the percentage of travel from the current length to the next
|
||||
// where the distance is.
|
||||
//var deltaAmount = Mathf.InverseLerp(lengths[index-1], lengths[index], distance);
|
||||
|
||||
float deltaDistanceRatio = (distance-lengths[index-1])/(lengths [index] - lengths [index - 1]) ;
|
||||
|
||||
float deltaTime = (lengthsTime [index] - lengthsTime [index - 1]) * deltaDistanceRatio;
|
||||
//float splineDistance = (lengths [index - 1] + (lengths [index] - lengths [index - 1]) * amount) / this.TotalLength;
|
||||
|
||||
|
||||
return GetPoint(this.lengthsTime[index]+deltaTime);
|
||||
// we use that, to get the actual point
|
||||
// return Vector3.Lerp(points[index-1], points[index], amount);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b154883273c2845f39445c8015d81639
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d748ea8848c248e449a5ca71e00d9bce
|
||||
folderAsset: yes
|
||||
timeCreated: 1504880005
|
||||
licenseType: Store
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,73 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="Bezier.cs" company="Exit Games GmbH">
|
||||
// Part of: Photon Unity Networking Demos
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Original: http://catlikecoding.com/unity/tutorials/curves-and-splines/
|
||||
// Used in SlotRacer Demo
|
||||
// </summary>
|
||||
// <author>developer@exitgames.com</author>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Photon.Pun.Demo.SlotRacer.Utils
|
||||
{
|
||||
[CustomEditor(typeof(BezierCurve))]
|
||||
public class BezierCurveInspector : Editor
|
||||
{
|
||||
private const int lineSteps = 10;
|
||||
private const float directionScale = 0.5f;
|
||||
|
||||
private BezierCurve curve;
|
||||
private Transform handleTransform;
|
||||
private Quaternion handleRotation;
|
||||
|
||||
private void OnSceneGUI()
|
||||
{
|
||||
curve = target as BezierCurve;
|
||||
handleTransform = curve.transform;
|
||||
handleRotation = Tools.pivotRotation == PivotRotation.Local ?
|
||||
handleTransform.rotation : Quaternion.identity;
|
||||
|
||||
Vector3 p0 = ShowPoint(0);
|
||||
Vector3 p1 = ShowPoint(1);
|
||||
Vector3 p2 = ShowPoint(2);
|
||||
Vector3 p3 = ShowPoint(3);
|
||||
|
||||
Handles.color = Color.gray;
|
||||
Handles.DrawLine(p0, p1);
|
||||
Handles.DrawLine(p2, p3);
|
||||
|
||||
ShowDirections();
|
||||
Handles.DrawBezier(p0, p3, p1, p2, Color.white, null, 2f);
|
||||
}
|
||||
|
||||
private void ShowDirections()
|
||||
{
|
||||
Handles.color = Color.green;
|
||||
Vector3 point = curve.GetPoint(0f);
|
||||
Handles.DrawLine(point, point + curve.GetDirection(0f) * directionScale);
|
||||
for (int i = 1; i <= lineSteps; i++)
|
||||
{
|
||||
point = curve.GetPoint(i / (float)lineSteps);
|
||||
Handles.DrawLine(point, point + curve.GetDirection(i / (float)lineSteps) * directionScale);
|
||||
}
|
||||
}
|
||||
|
||||
private Vector3 ShowPoint(int index)
|
||||
{
|
||||
Vector3 point = handleTransform.TransformPoint(curve.points[index]);
|
||||
EditorGUI.BeginChangeCheck();
|
||||
point = Handles.DoPositionHandle(point, handleRotation);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(curve, "Move Point");
|
||||
EditorUtility.SetDirty(curve);
|
||||
curve.points[index] = handleTransform.InverseTransformPoint(point);
|
||||
}
|
||||
return point;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 28cd1cdefdaf24d6cb98f0cb87845b3a
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,154 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="BezierSplineInspector.cs" company="Exit Games GmbH">
|
||||
// Part of: Photon Unity Networking Demos
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Original: http://catlikecoding.com/unity/tutorials/curves-and-splines/
|
||||
// Used in SlotRacer Demo
|
||||
// </summary>
|
||||
// <author>developer@exitgames.com</author>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Photon.Pun.Demo.SlotRacer.Utils
|
||||
{
|
||||
[CustomEditor(typeof(BezierSpline))]
|
||||
public class BezierSplineInspector : Editor
|
||||
{
|
||||
private const int stepsPerCurve = 10;
|
||||
private const float directionScale = 0.5f;
|
||||
private const float handleSize = 0.04f;
|
||||
private const float pickSize = 0.06f;
|
||||
|
||||
private static Color[] modeColors = {
|
||||
Color.white,
|
||||
Color.yellow,
|
||||
Color.cyan
|
||||
};
|
||||
|
||||
private BezierSpline spline;
|
||||
private Transform handleTransform;
|
||||
private Quaternion handleRotation;
|
||||
private int selectedIndex = -1;
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
spline = target as BezierSpline;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
bool loop = EditorGUILayout.Toggle("Loop", spline.Loop);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(spline, "Toggle Loop");
|
||||
EditorUtility.SetDirty(spline);
|
||||
spline.Loop = loop;
|
||||
}
|
||||
|
||||
if (selectedIndex >= 0 && selectedIndex < spline.ControlPointCount)
|
||||
{
|
||||
DrawSelectedPointInspector();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Add Curve"))
|
||||
{
|
||||
Undo.RecordObject(spline, "Add Curve");
|
||||
spline.AddCurve();
|
||||
EditorUtility.SetDirty(spline);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawSelectedPointInspector()
|
||||
{
|
||||
GUILayout.Label("Selected Point");
|
||||
EditorGUI.BeginChangeCheck();
|
||||
Vector3 point = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(selectedIndex));
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(spline, "Move Point");
|
||||
EditorUtility.SetDirty(spline);
|
||||
spline.SetControlPoint(selectedIndex, point);
|
||||
}
|
||||
EditorGUI.BeginChangeCheck();
|
||||
BezierControlPointMode mode = (BezierControlPointMode)EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(selectedIndex));
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(spline, "Change Point Mode");
|
||||
spline.SetControlPointMode(selectedIndex, mode);
|
||||
EditorUtility.SetDirty(spline);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnSceneGUI()
|
||||
{
|
||||
spline = target as BezierSpline;
|
||||
handleTransform = spline.transform;
|
||||
handleRotation = Tools.pivotRotation == PivotRotation.Local ?
|
||||
handleTransform.rotation : Quaternion.identity;
|
||||
|
||||
Vector3 p0 = ShowPoint(0);
|
||||
for (int i = 1; i < spline.ControlPointCount; i += 3)
|
||||
{
|
||||
Vector3 p1 = ShowPoint(i);
|
||||
Vector3 p2 = ShowPoint(i + 1);
|
||||
Vector3 p3 = ShowPoint(i + 2);
|
||||
|
||||
Handles.color = Color.gray;
|
||||
Handles.DrawLine(p0, p1);
|
||||
Handles.DrawLine(p2, p3);
|
||||
|
||||
Handles.DrawBezier(p0, p3, p1, p2, Color.white, null, 2f);
|
||||
p0 = p3;
|
||||
}
|
||||
ShowDirections();
|
||||
}
|
||||
|
||||
private void ShowDirections()
|
||||
{
|
||||
Handles.color = Color.green;
|
||||
Vector3 point = spline.GetPoint(0f);
|
||||
Handles.DrawLine(point, point + spline.GetDirection(0f) * directionScale);
|
||||
int steps = stepsPerCurve * spline.CurveCount;
|
||||
for (int i = 1; i <= steps; i++)
|
||||
{
|
||||
point = spline.GetPoint(i / (float)steps);
|
||||
Handles.DrawLine(point, point + spline.GetDirection(i / (float)steps) * directionScale);
|
||||
}
|
||||
}
|
||||
|
||||
private Vector3 ShowPoint(int index)
|
||||
{
|
||||
Vector3 point = handleTransform.TransformPoint(spline.GetControlPoint(index));
|
||||
float size = HandleUtility.GetHandleSize(point);
|
||||
if (index == 0)
|
||||
{
|
||||
size *= 2f;
|
||||
}
|
||||
Handles.color = modeColors[(int)spline.GetControlPointMode(index)];
|
||||
|
||||
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
if (Handles.Button(point, handleRotation, size * handleSize, size * pickSize, Handles.DotHandleCap))
|
||||
#else
|
||||
if (Handles.Button(point, handleRotation, size * handleSize, size * pickSize, Handles.DotCap))
|
||||
#endif
|
||||
{
|
||||
selectedIndex = index;
|
||||
Repaint();
|
||||
}
|
||||
|
||||
if (selectedIndex == index)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
point = Handles.DoPositionHandle(point, handleRotation);
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Undo.RecordObject(spline, "Move Point");
|
||||
EditorUtility.SetDirty(spline);
|
||||
spline.SetControlPoint(index, handleTransform.InverseTransformPoint(point));
|
||||
}
|
||||
}
|
||||
return point;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 127eddf8173c549d9976751e82f3face
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,47 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="LineInspector.cs" company="Exit Games GmbH">
|
||||
// Part of: Photon Unity Networking Demos
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Original: http://catlikecoding.com/unity/tutorials/curves-and-splines/
|
||||
// Used in SlotRacer Demo
|
||||
// </summary>
|
||||
// <author>developer@exitgames.com</author>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Photon.Pun.Demo.SlotRacer.Utils
|
||||
{
|
||||
[CustomEditor(typeof(Line))]
|
||||
public class LineInspector : Editor
|
||||
{
|
||||
|
||||
private void OnSceneGUI()
|
||||
{
|
||||
Line line = target as Line;
|
||||
Transform handleTransform = line.transform;
|
||||
Quaternion handleRotation = Tools.pivotRotation == PivotRotation.Local ? handleTransform.rotation : Quaternion.identity;
|
||||
Vector3 p0 = handleTransform.TransformPoint(line.p0);
|
||||
Vector3 p1 = handleTransform.TransformPoint(line.p1);
|
||||
|
||||
Handles.color = Color.white;
|
||||
Handles.DrawLine(p0, p1);
|
||||
EditorGUI.BeginChangeCheck();
|
||||
p0 = Handles.DoPositionHandle(p0, handleRotation);
|
||||
if (EditorGUI.EndChangeCheck()) {
|
||||
Undo.RecordObject(line, "Move Point");
|
||||
EditorUtility.SetDirty(line);
|
||||
line.p0 = handleTransform.InverseTransformPoint(p0);
|
||||
}
|
||||
EditorGUI.BeginChangeCheck();
|
||||
p1 = Handles.DoPositionHandle(p1, handleRotation);
|
||||
if (EditorGUI.EndChangeCheck()) {
|
||||
Undo.RecordObject(line, "Move Point");
|
||||
EditorUtility.SetDirty(line);
|
||||
line.p1 = handleTransform.InverseTransformPoint(p1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 668731f6cd4a54b7cbeaea95414d6cec
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "PunDemos.DemoSlotcarEditor",
|
||||
"references": [
|
||||
"PhotonUnityNetworking.Demos"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": []
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66eabdb1ed6f5d041a6906290472e432
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,19 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="Line.cs" company="Exit Games GmbH">
|
||||
// Part of: Photon Unity Networking Demos
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Original: http://catlikecoding.com/unity/tutorials/curves-and-splines/
|
||||
// Used in SlotRacer Demo
|
||||
// </summary>
|
||||
// <author>developer@exitgames.com</author>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace Photon.Pun.Demo.SlotRacer.Utils
|
||||
{
|
||||
public class Line : MonoBehaviour {
|
||||
public Vector3 p0, p1;
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3886e96ecea4f4f0eb98bb0c41a31fbe
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,57 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="SplinePosition.cs" company="Exit Games GmbH">
|
||||
// Part of: Photon Unity Networking Demos
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Original: http://catlikecoding.com/unity/tutorials/curves-and-splines/
|
||||
// Used in SlotRacer Demo
|
||||
// </summary>
|
||||
// <author>developer@exitgames.com</author>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace Photon.Pun.Demo.SlotRacer.Utils
|
||||
{
|
||||
[ExecuteInEditMode]
|
||||
public class SplinePosition : MonoBehaviour {
|
||||
|
||||
public BezierSpline Spline;
|
||||
public bool reverse;
|
||||
public bool lookForward;
|
||||
public float currentDistance = 0f;
|
||||
|
||||
public float currentClampedDistance;
|
||||
|
||||
float LastDistance;
|
||||
|
||||
public void SetPositionOnSpline(float position)
|
||||
{
|
||||
this.currentDistance = position;
|
||||
ExecutePositioning ();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
ExecutePositioning ();
|
||||
}
|
||||
|
||||
void ExecutePositioning()
|
||||
{
|
||||
if(this.Spline==null || this.LastDistance == this.currentDistance )
|
||||
{
|
||||
return;
|
||||
}
|
||||
LastDistance = this.currentDistance;
|
||||
|
||||
// move the transform to the new point
|
||||
this.transform.position = this.Spline.GetPositionAtDistance(currentDistance,this.reverse);
|
||||
|
||||
if (this.lookForward) {
|
||||
this.transform.LookAt(this.Spline.GetPositionAtDistance(currentDistance+1,this.reverse));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 92fca85ea3a014374a5c052f9cc2326b
|
||||
timeCreated: 1505310635
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,64 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="SplineWalker.cs" company="Exit Games GmbH">
|
||||
// Part of: Photon Unity Networking Demos
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Original: http://catlikecoding.com/unity/tutorials/curves-and-splines/
|
||||
// Used in SlotRacer Demo
|
||||
// </summary>
|
||||
// <author>developer@exitgames.com</author>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace Photon.Pun.Demo.SlotRacer.Utils
|
||||
{
|
||||
[ExecuteInEditMode]
|
||||
public class SplineWalker : MonoBehaviour {
|
||||
|
||||
public BezierSpline spline;
|
||||
|
||||
public float Speed = 0f;
|
||||
|
||||
public bool lookForward;
|
||||
|
||||
public bool reverse;
|
||||
|
||||
private float progress;
|
||||
|
||||
public float currentDistance =0f;
|
||||
|
||||
public float currentClampedDistance;
|
||||
|
||||
public void SetPositionOnSpline(float position)
|
||||
{
|
||||
currentDistance = position;
|
||||
ExecutePositioning ();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// update the distance used.
|
||||
currentDistance += Speed * Time.deltaTime;
|
||||
ExecutePositioning ();
|
||||
}
|
||||
|
||||
public void ExecutePositioning()
|
||||
{
|
||||
if(spline==null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// move the transform to the new point
|
||||
transform.position = spline.GetPositionAtDistance(currentDistance,this.reverse);
|
||||
|
||||
// update the distance used.
|
||||
currentDistance += Speed * Time.deltaTime;
|
||||
|
||||
|
||||
if (lookForward) {
|
||||
transform.LookAt(spline.GetPositionAtDistance(currentDistance+1,this.reverse));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 541a76f9c03874323b5154b14ac00427
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,232 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="PlayerControl.cs" company="Exit Games GmbH">
|
||||
// Part of: Photon Unity Networking Demos
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Used in SlotRacer Demo
|
||||
// </summary>
|
||||
// <author>developer@exitgames.com</author>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
using System.Collections;
|
||||
|
||||
using Photon.Pun.Demo.SlotRacer.Utils;
|
||||
using Photon.Pun.UtilityScripts;
|
||||
|
||||
namespace Photon.Pun.Demo.SlotRacer
|
||||
{
|
||||
/// <summary>
|
||||
/// Player control.
|
||||
/// Interface the User Inputs and PUN
|
||||
/// Handle the Car instance
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(SplineWalker))]
|
||||
public class PlayerControl : MonoBehaviourPun, IPunObservable
|
||||
{
|
||||
/// <summary>
|
||||
/// The car prefabs to pick depending on the grid position.
|
||||
/// </summary>
|
||||
public GameObject[] CarPrefabs;
|
||||
|
||||
/// <summary>
|
||||
/// The maximum speed. Maximum speed is reached with a 1 unit per seconds acceleration
|
||||
/// </summary>
|
||||
public float MaximumSpeed = 20;
|
||||
|
||||
/// <summary>
|
||||
/// The drag when user is not accelerating
|
||||
/// </summary>
|
||||
public float Drag = 5;
|
||||
|
||||
/// <summary>
|
||||
/// The current speed.
|
||||
/// Only used for locaPlayer
|
||||
/// </summary>
|
||||
private float CurrentSpeed;
|
||||
|
||||
/// <summary>
|
||||
/// The current distance on the spline
|
||||
/// Only used for locaPlayer
|
||||
/// </summary>
|
||||
private float CurrentDistance;
|
||||
|
||||
/// <summary>
|
||||
/// The car instance.
|
||||
/// </summary>
|
||||
private GameObject CarInstance;
|
||||
|
||||
/// <summary>
|
||||
/// The spline walker. Must be on this GameObject
|
||||
/// </summary>
|
||||
private SplineWalker SplineWalker;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// flag to force latest data to avoid initial drifts when player is instantiated.
|
||||
/// </summary>
|
||||
private bool m_firstTake = true;
|
||||
|
||||
|
||||
private float m_input;
|
||||
|
||||
|
||||
#region IPunObservable implementation
|
||||
|
||||
/// <summary>
|
||||
/// this is where data is sent and received for this Component from the PUN Network.
|
||||
/// </summary>
|
||||
/// <param name="stream">Stream.</param>
|
||||
/// <param name="info">Info.</param>
|
||||
void IPunObservable.OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
|
||||
{
|
||||
// currently there is no strategy to improve on bandwidth, just passing the current distance and speed is enough,
|
||||
// Input could be passed and then used to better control speed value
|
||||
// Data could be wrapped as a vector2 or vector3 to save a couple of bytes
|
||||
if (stream.IsWriting)
|
||||
{
|
||||
stream.SendNext(this.CurrentDistance);
|
||||
stream.SendNext(this.CurrentSpeed);
|
||||
stream.SendNext(this.m_input);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.m_firstTake)
|
||||
{
|
||||
this.m_firstTake = false;
|
||||
}
|
||||
|
||||
this.CurrentDistance = (float) stream.ReceiveNext();
|
||||
this.CurrentSpeed = (float) stream.ReceiveNext();
|
||||
this.m_input = (float) stream.ReceiveNext();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion IPunObservable implementation
|
||||
|
||||
|
||||
#region private
|
||||
|
||||
/// <summary>
|
||||
/// Setups the car on track.
|
||||
/// </summary>
|
||||
/// <param name="gridStartIndex">Grid start index.</param>
|
||||
private void SetupCarOnTrack(int gridStartIndex)
|
||||
{
|
||||
// Setup the SplineWalker to be on the right starting grid position.
|
||||
this.SplineWalker.spline = SlotLanes.Instance.GridPositions[gridStartIndex].Spline;
|
||||
this.SplineWalker.currentDistance = SlotLanes.Instance.GridPositions[gridStartIndex].currentDistance;
|
||||
this.SplineWalker.ExecutePositioning();
|
||||
|
||||
// create a new car
|
||||
this.CarInstance = (GameObject) Instantiate(this.CarPrefabs[gridStartIndex], this.transform.position, this.transform.rotation);
|
||||
|
||||
// We'll wait for the first serializatin to pass, else we'll have a glitch where the car is positioned at the wrong position.
|
||||
if (!this.photonView.IsMine)
|
||||
{
|
||||
this.CarInstance.SetActive(false);
|
||||
}
|
||||
|
||||
// depending on wether we control this instance locally, we force the car to become active ( because when you are alone in the room, serialization doesn't happen, but still we want to allow the user to race around)
|
||||
if (PhotonNetwork.CurrentRoom.PlayerCount == 1)
|
||||
{
|
||||
this.m_firstTake = false;
|
||||
}
|
||||
|
||||
this.CarInstance.transform.SetParent(this.transform);
|
||||
}
|
||||
|
||||
#endregion private
|
||||
|
||||
|
||||
#region Monobehaviour
|
||||
|
||||
/// <summary>
|
||||
/// Cache the SplineWalker and flag context for clean serialization when joining late.
|
||||
/// </summary>
|
||||
private void Awake()
|
||||
{
|
||||
this.SplineWalker = this.GetComponent<SplineWalker>();
|
||||
this.m_firstTake = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start this instance as a coroutine
|
||||
/// Waits for a Playernumber to be assigned and only then setup the car and put it on the right starting position on the lane.
|
||||
/// </summary>
|
||||
private IEnumerator Start()
|
||||
{
|
||||
// Wait until a Player Number is assigned
|
||||
// PlayerNumbering component must be in the scene.
|
||||
yield return new WaitUntil(() => this.photonView.Owner.GetPlayerNumber() >= 0);
|
||||
|
||||
// now we can set it up.
|
||||
this.SetupCarOnTrack(this.photonView.Owner.GetPlayerNumber());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make sure we delete instances linked to this component, else when user is leaving the room, its car instance would remain
|
||||
/// </summary>
|
||||
private void OnDestroy()
|
||||
{
|
||||
Destroy(this.CarInstance);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
if (this.SplineWalker == null || this.CarInstance == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.photonView.IsMine)
|
||||
{
|
||||
this.m_input = Input.GetAxis("Vertical");
|
||||
if (this.m_input == 0f)
|
||||
{
|
||||
this.CurrentSpeed -= Time.deltaTime * this.Drag;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.CurrentSpeed += this.m_input;
|
||||
}
|
||||
this.CurrentSpeed = Mathf.Clamp(this.CurrentSpeed, 0f, this.MaximumSpeed);
|
||||
this.SplineWalker.Speed = this.CurrentSpeed;
|
||||
|
||||
this.CurrentDistance = this.SplineWalker.currentDistance;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.m_input == 0f)
|
||||
{
|
||||
this.CurrentSpeed -= Time.deltaTime * this.Drag;
|
||||
}
|
||||
|
||||
this.CurrentSpeed = Mathf.Clamp (this.CurrentSpeed, 0f, this.MaximumSpeed);
|
||||
this.SplineWalker.Speed = this.CurrentSpeed;
|
||||
|
||||
|
||||
|
||||
if (this.CurrentDistance != 0 && this.SplineWalker.currentDistance != this.CurrentDistance)
|
||||
{
|
||||
//Debug.Log ("SplineWalker.currentDistance=" + SplineWalker.currentDistance + " CurrentDistance=" + CurrentDistance);
|
||||
this.SplineWalker.Speed += (this.CurrentDistance - this.SplineWalker.currentDistance) * Time.deltaTime * 50f;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Only activate the car if we are sure we have the proper positioning, else it will glitch visually during the initialisation process.
|
||||
if (!this.m_firstTake && !this.CarInstance.activeSelf)
|
||||
{
|
||||
this.CarInstance.SetActive(true);
|
||||
this.SplineWalker.Speed = this.CurrentSpeed;
|
||||
this.SplineWalker.SetPositionOnSpline (this.CurrentDistance);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Monobehaviour
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4fde14656bc40455ba65844c093b79a3
|
||||
timeCreated: 1505220041
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,38 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="SlotLanes.cs" company="Exit Games GmbH">
|
||||
// Part of: Photon Unity Networking Demos
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Used in SlotRacer Demo
|
||||
// </summary>
|
||||
// <author>developer@exitgames.com</author>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
using Photon.Pun.Demo.SlotRacer.Utils;
|
||||
|
||||
namespace Photon.Pun.Demo.SlotRacer
|
||||
{
|
||||
/// <summary>
|
||||
/// Define Slot lanes and grid positions placeholders.
|
||||
/// This is a convenient approach to visually define the lanes and their grid positions without any complicated editors and setup framework.
|
||||
/// </summary>
|
||||
public class SlotLanes : MonoBehaviour {
|
||||
|
||||
/// <summary>
|
||||
/// Instance Pointer to access GridPositions
|
||||
/// </summary>
|
||||
public static SlotLanes Instance;
|
||||
|
||||
/// <summary>
|
||||
/// The grid positions.
|
||||
/// </summary>
|
||||
public SplinePosition[] GridPositions;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 54c0aa0c215c64226bdfacbeed74edbb
|
||||
timeCreated: 1505307723
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,96 @@
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
// <copyright file="SlotRacerSpashScreen.cs" company="Exit Games GmbH">
|
||||
// Part of: Photon Unity Networking Demos
|
||||
// </copyright>
|
||||
// <summary>
|
||||
// Used in SlotRacer Demo
|
||||
// </summary>
|
||||
// <author>developer@exitgames.com</author>
|
||||
// --------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
|
||||
namespace Photon.Pun.Demo.SlotRacer
|
||||
{
|
||||
/// <summary>
|
||||
/// Slot racer splash screen. Inform about the slotRacer demo and the Cockpit control setup
|
||||
/// Gets deleted as soon as the scene plays
|
||||
/// </summary>
|
||||
[ExecuteInEditMode]
|
||||
public class SlotRacerSplashScreen : MonoBehaviour
|
||||
{
|
||||
#pragma warning disable 0414
|
||||
private string PunCockpit_scene = "PunCockpit-Scene";
|
||||
#pragma warning restore 0414
|
||||
|
||||
public Text WarningText;
|
||||
public GameObject SplashScreen;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
Destroy(this.SplashScreen);
|
||||
Destroy(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
if (this.WarningText == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
bool _found = false;
|
||||
bool _enabled = false;
|
||||
|
||||
foreach (EditorBuildSettingsScene _scene in EditorBuildSettings.scenes)
|
||||
{
|
||||
if (_scene.path.EndsWith(this.PunCockpit_scene + ".unity"))
|
||||
{
|
||||
_found = true;
|
||||
_enabled = _scene.enabled;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (_found && _enabled)
|
||||
{
|
||||
this.WarningText.text = string.Empty;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_found && !_enabled)
|
||||
{
|
||||
this.WarningText.text = "<Color=Green>INFORMATION:</Color>\nThis demo can run with the PunCockpit Scene." +
|
||||
"\nFor this, the Scene '" +
|
||||
this.PunCockpit_scene +
|
||||
"' needs to be enabled to the build settings." +
|
||||
"\nElse, you'll get only a minimal Menu to connect";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_found)
|
||||
{
|
||||
this.WarningText.text = "<Color=Green>INFORMATION:</Color>\nThis demo can run with the PunCockpit Scene." +
|
||||
"\n For this, the Scene '" +
|
||||
this.PunCockpit_scene +
|
||||
"' needs to be added to the build settings." +
|
||||
"\nElse, you'll get only a minimal Menu to connect";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fda2ec3ef73274d5886232a03b450769
|
||||
timeCreated: 1524830295
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user