架构大更
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using DamageNumbersPro;
|
||||
|
||||
namespace DamageNumbersPro.Internal
|
||||
{
|
||||
public class DNPUpdater : MonoBehaviour
|
||||
{
|
||||
// Dicitonary
|
||||
static Dictionary<float, DNPUpdater> unscaledUpdaters;
|
||||
static Dictionary<float, DNPUpdater> scaledUpdaters;
|
||||
private static Dictionary<float, DNPUpdater> unscaledUpdaters;
|
||||
private static Dictionary<float, DNPUpdater> scaledUpdaters;
|
||||
|
||||
// Static
|
||||
public static Vector3 upVector;
|
||||
@@ -18,51 +17,42 @@ namespace DamageNumbersPro.Internal
|
||||
public static Quaternion cameraRotation;
|
||||
|
||||
// Settings
|
||||
public bool isUnscaled = false;
|
||||
public bool isUnscaled;
|
||||
public float updateDelay = 0.0125f;
|
||||
public HashSet<DamageNumber> activePopups;
|
||||
public HashSet<DamageNumber> removedPopups;
|
||||
private float delta;
|
||||
|
||||
// Internal
|
||||
float lastUpdateTime = 0;
|
||||
float delta = 0;
|
||||
float time = 0;
|
||||
private float lastUpdateTime;
|
||||
public HashSet<DamageNumber> removedPopups;
|
||||
private float time;
|
||||
|
||||
void Start()
|
||||
private void Start()
|
||||
{
|
||||
StartCoroutine(UpdatePopups());
|
||||
}
|
||||
|
||||
IEnumerator UpdatePopups()
|
||||
private IEnumerator UpdatePopups()
|
||||
{
|
||||
// Delay
|
||||
WaitForSecondsRealtime delay = new WaitForSecondsRealtime(updateDelay);
|
||||
var delay = new WaitForSecondsRealtime(updateDelay);
|
||||
|
||||
while(true)
|
||||
while (true)
|
||||
{
|
||||
// Vector Update
|
||||
vectorsNeedUpdate = true;
|
||||
|
||||
// Update
|
||||
foreach (DamageNumber popup in activePopups)
|
||||
{
|
||||
if(popup != null)
|
||||
{
|
||||
foreach (var popup in activePopups)
|
||||
if (popup != null)
|
||||
popup.UpdateDamageNumber(delta, time);
|
||||
}
|
||||
else
|
||||
{
|
||||
removedPopups.Add(popup);
|
||||
}
|
||||
}
|
||||
|
||||
// Clean Up
|
||||
if(removedPopups.Count > 0)
|
||||
if (removedPopups.Count > 0)
|
||||
{
|
||||
foreach (DamageNumber removed in removedPopups)
|
||||
{
|
||||
activePopups.Remove(removed);
|
||||
}
|
||||
foreach (var removed in removedPopups) activePopups.Remove(removed);
|
||||
removedPopups = new HashSet<DamageNumber>();
|
||||
}
|
||||
|
||||
@@ -86,29 +76,23 @@ namespace DamageNumbersPro.Internal
|
||||
|
||||
public static void RegisterPopup(bool unscaledTime, float updateDelay, DamageNumber popup)
|
||||
{
|
||||
ref Dictionary<float, DNPUpdater> updaters = ref unscaledTime ? ref unscaledUpdaters : ref scaledUpdaters;
|
||||
ref var updaters = ref unscaledTime ? ref unscaledUpdaters : ref scaledUpdaters;
|
||||
|
||||
if (updaters == null)
|
||||
{
|
||||
updaters = new Dictionary<float, DNPUpdater>();
|
||||
}
|
||||
if (updaters == null) updaters = new Dictionary<float, DNPUpdater>();
|
||||
|
||||
bool containsKey = updaters.ContainsKey(updateDelay);
|
||||
var containsKey = updaters.ContainsKey(updateDelay);
|
||||
if (containsKey && updaters[updateDelay] != null)
|
||||
{
|
||||
updaters[updateDelay].activePopups.Add(popup);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(containsKey)
|
||||
{
|
||||
updaters.Remove(updateDelay);
|
||||
}
|
||||
if (containsKey) updaters.Remove(updateDelay);
|
||||
|
||||
GameObject newUpdater = new GameObject("");
|
||||
var newUpdater = new GameObject("");
|
||||
newUpdater.hideFlags = HideFlags.HideInHierarchy;
|
||||
|
||||
DNPUpdater dnpUpdater = newUpdater.AddComponent<DNPUpdater>();
|
||||
var dnpUpdater = newUpdater.AddComponent<DNPUpdater>();
|
||||
dnpUpdater.activePopups = new HashSet<DamageNumber>();
|
||||
dnpUpdater.removedPopups = new HashSet<DamageNumber>();
|
||||
dnpUpdater.isUnscaled = unscaledTime;
|
||||
@@ -123,12 +107,10 @@ namespace DamageNumbersPro.Internal
|
||||
|
||||
public static void UnregisterPopup(bool unscaledTime, float updateDelay, DamageNumber popup)
|
||||
{
|
||||
Dictionary<float, DNPUpdater> updaters = unscaledTime ? unscaledUpdaters : scaledUpdaters;
|
||||
var updaters = unscaledTime ? unscaledUpdaters : scaledUpdaters;
|
||||
|
||||
if (updaters != null && updaters.ContainsKey(updateDelay) && updaters[updateDelay].activePopups.Contains(popup))
|
||||
{
|
||||
updaters[updateDelay].removedPopups.Add(popup);
|
||||
}
|
||||
if (updaters != null && updaters.ContainsKey(updateDelay) &&
|
||||
updaters[updateDelay].activePopups.Contains(popup)) updaters[updateDelay].removedPopups.Add(popup);
|
||||
}
|
||||
|
||||
public static void UpdateVectors(Transform popup)
|
||||
@@ -138,4 +120,4 @@ namespace DamageNumbersPro.Internal
|
||||
rightVector = popup.right;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,10 +1,9 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DamageNumbersPro
|
||||
{
|
||||
[System.Serializable]
|
||||
[Serializable]
|
||||
public struct DestructionSettings
|
||||
{
|
||||
public DestructionSettings(float customDefault)
|
||||
@@ -17,18 +16,18 @@ namespace DamageNumbersPro
|
||||
alphaCurve = new AnimationCurve(new Keyframe(0, 1), new Keyframe(1, 0));
|
||||
}
|
||||
|
||||
[Header("Main:")]
|
||||
[Tooltip("The maximum distance at which damage numbers will be destroyed.")]
|
||||
[Header("Main:")] [Tooltip("The maximum distance at which damage numbers will be destroyed.")]
|
||||
public float maxDistance;
|
||||
|
||||
[Tooltip("The delay after spawning that numbers will be destroyed.")]
|
||||
public float spawnDelay;
|
||||
|
||||
[Header("Animation:")]
|
||||
public float duration;
|
||||
[Header("Animation:")] public float duration;
|
||||
|
||||
[Tooltip("The scale over the destruction duration.")]
|
||||
public AnimationCurve scaleCurve;
|
||||
|
||||
[Tooltip("The alpha over the destruction duration.")]
|
||||
public AnimationCurve alphaCurve;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DamageNumbersPro {
|
||||
[System.Serializable]
|
||||
namespace DamageNumbersPro
|
||||
{
|
||||
[Serializable]
|
||||
public struct TextSettings
|
||||
{
|
||||
public TextSettings(float customDefault)
|
||||
@@ -28,13 +28,14 @@ namespace DamageNumbersPro {
|
||||
strike = false;
|
||||
}
|
||||
|
||||
[Header("Basics:")]
|
||||
[Tooltip("Makes the text bold.")]
|
||||
[Header("Basics:")] [Tooltip("Makes the text bold.")]
|
||||
public bool bold;
|
||||
[Tooltip("Makes the text italic.")]
|
||||
public bool italic;
|
||||
|
||||
[Tooltip("Makes the text italic.")] public bool italic;
|
||||
|
||||
[Tooltip("Adds an underline to the text.")]
|
||||
public bool underline;
|
||||
|
||||
[Tooltip("Strikes through the text with a line.")]
|
||||
public bool strike;
|
||||
|
||||
@@ -43,26 +44,25 @@ namespace DamageNumbersPro {
|
||||
[Tooltip("Changes the alpha of the text.\nWon't work if Custom Color is used.")]
|
||||
public float alpha;
|
||||
|
||||
[Header("Color:")]
|
||||
[Tooltip("Changes the color of the text.\nOverrides the alpha option above.")]
|
||||
[Header("Color:")] [Tooltip("Changes the color of the text.\nOverrides the alpha option above.")]
|
||||
public bool customColor;
|
||||
|
||||
public Color color;
|
||||
|
||||
[Header("Mark:")]
|
||||
[Tooltip("Highlights the text with a custom color.")]
|
||||
[Header("Mark:")] [Tooltip("Highlights the text with a custom color.")]
|
||||
public bool mark;
|
||||
|
||||
public Color markColor;
|
||||
|
||||
[Header("Offset:")]
|
||||
[Tooltip("Horizontally moves the text.\nCan be used to offset the prefix or suffix.")]
|
||||
[Header("Offset:")] [Tooltip("Horizontally moves the text.\nCan be used to offset the prefix or suffix.")]
|
||||
public float horizontal;
|
||||
|
||||
[Tooltip("Vertically moves the text.\nCan be used to offset the prefix or suffix.")]
|
||||
public float vertical;
|
||||
|
||||
[Header("Extra:")]
|
||||
[Tooltip("Changes the character spacing.")]
|
||||
[Header("Extra:")] [Tooltip("Changes the character spacing.")]
|
||||
public float characterSpacing;
|
||||
[Tooltip("Changes the font size.")]
|
||||
public float size;
|
||||
|
||||
[Tooltip("Changes the font size.")] public float size;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user