Before 优化 机场
This commit is contained in:
@@ -135,7 +135,9 @@ namespace BITKit
|
||||
[RuntimeInitializeOnLoadMethod]
|
||||
private static void Reload()
|
||||
{
|
||||
|
||||
BITApp.WalkUntilInitialize = new();
|
||||
|
||||
|
||||
IsPlaying = true;
|
||||
//启动BITApp
|
||||
BITApp.SynchronizationContext = SynchronizationContext.Current;
|
||||
|
8
Assets/BITKit/Unity/Scripts/Impact.meta
Normal file
8
Assets/BITKit/Unity/Scripts/Impact.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee77d81b8f27d6a44923a2a6901a66e0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "Net.BITKit.Impact.Unity",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:89bd0da52dc3cc94daadea6252c6ad1b",
|
||||
"GUID:d525ad6bd40672747bde77962f1c401e",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 24866f14213d2124aa20be037476b521
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
29
Assets/BITKit/Unity/Scripts/Impact/ScriptableImpact.cs
Normal file
29
Assets/BITKit/Unity/Scripts/Impact/ScriptableImpact.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Policy;
|
||||
using AYellowpaper.SerializedCollections;
|
||||
using BITKit;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Net.BITKit.Impact
|
||||
{
|
||||
|
||||
public class ScriptableImpact : ScriptableObject,ITag
|
||||
{
|
||||
[SerializeReference, SubclassSelector] private IReference[] tags;
|
||||
[SerializeField] private int priority;
|
||||
|
||||
[SerializeField] private Transform[] prefabs;
|
||||
[SerializeField] private AudioClip[] audioClips;
|
||||
|
||||
public int Hash { get; set; }
|
||||
public IReadOnlyCollection<string> Tags => tags.Select(x=>x.Get()).ToArray();
|
||||
|
||||
public Transform Prefab => prefabs.Random();
|
||||
public AudioClip AudioClip => audioClips.Random();
|
||||
public int Priority => priority;
|
||||
}
|
||||
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c2048d435d8387842b5b0c9bf5498a1f
|
||||
guid: ac8fd6229773587428b5dca77471e986
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -42,7 +42,9 @@ namespace BITKit.Pool
|
||||
ReadyPool.Clear();
|
||||
}
|
||||
|
||||
public async UniTask<T> Spawn<T>(string path) where T : class
|
||||
public int DefaultCapacity { get; set; } = 8;
|
||||
|
||||
public async UniTask<T> Spawn<T>(string path,object prefab) where T : class
|
||||
{
|
||||
if (Pool.ContainsKey(path))
|
||||
{
|
||||
@@ -55,7 +57,7 @@ namespace BITKit.Pool
|
||||
return obj as T;
|
||||
}
|
||||
|
||||
if (usingList.Count>0)
|
||||
if (usingList.Count>=DefaultCapacity)
|
||||
{
|
||||
obj = usingList[0];
|
||||
usingList.RemoveAt(0);
|
||||
@@ -81,13 +83,33 @@ namespace BITKit.Pool
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
if (typeof(Object).IsAssignableFrom(typeof(T)))
|
||||
{
|
||||
var asset =await ModService.LoadAsset<T>(path);
|
||||
var asset =prefab as T ?? await ModService.LoadAsset<T>(path);
|
||||
if (asset is Object o)
|
||||
{
|
||||
var instance = Object.Instantiate(o);
|
||||
list.Add(instance);
|
||||
UsingPool.GetOrCreate(path).Add(instance);
|
||||
ReadyPool.GetOrCreate(path);
|
||||
|
||||
if (instance is GameObject gameObject)
|
||||
{
|
||||
gameObject.GetCancellationTokenOnDestroy().Register(DisposeGo);
|
||||
|
||||
void DisposeGo()
|
||||
{
|
||||
Pool.GetOrCreate(path).TryRemove(gameObject);
|
||||
UsingPool.GetOrCreate(path).TryRemove(gameObject);
|
||||
var queue = ReadyPool.GetOrCreate(path);
|
||||
var removeObjectList = new List<object>(queue);
|
||||
removeObjectList.TryRemove(gameObject);
|
||||
queue.Clear();
|
||||
foreach (var x in removeObjectList)
|
||||
{
|
||||
queue.Enqueue(x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return instance as T;
|
||||
}
|
||||
}
|
||||
|
@@ -1,18 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class NewBehaviourScript : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
8
Assets/BITKit/Unity/Scripts/UX/Localization.meta
Normal file
8
Assets/BITKit/Unity/Scripts/UX/Localization.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c849275eb4fd266468253c3fb286f6c1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using BITKit;
|
||||
using BITKit.UX;
|
||||
using Net.BITKit.Localization;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace Net.BITKit.UX
|
||||
{
|
||||
public class UXLocalization
|
||||
{
|
||||
public string USS { get; set; } = "localized";
|
||||
private readonly IUXService _uxService;
|
||||
private readonly ILocalizationService _localizationService;
|
||||
|
||||
public UXLocalization(IUXService uxService, ILocalizationService localizationService)
|
||||
{
|
||||
_uxService = uxService;
|
||||
_localizationService = localizationService;
|
||||
|
||||
_localizationService.OnLanguageChanged += OnLanguageChanged;
|
||||
}
|
||||
|
||||
private void OnLanguageChanged(string arg1, string arg2)
|
||||
{
|
||||
if(_uxService.Root is not VisualElement visualElement)return;
|
||||
|
||||
foreach (var x in visualElement.Query<Label>(className:USS).ToList())
|
||||
{
|
||||
if (string.IsNullOrEmpty(x.viewDataKey))continue;
|
||||
x.text = _localizationService.GetLocalizedString('#'+x.viewDataKey);
|
||||
}
|
||||
|
||||
foreach (var x in visualElement.Query<Button>(className:USS).ToList())
|
||||
{
|
||||
if(string.IsNullOrEmpty(x.viewDataKey))continue;
|
||||
x.text = _localizationService.GetLocalizedString('#'+x.viewDataKey);
|
||||
}
|
||||
|
||||
foreach (var x in visualElement.Query(className:USS).ToList())
|
||||
{
|
||||
if(string.IsNullOrEmpty(x.viewDataKey))continue;
|
||||
|
||||
ContinueWithBaseType(x.GetType());
|
||||
continue;
|
||||
|
||||
void ContinueWithBaseType(Type type)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (type == null || type == typeof(object)) return;
|
||||
if (type.GetProperty("label", ReflectionHelper.Flags) is { } propertyInfo)
|
||||
{
|
||||
//Debug.Log($"{x.name}:#{x.viewDataKey}");
|
||||
propertyInfo.SetValue(x, _localizationService.GetLocalizedString('#' + x.viewDataKey));
|
||||
}
|
||||
else
|
||||
{
|
||||
type = type.BaseType;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 01963dbed2bec23468d2a4b617bdcfc5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -3,6 +3,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Net.BITKit.Localization;
|
||||
using Newtonsoft.Json;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
@@ -15,11 +16,13 @@ namespace BITKit.UX.Settings
|
||||
public interface IUXSettings:IUXPanel{}
|
||||
public class UXSettings<T,TValue> : UIToolkitSubPanel<T>,IUXSettings where T: IUXPanel
|
||||
{
|
||||
private readonly ILocalizationService _localizationService;
|
||||
private readonly TValue _value;
|
||||
private readonly IWrapper<TValue> _valueWrapper;
|
||||
public UXSettings(IServiceProvider serviceProvider, IWrapper<TValue> valueWrapper) : base(serviceProvider)
|
||||
public UXSettings(IServiceProvider serviceProvider, IWrapper<TValue> valueWrapper, ILocalizationService localizationService) : base(serviceProvider)
|
||||
{
|
||||
_valueWrapper = valueWrapper;
|
||||
_localizationService = localizationService;
|
||||
_value = _valueWrapper.Value;
|
||||
}
|
||||
|
||||
@@ -36,80 +39,98 @@ namespace BITKit.UX.Settings
|
||||
_settingsContainer.Clear();
|
||||
foreach (var propertyInfo in typeof(TValue).GetProperties())
|
||||
{
|
||||
if(propertyInfo.SetMethod is null)continue;
|
||||
var name = propertyInfo.GetDisplayName();
|
||||
var value = propertyInfo.GetValue(_valueWrapper.Value);
|
||||
switch (propertyInfo.PropertyType)
|
||||
|
||||
if (CreateVisualElement() is { } visualElement)
|
||||
{
|
||||
case var type when type == typeof(bool):
|
||||
visualElement.viewDataKey = name;
|
||||
visualElement.AddToClassList("localized");
|
||||
}
|
||||
|
||||
VisualElement CreateVisualElement()
|
||||
{
|
||||
switch (propertyInfo.PropertyType)
|
||||
{
|
||||
var checkBox = _settingsContainer.Create<Toggle>();
|
||||
checkBox.label = name;
|
||||
checkBox.SetValueWithoutNotify(value.As<bool>());
|
||||
checkBox.RegisterValueChangedCallback(x =>
|
||||
case var type when type == typeof(bool):
|
||||
{
|
||||
propertyInfo.SetValue(_value,x.newValue);
|
||||
Save();
|
||||
});
|
||||
}
|
||||
break;
|
||||
case var type when type == typeof(float):
|
||||
{
|
||||
var slider = _settingsContainer.Create<Slider>();
|
||||
slider.label = name;
|
||||
slider.showInputField = true;
|
||||
slider.showMixedValue = true;
|
||||
slider.lowValue = 1;
|
||||
slider.highValue = 100;
|
||||
slider.SetValueWithoutNotify(value.As<float>());
|
||||
slider.RegisterValueChangedCallback(x =>
|
||||
var checkBox = _settingsContainer.Create<Toggle>();
|
||||
checkBox.label = _localizationService.GetLocalizedString(name);
|
||||
checkBox.SetValueWithoutNotify(value.As<bool>());
|
||||
checkBox.RegisterValueChangedCallback(x =>
|
||||
{
|
||||
propertyInfo.SetValue(_value, x.newValue);
|
||||
Save();
|
||||
});
|
||||
return checkBox;
|
||||
}
|
||||
break;
|
||||
case var type when type == typeof(float):
|
||||
{
|
||||
propertyInfo.SetValue(_value,x.newValue);
|
||||
Save();
|
||||
});
|
||||
}
|
||||
break;
|
||||
case var type when type == typeof(int):
|
||||
{
|
||||
var slider = _settingsContainer.Create<SliderInt>();
|
||||
slider.label = name;
|
||||
slider.showInputField = true;
|
||||
slider.showMixedValue = true;
|
||||
slider.lowValue = 1;
|
||||
slider.highValue = 100;
|
||||
slider.SetValueWithoutNotify(value.As<int>());
|
||||
slider.RegisterValueChangedCallback(x =>
|
||||
var slider = _settingsContainer.Create<Slider>();
|
||||
slider.label = _localizationService.GetLocalizedString(name);
|
||||
slider.showInputField = true;
|
||||
slider.showMixedValue = true;
|
||||
slider.lowValue = 1;
|
||||
slider.highValue = 100;
|
||||
slider.SetValueWithoutNotify(value.As<float>());
|
||||
slider.RegisterValueChangedCallback(x =>
|
||||
{
|
||||
propertyInfo.SetValue(_value, x.newValue);
|
||||
Save();
|
||||
});
|
||||
return slider;
|
||||
}
|
||||
break;
|
||||
case var type when type == typeof(int):
|
||||
{
|
||||
propertyInfo.SetValue(_value,x.newValue);
|
||||
Save();
|
||||
});
|
||||
}
|
||||
break;
|
||||
case var type when type == typeof(string):
|
||||
{
|
||||
var textField = _settingsContainer.Create<TextField>();
|
||||
textField.label = name;
|
||||
textField.SetValueWithoutNotify(value.As<string>());
|
||||
textField.RegisterValueChangedCallback(x =>
|
||||
var slider = _settingsContainer.Create<SliderInt>();
|
||||
slider.label = _localizationService.GetLocalizedString(name);
|
||||
slider.showInputField = true;
|
||||
slider.showMixedValue = true;
|
||||
slider.lowValue = 1;
|
||||
slider.highValue = 100;
|
||||
slider.SetValueWithoutNotify(value.As<int>());
|
||||
slider.RegisterValueChangedCallback(x =>
|
||||
{
|
||||
propertyInfo.SetValue(_value, x.newValue);
|
||||
Save();
|
||||
});
|
||||
return slider;
|
||||
}
|
||||
break;
|
||||
case var type when type == typeof(string):
|
||||
{
|
||||
propertyInfo.SetValue(_value,x.newValue);
|
||||
Save();
|
||||
});
|
||||
}
|
||||
break;
|
||||
case var type when type.IsEnum:
|
||||
{
|
||||
var enumField = _settingsContainer.Create<EnumField>();
|
||||
enumField.label = name;
|
||||
|
||||
enumField.Init(value as Enum);
|
||||
enumField.SetValueWithoutNotify(value as Enum);
|
||||
enumField.RegisterValueChangedCallback(x =>
|
||||
var textField = _settingsContainer.Create<TextField>();
|
||||
textField.label = _localizationService.GetLocalizedString(name);
|
||||
textField.SetValueWithoutNotify(value.As<string>());
|
||||
textField.RegisterValueChangedCallback(x =>
|
||||
{
|
||||
propertyInfo.SetValue(_value, x.newValue);
|
||||
Save();
|
||||
});
|
||||
return textField;
|
||||
}
|
||||
break;
|
||||
case var type when type.IsEnum:
|
||||
{
|
||||
propertyInfo.SetValue(_value,x.newValue);
|
||||
Save();
|
||||
});
|
||||
var enumField = _settingsContainer.Create<EnumField>();
|
||||
enumField.label = _localizationService.GetLocalizedString(name);
|
||||
|
||||
enumField.Init(value as Enum);
|
||||
enumField.SetValueWithoutNotify(value as Enum);
|
||||
enumField.RegisterValueChangedCallback(x =>
|
||||
{
|
||||
propertyInfo.SetValue(_value, x.newValue);
|
||||
Save();
|
||||
});
|
||||
return enumField;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -461,6 +461,11 @@ namespace BITKit
|
||||
return true;
|
||||
}
|
||||
component = self.GetComponentInParent<T>(true);
|
||||
if (component is not null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
component = self.GetComponent<T>();
|
||||
return component is not null;
|
||||
}
|
||||
public static bool TryGetFirstOrDefault<T>(this IEnumerable<T> self, out T value)
|
||||
|
8
Assets/BITKit/Unity/Scripts/VFX.meta
Normal file
8
Assets/BITKit/Unity/Scripts/VFX.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fdd91b53bafc0804d8d8382169b67308
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "Net.Project.B.VFX.Unity",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:d525ad6bd40672747bde77962f1c401e",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:24866f14213d2124aa20be037476b521"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 21442fa5e0c49e3408652e96f6565891
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
63
Assets/BITKit/Unity/Scripts/VFX/VFXService.cs
Normal file
63
Assets/BITKit/Unity/Scripts/VFX/VFXService.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using Net.BITKit.Impact;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Net.BITKit.VFX
|
||||
{
|
||||
public class VFXService
|
||||
{
|
||||
private readonly IEntitiesService _entitiesService;
|
||||
private readonly IReadOnlyCollection<ScriptableImpact> _scriptableImpacts;
|
||||
|
||||
public VFXService(IEntitiesService entitiesService)
|
||||
{
|
||||
_entitiesService = entitiesService;
|
||||
_scriptableImpacts = _entitiesService.QueryComponents<ScriptableImpact>().ToArray();
|
||||
}
|
||||
|
||||
public AudioClip GetAudioClip(IReadOnlyCollection<string> tags)
|
||||
{
|
||||
var bestMatches = Search(tags);
|
||||
|
||||
return bestMatches.AudioClip;
|
||||
}
|
||||
|
||||
public Transform GetPrefab(IReadOnlyCollection<string> tags)
|
||||
{
|
||||
var bestMatches = Search(tags);
|
||||
return bestMatches.Prefab;
|
||||
}
|
||||
|
||||
private ScriptableImpact Search(IReadOnlyCollection<string> tags)
|
||||
{
|
||||
var maxPoint = 0;
|
||||
var max = new HashSet<ScriptableImpact>();
|
||||
foreach (var impact in _scriptableImpacts)
|
||||
{
|
||||
var point = impact.Tags.Intersect(tags).Count();
|
||||
if (point > maxPoint)
|
||||
{
|
||||
maxPoint = point;
|
||||
max.Clear();
|
||||
max.Add(impact);
|
||||
}else if (point == maxPoint)
|
||||
{
|
||||
max.Add(impact);
|
||||
}
|
||||
}
|
||||
|
||||
if (max.Count is 1)
|
||||
{
|
||||
return max.First();
|
||||
}
|
||||
|
||||
return max.OrderByDescending(x => x.Priority).First();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
11
Assets/BITKit/Unity/Scripts/VFX/VFXService.cs.meta
Normal file
11
Assets/BITKit/Unity/Scripts/VFX/VFXService.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0bee817d1b196f842899232c3a28d504
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user