更改文件架构

This commit is contained in:
CortexCore
2023-06-07 18:38:07 +08:00
parent 93292b1a59
commit ed84166723
720 changed files with 297 additions and 65 deletions

View File

@@ -0,0 +1,35 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace BITKit
{
public class AutoInvoke : MonoBehaviour
{
public UnityEvent onAwake = new();
public UnityEvent onStart = new();
public UnityEvent onEnabled = new();
public UnityEvent onDisabled = new();
public UnityEvent onDestory = new();
void Awake()
{
onAwake.Invoke();
}
void Start()
{
onStart.Invoke();
}
void OnEnabled()
{
onEnabled.Invoke();
}
void OnDisable()
{
onDisabled.Invoke();
}
void OnDestroy()
{
onDestory.Invoke();
}
}
}

View File

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

View File

@@ -0,0 +1,17 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit
{
public class AutoSetLayer : MonoBehaviour
{
public int layer;
void Start()
{
GetComponentsInChildren<Transform>(true).ForEach(x=>
{
x.gameObject.layer=layer;
});
}
}
}

View File

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

View File

@@ -0,0 +1,14 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit
{
public class ClipBoardHelper : MonoBehaviour
{
public string clip;
public void Excute()
{
UnityEngine.GUIUtility.systemCopyBuffer = clip;
}
}
}

View File

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

View File

@@ -0,0 +1,40 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cysharp.Threading.Tasks;
namespace BITKit
{
public class EffectPlayer : MonoBehaviour
{
[Header(Constant.Header.Settings)]
[SerializeField] float duration;
[Header(Constant.Header.Components)]
[SerializeField] ParticleSystem[] particleSystems;
[SerializeField] Behaviour[] behaviours;
void Start()
{
particleSystems.ForEach(x => x.Stop());
behaviours.ForEach(x => x.enabled = false);
}
public async void Excute()
{
particleSystems.ForEach(x =>
{
x.time = 0;
x.Play(true);
});
behaviours.ForEach(x =>
{
x.enabled = true;
});
await UniTask.Delay(System.TimeSpan.FromSeconds(duration));
if (BehaviourHelper.Actived)
{
behaviours.ForEach(x =>
{
x.enabled = false;
});
}
}
}
}

View File

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

View File

@@ -0,0 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Sirenix.OdinInspector;
namespace BITKit
{
public class ExcuteCommand : MonoBehaviour
{
public string command;
public void Excute()
{
Data.Set("Cmd", command);
}
}
}

View File

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

View File

@@ -0,0 +1,25 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace BITKit
{
public class ExcuteOnBehaviour : MonoBehaviour
{
public UnityEvent onAwake = new();
public UnityEvent onStart = new();
public UnityEvent onDestroy = new();
void Awake()
{
onAwake.Invoke();
}
void Start()
{
onStart.Invoke();
}
void OnDestroy()
{
onDestroy.Invoke();
}
}
}

View File

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

View File

@@ -0,0 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace BITKit
{
public class NewBehaviourScript : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
}

View File

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

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9bef47e46bf365c40939e75d554ac2b8
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,10 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit
{
public abstract class FormatData : Provider<string>
{
}
}

View File

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

View File

@@ -0,0 +1,24 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit
{
public class FormatDataToKeyValue : FormatData
{
[SubclassSelector, SerializeReference] public References key;
public Provider output;
Dictionary<string, string> dictionary = new();
public override string Get()
{
throw new System.NotImplementedException();
}
public override void Set(string value)
{
WWWForm form = new();
form.AddField("key", key);
form.AddField("value", value);
output?.Set(form);
}
}
}

View File

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

View File

@@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit
{
public class IfGreater : Provider<float>
{
public float value;
public bool inverse;
public Provider<bool> output;
public override float Get()
{
throw new System.NotImplementedException();
}
public override void Set(float t)
{
output?.Set(t > value ? inverse ? false : true : false);
}
}
}

View File

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

View File

@@ -0,0 +1,20 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace BITKit
{
public class JsonToJObject : Provider<string>
{
public Provider output;
public override string Get()
{
throw new System.NotImplementedException();
}
public override void Set(string t)
{
output.Set(JObject.Parse(t));
}
}
}

View File

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

View File

@@ -0,0 +1,17 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace BITKit
{
public class LoopEvent : MonoBehaviour
{
public UnityEvent[] events;
int currentIndex;
public void Excute()
{
events[currentIndex].Invoke();
currentIndex = ++currentIndex % events.Length;
}
}
}

View File

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

View File

@@ -0,0 +1,19 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Sirenix.OdinInspector;
using System.IO;
namespace BITKit
{
public class ReadFile : MonoBehaviour
{
[FilePath(AbsolutePath = true)]
public string path;
public Provider output;
[Button]
public void Excute()
{
output.Set(File.ReadAllText(path));
}
}
}

View File

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

View File

@@ -0,0 +1,46 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.UIElements;
#endif
namespace BITKit
{
public class ReadFromTextAsset : BITAction
{
public TextAsset asset;
public Provider output;
public TranslateSO translateSO;
public override void Excute()
{
BITAppForUnity.ThrowIfNotPlaying();
var value = asset.text;
if (translateSO)
{
value = translateSO.Get(value);
}
output.Set<string>(value);
}
}
#if UNITY_EDITOR
[UnityEditor.CustomEditor(typeof(ReadFromTextAsset))]
public class ReadFromTextAssetInspector : BITInspector<ReadFromTextAsset>
{
public override VisualElement CreateInspectorGUI()
{
CreateSubTitle("TextAsset Reader");
FillDefaultInspector(root, serializedObject, true);
var excute = root.Create<Button>();
//excute.bindingPath = nameof(ReadFromTextAsset.Excute);
excute.text = "读取文本";
excute.clicked += agent.Excute;
return root;
}
}
#endif
}

View File

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

View File

@@ -0,0 +1,78 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Sirenix.OdinInspector;
using System.IO;
using Cysharp.Threading.Tasks;
using BITKit.IO;
namespace BITKit
{
public class SaveToFile : Provider, IAction
{
public bool isPersistentData;
public bool crypto;
[SerializeReference, SubclassSelector] public References extensions;
[SerializeReference, SubclassSelector] public References path;
[SerializeReference, SubclassSelector] public NameProvider nameProvider;
public void Excute()
{
string path;
if (isPersistentData)
{
path = PathHelper.GetFolderPath(Utility.Path.persistentDataPath, this.path.Get());
}
else
{
path = PathHelper.GetFolderPath(Utility.Path.dataPath, this.path);
}
BITApp.Open(path);
}
public override async void Set<T>(T obj)
{
await UniTask.SwitchToThreadPool();
var path = GetPath();
BIT4Log.Log<SaveToFile>($"正在保存文件为:{path}");
switch (obj)
{
case string _string:
try
{
if (crypto)
{
_string = GZipHelper.GZipCompressString(_string);
}
File.WriteAllText(path, _string);
}
catch (System.Exception e)
{
Debug.LogWarning(e);
}
break;
case BITAssets assets:
assets.Build(path);
break;
case byte[] _bytes:
File.WriteAllBytes(path, _bytes);
break;
}
}
string GetPath()
{
string path;
var fileName = nameProvider.GetName(null, extensions);
if (isPersistentData)
{
path = PathHelper.GetFilePath(Utility.Path.persistentDataPath, this.path.Get(), fileName);
}
else
{
path = PathHelper.GetFilePath(Utility.Path.dataPath, this.path, fileName);
}
return path;
}
}
}

View File

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

View File

@@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit
{
public class SetColor : Provider<Color>
{
public MeshRenderer meshRenderer;
public override Color Get()
{
return meshRenderer.sharedMaterial.color;
}
public override void Set(Color t)
{
meshRenderer.sharedMaterial.color = t; ;
}
}
}

View File

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

View File

@@ -0,0 +1,44 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering.Universal;
using UnityEngine.UIElements;
namespace BITKit
{
public class SetRenderScale : Provider<float>
{
public UniversalRenderPipelineAsset asset;
public override float Get()
{
return asset.renderScale;
}
public override void Set(float t)
{
asset.renderScale = t;
}
}
#if UNITY_EDITOR
[UnityEditor.CustomEditor(typeof(SetRenderScale))]
public class SetRenderScaleInspector : BITInspector<SetRenderScale>
{
public override VisualElement CreateInspectorGUI()
{
FillDefaultInspector(root, serializedObject, true);
var slider = root.Create<Slider>();
slider.SetValueWithoutNotify(agent.asset.renderScale);
slider.label = "渲染倍数";
slider.showInputField=true;
slider.RegisterValueChangedCallback(OnValueUpdate);
return root;
}
void OnValueUpdate(ChangeEvent<float> newValueEvent)
{
BITAppForUnity.ThrowIfNotPlaying();
agent.Set(newValueEvent.newValue);
}
}
#endif
}

View File

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

View File

@@ -0,0 +1,46 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit
{
public class SetRotation : Provider
{
public Transform root;
public bool isLocal;
public Vector3 weight;
public Vector3 defaultEulur;
void Awake()
{
defaultEulur = isLocal ? transform.localEulerAngles : transform.eulerAngles;
}
public override void Set<T>(T obj)
{
switch (obj)
{
case float _float:
_SetRotation(Quaternion.Euler(defaultEulur + weight * _float));
break;
case Vector3 _vector3:
_SetRotation(Quaternion.Euler(_vector3));
break;
case Quaternion quaternion:
_SetRotation(quaternion);
break;
}
}
void _SetRotation(Quaternion eulur)
{
if (root)
{
if (isLocal)
{
root.localRotation = eulur;
}
else
{
root.rotation = eulur;
}
}
}
}
}

View File

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

View File

@@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit
{
public class ShowDictionary : Provider<IDictionary<string, string>>
{
public IDictionary<string, string> dictionary = new Dictionary<string, string>();
public override IDictionary<string, string> Get()
{
throw new System.NotImplementedException();
}
public override void Set(IDictionary<string, string> t)
{
dictionary = t;
}
}
}

View File

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

View File

@@ -0,0 +1,45 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit
{
public class ShowProfiler : BITBehavior, IDiagnostics
{
[Header(Constant.Header.Settings)]
[SubclassSelector, SerializeReference] public References pingAddress;
[Header(Constant.Header.Output)]
public Provider fpsOutput;
public Provider pingOutput;
DeltaTimer timer = new();
Ping ping;
[Header(Constant.Header.InternalVariables)]
public int frameRate;
// Update is called once per frame
void Update()
{
timer.Update();
frameRate = timer;
fpsOutput.Set((string)timer);
if (pingOutput is not null && (ping is null || ping.isDone))
{
if (ping is not null && ping.isDone)
{
pingOutput.Set(ping.time.ToString());
}
ping = new(pingAddress);
}
}
public override string GetName()
{
return nameof(ShowProfiler);
}
public override object GetDiagnostics()
{
Dictionary<string, string> dictioanry = new();
dictioanry.Add(nameof(fpsOutput), fpsOutput ? "有效" : "未定义");
dictioanry.Add(nameof(pingOutput), pingOutput ? "有效" : "未定义");
dictioanry.Add("FPS", timer);
return dictioanry;
}
}
}

View File

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

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Sirenix.OdinInspector;
namespace BITKit
{
public class ShowTime : BITBehavior
{
[SerializeReference,SubclassSelector]public References timeFormat;
public Provider output;
// Update is called once per frame
void Update()
{
output?.Set(timeFormat is not null ? DateTime.Now.ToString(timeFormat) : DateTime.Now.ToString());
}
}
}

View File

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

View File

@@ -0,0 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Sirenix.OdinInspector;
namespace BITKit
{
public class ShowVersion : MonoBehaviour
{
public Provider output;
void Start()
{
output?.Set(Application.version);
}
}
}

View File

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

View File

@@ -0,0 +1,360 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using Cinemachine;
using Cinemachine.Utility;
using TouchPhase = UnityEngine.InputSystem.TouchPhase;
using UnityEngine.InputSystem.EnhancedTouch;
using Touch = UnityEngine.InputSystem.EnhancedTouch.Touch;
using BITKit.IO;
using Newtonsoft.Json;
using System.IO;
using Cysharp.Threading.Tasks;
namespace BITKit
{
public class SimpleCameraLook : MonoBehaviour
{
private string fileName => Path.Combine(Utility.Path.persistentDataPath, gameObject.scene.name, $"{gameObject.GetInstanceID()}.bit");
public enum State
{
Mouse,
Touchscreen,
}
[Header(Constant.Header.Gameobjects)]
public Transform cameraRoot;
public CinemachineVirtualCamera virtualCamera;
[Header(Constant.Header.Settings)]
public TransformMode touchMode;
[Header(Constant.Header.Settings)]
public InputActionReference viewAction;
public InputActionReference movementAction;
public InputActionReference adsAction;
public InputActionReference entryAction;
public InputActionReference entryMoveAction;
public InputActionGroup inputGroup = new();
[Header(Constant.Header.Settings)]
public float minEntrySqrMagnitude = 1;
public LayerMask layerMask;
[Header(Constant.Header.Settings)]
public AnimationCurve scollCurve = new();
public AnimationCurve moveCurve = new();
public AnimationCurve touchMoveCurve = new();
public Vector2 cameraDistanceLimit = new(1, 64);
[Header(Constant.Header.Debug)]
public int touchesCount;
public bool isParallelVector;
[Header(Constant.Header.InternalVariables)]
public Vector3 lookInput;
public Vector3 moveVector;
public ValidHandle freeLooking = new();
public ValidHandle moving = new();
private Cinemachine3rdPersonFollow tpv;
private Location startLocation;
private Location savedLocation;
private float savedDistance;
private float startDistance;
private CinemachineBrain _brain;
public void Reset()
{
lookInput = startLocation.position.TransientRotationAxis();
cameraRoot.position = startLocation;
tpv.CameraDistance = startDistance;
}
public void DisableInput(bool disable)
{
inputGroup.allowInput.SetDisableElements(nameof(DisableInput), disable);
}
public void SetTouchMode(int index)
{
SetTouchMode((TransformMode)index);
}
public void SetTouchMode(TransformMode mode)
{
touchMode = mode;
}
public void Align(Transform target)
{
if (target.TryGetComponent<SimpleCameraLook>(out var x))
{
cameraRoot.position = x.cameraRoot.position;
//lookInput = x.lookInput;
lookInput = x.cameraRoot.rotation.eulerAngles.TransientRotationAxis();
if (x.tpv)
tpv.CameraDistance = x.tpv.CameraDistance;
}
else if (target.TryGetComponent<CinemachineVirtualCamera>(out var vCam))
{
cameraRoot.position = vCam.Follow.position;
lookInput = vCam.LookAt.rotation.eulerAngles.TransientRotationAxis();
var e = vCam.GetCinemachineComponent<Cinemachine3rdPersonFollow>();
if (e)
{
tpv.CameraDistance = e.CameraDistance;
}
}
else
{
cameraRoot.position = target.position;
lookInput = target.eulerAngles.TransientRotationAxis();
}
}
public void SaveLocation()
{
savedLocation = new(cameraRoot);
savedDistance = tpv.CameraDistance;
BITAssets.Build(
PathHelper.GetFilePath(fileName),
new IAsset[]
{
new BITAsset(nameof(savedLocation),JsonUtility.ToJson(savedLocation)),
new BITAsset(nameof(savedDistance),JsonConvert.SerializeObject(savedDistance)),
}
);
}
public void LoadLocation()
{
lookInput = savedLocation.rotation.eulerAngles.TransientRotationAxis();
cameraRoot.position = savedLocation;
tpv.CameraDistance = savedDistance;
}
private void Awake()
{
freeLooking.AddListener(OnFreeLook);
tpv = virtualCamera.GetCinemachineComponent<Cinemachine3rdPersonFollow>();
savedLocation = startLocation = new(cameraRoot);
savedDistance = startDistance = tpv.CameraDistance;
inputGroup.RegisterCallback(viewAction, OnView);
inputGroup.RegisterCallback(movementAction, OnMovement);
inputGroup.RegisterCallback(adsAction, OnAds);
inputGroup.RegisterCallback(entryAction, OnEntry);
inputGroup.RegisterCallback(entryMoveAction, OnEntryMoveAction);
if (Camera.main != null) _brain = Camera.main.GetComponent<CinemachineBrain>();
}
private async void Start()
{
var fileName = this.fileName;
await UniTask.SwitchToThreadPool();
if (File.Exists(fileName))
{
savedLocation = BITAssets.Read<Location>(fileName, nameof(savedLocation));
savedDistance = BITAssets.Read<float>(fileName, nameof(savedDistance));
}
}
private void OnEnable()
{
SetEnabled(true);
lookInput = cameraRoot.eulerAngles.TransientRotationAxis();
freeLooking.RemoveDisableElements(this);
virtualCamera.enabled = true;
}
private void OnDisable()
{
SetEnabled(false);
freeLooking.AddDisableElements(this);
virtualCamera.enabled = false;
}
private void OnDestroy()
{
inputGroup.Dispose();
}
private void SetEnabled(bool enabled)
{
//BIT4Log.Log<SimpleCameraLook>($"正在设置输入状态:{enabled}");
BITAppForUnity.AllowTouchSupport.SetElements(this, enabled);
inputGroup.allowInput.SetElements(this, enabled);
}
private void Update()
{
//var debuger = DI.Get<IDebuger>();
var playerConfig = PlayerConfig.singleton;
var sensitivity = playerConfig.touchSensitivity;
//debuger.Log(nameof(Touch.activeTouches), Touch.activeTouches.Count.ToString());
touchesCount = Touch.activeTouches.Count;
if (Mouse.current.leftButton.wasPressedThisFrame)
{
var ray = Camera.main.ScreenPointToRay(Mouse.current.position.ReadValue());
if (Physics.Raycast(ray, out var raycast, 256, layerMask))
{
cameraRoot.position = raycast.point;
}
}
if (_brain)
{
inputGroup.allowInput.SetDisableElements(nameof(CinemachineBrain),virtualCamera != (CinemachineVirtualCamera)_brain.ActiveVirtualCamera);
}
}
private void LateUpdate()
{
lookInput.x = Mathf.Clamp(lookInput.x, -80, 80);
var newRotation = Quaternion.Euler(lookInput);
cameraRoot.rotation = Quaternion.Lerp(cameraRoot.rotation, newRotation, 48 * Time.deltaTime);
var offset = cameraRoot.localRotation * moveVector;
cameraRoot.localPosition -= offset * Time.deltaTime;
}
private void OnView(InputAction.CallbackContext context)
{
var playerConfig = PlayerConfig.singleton;
var sensitivity = playerConfig.sensitivity * playerConfig.m_yaw;
var delta = context.ReadValue<Vector2>();
switch (context.control.device)
{
case Mouse mouse:
if (freeLooking && !moving)
{
lookInput.x -= delta.y * sensitivity;
lookInput.y += delta.x * sensitivity;
}
break;
case Touchscreen touchscreen:
/* lookInput.x -= delta.y * sensitivity;
lookInput.y += delta.x * sensitivity; */
switch (touchMode)
{
case TransformMode.Move:
break;
case TransformMode.Rotate:
lookInput.x -= delta.y * sensitivity;
lookInput.y += delta.x * sensitivity;
moveVector = default;
break;
case TransformMode.Scale:
break;
}
if (touchMode is TransformMode.Scale)
{
OnAds(context);
}
break;
}
}
private void OnAds(InputAction.CallbackContext context)
{
try
{
BITAppForUnity.ThrowIfWindowNotFocus();
switch (context.control.device)
{
case Mouse mouse:
OnAds(context.ReadValue<Vector2>().y);
break;
case Touchscreen touchscreen:
/* lookInput.x -= delta.y * sensitivity;
lookInput.y += delta.x * sensitivity; */
switch (touchMode)
{
case TransformMode.Move:
break;
case TransformMode.Rotate:
moveVector = default;
break;
case TransformMode.Scale:
OnAds(context.ReadValue<Vector2>().y);
break;
}
break;
}
}
catch (MouseNotOverGameViewException)
{
}
catch (System.Exception)
{
throw;
}
}
private void OnAds(float delta)
{
var newDistance = tpv.CameraDistance -
delta * Time.deltaTime * scollCurve.Evaluate(tpv.CameraDistance);
tpv.CameraDistance = Mathf.Clamp(newDistance, cameraDistanceLimit.x, cameraDistanceLimit.y);
}
private void OnFreeLook(bool active)
{
BITAppForUnity.AllowCursor.SetDisableElements(this, active);
}
private void OnEntry(InputAction.CallbackContext context)
{
if (context.started)
{
var delta = viewAction.action.ReadValue<Vector2>();
if (delta.sqrMagnitude > minEntrySqrMagnitude)
freeLooking.AddElement(this);
}
else if (context.canceled)
{
freeLooking.RemoveElement(this);
}
}
private void OnMovement(InputAction.CallbackContext context)
{
switch (context.control.device)
{
case Mouse mouse:
if (moving && freeLooking)
{
moveVector = context.ReadValue<Vector2>() * moveCurve.Evaluate(tpv.CameraDistance);
}
break;
case Touchscreen touchscreen:
/* lookInput.x -= delta.y * sensitivity;
lookInput.y += delta.x * sensitivity; */
switch (touchMode)
{
case TransformMode.Move:
moveVector = context.ReadValue<Vector2>() * moveCurve.Evaluate(tpv.CameraDistance);
break;
case TransformMode.Rotate:
break;
case TransformMode.Scale:
break;
}
break;
}
if (context.canceled)
{
moveVector = default;
}
}
private void OnEntryMoveAction(InputAction.CallbackContext context)
{
if (context.started)
{
moving.AddElement(this);
}
else if (context.canceled)
{
moving.RemoveElement(this);
}
}
}
}

View File

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

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit
{
public class StopWatcher : MonoBehaviour
{
[SerializeReference, SubclassSelector] public References timeFormat;
public bool autoStart;
public Provider output;
bool started;
DateTime dateTime = new();
void Start()
{
if (autoStart)
{
started = true;
}
}
// Update is called once per frame
void Update()
{
if (started)
{
dateTime = dateTime.AddSeconds(Time.deltaTime);
var timeStr = dateTime.ToString();
if (timeFormat is not null)
{
timeStr = dateTime.ToString(timeFormat);
}
output.Set(timeStr);
}
}
}
}

View File

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

View File

@@ -0,0 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit
{
public class StringProviders : Provider<string>
{
public Provider<string>[] providers;
public override string Get()
{
throw new System.NotImplementedException();
}
public override void Set(string t)
{
foreach (var provider in providers)
{
provider.Set(t);
}
}
}
}

View File

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

View File

@@ -0,0 +1,29 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cysharp.Threading.Tasks;
namespace BITKit
{
public sealed class TranslateComponent : Provider<string>
{
[Header(Constant.Header.Settings)]
public TranslateSO so;
public bool async;
[Header(Constant.Header.Output)]
public Provider output;
[TextArea]
public string result;
public override string Get()
{
throw new System.NotImplementedException();
}
public override async void Set(string t)
{
if (async)
{
await UniTask.SwitchToThreadPool();
}
output.Set(result = so.Get(t, false));
}
}
}

View File

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

View File

@@ -0,0 +1,37 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using BITKit;
using UnityEngine.Events;
using UnityEngine.UIElements;
namespace BITKit
{
public class WorldToScreenPoint : MonoBehaviour
{
[Header(Constant.Header.Settings)]
[SerializeField] Transform root;
[SerializeField] Vector3 offset;
[SerializeField] Optional<float> activeDistance;
[Header(Constant.Header.Events)]
[SerializeField] private UnityEvent<bool> setHeaderEnabled;
[SerializeField] private UnityEvent<Vector3> setHeaderPosition;
Transform cameraTrans;
void Start()
{
if (Camera.main != null) cameraTrans = Camera.main.transform;
}
void Update()
{
var position = root.position + root.rotation * offset;
setHeaderPosition.Invoke(position);
if (activeDistance.Allow)
{
var distance = Vector3.Distance(position, cameraTrans.position);
var _enabled = distance < activeDistance;
setHeaderEnabled.Invoke(_enabled);
}
}
}
}

View File

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