1
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "BITKits.UX.Components",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:a209c53514018594f9f482516f2a6781",
|
||||
"GUID:6ef4ed8ff60a7aa4bb60a8030e6f4008",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
||||
"GUID:be17a8778dbfe454890ed8279279e153",
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
37
Unity/Scripts/UX/Components/UXDataComponents/QRBuilder.cs
Normal file
37
Unity/Scripts/UX/Components/UXDataComponents/QRBuilder.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using BITKit;
|
||||
using BITKit.UX;
|
||||
using UnityEngine.Networking;
|
||||
namespace BITKit.UX.Components
|
||||
{
|
||||
[System.Serializable]
|
||||
public class QRBuilder : StringComponent
|
||||
{
|
||||
public TranslateSO so;
|
||||
public UXImage image;
|
||||
public InitializationState state;
|
||||
protected override async void OnSet(string value)
|
||||
{
|
||||
state = InitializationState.Initializing;
|
||||
var url = so.Get(value);
|
||||
using (var request = UnityWebRequestTexture.GetTexture(url))
|
||||
{
|
||||
Debug.Log(url);
|
||||
await request.SendWebRequest();
|
||||
BITApp.CancellationTokenSource.Token.ThrowIfCancellationRequested();
|
||||
if (request.result is UnityWebRequest.Result.Success)
|
||||
{
|
||||
var texture = DownloadHandlerTexture.GetContent(request);
|
||||
image.Set(texture);
|
||||
state = InitializationState.Initialized;
|
||||
}
|
||||
else
|
||||
{
|
||||
state = InitializationState.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
108
Unity/Scripts/UX/Components/UXDataComponents/UXDataComponents.cs
Normal file
108
Unity/Scripts/UX/Components/UXDataComponents/UXDataComponents.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine.Events;
|
||||
using BITKit.UX;
|
||||
namespace BITKit.UX.Components
|
||||
{
|
||||
public abstract class StringComponent : DataComponents
|
||||
{
|
||||
public override void OnStart()
|
||||
{
|
||||
Data.AddListener<string>(key, OnSet);
|
||||
}
|
||||
public override void OnStop()
|
||||
{
|
||||
Data.RemoveListender<string>(key, OnSet);
|
||||
}
|
||||
protected abstract void OnSet(string value);
|
||||
}
|
||||
[System.Serializable]
|
||||
public sealed class Text : StringComponent
|
||||
{
|
||||
public Provider output;
|
||||
protected override async void OnSet(string value)
|
||||
{
|
||||
await UniTask.SwitchToMainThread();
|
||||
output.Set(value);
|
||||
}
|
||||
}
|
||||
[System.Serializable]
|
||||
public sealed class TranslateText : StringComponent
|
||||
{
|
||||
ITranslator translator;
|
||||
public Provider output;
|
||||
public TranslateSO so;
|
||||
public string source;
|
||||
public override void OnStart()
|
||||
{
|
||||
base.OnStart();
|
||||
source = output.Get<string>();
|
||||
translator = DI.Get<ITranslator>();
|
||||
translator.OnChangeLanguage += OnTranslate;
|
||||
}
|
||||
protected override async void OnSet(string value)
|
||||
{
|
||||
source = value;
|
||||
value = so?.GetAt(value);
|
||||
await UniTask.SwitchToMainThread();
|
||||
output.Set(value);
|
||||
}
|
||||
public override void OnStop()
|
||||
{
|
||||
translator.OnChangeLanguage -= OnTranslate;
|
||||
}
|
||||
void OnTranslate(string langs)
|
||||
{
|
||||
OnSet(source);
|
||||
}
|
||||
}
|
||||
[System.Serializable]
|
||||
public sealed class Event : StringComponent
|
||||
{
|
||||
public UnityEvent<string> output;
|
||||
protected override async void OnSet(string value)
|
||||
{
|
||||
await UniTask.SwitchToMainThread();
|
||||
output.Invoke(value);
|
||||
}
|
||||
}
|
||||
[System.Serializable]
|
||||
public sealed class BoolEvent : DataComponents
|
||||
{
|
||||
public UnityEvent<bool> outputEvent;
|
||||
public UnityEvent ifTrueEvent;
|
||||
public UnityEvent ifFlaseEvent;
|
||||
public override void OnStart()
|
||||
{
|
||||
Data.AddListener<bool>(key, OnSetBool, true);
|
||||
}
|
||||
public override void OnStop()
|
||||
{
|
||||
Data.RemoveListender<bool>(key, OnSetBool);
|
||||
}
|
||||
async void OnSetBool(bool boolean)
|
||||
{
|
||||
try
|
||||
{
|
||||
await UniTask.SwitchToMainThread(BITApp.CancellationTokenSource.Token);
|
||||
outputEvent.Invoke(boolean);
|
||||
|
||||
if (boolean is true)
|
||||
ifTrueEvent.Invoke();
|
||||
else
|
||||
ifFlaseEvent.Invoke();
|
||||
}
|
||||
catch (System.OperationCanceledException)
|
||||
{
|
||||
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user