This commit is contained in:
CortexCore
2024-05-31 01:23:15 +08:00
parent c798b224be
commit 299082fe27
164 changed files with 3604 additions and 2018 deletions

View File

@@ -0,0 +1,44 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
namespace BITKit.UX
{
public class UXDateTime : MonoBehaviour
{
[SerializeReference,SubclassSelector]private IReference timeFormat;
[SerializeReference, SubclassSelector] private IReference path;
[SerializeField] private bool isTimerNotClock;
private DateTime _dateTime;
private DateTime _startTime;
private Label timeLabel;
private string lastTime;
private void Start()
{
timeLabel = GetComponent<UIDocument>().rootVisualElement.Q<Label>(path.Value);
_startTime = DateTime.Now;
}
private void Update()
{
var time = DateTime.Now;
if (isTimerNotClock)
{
time = new DateTime(DateTime.Now.Ticks - _startTime.Ticks);
}
var str = GetTime();
if(Equals(str,lastTime)) return;
lastTime = str;
timeLabel.text = lastTime;
return;
string GetTime() => timeFormat is not null
? time.ToString(timeFormat.Value)
: time.ToString(CultureInfo.InvariantCulture);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2ed057e1d7e0e5349a687d9ba41abcc7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,44 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net.Http;
using BITKit;
using BITKit.UX;
using Cysharp.Threading.Tasks;
using Newtonsoft.Json.Linq;
using UnityEngine;
using UnityEngine.UIElements;
public class UXWeather : MonoBehaviour
{
[SerializeReference,SubclassSelector] private ITicker ticker;
[SerializeReference,SubclassSelector] private IReference api;
private readonly HttpClient _httpClient=new();
[UXBindPath("temperature-label")] private Label _temperatureLabel;
private void OnEnable()
{
ticker.Add(OnTick);
}
private void OnDisable()
{
ticker.Remove(OnTick);
}
private void Start()
{
UXUtils.Inject(this);
OnTick(Time.deltaTime);
}
private async void OnTick(float obj)
{
var json =await _httpClient.GetStringAsync(api.Value);
if(destroyCancellationToken.IsCancellationRequested)return;
var jObject = JObject.Parse(json);
var temperature = jObject["lives"]![0]!["temperature"]!.ToObject<string>();
await UniTask.SwitchToMainThread();
if (destroyCancellationToken.IsCancellationRequested) return;
_temperatureLabel.text = $"{temperature}℃";
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e21061d5a601e8a4099d30674e76803a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: