架构大更
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user