[Fix] Refactor project
This commit is contained in:
+17
-23
@@ -23,22 +23,15 @@ namespace YachtDice.Dice
|
||||
|
||||
private void Awake() => RebuildSet();
|
||||
private void OnValidate() => RebuildSet();
|
||||
|
||||
public void Test()
|
||||
{
|
||||
if (!TryGetTopValue(out var top) || !TryGetBottomValue(out var bottom))
|
||||
return;
|
||||
|
||||
Debug.Log($"Top Value: {top}, Bottom Value: {bottom}");
|
||||
|
||||
AlignToTopByLocalAngles();
|
||||
}
|
||||
|
||||
|
||||
private void RebuildSet()
|
||||
{
|
||||
_entrySet = new HashSet<Entry>();
|
||||
|
||||
if (entries == null) return;
|
||||
for (int i = 0; i < entries.Count; i++) _entrySet.Add(entries[i]);
|
||||
|
||||
foreach (var t in entries)
|
||||
_entrySet.Add(t);
|
||||
}
|
||||
|
||||
public bool TryGetTopValue(out int value) => TryGetExtremeValue(isTop: true, out value);
|
||||
@@ -65,8 +58,8 @@ namespace YachtDice.Dice
|
||||
if (_entrySet == null || _entrySet.Count == 0)
|
||||
return false;
|
||||
|
||||
bool found = false;
|
||||
float bestY = isTop ? float.NegativeInfinity : float.PositiveInfinity;
|
||||
var found = false;
|
||||
var bestY = isTop ? float.NegativeInfinity : float.PositiveInfinity;
|
||||
int best = default;
|
||||
|
||||
foreach (var e in _entrySet)
|
||||
@@ -94,22 +87,23 @@ namespace YachtDice.Dice
|
||||
if (_entrySet == null || _entrySet.Count == 0)
|
||||
throw new InvalidOperationException("Dice: коллекция пуста.");
|
||||
|
||||
bool found = false;
|
||||
float bestY = isTop ? float.NegativeInfinity : float.PositiveInfinity;
|
||||
var found = false;
|
||||
var bestY = isTop ? float.NegativeInfinity : float.PositiveInfinity;
|
||||
Entry best = default;
|
||||
|
||||
foreach (var e in _entrySet)
|
||||
{
|
||||
var p = e.Point;
|
||||
|
||||
if (!p) continue;
|
||||
|
||||
float y = p.position.y;
|
||||
if (!found || (isTop ? y > bestY : y < bestY))
|
||||
{
|
||||
found = true;
|
||||
bestY = y;
|
||||
best = e;
|
||||
}
|
||||
var y = p.position.y;
|
||||
|
||||
if (found && (isTop ? !(y > bestY) : !(y < bestY))) continue;
|
||||
|
||||
found = true;
|
||||
bestY = y;
|
||||
best = e;
|
||||
}
|
||||
|
||||
if (!found)
|
||||
|
||||
@@ -12,11 +12,12 @@ namespace YachtDice.Dice
|
||||
|
||||
public DiceDefinition FindById(string id)
|
||||
{
|
||||
for (int i = 0; i < dice.Count; i++)
|
||||
foreach (var t in dice)
|
||||
{
|
||||
if (dice[i] != null && dice[i].Id == id)
|
||||
return dice[i];
|
||||
if (t != null && t.Id == id)
|
||||
return t;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,10 +20,14 @@ namespace YachtDice.Dice
|
||||
|
||||
public bool IsRepurchasable => false;
|
||||
|
||||
/// <summary>Количество граней.</summary>
|
||||
/// <summary>
|
||||
/// Количество граней.
|
||||
/// </summary>
|
||||
public abstract int FaceCount { get; }
|
||||
|
||||
/// <summary>Возвращает массив всех возможных значений граней.</summary>
|
||||
/// <summary>
|
||||
/// Возвращает массив всех возможных значений граней.
|
||||
/// </summary>
|
||||
public abstract int[] GetFaceValues();
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
||||
@@ -103,8 +103,8 @@ namespace YachtDice.Dice
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
|
||||
// ── 4. Ждём пока кубик успокоится ───────────────────────────
|
||||
float stillTimer = 0f;
|
||||
float sqrThreshold = settleSpeed * settleSpeed;
|
||||
var stillTimer = 0f;
|
||||
var sqrThreshold = settleSpeed * settleSpeed;
|
||||
|
||||
while (stillTimer < settleDelay)
|
||||
{
|
||||
@@ -138,7 +138,7 @@ namespace YachtDice.Dice
|
||||
// Откатываемся обратно — будем интерполировать
|
||||
transform.rotation = startRot;
|
||||
|
||||
float elapsed = 0f;
|
||||
var elapsed = 0f;
|
||||
while (elapsed < snapDuration)
|
||||
{
|
||||
elapsed += Time.deltaTime;
|
||||
|
||||
@@ -6,10 +6,14 @@ namespace YachtDice.Dice
|
||||
/// </summary>
|
||||
public interface IDice
|
||||
{
|
||||
/// <summary>Текущее значение верхней грани.</summary>
|
||||
/// <summary>
|
||||
/// Текущее значение верхней грани.
|
||||
/// </summary>
|
||||
int Value { get; }
|
||||
|
||||
/// <summary>Определение типа дайса (ScriptableObject).</summary>
|
||||
/// <summary>
|
||||
/// Определение типа дайса (ScriptableObject).
|
||||
/// </summary>
|
||||
DiceDefinition Definition { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace YachtDice.Dice
|
||||
|
||||
public override int[] GetFaceValues()
|
||||
{
|
||||
int[] copy = new int[faceValues.Length];
|
||||
var copy = new int[faceValues.Length];
|
||||
System.Array.Copy(faceValues, copy, faceValues.Length);
|
||||
return copy;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user