-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "BetterServices.Editor", | ||
"rootNamespace": "Better.Services", | ||
"references": [ | ||
"GUID:1c5574afb40e5fe4ca9e9c156009297b" | ||
], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Arcueid D'athemon (https://github.com/uurha) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Better Services | ||
This plugins provides basic implementation for services pattern | ||
|
||
## Install | ||
[How to install](https://github.com/uurha/BetterPluginCollection/wiki/How-to-install) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "BetterServices.Runtime", | ||
"rootNamespace": "Better.Services", | ||
"references": [ | ||
"GUID:441b78e90a9cf724ab41c6eed8c0b93d", | ||
"GUID:a59e3daedde9ca94bba45364d4ead25f" | ||
], | ||
"includePlatforms": [], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Better.Services.Runtime.Interfaces | ||
{ | ||
public interface IService | ||
{ | ||
public bool Initialized { get; } | ||
|
||
public Task InitializeAsync(CancellationToken cancellationToken); | ||
|
||
public Task PostInitializeAsync(CancellationToken cancellationToken); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Better.Services.Runtime.Interfaces; | ||
using UnityEngine; | ||
|
||
namespace Better.Services.Runtime | ||
{ | ||
public abstract class MonoService : MonoBehaviour, IService | ||
{ | ||
// TODO: Add version dependency | ||
private CancellationTokenSource _destroyCancellationToken; | ||
|
||
public bool Initialized { get; private set; } | ||
protected CancellationToken DestroyCancellationToken => _destroyCancellationToken.Token; | ||
|
||
protected virtual void Awake() | ||
{ | ||
_destroyCancellationToken = new(); | ||
} | ||
|
||
async Task IService.InitializeAsync(CancellationToken cancellationToken) | ||
{ | ||
Debug.Log($"[{GetType().Name}] {nameof(IService.InitializeAsync)}"); | ||
|
||
if (Initialized) | ||
{ | ||
Debug.LogError($"[{GetType().Name}] {nameof(IService.InitializeAsync)}: already initialized"); | ||
return; | ||
} | ||
|
||
var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(DestroyCancellationToken, cancellationToken); | ||
cancellationToken = linkedTokenSource.Token; | ||
|
||
await OnInitializeAsync(cancellationToken); | ||
if (cancellationToken.IsCancellationRequested) | ||
{ | ||
return; | ||
} | ||
|
||
Initialized = true; | ||
} | ||
|
||
Task IService.PostInitializeAsync(CancellationToken cancellationToken) | ||
{ | ||
if (!Initialized) | ||
{ | ||
Debug.LogError($"[{GetType().Name}] {nameof(IService.PostInitializeAsync)}: not initialized"); | ||
return Task.CompletedTask; | ||
} | ||
|
||
Debug.Log($"[{GetType().Name}] {nameof(IService.PostInitializeAsync)}"); | ||
|
||
var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(DestroyCancellationToken, cancellationToken); | ||
cancellationToken = linkedTokenSource.Token; | ||
|
||
return OnPostInitializeAsync(cancellationToken); | ||
} | ||
|
||
protected abstract Task OnInitializeAsync(CancellationToken cancellationToken); | ||
protected abstract Task OnPostInitializeAsync(CancellationToken cancellationToken); | ||
|
||
protected virtual void OnDestroy() | ||
{ | ||
_destroyCancellationToken?.Cancel(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Better.Services.Runtime.Interfaces; | ||
using Better.Validation.Runtime.Attributes; | ||
using UnityEngine; | ||
|
||
namespace Better.Services.Runtime | ||
{ | ||
[Serializable] | ||
public abstract class PocoService : IService | ||
{ | ||
public bool Initialized { get; private set; } | ||
|
||
async Task IService.InitializeAsync(CancellationToken cancellationToken) | ||
{ | ||
Debug.Log($"[{GetType().Name}] {nameof(IService.InitializeAsync)}"); | ||
|
||
if (Initialized) | ||
{ | ||
Debug.LogError($"[{GetType().Name}] {nameof(IService.InitializeAsync)}: already initialized"); | ||
return; | ||
} | ||
|
||
Initialized = true; | ||
await OnInitializeAsync(cancellationToken); | ||
Initialized = !cancellationToken.IsCancellationRequested; | ||
} | ||
|
||
Task IService.PostInitializeAsync(CancellationToken cancellationToken) | ||
{ | ||
if (!Initialized) | ||
{ | ||
Debug.LogError($"[{GetType().Name}] {nameof(IService.PostInitializeAsync)}: not initialized"); | ||
return Task.CompletedTask; | ||
} | ||
|
||
Debug.Log($"[{GetType().Name}] {nameof(IService.PostInitializeAsync)}"); | ||
return OnPostInitializeAsync(cancellationToken); | ||
} | ||
|
||
protected abstract Task OnInitializeAsync(CancellationToken cancellationToken); | ||
protected abstract Task OnPostInitializeAsync(CancellationToken cancellationToken); | ||
} | ||
|
||
[Serializable] | ||
public abstract class PocoService<TSettings> : PocoService where TSettings : ScriptableObject | ||
{ | ||
[NotNull] [SerializeField] private TSettings _settings; | ||
|
||
protected TSettings Settings => _settings; | ||
|
||
protected override Task OnInitializeAsync(CancellationToken cancellationToken) | ||
{ | ||
if (Settings == null) | ||
{ | ||
throw new NullReferenceException($"[{GetType().Name}] {nameof(OnInitializeAsync)}: {nameof(Settings)} cannot be null"); | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
protected override Task OnPostInitializeAsync(CancellationToken cancellationToken) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "com.tdw.betterservices", | ||
"displayName": "Better Services", | ||
"version": "0.0.1", | ||
"unity": "2021.3", | ||
"description": " ", | ||
"dependencies": { | ||
"com.uurha.bettervalidation": "1.0.55" | ||
}, | ||
"author": { | ||
"name": "Techno Dwarf Works", | ||
"url": "https://github.com/techno-dwarf-works" | ||
}, | ||
"changelogUrl": "https://github.com/techno-dwarf-works/better-services", | ||
"documentationUrl": "https://github.com/techno-dwarf-works/better-services/tree/main#readme", | ||
"license": "MIT", | ||
"licensesUrl":"https://github.com/techno-dwarf-works/better-services/blob/main/LICENSE", | ||
"keywords": [ | ||
"better", | ||
"services", | ||
"reference managment", | ||
"pattern" | ||
], | ||
"samples": [ | ||
{ | ||
"displayName": "Default samples", | ||
"description": "Contains test samples", | ||
"path": "Samples~/TestSamples" | ||
} | ||
] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.