time 增加
All checks were successful
Plugin Library CI / publish (00.BuildOriginality) (push) Successful in 7s
Plugin Library CI / publish (00.StaryEvo) (push) Successful in 11s
Plugin Library CI / publish (00.StaryEvoTools) (push) Successful in 10s
Plugin Library CI / publish (01.HybridCLR) (push) Successful in 7s
Plugin Library CI / publish (02.InformationSave) (push) Successful in 5s
Plugin Library CI / publish (03.YooAsset) (push) Successful in 38s
Plugin Library CI / publish (04.AudioCore) (push) Successful in 3s
Plugin Library CI / publish (05.TableTextConversion) (push) Successful in 4s
Plugin Library CI / publish (06.UIFarme) (push) Successful in 17s
Plugin Library CI / publish (09.CodeChecker) (push) Successful in 19s
Plugin Library CI / publish (11.PointCloudTools) (push) Successful in 3s
Plugin Library CI / publish (12.WeixinMinigame) (push) Successful in 1m2s
Plugin Library CI / publish (07.RKTools) (push) Successful in 3s
Plugin Library CI / publish (08.UniTask) (push) Successful in 3s
Plugin Library CI / publish (10.StoryEditor) (push) Successful in 4s
Plugin Library CI / publish (10.XNode) (push) Successful in 4s
All checks were successful
Plugin Library CI / publish (00.BuildOriginality) (push) Successful in 7s
Plugin Library CI / publish (00.StaryEvo) (push) Successful in 11s
Plugin Library CI / publish (00.StaryEvoTools) (push) Successful in 10s
Plugin Library CI / publish (01.HybridCLR) (push) Successful in 7s
Plugin Library CI / publish (02.InformationSave) (push) Successful in 5s
Plugin Library CI / publish (03.YooAsset) (push) Successful in 38s
Plugin Library CI / publish (04.AudioCore) (push) Successful in 3s
Plugin Library CI / publish (05.TableTextConversion) (push) Successful in 4s
Plugin Library CI / publish (06.UIFarme) (push) Successful in 17s
Plugin Library CI / publish (09.CodeChecker) (push) Successful in 19s
Plugin Library CI / publish (11.PointCloudTools) (push) Successful in 3s
Plugin Library CI / publish (12.WeixinMinigame) (push) Successful in 1m2s
Plugin Library CI / publish (07.RKTools) (push) Successful in 3s
Plugin Library CI / publish (08.UniTask) (push) Successful in 3s
Plugin Library CI / publish (10.StoryEditor) (push) Successful in 4s
Plugin Library CI / publish (10.XNode) (push) Successful in 4s
This commit is contained in:
8
Assets/00.StaryEvo/Runtime/Tool/Timer.meta
Normal file
8
Assets/00.StaryEvo/Runtime/Tool/Timer.meta
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: cdd5f630d231efb48b075b3b7c318b34
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
56
Assets/00.StaryEvo/Runtime/Tool/Timer/TimerController.cs
Normal file
56
Assets/00.StaryEvo/Runtime/Tool/Timer/TimerController.cs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
using System;
|
||||||
|
using Stary.Evo;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.Serialization;
|
||||||
|
|
||||||
|
namespace Stary.Evo
|
||||||
|
{
|
||||||
|
public class TimerController : MonoBehaviour, IController
|
||||||
|
{
|
||||||
|
public string TimerName => gameObject.name;
|
||||||
|
private bool isStart = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 持续时间
|
||||||
|
/// </summary>
|
||||||
|
private float timeDuration;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 时间到达的事件
|
||||||
|
/// </summary>
|
||||||
|
private Action onArrivalTimeComplete;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 持续时间最大阈值
|
||||||
|
/// </summary>
|
||||||
|
public float timeDurationMax;
|
||||||
|
|
||||||
|
public void StartTimer(float timeDurationMax, Action onArrivalTimeComplete)
|
||||||
|
{
|
||||||
|
this.timeDurationMax = timeDurationMax;
|
||||||
|
this.onArrivalTimeComplete = onArrivalTimeComplete;
|
||||||
|
timeDuration = 0;
|
||||||
|
isStart = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Update()
|
||||||
|
{
|
||||||
|
if (isStart)
|
||||||
|
{
|
||||||
|
timeDuration += Time.deltaTime;
|
||||||
|
if (timeDuration >= timeDurationMax)
|
||||||
|
{
|
||||||
|
onArrivalTimeComplete?.Invoke();
|
||||||
|
this.GetSystem<TimerSystem>().RemoveTimer(TimerName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public IArchitecture GetArchitecture()
|
||||||
|
{
|
||||||
|
ITimerSystem system = this.GetSystem<TimerSystem>();
|
||||||
|
return system.GetArchitecture();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a0837a1376a9b5f4db88fe9e9601b981
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
67
Assets/00.StaryEvo/Runtime/Tool/Timer/TimerSystem.cs
Normal file
67
Assets/00.StaryEvo/Runtime/Tool/Timer/TimerSystem.cs
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Stary.Evo;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Stary.Evo
|
||||||
|
{
|
||||||
|
public interface ITimerSystem : ISystem
|
||||||
|
{
|
||||||
|
void CreateTimer(string timerName, float timeDuration, Action onArrivalTimeComplete);
|
||||||
|
void RemoveTimer(string timerName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TimerSystem : AbstractSystem, ITimerSystem
|
||||||
|
{
|
||||||
|
private static Dictionary<string, TimerController>
|
||||||
|
_timerControllers = new Dictionary<string, TimerController>();
|
||||||
|
|
||||||
|
private static GameObject timerSystem;
|
||||||
|
|
||||||
|
protected override void OnInit()
|
||||||
|
{
|
||||||
|
_timerControllers = new Dictionary<string, TimerController>();
|
||||||
|
timerSystem = new GameObject("Timer");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CreateTimer(string timerName, float timeDuration, Action onArrivalTimeComplete)
|
||||||
|
{
|
||||||
|
if (_timerControllers.ContainsKey(timerName))
|
||||||
|
{
|
||||||
|
Debug.LogError($"TimerSystem CreateTimer 重复创建定时器 {timerName}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var _timer = new GameObject(timerName);
|
||||||
|
_timer.transform.SetParent(timerSystem.transform);
|
||||||
|
var timerController = _timer.AddComponent<TimerController>();
|
||||||
|
_timerControllers.Add(timerName, timerController);
|
||||||
|
timerController.StartTimer(timeDuration, onArrivalTimeComplete);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveTimer(string timerName)
|
||||||
|
{
|
||||||
|
if (_timerControllers.ContainsKey(timerName))
|
||||||
|
{
|
||||||
|
var timerController = _timerControllers[timerName];
|
||||||
|
GameObject.Destroy(timerController.gameObject);
|
||||||
|
_timerControllers.Remove(timerName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public override void Dispose()
|
||||||
|
{
|
||||||
|
foreach (var controller in _timerControllers)
|
||||||
|
{
|
||||||
|
if (controller.Value != null)
|
||||||
|
{
|
||||||
|
GameObject.Destroy(controller.Value.gameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GameObject.Destroy(timerSystem.gameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/00.StaryEvo/Runtime/Tool/Timer/TimerSystem.cs.meta
Normal file
11
Assets/00.StaryEvo/Runtime/Tool/Timer/TimerSystem.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8b5962b06d3756b41b29b0496e9e996f
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "com.staryevo.main",
|
"name": "com.staryevo.main",
|
||||||
"version": "2.1.14",
|
"version": "2.1.15",
|
||||||
"displayName": "00.StaryEvo",
|
"displayName": "00.StaryEvo",
|
||||||
"description": "This is an Framework package(后台服务器版本,端口9527)",
|
"description": "This is an Framework package(后台服务器版本,端口9527)",
|
||||||
"unity": "2021.3",
|
"unity": "2021.3",
|
||||||
|
|||||||
Reference in New Issue
Block a user