feat: polish VR gameplay and sync tools
This commit is contained in:
@@ -39,6 +39,11 @@ namespace VRBeats
|
||||
|
||||
if (Cut(info.hitPoint, cutDir, insideMaterial))
|
||||
{
|
||||
Color trailColor = beatCube != null
|
||||
? VR_BeatManager.instance.GetColorFromColorSide(beatCube.ThisColorSide)
|
||||
: Color.white;
|
||||
Vector3 saberUp = beatDamageInfo.hitObject != null ? beatDamageInfo.hitObject.transform.up : cutDir;
|
||||
SliceTrailEffect.Spawn(info.hitPoint, info.hitDir, saberUp, trailColor);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,450 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace VRBeats
|
||||
{
|
||||
/// <summary>
|
||||
/// Builds a short world-space ribbon from the whole saber blade instead of
|
||||
/// attaching a TrailRenderer to the tip. This keeps the afterimage on the
|
||||
/// blade surface and avoids the "propeller" look from a single end point.
|
||||
/// </summary>
|
||||
public class SaberTrailEffect : MonoBehaviour
|
||||
{
|
||||
private const int MaxSamples = 18;
|
||||
private const float TrailLifetime = 0.13f;
|
||||
private const float MinSwingSpeed = 0.75f;
|
||||
private const float MinSampleDistance = 0.012f;
|
||||
private const float BladeBaseT = 0.10f;
|
||||
private const float BladeTipT = 0.98f;
|
||||
|
||||
private readonly List<BladeSample> samples = new List<BladeSample>(MaxSamples);
|
||||
private readonly List<Vector3> vertices = new List<Vector3>(MaxSamples * 2);
|
||||
private readonly List<Color> colors = new List<Color>(MaxSamples * 2);
|
||||
private readonly List<Vector2> uvs = new List<Vector2>(MaxSamples * 2);
|
||||
private readonly List<int> triangles = new List<int>((MaxSamples - 1) * 12);
|
||||
|
||||
private Transform bladeStart;
|
||||
private Transform bladeEnd;
|
||||
private GameObject wideObject;
|
||||
private GameObject coreObject;
|
||||
private Mesh wideMesh;
|
||||
private Mesh coreMesh;
|
||||
private MeshRenderer wideRenderer;
|
||||
private MeshRenderer coreRenderer;
|
||||
private Material wideMaterial;
|
||||
private Material coreMaterial;
|
||||
|
||||
private Color trailColor = Color.cyan;
|
||||
private bool visible = true;
|
||||
private bool hasLastFrame;
|
||||
private Vector3 lastBase;
|
||||
private Vector3 lastTip;
|
||||
|
||||
private struct BladeSample
|
||||
{
|
||||
public Vector3 basePos;
|
||||
public Vector3 tipPos;
|
||||
public float time;
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
RemoveLegacyTrailRenderers();
|
||||
ResolveBladeAnchors();
|
||||
EnsureRenderers();
|
||||
SetColor(trailColor);
|
||||
SetVisible(visible);
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (!visible)
|
||||
{
|
||||
Clear();
|
||||
hasLastFrame = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (bladeEnd == null)
|
||||
{
|
||||
ResolveBladeAnchors();
|
||||
}
|
||||
|
||||
Vector3 basePos;
|
||||
Vector3 tipPos;
|
||||
GetBladeSegment(out basePos, out tipPos);
|
||||
|
||||
float now = Time.time;
|
||||
float speed = 0f;
|
||||
float moved = 0f;
|
||||
|
||||
if (hasLastFrame)
|
||||
{
|
||||
float deltaTime = Mathf.Max(Time.deltaTime, 0.0001f);
|
||||
speed = Mathf.Max(
|
||||
Vector3.Distance(basePos, lastBase),
|
||||
Vector3.Distance(tipPos, lastTip)) / deltaTime;
|
||||
moved = Mathf.Max(
|
||||
Vector3.Distance(basePos, lastBase),
|
||||
Vector3.Distance(tipPos, lastTip));
|
||||
}
|
||||
|
||||
if (!hasLastFrame || (speed >= MinSwingSpeed && moved >= MinSampleDistance))
|
||||
{
|
||||
AddSample(basePos, tipPos, now);
|
||||
}
|
||||
|
||||
TrimExpiredSamples(now);
|
||||
BuildRibbon(wideMesh, now, 0f, 1f, trailColor, 0.10f, 0.36f);
|
||||
|
||||
Color coreColor = Color.Lerp(Color.white, trailColor, 0.45f);
|
||||
BuildRibbon(coreMesh, now, 0.42f, 1f, coreColor, 0.14f, 0.48f);
|
||||
|
||||
lastBase = basePos;
|
||||
lastTip = tipPos;
|
||||
hasLastFrame = true;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
Clear();
|
||||
hasLastFrame = false;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
DestroyRuntimeObject(wideObject);
|
||||
DestroyRuntimeObject(coreObject);
|
||||
DestroyRuntimeObject(wideMesh);
|
||||
DestroyRuntimeObject(coreMesh);
|
||||
DestroyRuntimeObject(wideMaterial);
|
||||
DestroyRuntimeObject(coreMaterial);
|
||||
}
|
||||
|
||||
public void SetVisible(bool value)
|
||||
{
|
||||
visible = value;
|
||||
|
||||
if (wideRenderer != null)
|
||||
{
|
||||
wideRenderer.enabled = value;
|
||||
}
|
||||
|
||||
if (coreRenderer != null)
|
||||
{
|
||||
coreRenderer.enabled = value;
|
||||
}
|
||||
|
||||
if (!value)
|
||||
{
|
||||
Clear();
|
||||
hasLastFrame = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetColor(Color color)
|
||||
{
|
||||
trailColor = NormalizeColor(color);
|
||||
EnsureRenderers();
|
||||
ApplyMaterialColor(wideMaterial, trailColor, 0.34f);
|
||||
|
||||
Color coreColor = Color.Lerp(Color.white, trailColor, 0.45f);
|
||||
ApplyMaterialColor(coreMaterial, coreColor, 0.50f);
|
||||
}
|
||||
|
||||
private void ResolveBladeAnchors()
|
||||
{
|
||||
bladeStart = FindChildRecursive(transform, "Start");
|
||||
bladeEnd = FindChildRecursive(transform, "End");
|
||||
|
||||
if (bladeEnd == null)
|
||||
{
|
||||
bladeEnd = transform;
|
||||
}
|
||||
|
||||
if (bladeStart == null)
|
||||
{
|
||||
bladeStart = transform;
|
||||
}
|
||||
}
|
||||
|
||||
private void GetBladeSegment(out Vector3 basePos, out Vector3 tipPos)
|
||||
{
|
||||
Vector3 start = bladeStart != null ? bladeStart.position : transform.position;
|
||||
Vector3 end = bladeEnd != null ? bladeEnd.position : transform.position + transform.forward;
|
||||
|
||||
if (Vector3.Distance(start, end) < 0.001f)
|
||||
{
|
||||
end = start + transform.forward * 0.8f;
|
||||
}
|
||||
|
||||
basePos = Vector3.Lerp(start, end, BladeBaseT);
|
||||
tipPos = Vector3.Lerp(start, end, BladeTipT);
|
||||
}
|
||||
|
||||
private void AddSample(Vector3 basePos, Vector3 tipPos, float time)
|
||||
{
|
||||
if (samples.Count >= MaxSamples)
|
||||
{
|
||||
samples.RemoveAt(0);
|
||||
}
|
||||
|
||||
samples.Add(new BladeSample
|
||||
{
|
||||
basePos = basePos,
|
||||
tipPos = tipPos,
|
||||
time = time
|
||||
});
|
||||
}
|
||||
|
||||
private void TrimExpiredSamples(float now)
|
||||
{
|
||||
for (int i = samples.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (now - samples[i].time > TrailLifetime)
|
||||
{
|
||||
samples.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildRibbon(Mesh mesh, float now, float innerT, float outerT, Color color, float innerAlpha, float outerAlpha)
|
||||
{
|
||||
if (mesh == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vertices.Clear();
|
||||
colors.Clear();
|
||||
uvs.Clear();
|
||||
triangles.Clear();
|
||||
|
||||
if (samples.Count < 2)
|
||||
{
|
||||
mesh.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < samples.Count; i++)
|
||||
{
|
||||
BladeSample sample = samples[i];
|
||||
float age01 = Mathf.Clamp01((now - sample.time) / TrailLifetime);
|
||||
float fade = Mathf.Pow(1f - age01, 1.7f);
|
||||
float along = samples.Count <= 1 ? 0f : i / (float)(samples.Count - 1);
|
||||
|
||||
Vector3 inner = Vector3.Lerp(sample.basePos, sample.tipPos, innerT);
|
||||
Vector3 outer = Vector3.Lerp(sample.basePos, sample.tipPos, outerT);
|
||||
|
||||
vertices.Add(inner);
|
||||
vertices.Add(outer);
|
||||
colors.Add(WithAlpha(color, fade * innerAlpha));
|
||||
colors.Add(WithAlpha(color, fade * outerAlpha));
|
||||
uvs.Add(new Vector2(0f, along));
|
||||
uvs.Add(new Vector2(1f, along));
|
||||
}
|
||||
|
||||
for (int i = 0; i < samples.Count - 1; i++)
|
||||
{
|
||||
int a = i * 2;
|
||||
int b = a + 1;
|
||||
int c = a + 2;
|
||||
int d = a + 3;
|
||||
|
||||
triangles.Add(a);
|
||||
triangles.Add(b);
|
||||
triangles.Add(c);
|
||||
triangles.Add(b);
|
||||
triangles.Add(d);
|
||||
triangles.Add(c);
|
||||
|
||||
triangles.Add(c);
|
||||
triangles.Add(b);
|
||||
triangles.Add(a);
|
||||
triangles.Add(c);
|
||||
triangles.Add(d);
|
||||
triangles.Add(b);
|
||||
}
|
||||
|
||||
mesh.Clear();
|
||||
mesh.SetVertices(vertices);
|
||||
mesh.SetColors(colors);
|
||||
mesh.SetUVs(0, uvs);
|
||||
mesh.SetTriangles(triangles, 0);
|
||||
mesh.RecalculateBounds();
|
||||
}
|
||||
|
||||
private void EnsureRenderers()
|
||||
{
|
||||
if (wideObject == null)
|
||||
{
|
||||
wideRenderer = CreateRibbonObject("SaberBladeAfterimage_Wide", out wideObject, out wideMesh, out wideMaterial, false);
|
||||
}
|
||||
|
||||
if (coreObject == null)
|
||||
{
|
||||
coreRenderer = CreateRibbonObject("SaberBladeAfterimage_Core", out coreObject, out coreMesh, out coreMaterial, true);
|
||||
}
|
||||
}
|
||||
|
||||
private MeshRenderer CreateRibbonObject(string objectName, out GameObject ribbonObject, out Mesh mesh, out Material material, bool additive)
|
||||
{
|
||||
ribbonObject = new GameObject(objectName);
|
||||
ribbonObject.hideFlags = HideFlags.DontSave;
|
||||
ribbonObject.transform.SetPositionAndRotation(Vector3.zero, Quaternion.identity);
|
||||
ribbonObject.transform.localScale = Vector3.one;
|
||||
|
||||
mesh = new Mesh
|
||||
{
|
||||
name = objectName + " Mesh"
|
||||
};
|
||||
mesh.MarkDynamic();
|
||||
|
||||
MeshFilter filter = ribbonObject.AddComponent<MeshFilter>();
|
||||
filter.sharedMesh = mesh;
|
||||
|
||||
MeshRenderer renderer = ribbonObject.AddComponent<MeshRenderer>();
|
||||
material = CreateTrailMaterial(objectName + " Material", additive);
|
||||
renderer.sharedMaterial = material;
|
||||
renderer.shadowCastingMode = ShadowCastingMode.Off;
|
||||
renderer.receiveShadows = false;
|
||||
renderer.motionVectorGenerationMode = MotionVectorGenerationMode.ForceNoMotion;
|
||||
renderer.enabled = visible;
|
||||
|
||||
return renderer;
|
||||
}
|
||||
|
||||
private Material CreateTrailMaterial(string materialName, bool additive)
|
||||
{
|
||||
Shader shader = Shader.Find("Sprites/Default");
|
||||
if (shader == null)
|
||||
{
|
||||
shader = Shader.Find("Unlit/Transparent");
|
||||
}
|
||||
|
||||
Material material = new Material(shader)
|
||||
{
|
||||
name = materialName,
|
||||
hideFlags = HideFlags.DontSave,
|
||||
renderQueue = (int)RenderQueue.Transparent
|
||||
};
|
||||
|
||||
if (material.HasProperty("_SrcBlend"))
|
||||
{
|
||||
material.SetInt("_SrcBlend", additive ? (int)BlendMode.SrcAlpha : (int)BlendMode.SrcAlpha);
|
||||
}
|
||||
|
||||
if (material.HasProperty("_DstBlend"))
|
||||
{
|
||||
material.SetInt("_DstBlend", additive ? (int)BlendMode.One : (int)BlendMode.OneMinusSrcAlpha);
|
||||
}
|
||||
|
||||
if (material.HasProperty("_ZWrite"))
|
||||
{
|
||||
material.SetInt("_ZWrite", 0);
|
||||
}
|
||||
|
||||
return material;
|
||||
}
|
||||
|
||||
private void ApplyMaterialColor(Material material, Color color, float alpha)
|
||||
{
|
||||
if (material == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Color materialColor = WithAlpha(color, alpha);
|
||||
if (material.HasProperty("_Color"))
|
||||
{
|
||||
material.SetColor("_Color", materialColor);
|
||||
}
|
||||
}
|
||||
|
||||
private void Clear()
|
||||
{
|
||||
samples.Clear();
|
||||
|
||||
if (wideMesh != null)
|
||||
{
|
||||
wideMesh.Clear();
|
||||
}
|
||||
|
||||
if (coreMesh != null)
|
||||
{
|
||||
coreMesh.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveLegacyTrailRenderers()
|
||||
{
|
||||
TrailRenderer[] legacyTrails = GetComponentsInChildren<TrailRenderer>(true);
|
||||
for (int i = legacyTrails.Length - 1; i >= 0; i--)
|
||||
{
|
||||
DestroyRuntimeObject(legacyTrails[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private static Transform FindChildRecursive(Transform root, string childName)
|
||||
{
|
||||
if (root == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (root.name == childName)
|
||||
{
|
||||
return root;
|
||||
}
|
||||
|
||||
for (int i = 0; i < root.childCount; i++)
|
||||
{
|
||||
Transform found = FindChildRecursive(root.GetChild(i), childName);
|
||||
if (found != null)
|
||||
{
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Color NormalizeColor(Color color)
|
||||
{
|
||||
float max = Mathf.Max(color.r, color.g, color.b);
|
||||
if (max > 1f)
|
||||
{
|
||||
color.r /= max;
|
||||
color.g /= max;
|
||||
color.b /= max;
|
||||
}
|
||||
|
||||
color.a = 1f;
|
||||
return color;
|
||||
}
|
||||
|
||||
private static Color WithAlpha(Color color, float alpha)
|
||||
{
|
||||
color.a = Mathf.Clamp01(alpha);
|
||||
return color;
|
||||
}
|
||||
|
||||
private static void DestroyRuntimeObject(Object target)
|
||||
{
|
||||
if (target == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
Destroy(target);
|
||||
}
|
||||
else
|
||||
{
|
||||
DestroyImmediate(target);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f4ab89ec5474db497559af138ed0a6f
|
||||
@@ -0,0 +1,140 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace VRBeats
|
||||
{
|
||||
public class SliceTrailEffect : MonoBehaviour
|
||||
{
|
||||
private const float Lifetime = 0.24f;
|
||||
private const int PointCount = 7;
|
||||
|
||||
private LineRenderer glowLine = null;
|
||||
private LineRenderer coreLine = null;
|
||||
private Vector3 center = Vector3.zero;
|
||||
private Vector3 tangent = Vector3.right;
|
||||
private Vector3 lift = Vector3.up;
|
||||
private Color effectColor = Color.cyan;
|
||||
|
||||
public static void Spawn(Vector3 position, Vector3 hitDir, Vector3 saberUp, Color color)
|
||||
{
|
||||
GameObject effectObject = new GameObject("SliceTrailEffect");
|
||||
SliceTrailEffect effect = effectObject.AddComponent<SliceTrailEffect>();
|
||||
effect.Construct(position, hitDir, saberUp, color);
|
||||
}
|
||||
|
||||
private void Construct(Vector3 position, Vector3 hitDir, Vector3 saberUp, Color color)
|
||||
{
|
||||
center = position;
|
||||
transform.position = position;
|
||||
effectColor = NormalizeColor(color);
|
||||
|
||||
tangent = saberUp.sqrMagnitude > 0.001f ? saberUp.normalized : Vector3.right;
|
||||
lift = hitDir.sqrMagnitude > 0.001f ? hitDir.normalized : Vector3.up;
|
||||
|
||||
glowLine = CreateLine("Glow", 0.16f, 0.45f);
|
||||
coreLine = CreateLine("Core", 0.045f, 0.95f);
|
||||
StartCoroutine(Animate());
|
||||
}
|
||||
|
||||
private LineRenderer CreateLine(string name, float width, float alpha)
|
||||
{
|
||||
GameObject lineObject = new GameObject(name);
|
||||
lineObject.transform.SetParent(transform, false);
|
||||
|
||||
LineRenderer line = lineObject.AddComponent<LineRenderer>();
|
||||
line.positionCount = PointCount;
|
||||
line.useWorldSpace = true;
|
||||
line.alignment = LineAlignment.View;
|
||||
line.textureMode = LineTextureMode.Stretch;
|
||||
line.numCornerVertices = 8;
|
||||
line.numCapVertices = 8;
|
||||
line.shadowCastingMode = ShadowCastingMode.Off;
|
||||
line.receiveShadows = false;
|
||||
line.material = CreateMaterial();
|
||||
line.widthMultiplier = width;
|
||||
ApplyGradient(line, alpha);
|
||||
return line;
|
||||
}
|
||||
|
||||
private IEnumerator Animate()
|
||||
{
|
||||
float age = 0.0f;
|
||||
while (age < Lifetime)
|
||||
{
|
||||
float t = age / Lifetime;
|
||||
float length = Mathf.Lerp(0.72f, 1.45f, t);
|
||||
float bend = Mathf.Lerp(0.12f, 0.34f, t);
|
||||
float alpha = 1.0f - t;
|
||||
|
||||
UpdateLine(glowLine, length, bend, alpha * 0.45f);
|
||||
UpdateLine(coreLine, length * 0.88f, bend * 0.55f, alpha * 0.95f);
|
||||
|
||||
age += Time.deltaTime;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
private void UpdateLine(LineRenderer line, float length, float bend, float alpha)
|
||||
{
|
||||
if (line == null)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < PointCount; i++)
|
||||
{
|
||||
float normalized = PointCount <= 1 ? 0.0f : (float)i / (PointCount - 1);
|
||||
float offset = normalized - 0.5f;
|
||||
float curve = Mathf.Sin(normalized * Mathf.PI) * bend;
|
||||
line.SetPosition(i, center + tangent * (offset * length) + lift * curve);
|
||||
}
|
||||
|
||||
ApplyGradient(line, alpha);
|
||||
}
|
||||
|
||||
private static Material CreateMaterial()
|
||||
{
|
||||
Shader shader = Shader.Find("Sprites/Default");
|
||||
if (shader == null)
|
||||
shader = Shader.Find("Unlit/Transparent");
|
||||
|
||||
Material material = new Material(shader);
|
||||
material.name = "Runtime Slice Trail";
|
||||
return material;
|
||||
}
|
||||
|
||||
private void ApplyGradient(LineRenderer line, float alpha)
|
||||
{
|
||||
Color start = new Color(effectColor.r, effectColor.g, effectColor.b, 0.0f);
|
||||
Color mid = new Color(effectColor.r, effectColor.g, effectColor.b, alpha);
|
||||
Color end = new Color(effectColor.r, effectColor.g, effectColor.b, 0.0f);
|
||||
|
||||
Gradient gradient = new Gradient();
|
||||
gradient.SetKeys(
|
||||
new[]
|
||||
{
|
||||
new GradientColorKey(start, 0.0f),
|
||||
new GradientColorKey(mid, 0.5f),
|
||||
new GradientColorKey(end, 1.0f),
|
||||
},
|
||||
new[]
|
||||
{
|
||||
new GradientAlphaKey(0.0f, 0.0f),
|
||||
new GradientAlphaKey(alpha, 0.5f),
|
||||
new GradientAlphaKey(0.0f, 1.0f),
|
||||
});
|
||||
line.colorGradient = gradient;
|
||||
}
|
||||
|
||||
private static Color NormalizeColor(Color color)
|
||||
{
|
||||
float max = Mathf.Max(color.r, Mathf.Max(color.g, color.b));
|
||||
if (max > 1.0f)
|
||||
color /= max;
|
||||
|
||||
color.a = 1.0f;
|
||||
return color;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 41e40f1c9d0c48af9e2ad90cb8c5108c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -56,10 +56,12 @@ namespace VRBeats
|
||||
//notify to whoever is listening that the player did a correct/incorrect slice
|
||||
if ( IsCutIntentValid(info as BeatDamageInfo) )
|
||||
{
|
||||
ScoreManager.ReportSliceTiming(GetTimingErrorSeconds());
|
||||
onCorrectSlice.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
ScoreManager.ReportMiss();
|
||||
onIncorrectSlice.Invoke();
|
||||
}
|
||||
|
||||
@@ -98,6 +100,7 @@ namespace VRBeats
|
||||
|
||||
public void Kill()
|
||||
{
|
||||
ScoreManager.ReportMiss();
|
||||
onPlayerMiss.Invoke();
|
||||
canBeKilled = false;
|
||||
transform.ScaleTween(Vector3.zero, 2.0f).SetEase(Ease.EaseOutExpo).SetOnComplete( delegate
|
||||
@@ -107,6 +110,13 @@ namespace VRBeats
|
||||
} );
|
||||
}
|
||||
|
||||
private float GetTimingErrorSeconds()
|
||||
{
|
||||
float speed = Mathf.Max(Mathf.Abs(thisSpawneable.Speed), 0.001f);
|
||||
float distanceFromPlayer = Mathf.Abs(transform.position.z - player.position.z);
|
||||
return distanceFromPlayer / speed;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using Platinio;
|
||||
using UnityEngine.Playables;
|
||||
using UnityEngine.SceneManagement;
|
||||
using VRBeats.ScriptableEvents;
|
||||
using VRSDK;
|
||||
|
||||
@@ -60,24 +62,22 @@ namespace VRBeats
|
||||
Vector3 finalPosition = CalculateSpawnPosition( info.position);
|
||||
Vector3 travelOffset = Vector3.forward * -settings.TargetTravelDistance;
|
||||
Vector3 spawnPosition = finalPosition - travelOffset;
|
||||
|
||||
Spawneable clone = Instantiate( spawneable , spawnPosition , Quaternion.Euler( info.rotation ) );
|
||||
SetSpeedRelativeToPlayZone(info);
|
||||
clone.Construct(info);
|
||||
|
||||
Vector3 finalScale = clone.transform.localScale;
|
||||
clone.transform.localScale = Vector3.zero;
|
||||
|
||||
float travelTime = info.travelTimeOverride > 0f ? info.travelTimeOverride : settings.TargetTravelTime;
|
||||
|
||||
clone.transform.Move(finalPosition, travelTime).SetEase(settings.TargetTravelEase).SetOnComplete(delegate
|
||||
{
|
||||
info.speed = settings.TargetTravelDistance / Mathf.Max(0.05f, travelTime);
|
||||
SetSpeedRelativeToPlayZone(info);
|
||||
|
||||
Spawneable clone = Instantiate( spawneable , spawnPosition , Quaternion.Euler( info.rotation ) );
|
||||
clone.Construct(info);
|
||||
StartCoroutine(BeginContinuousSpawnNextFrame(clone));
|
||||
}
|
||||
|
||||
private IEnumerator BeginContinuousSpawnNextFrame(Spawneable clone)
|
||||
{
|
||||
yield return null;
|
||||
|
||||
if (clone != null)
|
||||
clone.OnSpawn();
|
||||
}).SetUpdateMode(Platinio.TweenEngine.UpdateMode.Update);
|
||||
|
||||
|
||||
clone.transform.ScaleTween(finalScale, travelTime).SetEase(settings.TargetTravelEase);
|
||||
|
||||
}
|
||||
|
||||
private void SetSpeedRelativeToPlayZone(SpawnEventInfo info)
|
||||
@@ -122,13 +122,7 @@ namespace VRBeats
|
||||
|
||||
public void RestartLevel()
|
||||
{
|
||||
gameObject.CancelAllTweens();
|
||||
|
||||
isGameRunning = true;
|
||||
audioManager.SetAudioMixerPitch(1.0f);
|
||||
enviromentController.TurnLightsOn();
|
||||
playableDirector.time = 0.0f;
|
||||
playableDirector.Play();
|
||||
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,9 +39,9 @@ namespace VRBeats
|
||||
public void EnableXRRayInteractorComponents()
|
||||
{
|
||||
if (rayInteractor != null)
|
||||
rayInteractor.enabled = true;
|
||||
rayInteractor.enabled = false;
|
||||
if (interactorLineVisual != null)
|
||||
interactorLineVisual.enabled = true;
|
||||
interactorLineVisual.enabled = false;
|
||||
if (lineRender != null)
|
||||
lineRender.enabled = true;
|
||||
|
||||
|
||||
@@ -15,10 +15,14 @@ namespace VRBeats
|
||||
private VR_Grabbable grabbable = null;
|
||||
private ColorSide colorSide = ColorSide.Left;
|
||||
private MeshRenderer[] renderArray = null;
|
||||
private SaberTrailEffect trailEffect = null;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
renderArray = transform.GetComponentsInChildren<MeshRenderer>();
|
||||
trailEffect = GetComponent<SaberTrailEffect>();
|
||||
if (trailEffect == null)
|
||||
trailEffect = gameObject.AddComponent<SaberTrailEffect>();
|
||||
|
||||
grabbable = GetComponent<VR_Grabbable>();
|
||||
grabbable.OnGrabStateChange.AddListener(OnGrabStateChange);
|
||||
@@ -44,6 +48,9 @@ namespace VRBeats
|
||||
{
|
||||
SetMaterialBindings(materialBindingArray[n], c);
|
||||
}
|
||||
|
||||
if (trailEffect != null)
|
||||
trailEffect.SetColor(c);
|
||||
}
|
||||
|
||||
private void SetMaterialBindings(MaterialBindings matBindings, Color c)
|
||||
@@ -55,11 +62,15 @@ namespace VRBeats
|
||||
public void MakeVisible()
|
||||
{
|
||||
SetRenderArrayEnableValue(true);
|
||||
if (trailEffect != null)
|
||||
trailEffect.SetVisible(true);
|
||||
}
|
||||
|
||||
public void MakeInvisible()
|
||||
{
|
||||
SetRenderArrayEnableValue(false);
|
||||
if (trailEffect != null)
|
||||
trailEffect.SetVisible(false);
|
||||
}
|
||||
|
||||
private void SetRenderArrayEnableValue(bool value)
|
||||
@@ -72,4 +83,4 @@ namespace VRBeats
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,24 +13,42 @@ namespace VRBeats
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (colorSide == ColorSide.Left) controller = VR_Manager.instance.Player.LeftController;
|
||||
if (colorSide == ColorSide.Right) controller = VR_Manager.instance.Player.RightController;
|
||||
ResolveController();
|
||||
}
|
||||
|
||||
protected override DamageInfo CreateDamageInfo(Vector3 hitPoint)
|
||||
{
|
||||
ResolveController();
|
||||
|
||||
var damageInfo = base.CreateDamageInfo(hitPoint);
|
||||
BeatDamageInfo beatDamageInfo = new BeatDamageInfo(damageInfo);
|
||||
|
||||
Vector3 controllerVelocity = controller.Velocity;
|
||||
Vector3 controllerVelocity = controller != null ? controller.Velocity : Vector3.zero;
|
||||
|
||||
beatDamageInfo.hitForce = Mathf.Min((controllerVelocity * hitForce).magnitude, maxHitForce);
|
||||
beatDamageInfo.hitObject = gameObject;
|
||||
beatDamageInfo.colorSide = colorSide;
|
||||
beatDamageInfo.velocity = controller.Velocity.magnitude;
|
||||
beatDamageInfo.velocity = controllerVelocity.magnitude;
|
||||
|
||||
return beatDamageInfo;
|
||||
}
|
||||
|
||||
private void ResolveController()
|
||||
{
|
||||
VR_Grabbable grabbable = GetComponent<VR_Grabbable>();
|
||||
if (grabbable != null && grabbable.GrabController != null)
|
||||
{
|
||||
controller = grabbable.GrabController;
|
||||
colorSide = controller.ControllerType == VR_ControllerType.Right ? ColorSide.Right : ColorSide.Left;
|
||||
return;
|
||||
}
|
||||
|
||||
if (VR_Manager.instance == null || VR_Manager.instance.Player == null)
|
||||
return;
|
||||
|
||||
controller = colorSide == ColorSide.Left
|
||||
? VR_Manager.instance.Player.LeftController
|
||||
: VR_Manager.instance.Player.RightController;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace VRBeats
|
||||
public Vector3 rotation = Vector3.zero;
|
||||
public float speed = 2.0f;
|
||||
public int speedMultiplier = 1;
|
||||
// 0 이면 Settings.TargetTravelTime 사용, 양수면 해당 시간으로 이동
|
||||
// 0이면 Settings.TargetTravelTime 사용, 양수면 해당 시간 동안 일정 속도로 이동
|
||||
public float travelTimeOverride = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,21 +21,30 @@ namespace VRBeats
|
||||
}
|
||||
|
||||
scoreManager = FindFirstObjectByType<ScoreManager>();
|
||||
ApplyPopupTextStyle();
|
||||
|
||||
}
|
||||
|
||||
public void ShowScore()
|
||||
{
|
||||
PlatinioTween.instance.ValueTween( 0.0f , scoreManager.CurrentScore , scoreFadeTime).SetOnUpdateFloat(delegate (float v)
|
||||
if (scoreText == null || scoreManager == null)
|
||||
return;
|
||||
|
||||
PlatinioTween.instance.ValueTween( 0.0f , scoreManager.CurrentScore , Mathf.Min(scoreFadeTime, 0.8f)).SetOnUpdateFloat(delegate (float v)
|
||||
{
|
||||
SetScore( (int)v );
|
||||
}).SetOnComplete(delegate
|
||||
{
|
||||
scoreText.text = scoreManager.BuildResultSummary(length);
|
||||
});
|
||||
}
|
||||
|
||||
public void ResetValues()
|
||||
{
|
||||
gameObject.CancelAllTweens();
|
||||
scoreText.text = initialValue;
|
||||
ApplyPopupTextStyle();
|
||||
if (scoreText != null)
|
||||
scoreText.text = initialValue;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,5 +65,20 @@ namespace VRBeats
|
||||
|
||||
}
|
||||
|
||||
private void ApplyPopupTextStyle()
|
||||
{
|
||||
if (scoreText == null)
|
||||
return;
|
||||
|
||||
scoreText.enableAutoSizing = false;
|
||||
scoreText.fontSize = 4.4f;
|
||||
scoreText.alignment = TextAlignmentOptions.Center;
|
||||
scoreText.overflowMode = TextOverflowModes.Overflow;
|
||||
scoreText.textWrappingMode = TextWrappingModes.NoWrap;
|
||||
scoreText.lineSpacing = -18.0f;
|
||||
scoreText.color = Color.white;
|
||||
scoreText.richText = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Platinio.TweenEngine;
|
||||
using VRBeats.ScriptableEvents;
|
||||
@@ -7,6 +7,14 @@ namespace VRBeats
|
||||
{
|
||||
public class ScoreManager : MonoBehaviour
|
||||
{
|
||||
private enum BeatJudgement
|
||||
{
|
||||
Perfect,
|
||||
Great,
|
||||
Good,
|
||||
Miss
|
||||
}
|
||||
|
||||
[SerializeField] private Text multiplierLabel = null;
|
||||
[SerializeField] private Text scoreLabel = null;
|
||||
[SerializeField] private Image multiplierLoader = null;
|
||||
@@ -14,61 +22,167 @@ namespace VRBeats
|
||||
[SerializeField] private CanvasGroup canvasGroup = null;
|
||||
[SerializeField] private GameEvent onGameOver = null;
|
||||
|
||||
[Header("DJMAX Style Score")]
|
||||
[SerializeField] private Text comboLabel = null;
|
||||
[SerializeField] private Text accuracyLabel = null;
|
||||
[SerializeField] private Text judgementLabel = null;
|
||||
[SerializeField] private bool createMissingHudLabels = true;
|
||||
[SerializeField] private bool applyHudPlacement = true;
|
||||
[SerializeField] private Vector2 hudAnchoredPosition = new Vector2(0.0f, 1.65f);
|
||||
[SerializeField] private float perfectWindow = 0.08f;
|
||||
[SerializeField] private float greatWindow = 0.15f;
|
||||
[SerializeField] private float goodWindow = 0.25f;
|
||||
|
||||
private int maxMultiplier = 0;
|
||||
private int scorePerHit = 0;
|
||||
private int currentScore = 0;
|
||||
private int currentMultiplier = 0;
|
||||
private int toNextMultiplierIncrease = 2;
|
||||
private int acumulateCorrectSlices = 0;
|
||||
private const int MaxCourseScore = 1000000;
|
||||
private float currentMultiplier = 1.0f;
|
||||
private int acumulateErrors = 0;
|
||||
private int errorLimit = 0;
|
||||
private int totalNoteCount = 0;
|
||||
private int judgedNoteCount = 0;
|
||||
private int currentCombo = 0;
|
||||
private int maxCombo = 0;
|
||||
private int perfectCount = 0;
|
||||
private int greatCount = 0;
|
||||
private int goodCount = 0;
|
||||
private int missCount = 0;
|
||||
private int earnedAccuracyPoints = 0;
|
||||
private float visualScore = 0.0f;
|
||||
private int scoreTweenID = -1;
|
||||
private int loaderTweenID = -1;
|
||||
|
||||
private BeatJudgement lastJudgement = BeatJudgement.Perfect;
|
||||
private float judgementTimer = 0.0f;
|
||||
private Text progressLabel = null;
|
||||
private Text rankLabel = null;
|
||||
private Vector3 comboBaseScale = Vector3.one;
|
||||
private float songCurrentTime = 0.0f;
|
||||
private float songDuration = 0.0f;
|
||||
private bool resultFinalized = false;
|
||||
private bool destroyed = false;
|
||||
|
||||
public int CurrentScore
|
||||
private static bool hasPendingSliceTiming = false;
|
||||
private static float pendingSliceTiming = 0.0f;
|
||||
|
||||
public int CurrentScore => Mathf.RoundToInt(MaxCourseScore * AccuracyPercent / 100.0f);
|
||||
public float AccuracyPercent
|
||||
{
|
||||
get
|
||||
{
|
||||
return currentScore;
|
||||
int denominatorNotes = totalNoteCount > 0 ? totalNoteCount : judgedNoteCount;
|
||||
if (denominatorNotes <= 0)
|
||||
return 100.0f;
|
||||
|
||||
return (float)earnedAccuracyPoints / (denominatorNotes * 1000) * 100.0f;
|
||||
}
|
||||
}
|
||||
|
||||
public string Rank
|
||||
{
|
||||
get
|
||||
{
|
||||
float accuracy = AccuracyPercent;
|
||||
if (accuracy >= 98.0f) return "S+";
|
||||
if (accuracy >= 95.0f) return "S";
|
||||
if (accuracy >= 90.0f) return "A";
|
||||
if (accuracy >= 80.0f) return "B";
|
||||
if (accuracy >= 70.0f) return "C";
|
||||
if (accuracy >= 60.0f) return "D";
|
||||
return "F";
|
||||
}
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
maxMultiplier = VR_BeatManager.instance.GameSettings.MaxMultiplier;
|
||||
scorePerHit = VR_BeatManager.instance.GameSettings.ScorePerHit;
|
||||
errorLimit = VR_BeatManager.instance.GameSettings.ErrorLimit;
|
||||
multiplierLoader.fillAmount = 0.0f;
|
||||
}
|
||||
|
||||
if (multiplierLoader != null)
|
||||
multiplierLoader.fillAmount = 0.0f;
|
||||
|
||||
PrepareHud();
|
||||
}
|
||||
|
||||
public static void ReportSliceTiming(float timingErrorSeconds)
|
||||
{
|
||||
pendingSliceTiming = timingErrorSeconds;
|
||||
hasPendingSliceTiming = true;
|
||||
}
|
||||
|
||||
public static void ReportMiss()
|
||||
{
|
||||
hasPendingSliceTiming = false;
|
||||
pendingSliceTiming = 0.0f;
|
||||
}
|
||||
|
||||
public void SetTotalNotes(int noteCount)
|
||||
{
|
||||
totalNoteCount = Mathf.Max(0, noteCount);
|
||||
resultFinalized = false;
|
||||
UpdateScoreTween();
|
||||
}
|
||||
|
||||
public void CompleteSong()
|
||||
{
|
||||
if (resultFinalized)
|
||||
return;
|
||||
|
||||
resultFinalized = true;
|
||||
|
||||
int missedUnjudgedNotes = Mathf.Max(0, totalNoteCount - judgedNoteCount);
|
||||
if (missedUnjudgedNotes > 0)
|
||||
{
|
||||
missCount += missedUnjudgedNotes;
|
||||
judgedNoteCount += missedUnjudgedNotes;
|
||||
currentCombo = 0;
|
||||
currentMultiplier = 1.0f;
|
||||
}
|
||||
|
||||
UpdateScoreTween();
|
||||
}
|
||||
|
||||
public void SetSongProgress(float currentTime, float duration)
|
||||
{
|
||||
songCurrentTime = Mathf.Max(0.0f, currentTime);
|
||||
songDuration = Mathf.Max(0.0f, duration);
|
||||
}
|
||||
|
||||
public void OnGameOver()
|
||||
{
|
||||
{
|
||||
gameObject.CancelAllTweens();
|
||||
canvasGroup.Fade(0.0f, 0.5f).SetEase(Ease.EaseOutExpo).SetOwner(gameObject);
|
||||
if (canvasGroup != null)
|
||||
canvasGroup.Fade(0.0f, 0.5f).SetEase(Ease.EaseOutExpo).SetOwner(gameObject);
|
||||
}
|
||||
|
||||
public void OnGameRestart()
|
||||
{
|
||||
{
|
||||
ResetThisComponent();
|
||||
gameObject.CancelAllTweens();
|
||||
canvasGroup.Fade(1.0f, 0.5f).SetEase(Ease.EaseOutExpo).SetOwner(gameObject);
|
||||
if (canvasGroup != null)
|
||||
canvasGroup.Fade(1.0f, 0.5f).SetEase(Ease.EaseOutExpo).SetOwner(gameObject);
|
||||
}
|
||||
|
||||
public void ResetThisComponent()
|
||||
{
|
||||
currentMultiplier = 0;
|
||||
currentScore = 0;
|
||||
acumulateCorrectSlices = 0;
|
||||
{
|
||||
currentMultiplier = 1.0f;
|
||||
visualScore = 0;
|
||||
acumulateErrors = 0;
|
||||
toNextMultiplierIncrease = 2;
|
||||
judgedNoteCount = 0;
|
||||
currentCombo = 0;
|
||||
maxCombo = 0;
|
||||
perfectCount = 0;
|
||||
greatCount = 0;
|
||||
goodCount = 0;
|
||||
missCount = 0;
|
||||
earnedAccuracyPoints = 0;
|
||||
judgementTimer = 0.0f;
|
||||
resultFinalized = false;
|
||||
hasPendingSliceTiming = false;
|
||||
pendingSliceTiming = 0.0f;
|
||||
|
||||
if (multiplierLoader != null)
|
||||
multiplierLoader.fillAmount = 0.0f;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void Update()
|
||||
{
|
||||
UpdateUI();
|
||||
@@ -79,46 +193,13 @@ namespace VRBeats
|
||||
if (destroyed)
|
||||
return;
|
||||
|
||||
acumulateErrors = 0;
|
||||
acumulateCorrectSlices++;
|
||||
currentScore += scorePerHit + (scorePerHit * currentMultiplier);
|
||||
BeatJudgement judgement = ConsumeJudgement();
|
||||
RegisterJudgement(judgement);
|
||||
|
||||
CancelTweenById(scoreTweenID);
|
||||
scoreTweenID = PlatinioTween.instance.ValueTween(visualScore, currentScore, scoreFollowTime).SetEase(Ease.EaseOutExpo).SetOnUpdateFloat(delegate (float value)
|
||||
{
|
||||
visualScore = value;
|
||||
}).ID;
|
||||
acumulateErrors = judgement == BeatJudgement.Miss ? acumulateErrors + 1 : 0;
|
||||
|
||||
UpdateScoreTween();
|
||||
UpdateMultiplierLoaderValue();
|
||||
|
||||
if (acumulateCorrectSlices >= toNextMultiplierIncrease)
|
||||
{
|
||||
IncreaseMultiplier();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void CancelTweenById(int id)
|
||||
{
|
||||
if(id != -1)
|
||||
PlatinioTween.instance.CancelTween(id);
|
||||
}
|
||||
|
||||
private void UpdateMultiplierLoaderValue()
|
||||
{
|
||||
if (destroyed)
|
||||
return;
|
||||
|
||||
float multiplierLoaderValue = (float)acumulateCorrectSlices / (float)toNextMultiplierIncrease;
|
||||
|
||||
|
||||
CancelTweenById(loaderTweenID);
|
||||
loaderTweenID = PlatinioTween.instance.ValueTween(multiplierLoader.fillAmount, multiplierLoaderValue, 1.0f).SetEase(Ease.EaseOutExpo).SetOnUpdateFloat(delegate (float value)
|
||||
{
|
||||
if(multiplierLoader != null)
|
||||
multiplierLoader.fillAmount = value;
|
||||
}).SetOwner(multiplierLoader.gameObject).ID;
|
||||
}
|
||||
|
||||
public void OnIncorrectSlice()
|
||||
@@ -126,18 +207,63 @@ namespace VRBeats
|
||||
if (destroyed)
|
||||
return;
|
||||
|
||||
RegisterJudgement(BeatJudgement.Miss);
|
||||
acumulateErrors++;
|
||||
acumulateCorrectSlices = 0;
|
||||
currentMultiplier = 0;
|
||||
toNextMultiplierIncrease = 2;
|
||||
currentMultiplier = 1.0f;
|
||||
|
||||
UpdateScoreTween();
|
||||
UpdateMultiplierLoaderValue();
|
||||
|
||||
if (acumulateErrors > errorLimit)
|
||||
{
|
||||
onGameOver.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public string BuildResultSummary(int minScoreLength)
|
||||
{
|
||||
string score = CurrentScore.ToString();
|
||||
score = new string('0', Mathf.Max(minScoreLength - score.Length, 0)) + score;
|
||||
string badge = missCount == 0
|
||||
? (greatCount == 0 && goodCount == 0 ? "PERFECT PLAY" : "FULL COMBO")
|
||||
: "TRY AGAIN";
|
||||
|
||||
return $"<size=150%><color=#41F2FF>{Rank}</color></size>\n" +
|
||||
$"<size=118%>{score}</size>\n" +
|
||||
$"<size=56%><color=#D7F7FF>ACC {AccuracyPercent:0.0}% {badge}</color></size>\n" +
|
||||
$"<size=50%>MAX COMBO {maxCombo}</size>\n" +
|
||||
$"<size=42%><color=#A9B7C0>P {perfectCount} G {greatCount} GOOD {goodCount} MISS {missCount}</color></size>";
|
||||
}
|
||||
|
||||
private void CancelTweenById(int id)
|
||||
{
|
||||
if (id != -1)
|
||||
PlatinioTween.instance.CancelTween(id);
|
||||
}
|
||||
|
||||
private void UpdateMultiplierLoaderValue()
|
||||
{
|
||||
if (destroyed || multiplierLoader == null)
|
||||
return;
|
||||
|
||||
float multiplierLoaderValue = GetComboTierProgress();
|
||||
CancelTweenById(loaderTweenID);
|
||||
loaderTweenID = PlatinioTween.instance.ValueTween(multiplierLoader.fillAmount, multiplierLoaderValue, 1.0f)
|
||||
.SetEase(Ease.EaseOutExpo)
|
||||
.SetOnUpdateFloat(delegate (float value)
|
||||
{
|
||||
if (multiplierLoader != null)
|
||||
multiplierLoader.fillAmount = value;
|
||||
})
|
||||
.SetOwner(multiplierLoader.gameObject)
|
||||
.ID;
|
||||
}
|
||||
|
||||
private void UpdateScoreTween()
|
||||
{
|
||||
CancelTweenById(scoreTweenID);
|
||||
scoreTweenID = PlatinioTween.instance.ValueTween(visualScore, CurrentScore, scoreFollowTime)
|
||||
.SetEase(Ease.EaseOutExpo)
|
||||
.SetOnUpdateFloat(delegate (float value) { visualScore = value; })
|
||||
.ID;
|
||||
}
|
||||
|
||||
private void UpdateUI()
|
||||
@@ -145,41 +271,230 @@ namespace VRBeats
|
||||
if (destroyed)
|
||||
return;
|
||||
|
||||
multiplierLabel.text = currentMultiplier.ToString();
|
||||
scoreLabel.text = Mathf.CeilToInt( visualScore ).ToString();
|
||||
}
|
||||
if (multiplierLabel != null)
|
||||
multiplierLabel.text = $"x{Mathf.RoundToInt(currentMultiplier)}";
|
||||
if (scoreLabel != null)
|
||||
scoreLabel.text = $"{Mathf.CeilToInt(visualScore):N0}";
|
||||
if (comboLabel != null)
|
||||
comboLabel.text = currentCombo > 0
|
||||
? $"<size=42%><color=#E6F8FF>COMBO</color></size>\n<size=125%>{currentCombo}</size>"
|
||||
: "<size=42%><color=#E6F8FF>COMBO</color></size>\n<size=125%>0</size>";
|
||||
if (accuracyLabel != null)
|
||||
accuracyLabel.text = $"{AccuracyPercent:0.0}%";
|
||||
if (rankLabel != null)
|
||||
rankLabel.text = $"<color={GetRankColorHex()}>{Rank}</color>";
|
||||
if (progressLabel != null)
|
||||
progressLabel.text = songDuration > 0.0f
|
||||
? $"{FormatTime(songCurrentTime)} / {FormatTime(songDuration)}"
|
||||
: "";
|
||||
|
||||
private void IncreaseMultiplier()
|
||||
{
|
||||
if (destroyed)
|
||||
if (judgementLabel == null)
|
||||
return;
|
||||
|
||||
acumulateCorrectSlices = 0;
|
||||
currentMultiplier = Mathf.Min( currentMultiplier + 1 , maxMultiplier );
|
||||
toNextMultiplierIncrease = (currentMultiplier + 1) * 2;
|
||||
|
||||
PlatinioTween.instance.CancelTween(multiplierLoader.gameObject);
|
||||
|
||||
PlatinioTween.instance.ValueTween(multiplierLoader.fillAmount, 1.0f, 1.0f).SetEase(Ease.EaseOutExpo).SetOnUpdateFloat(delegate (float value)
|
||||
{
|
||||
if(multiplierLoader != null)
|
||||
multiplierLoader.fillAmount = value;
|
||||
}).SetOwner(multiplierLoader.gameObject).SetOnComplete( delegate
|
||||
{
|
||||
if (multiplierLabel != null)
|
||||
{
|
||||
PlatinioTween.instance.ValueTween(multiplierLoader.fillAmount, 0.0f, 0.5f).SetEase(Ease.EaseOutExpo).SetOnUpdateFloat(delegate (float value)
|
||||
{
|
||||
if (multiplierLoader != null)
|
||||
multiplierLoader.fillAmount = value;
|
||||
}).SetOwner(multiplierLoader.gameObject);
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
judgementTimer -= Time.deltaTime;
|
||||
judgementLabel.text = judgementTimer > 0.0f ? GetJudgementText(lastJudgement) : "";
|
||||
judgementLabel.color = GetJudgementColor(lastJudgement);
|
||||
}
|
||||
|
||||
private BeatJudgement ConsumeJudgement()
|
||||
{
|
||||
if (!hasPendingSliceTiming)
|
||||
return BeatJudgement.Perfect;
|
||||
|
||||
float timing = pendingSliceTiming;
|
||||
hasPendingSliceTiming = false;
|
||||
pendingSliceTiming = 0.0f;
|
||||
|
||||
if (timing <= perfectWindow) return BeatJudgement.Perfect;
|
||||
if (timing <= greatWindow) return BeatJudgement.Great;
|
||||
if (timing <= goodWindow) return BeatJudgement.Good;
|
||||
return BeatJudgement.Good;
|
||||
}
|
||||
|
||||
private void RegisterJudgement(BeatJudgement judgement)
|
||||
{
|
||||
lastJudgement = judgement;
|
||||
judgementTimer = 0.45f;
|
||||
judgedNoteCount++;
|
||||
|
||||
if (judgement == BeatJudgement.Perfect)
|
||||
{
|
||||
perfectCount++;
|
||||
earnedAccuracyPoints += 1000;
|
||||
currentCombo++;
|
||||
}
|
||||
else if (judgement == BeatJudgement.Great)
|
||||
{
|
||||
greatCount++;
|
||||
earnedAccuracyPoints += 700;
|
||||
currentCombo++;
|
||||
}
|
||||
else if (judgement == BeatJudgement.Good)
|
||||
{
|
||||
goodCount++;
|
||||
earnedAccuracyPoints += 400;
|
||||
currentCombo++;
|
||||
}
|
||||
else
|
||||
{
|
||||
missCount++;
|
||||
currentCombo = 0;
|
||||
}
|
||||
|
||||
maxCombo = Mathf.Max(maxCombo, currentCombo);
|
||||
currentMultiplier = judgement == BeatJudgement.Miss
|
||||
? 1.0f
|
||||
: Mathf.Min(GetComboMultiplier(currentCombo), Mathf.Max(1.0f, maxMultiplier));
|
||||
|
||||
PulseComboLabel(judgement);
|
||||
}
|
||||
|
||||
private static float GetComboMultiplier(int combo)
|
||||
{
|
||||
if (combo >= 200) return 1.5f;
|
||||
if (combo >= 100) return 1.35f;
|
||||
if (combo >= 50) return 1.2f;
|
||||
if (combo >= 20) return 1.1f;
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
private static string GetJudgementText(BeatJudgement judgement)
|
||||
{
|
||||
switch (judgement)
|
||||
{
|
||||
case BeatJudgement.Perfect: return "PERFECT";
|
||||
case BeatJudgement.Great: return "GREAT";
|
||||
case BeatJudgement.Good: return "GOOD";
|
||||
default: return "BREAK";
|
||||
}
|
||||
}
|
||||
|
||||
private static Color GetJudgementColor(BeatJudgement judgement)
|
||||
{
|
||||
switch (judgement)
|
||||
{
|
||||
case BeatJudgement.Perfect: return new Color(0.25f, 0.95f, 1.0f, 1.0f);
|
||||
case BeatJudgement.Great: return new Color(0.58f, 1.0f, 0.45f, 1.0f);
|
||||
case BeatJudgement.Good: return new Color(1.0f, 0.8f, 0.35f, 1.0f);
|
||||
default: return new Color(1.0f, 0.25f, 0.45f, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
private float GetComboTierProgress()
|
||||
{
|
||||
int lower = 0;
|
||||
int upper = 20;
|
||||
if (currentCombo >= 200) return 1.0f;
|
||||
if (currentCombo >= 100) { lower = 100; upper = 200; }
|
||||
else if (currentCombo >= 50) { lower = 50; upper = 100; }
|
||||
else if (currentCombo >= 20) { lower = 20; upper = 50; }
|
||||
|
||||
return Mathf.InverseLerp(lower, upper, currentCombo);
|
||||
}
|
||||
|
||||
private void PrepareHud()
|
||||
{
|
||||
RectTransform rect = transform as RectTransform;
|
||||
if (applyHudPlacement && rect != null)
|
||||
rect.anchoredPosition = hudAnchoredPosition;
|
||||
|
||||
ConfigureText(scoreLabel, new Vector2(-255.0f, -18.0f), new Vector2(220.0f, 40.0f), 26, Color.white, TextAnchor.MiddleLeft);
|
||||
ConfigureText(multiplierLabel, new Vector2(255.0f, 36.0f), new Vector2(100.0f, 68.0f), 34, Color.white, TextAnchor.MiddleCenter);
|
||||
ConfigureImage(multiplierLoader, new Vector2(255.0f, 36.0f), new Vector2(104.0f, 104.0f));
|
||||
|
||||
if (!createMissingHudLabels)
|
||||
return;
|
||||
|
||||
comboLabel ??= CreateHudText("Combo", new Vector2(-255.0f, 74.0f), new Vector2(220.0f, 112.0f), 36, Color.white, TextAnchor.MiddleLeft);
|
||||
accuracyLabel ??= CreateHudText("Accuracy", new Vector2(-255.0f, -58.0f), new Vector2(220.0f, 34.0f), 20, new Color(0.88f, 0.95f, 1.0f, 1.0f), TextAnchor.MiddleLeft);
|
||||
rankLabel ??= CreateHudText("Rank", new Vector2(-255.0f, -105.0f), new Vector2(220.0f, 76.0f), 48, Color.white, TextAnchor.MiddleLeft);
|
||||
judgementLabel ??= CreateHudText("Judgement", new Vector2(0.0f, 112.0f), new Vector2(260.0f, 54.0f), 28, new Color(0.25f, 0.95f, 1.0f, 1.0f), TextAnchor.MiddleCenter);
|
||||
progressLabel ??= CreateHudText("SongProgress", new Vector2(255.0f, -62.0f), new Vector2(180.0f, 34.0f), 18, Color.white, TextAnchor.MiddleCenter);
|
||||
comboBaseScale = comboLabel != null ? comboLabel.transform.localScale : Vector3.one;
|
||||
}
|
||||
|
||||
private Text CreateHudText(string name, Vector2 anchoredPosition, Vector2 size, int fontSize, Color color, TextAnchor alignment)
|
||||
{
|
||||
GameObject textObject = new GameObject(name);
|
||||
textObject.layer = gameObject.layer;
|
||||
textObject.transform.SetParent(transform, false);
|
||||
|
||||
RectTransform rect = textObject.AddComponent<RectTransform>();
|
||||
textObject.AddComponent<CanvasRenderer>();
|
||||
Text text = textObject.AddComponent<Text>();
|
||||
ConfigureText(text, anchoredPosition, size, fontSize, color, alignment);
|
||||
return text;
|
||||
}
|
||||
|
||||
private static void ConfigureText(Text text, Vector2 anchoredPosition, Vector2 size, int fontSize, Color color, TextAnchor alignment)
|
||||
{
|
||||
if (text == null)
|
||||
return;
|
||||
|
||||
RectTransform rect = text.rectTransform;
|
||||
rect.anchorMin = new Vector2(0.5f, 0.5f);
|
||||
rect.anchorMax = new Vector2(0.5f, 0.5f);
|
||||
rect.anchoredPosition = anchoredPosition;
|
||||
rect.sizeDelta = size;
|
||||
|
||||
text.fontSize = fontSize;
|
||||
text.color = color;
|
||||
text.alignment = alignment;
|
||||
text.horizontalOverflow = HorizontalWrapMode.Overflow;
|
||||
text.verticalOverflow = VerticalWrapMode.Overflow;
|
||||
text.raycastTarget = false;
|
||||
text.supportRichText = true;
|
||||
text.lineSpacing = 0.86f;
|
||||
|
||||
Shadow shadow = text.GetComponent<Shadow>() ?? text.gameObject.AddComponent<Shadow>();
|
||||
shadow.effectColor = new Color(0.0f, 0.0f, 0.0f, 0.72f);
|
||||
shadow.effectDistance = new Vector2(3.0f, -3.0f);
|
||||
}
|
||||
|
||||
private static void ConfigureImage(Image image, Vector2 anchoredPosition, Vector2 size)
|
||||
{
|
||||
if (image == null)
|
||||
return;
|
||||
|
||||
RectTransform rect = image.rectTransform;
|
||||
rect.anchorMin = new Vector2(0.5f, 0.5f);
|
||||
rect.anchorMax = new Vector2(0.5f, 0.5f);
|
||||
rect.anchoredPosition = anchoredPosition;
|
||||
rect.sizeDelta = size;
|
||||
image.color = new Color(1.0f, 1.0f, 1.0f, 0.85f);
|
||||
image.raycastTarget = false;
|
||||
}
|
||||
|
||||
private string GetRankColorHex()
|
||||
{
|
||||
switch (Rank)
|
||||
{
|
||||
case "S+": return "#41F2FF";
|
||||
case "S": return "#69FFD1";
|
||||
case "A": return "#B9FF72";
|
||||
case "B": return "#FFE06A";
|
||||
case "C": return "#FFB15C";
|
||||
case "D": return "#FF7C7C";
|
||||
default: return "#A9B7C0";
|
||||
}
|
||||
}
|
||||
|
||||
private void PulseComboLabel(BeatJudgement judgement)
|
||||
{
|
||||
if (comboLabel == null || judgement == BeatJudgement.Miss)
|
||||
return;
|
||||
|
||||
comboLabel.gameObject.CancelAllTweens();
|
||||
comboLabel.transform.localScale = comboBaseScale * 1.08f;
|
||||
comboLabel.transform.ScaleTween(comboBaseScale, 0.16f).SetEase(Ease.EaseOutExpo).SetOwner(comboLabel.gameObject);
|
||||
}
|
||||
|
||||
private static string FormatTime(float seconds)
|
||||
{
|
||||
int wholeSeconds = Mathf.Max(0, Mathf.FloorToInt(seconds));
|
||||
int minutes = wholeSeconds / 60;
|
||||
int remainingSeconds = wholeSeconds % 60;
|
||||
return $"{minutes}:{remainingSeconds:00}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user