1
This commit is contained in:
18
Src/PlayerAction/Net.Project.B.PlayerAction.asmdef
Normal file
18
Src/PlayerAction/Net.Project.B.PlayerAction.asmdef
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "Net.Project.B.PlayerAction",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23",
|
||||
"GUID:d8b63aba1907145bea998dd612889d6b"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": true
|
||||
}
|
7
Src/PlayerAction/Net.Project.B.PlayerAction.asmdef.meta
Normal file
7
Src/PlayerAction/Net.Project.B.PlayerAction.asmdef.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 91a84969978233c4480e0c9f2fed1153
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
79
Src/PlayerAction/PlayerActionService.cs
Normal file
79
Src/PlayerAction/PlayerActionService.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using BITKit;
|
||||
using BITKit.Tween;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Unity.Mathematics;
|
||||
|
||||
namespace Net.Project.B.PlayerAction
|
||||
{
|
||||
public interface IPlayerAction
|
||||
{
|
||||
string Name { get; }
|
||||
float Progress { get; }
|
||||
float Duration { get;}
|
||||
bool IsCancelable { get; }
|
||||
UniTaskCompletionSource CompletionSource { get; }
|
||||
public event Action<float> OnProgress;
|
||||
UniTask StartAsync();
|
||||
}
|
||||
|
||||
public class PlayerAction:IPlayerAction,IDisposable
|
||||
{
|
||||
public PlayerAction()
|
||||
{
|
||||
OnProgress += SetProgress;
|
||||
}
|
||||
|
||||
private void SetProgress(float obj)
|
||||
{
|
||||
Progress = obj;
|
||||
}
|
||||
|
||||
public string Name { get; set; } = "Busy";
|
||||
public float Duration { get; set; } = 1;
|
||||
public float Progress { get;private set; }
|
||||
public bool IsCancelable { get; set; }
|
||||
public UniTaskCompletionSource CompletionSource { get; } = new();
|
||||
public event Action<float> OnProgress;
|
||||
public async UniTask StartAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
await BITween.Lerp(OnProgress, 0f, 1f, Duration, math.lerp);
|
||||
|
||||
CompletionSource.TrySetResult();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
BIT4Log.LogException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
CompletionSource.TrySetCanceled();
|
||||
}
|
||||
}
|
||||
|
||||
public interface IPlayerActionComponent
|
||||
{
|
||||
public event Action<IPlayerAction> OnPlayerActionStarted;
|
||||
UniTask StartAction(IPlayerAction action);
|
||||
}
|
||||
|
||||
public class PlayerActionComponent : IPlayerActionComponent
|
||||
{
|
||||
public event Action<IPlayerAction> OnPlayerActionStarted;
|
||||
|
||||
public async UniTask StartAction(IPlayerAction action)
|
||||
{
|
||||
OnPlayerActionStarted?.Invoke(action);
|
||||
await action.StartAsync();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
11
Src/PlayerAction/PlayerActionService.cs.meta
Normal file
11
Src/PlayerAction/PlayerActionService.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2d05900e4cb7b0e4884283b4e93af142
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user