1
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Experimental.Audio;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public class BITEditorForUnity : EditorWindow
|
||||
{
|
||||
private Slider _timeScaleSlider;
|
||||
private Button _resetTimeScaleButton;
|
||||
private TextField _commandTextField;
|
||||
|
||||
[MenuItem("Tools/Common Editor")]
|
||||
private static void OpenEditor()
|
||||
{
|
||||
var window = GetWindow<BITEditorForUnity>();
|
||||
window.titleContent = new GUIContent("BIT Editor");
|
||||
window.Show();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
rootVisualElement.styleSheets.Add(BITEditorUtils.InspectorStyleSheet);
|
||||
|
||||
_timeScaleSlider = new Slider()
|
||||
{
|
||||
label = "TimeScale",
|
||||
showInputField = true,
|
||||
value = Time.timeScale
|
||||
};
|
||||
_timeScaleSlider.RegisterValueChangedCallback(x => { Time.timeScale = x.newValue; });
|
||||
|
||||
_resetTimeScaleButton = new Button()
|
||||
{
|
||||
text = "Reset TimeScale",
|
||||
};
|
||||
_resetTimeScaleButton.clicked += () =>
|
||||
{
|
||||
Time.timeScale = 1;
|
||||
_timeScaleSlider.value = 1;
|
||||
};
|
||||
|
||||
rootVisualElement.Add(_timeScaleSlider);
|
||||
rootVisualElement.Add(_resetTimeScaleButton);
|
||||
|
||||
_commandTextField = rootVisualElement.Create<TextField>();
|
||||
_commandTextField.isDelayed = true;
|
||||
_commandTextField.RegisterCallback<ChangeEvent<string>>(ExecuteCommand);
|
||||
|
||||
}
|
||||
private void ExecuteCommand(ChangeEvent<string> evt)
|
||||
{
|
||||
Debug.Log($"Execute command: {evt.newValue}");
|
||||
_commandTextField.SetValueWithoutNotify(string.Empty);
|
||||
BITCommands.Excute(evt.newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "BITKit.Editor",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:a209c53514018594f9f482516f2a6781",
|
||||
"GUID:9e24947de15b9834991c9d8411ea37cf",
|
||||
"GUID:84651a3751eca9349aac36a66bba901b",
|
||||
"GUID:6ef4ed8ff60a7aa4bb60a8030e6f4008",
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:9400d40641bab5b4a9702f65bf5c6eb5"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [
|
||||
"UNITY_EDITOR"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
public static class FindMissingScriptsRecursively
|
||||
{
|
||||
[MenuItem("Auto/Remove Missing Scripts Recursively Visit Prefabs")]
|
||||
private static void FindAndRemoveMissingInSelected()
|
||||
{
|
||||
// EditorUtility.CollectDeepHierarchy does not include inactive children
|
||||
var deeperSelection = Selection.gameObjects.SelectMany(go => go.GetComponentsInChildren<Transform>(true))
|
||||
.Select(t => t.gameObject);
|
||||
var prefabs = new HashSet<Object>();
|
||||
int compCount = 0;
|
||||
int goCount = 0;
|
||||
foreach (var go in deeperSelection)
|
||||
{
|
||||
int count = GameObjectUtility.GetMonoBehavioursWithMissingScriptCount(go);
|
||||
if (count > 0)
|
||||
{
|
||||
if (PrefabUtility.IsPartOfAnyPrefab(go))
|
||||
{
|
||||
RecursivePrefabSource(go, prefabs, ref compCount, ref goCount);
|
||||
count = GameObjectUtility.GetMonoBehavioursWithMissingScriptCount(go);
|
||||
// if count == 0 the missing scripts has been removed from prefabs
|
||||
if (count == 0)
|
||||
continue;
|
||||
// if not the missing scripts must be prefab overrides on this instance
|
||||
}
|
||||
|
||||
Undo.RegisterCompleteObjectUndo(go, "Remove missing scripts");
|
||||
GameObjectUtility.RemoveMonoBehavioursWithMissingScript(go);
|
||||
compCount += count;
|
||||
goCount++;
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Log($"Found and removed {compCount} missing scripts from {goCount} GameObjects");
|
||||
}
|
||||
|
||||
// Prefabs can both be nested or variants, so best way to clean all is to go through them all
|
||||
// rather than jumping straight to the original prefab source.
|
||||
private static void RecursivePrefabSource(GameObject instance, HashSet<Object> prefabs, ref int compCount,
|
||||
ref int goCount)
|
||||
{
|
||||
var source = PrefabUtility.GetCorrespondingObjectFromSource(instance);
|
||||
// Only visit if source is valid, and hasn't been visited before
|
||||
if (source == null || !prefabs.Add(source))
|
||||
return;
|
||||
|
||||
// go deep before removing, to differantiate local overrides from missing in source
|
||||
RecursivePrefabSource(source, prefabs, ref compCount, ref goCount);
|
||||
|
||||
int count = GameObjectUtility.GetMonoBehavioursWithMissingScriptCount(source);
|
||||
if (count > 0)
|
||||
{
|
||||
Undo.RegisterCompleteObjectUndo(source, "Remove missing scripts");
|
||||
GameObjectUtility.RemoveMonoBehavioursWithMissingScript(source);
|
||||
compCount += count;
|
||||
goCount++;
|
||||
}
|
||||
}
|
||||
}
|
33
Assets/BITKit/UnityPluginsSupport/Editor/Helper_I18N.cs
Normal file
33
Assets/BITKit/UnityPluginsSupport/Editor/Helper_I18N.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Callbacks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public class Helper_I18N : MonoBehaviour
|
||||
{
|
||||
[PostProcessBuild(1)]
|
||||
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
|
||||
{
|
||||
return;
|
||||
var folder = Path.Combine(Path.GetDirectoryName(EditorApplication.applicationPath), "Data",
|
||||
"MonoBleedingEdge", "lib", "mono", "unityjit-win32");
|
||||
var list = new List<string>()
|
||||
{
|
||||
"I18N.CJK.dll", "I18N.dll", "I18N.MidEast.dll", "I18N.Other.dll", "I18N.Rare.dll", "I18N.West.dll"
|
||||
};
|
||||
foreach (var name in list)
|
||||
{
|
||||
var fileInfo = new FileInfo(Path.Combine(folder, name));
|
||||
var copyPath = Path.Combine(Path.GetDirectoryName(pathToBuiltProject),
|
||||
$"{Application.productName}_Data", "Plugins", "x86_64", name);
|
||||
fileInfo.CopyTo(copyPath);
|
||||
Debug.Log($"已复制{name}到{copyPath}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEditor.UIElements;
|
||||
//
|
||||
// namespace BITKit.Editors
|
||||
// {
|
||||
// [CustomPropertyDrawer(typeof(IntervalUpdate))]
|
||||
// public class IntervalUpdateInspector : PropertyDrawer
|
||||
// {
|
||||
// public override VisualElement CreatePropertyGUI(SerializedProperty property)
|
||||
// {
|
||||
// IntervalUpdate intervalUpdate = null;
|
||||
// try
|
||||
// {
|
||||
// intervalUpdate = property.serializedObject
|
||||
// .GetType()
|
||||
// .GetProperty(property.name)?
|
||||
// .GetValue(property.serializedObject) as IntervalUpdate;
|
||||
// }
|
||||
// catch (System.Exception e)
|
||||
// {
|
||||
// Debug.LogException(e);
|
||||
// }
|
||||
//
|
||||
// // Create property container element.
|
||||
// var container = new VisualElement();
|
||||
// // Create property fields.
|
||||
// var enable = new Toggle("Enabled");
|
||||
// var updateInterval = new PropertyField(property.FindPropertyRelative(nameof(IntervalUpdate.updateInterval)));
|
||||
//
|
||||
// enable.BindProperty(property.FindPropertyRelative(nameof(IntervalUpdate.enable)));
|
||||
// // Add fields to the container.
|
||||
// container.Add(enable);
|
||||
// container.Add(updateInterval);
|
||||
//
|
||||
// #if UNITY_EDITOR
|
||||
// enable.RegisterValueChangedCallback(x =>
|
||||
// {
|
||||
// if (UnityEditor.EditorApplication.isPlaying)
|
||||
// {
|
||||
// intervalUpdate?.SetActive(x.newValue);
|
||||
// }
|
||||
// });
|
||||
// #endif
|
||||
//
|
||||
// return container;
|
||||
// }
|
||||
// public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
// {
|
||||
// var enabled = property.FindPropertyRelative("enable");
|
||||
// var updateInterval = property.FindPropertyRelative("updateInterval");
|
||||
// EditorGUI.BeginProperty(position, label, property);
|
||||
// EditorGUI.PropertyField(position, enabled, label);
|
||||
// EditorGUI.PropertyField(position, updateInterval, label);
|
||||
// EditorGUI.EndProperty();
|
||||
// }
|
||||
// }
|
||||
// }
|
15
Assets/BITKit/UnityPluginsSupport/Editor/OpenPath.cs
Normal file
15
Assets/BITKit/UnityPluginsSupport/Editor/OpenPath.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
public partial class BITMonkeyCommand
|
||||
{
|
||||
[MenuItem("Tools/Open Persistent Folder")]
|
||||
static void OpenPersistentDataPath()
|
||||
{
|
||||
System.Diagnostics.Process.Start(Application.persistentDataPath);
|
||||
}
|
||||
[MenuItem("Tools/Open Root Folder")]
|
||||
static void OpenRoot()
|
||||
{
|
||||
System.Diagnostics.Process.Start(System.Environment.CurrentDirectory);
|
||||
}
|
||||
}
|
48
Assets/BITKit/UnityPluginsSupport/Editor/VersionUpdater.cs
Normal file
48
Assets/BITKit/UnityPluginsSupport/Editor/VersionUpdater.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using UnityEngine;
|
||||
using UnityEditor.Callbacks;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
namespace BITKit
|
||||
{
|
||||
class BuildVersionProcessor : IPreprocessBuildWithReport
|
||||
{
|
||||
private bool autoIncreamentBuildVersion = true;
|
||||
|
||||
public int callbackOrder { get { return 0; } }
|
||||
public void OnPreprocessBuild(BuildReport report)
|
||||
{
|
||||
//Debug.Log("MyCustomBuildProcessor.OnPreprocessBuild for target " + report.summary.platform + " at path " + report.summary.outputPath);
|
||||
if (autoIncreamentBuildVersion) { IncrementVersion(); }
|
||||
}
|
||||
|
||||
[MenuItem("File/Manually Increment Build Version", priority = 1)]
|
||||
public static void ButtonIncrementVersion()
|
||||
{
|
||||
Debug.Log("Button Increment Version called.");
|
||||
IncrementVersion();
|
||||
}
|
||||
|
||||
private static void IncrementVersion()
|
||||
{
|
||||
string versionCurrent = Application.version;
|
||||
string[] versionParts = versionCurrent.Split('.');
|
||||
|
||||
if (versionParts != null && versionParts.Length > 0)
|
||||
{
|
||||
int versionIncremented = int.Parse(versionParts[versionParts.Length - 1]);
|
||||
versionIncremented += 1;
|
||||
versionParts[versionParts.Length - 1] = versionIncremented.ToString();
|
||||
PlayerSettings.bundleVersion = string.Join(".", versionParts);
|
||||
|
||||
Debug.Log("Version: " + versionCurrent + " increased to: " + PlayerSettings.bundleVersion);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Version has no data, check Unity - Player Settings - Version, input box at top.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
16
Assets/BITKit/UnityPluginsSupport/FPS/BITKit.FPS.asmdef
Normal file
16
Assets/BITKit/UnityPluginsSupport/FPS/BITKit.FPS.asmdef
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "BITKit.FPS",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
31
Assets/BITKit/UnityPluginsSupport/FPS/Recoil.cs
Normal file
31
Assets/BITKit/UnityPluginsSupport/FPS/Recoil.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
/* using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
namespace BITKit.FPS
|
||||
{
|
||||
public class Recoil : MonoBehaviour
|
||||
{
|
||||
SpringEulerAngle recoilTarget;
|
||||
public float damp = 20;
|
||||
public float frequence = 15;
|
||||
void Awake()
|
||||
{
|
||||
recoilTarget = new SpringEulerAngle(damp, frequence);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void FixedUpdate()
|
||||
{
|
||||
recoilTarget.Update(Time.deltaTime, Vector3.zero);
|
||||
transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(recoilTarget.value), 0.75f); //这里使用一个较大的插值数字以实现枪口的迅速抬升
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
recoilTarget.value = new Vector3(Random.Range(-20, 0), Random.Range(-3, 3), 0); //这里做一个随机偏移来模拟后坐力。
|
||||
}
|
||||
}
|
||||
}
|
||||
} */
|
30
Assets/BITKit/UnityPluginsSupport/FPS/Spring3.cs
Normal file
30
Assets/BITKit/UnityPluginsSupport/FPS/Spring3.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
namespace BITKit.FPS
|
||||
{
|
||||
[Serializable]
|
||||
public class Spring3
|
||||
{
|
||||
public Vector3 value = Vector2.zero;
|
||||
[SerializeField] private Vector3 dampValue = Vector2.zero;
|
||||
[SerializeField] private float damp = 1;
|
||||
[SerializeField] private float frequence = 1;
|
||||
public void Clear()
|
||||
{
|
||||
value = Vector2.zero;
|
||||
dampValue = Vector2.zero;
|
||||
}
|
||||
public Spring3(float damp, float frequence)
|
||||
{
|
||||
this.damp = damp;
|
||||
this.frequence = frequence;
|
||||
}
|
||||
public void Update(float deltaTime, Vector3 target)
|
||||
{
|
||||
value -= dampValue * deltaTime * frequence;
|
||||
dampValue = Vector3.Lerp(dampValue, value - target, deltaTime * damp);
|
||||
}
|
||||
}
|
||||
}
|
37
Assets/BITKit/UnityPluginsSupport/FPS/SpringEulerAngle.cs
Normal file
37
Assets/BITKit/UnityPluginsSupport/FPS/SpringEulerAngle.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
[System.Serializable]
|
||||
public class SpringEulerAngle
|
||||
{
|
||||
public float damp = 20;
|
||||
public float frequence = 15;
|
||||
[HideInInspector]
|
||||
public Vector3 value = Vector2.zero;
|
||||
Vector3 dampValue = Vector2.zero;
|
||||
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
value = Vector2.zero;
|
||||
dampValue = Vector2.zero;
|
||||
}
|
||||
|
||||
public void Update(float deltaTime, Vector3 target)
|
||||
{
|
||||
value -= dampValue * deltaTime * frequence;
|
||||
dampValue = eulerLerp(dampValue, value - target, deltaTime * damp);
|
||||
}
|
||||
public static Vector3 eulerLerp(Vector3 left, Vector3 right, float t)
|
||||
{
|
||||
Vector3 ret;
|
||||
ret.x = Mathf.LerpAngle(left.x, right.x, t);
|
||||
ret.y = Mathf.LerpAngle(left.y, right.y, t);
|
||||
ret.z = Mathf.LerpAngle(left.z, right.z, t);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "BITKit.Extensions.MonkeyCommand",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:39db31f0562d9184c92881e43adea352"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [
|
||||
"UNITY_EDITOR"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using MonKey;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
namespace BITKit
|
||||
{
|
||||
public partial class BITMonkeyCommands
|
||||
{
|
||||
[Command(nameof(ExportPrefabPreview), "导出已选的预制预览图", QuickName = "exp"), MenuItem("Tools/Export Selected Prefab Preview")]
|
||||
private static void ExportPrefabPreview()
|
||||
{
|
||||
var exportPath = Path.Combine(Application.dataPath, "Temps");
|
||||
PathHelper.EnsureDirectoryCreated(exportPath);
|
||||
foreach (var image in UnityEditor.Selection.objects.Select(AssetPreview.GetAssetPreview))
|
||||
{
|
||||
var path = Path.Combine(exportPath, GUID.Generate() + ".png");
|
||||
File.WriteAllBytes( path, image.EncodeToPNG());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
using System.Collections;
|
||||
// ReSharper disable RedundantUsingDirective
|
||||
using System.Collections.Generic;
|
||||
// ReSharper restore RedundantUsingDirective
|
||||
using MonKey;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Selection = UnityEditor.Selection;
|
||||
namespace BITKit
|
||||
{
|
||||
public partial class BITMonkeyCommands
|
||||
{
|
||||
[Command(nameof(InstanceRendererMaterial), "Instance Material From Selected GameObject", QuickName = "ins"), MenuItem("Tools/Instance Material")]
|
||||
private static void InstanceRendererMaterial()
|
||||
{
|
||||
if (UnityEditor.Selection.activeTransform is null) return;
|
||||
if (UnityEditor.Selection.activeTransform.TryGetComponent<Renderer>(out var renderer))
|
||||
{
|
||||
renderer.sharedMaterial = Object.Instantiate(renderer.material);
|
||||
}
|
||||
EditorUtility.SetDirty(UnityEditor.Selection.activeTransform.GetComponent<Renderer>());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using MonKey;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.GameEditor
|
||||
{
|
||||
public class QuickFixFloatModel
|
||||
{
|
||||
[Command(nameof(FixedSelectedFloat), "Fixed Selected Model Position", QuickName = "ins"), MenuItem("Tools/Scenes/Fix Float Model Position")]
|
||||
public static void FixedSelectedFloat()
|
||||
{
|
||||
var transforms = UnityEditor.Selection.transforms;
|
||||
if (transforms is null or {Length:0}) return;
|
||||
|
||||
var reportBuilder = new StringBuilder();
|
||||
reportBuilder.AppendLine($"已选择{transforms.Length}个物体:");
|
||||
foreach (var x in transforms)
|
||||
{
|
||||
if (Physics.Raycast(x.position, Vector3.down, out var hit, 1000) is false) continue;
|
||||
x.position = hit.point;
|
||||
EditorUtility.SetDirty(x);
|
||||
reportBuilder.AppendLine($"已修复{x.name}的位置于{hit.point}");
|
||||
}
|
||||
Undo.RecordObjects(transforms,"修复浮动");
|
||||
|
||||
Debug.Log(reportBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using MonKey;
|
||||
using MonKey.Editor;
|
||||
namespace BITKit
|
||||
{
|
||||
public class RestartUnity
|
||||
{
|
||||
[Command(nameof(Restart), "Restart Unity Now", QuickName = "re"), MenuItem("Restart/Now")]
|
||||
static void Restart()
|
||||
{
|
||||
EditorApplication.OpenProject(Application.dataPath.Replace("Assets", string.Empty));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "BITKit.Extensions.Polaris",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:9c184a1e5cc20654384071dfebc106ed",
|
||||
"GUID:bdb069e155d2f944cb1bf28602b6d4c1",
|
||||
"GUID:1193c2664d97cc049a6e4c486c6bce71"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [
|
||||
"GRIFFIN"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,59 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Pinwheel.Griffin;
|
||||
using Quadtree;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.OpenWorld
|
||||
{
|
||||
public class PolarisTerrainChunkService : WorldChunkService<PolarisTerrainChunkService>
|
||||
{
|
||||
private class ChunkData:IWorldChunkObject
|
||||
{
|
||||
public Collider Collider { get; set; }
|
||||
public Bounds GetBounds() => Bounds;
|
||||
public Bounds Bounds { get; set; }
|
||||
public Node<IWorldChunkObject> ParentNode { get; set; }
|
||||
public void QuadTree_Root_Initialized(IQuadtreeRoot<IWorldChunkObject, Node<IWorldChunkObject>> root)
|
||||
{
|
||||
}
|
||||
|
||||
public int Id { get; set; }
|
||||
public int Lod
|
||||
{
|
||||
get => lod;
|
||||
set
|
||||
{
|
||||
Collider.enabled = value is 0;
|
||||
lod = value;
|
||||
}
|
||||
}
|
||||
private int lod=-1;
|
||||
}
|
||||
[SerializeField] private GStylizedTerrain[] terrains;
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
var reporter = new StringBuilder();
|
||||
foreach (var terrain in terrains)
|
||||
{
|
||||
reporter.AppendLine($"正在注册地形 {terrain.name},尺寸:{terrain.TerrainData.Geometry.Width}x{terrain.TerrainData.Geometry.Length}");
|
||||
foreach (var chunk in terrain.GetChunks())
|
||||
{
|
||||
var data =new ChunkData()
|
||||
{
|
||||
Collider = chunk.MeshColliderComponent,
|
||||
Bounds = chunk.MeshColliderComponent.bounds
|
||||
};
|
||||
data.Collider.enabled = false;
|
||||
Register(data);
|
||||
reporter.AppendLine($"注册地形碰撞体 {chunk.name},尺寸:{data.Bounds.size}");
|
||||
}
|
||||
}
|
||||
Debug.Log(reporter);
|
||||
OnTick(Time.deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "BITKit.Extensions.SkiaSharp",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:6ef4ed8ff60a7aa4bb60a8030e6f4008",
|
||||
"GUID:d525ad6bd40672747bde77962f1c401e",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
||||
"GUID:d8b63aba1907145bea998dd612889d6b",
|
||||
"GUID:6de01b04fa4e14662b03fa46366da151",
|
||||
"GUID:f19bbd83e3c264a5680926bf75d7e494"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [
|
||||
"_SkiaSharp"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
121
Assets/BITKit/UnityPluginsSupport/SkiaSharp/SkiaExtensions.cs
Normal file
121
Assets/BITKit/UnityPluginsSupport/SkiaSharp/SkiaExtensions.cs
Normal file
@@ -0,0 +1,121 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SkiaSharp;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public static class SkiaExtensions
|
||||
{
|
||||
public static Texture2D ToTexture2D(this SKImageInfo info,SKSurface surface)
|
||||
{
|
||||
// Okay, we're finished drawing. Now we create a Unity texture.
|
||||
TextureFormat format = (info.ColorType == SKColorType.Rgba8888) ? TextureFormat.RGBA32 : TextureFormat.BGRA32;
|
||||
var texture = new Texture2D(info.Width, info.Height, format, false, true);
|
||||
texture.wrapMode = TextureWrapMode.Clamp;
|
||||
|
||||
// Pull a Skia image object out of the canvas...
|
||||
var pixmap = surface.PeekPixels();
|
||||
// Copy it to the Unity texture...
|
||||
texture.LoadRawTextureData(pixmap.GetPixels(), pixmap.RowBytes * pixmap.Height);
|
||||
texture.Apply(false, true);
|
||||
// And drop it into the RawImage object.
|
||||
|
||||
return texture;
|
||||
}
|
||||
public static SKColor ToSKColor(this Color color,byte? alpha=null)
|
||||
{
|
||||
return new SKColor((byte)(color.r * 255), (byte)(color.g * 255), (byte)(color.b * 255), alpha??(byte)(color.a * 255));
|
||||
}
|
||||
public static SKColor ToSKColor(this Color32 color)
|
||||
{
|
||||
return new SKColor(color.r, color.g, color.b, color.a);
|
||||
}
|
||||
public static byte[] GetBytes(this SKSurface self)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
using var image = self.Snapshot();
|
||||
|
||||
|
||||
|
||||
using var data = image.Encode(SKEncodedImageFormat.Png, 40);
|
||||
|
||||
//using var stream = File.OpenWrite(exportPath.Value);
|
||||
var ms = new MemoryStream();
|
||||
// save the data to a stream
|
||||
data.SaveTo(ms);
|
||||
|
||||
var bytes = ms.ToArray();
|
||||
|
||||
var bitmap = OnFlipHorizontalClicked(bytes);
|
||||
|
||||
using var rotatedData = bitmap.Encode(SKEncodedImageFormat.Png, 40);
|
||||
|
||||
using var newMs = new MemoryStream();
|
||||
rotatedData.SaveTo(newMs);
|
||||
|
||||
return newMs.ToArray();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
StringBuilder exceptionBuilder = new();
|
||||
exceptionBuilder.AppendLine($"Surface:{self is not null}");
|
||||
BIT4Log.LogException( new InGameException(exceptionBuilder.ToString(),e));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public static string GetBase64(this SKSurface self)
|
||||
{
|
||||
try
|
||||
{
|
||||
var base64 = Convert.ToBase64String(self.GetBytes());
|
||||
|
||||
return "data:image/png;base64," + base64;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
StringBuilder exceptionBuilder = new();
|
||||
exceptionBuilder.AppendLine($"Surface:{self is not null}");
|
||||
BIT4Log.LogException( new InGameException(exceptionBuilder.ToString(),e));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public static SKBitmap OnFlipHorizontalClicked(byte[] bytes)
|
||||
{
|
||||
var bitmap = SKBitmap.Decode(bytes);
|
||||
var flippedBitmap = SKBitmap.Decode(bytes);
|
||||
|
||||
using var canvas = new SKCanvas(flippedBitmap);
|
||||
canvas.Clear();
|
||||
canvas.Scale(1, -1, 0, bitmap.Height / 2);
|
||||
canvas.DrawBitmap(bitmap, new SKPoint());
|
||||
return flippedBitmap;
|
||||
}
|
||||
public static SKBitmap Rotate(SKBitmap bitmap, double angle)
|
||||
{
|
||||
double radians = Math.PI * angle / 180;
|
||||
float sine = (float)Math.Abs(Math.Sin(radians));
|
||||
float cosine = (float)Math.Abs(Math.Cos(radians));
|
||||
int originalWidth = bitmap.Width;
|
||||
int originalHeight = bitmap.Height;
|
||||
int rotatedWidth = (int)(cosine * originalWidth + sine * originalHeight);
|
||||
int rotatedHeight = (int)(cosine * originalHeight + sine * originalWidth);
|
||||
|
||||
var rotatedBitmap = new SKBitmap(rotatedWidth, rotatedHeight);
|
||||
|
||||
using (var surface = new SKCanvas(rotatedBitmap))
|
||||
{
|
||||
surface.Translate(rotatedWidth / 2, rotatedHeight / 2);
|
||||
surface.RotateDegrees((float)angle);
|
||||
surface.Translate(-originalWidth / 2, -originalHeight / 2);
|
||||
surface.DrawBitmap(bitmap, new SKPoint());
|
||||
}
|
||||
return rotatedBitmap;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "BITKit.Extension.Steamwork",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23",
|
||||
"GUID:d525ad6bd40672747bde77962f1c401e",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [
|
||||
"STEAMWORKS_NET"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.Steamwork
|
||||
{
|
||||
public interface ISteamInventoryItemDef:IAddressable
|
||||
{
|
||||
ulong Id { get; }
|
||||
int DefId { get; }
|
||||
string Type { get; }
|
||||
}
|
||||
|
||||
}
|
35
Assets/BITKit/UnityPluginsSupport/Steamwork/ISteamService.cs
Normal file
35
Assets/BITKit/UnityPluginsSupport/Steamwork/ISteamService.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
using Steamworks;
|
||||
using Cysharp.Threading.Tasks;
|
||||
namespace BITKit.Steamwork
|
||||
{
|
||||
/// <summary>
|
||||
/// Steam服务接口
|
||||
/// </summary>
|
||||
public interface ISteamService
|
||||
{
|
||||
/// <summary>
|
||||
/// SteamId
|
||||
/// </summary>
|
||||
int Id { get; }
|
||||
/// <summary>
|
||||
/// Steam64位Id
|
||||
/// </summary>
|
||||
ulong SteamId { get; }
|
||||
/// <summary>
|
||||
/// Steam用户名
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
/// <summary>
|
||||
/// Steam客户端是否已经初始化
|
||||
/// </summary>
|
||||
bool IsInitialized { get; }
|
||||
UniTask<Texture2D> GetAvatarAsync(CancellationToken token);
|
||||
|
||||
UniTask<ISteamInventoryItemDef[]> GetInventoryItemDefsAsync(CancellationToken token);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,19 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.Steamwork
|
||||
{
|
||||
public sealed class ScriptableInventoryItemDef: ScriptableObject,ISteamInventoryItemDef
|
||||
{
|
||||
[SerializeField] private string addressablePath;
|
||||
[SerializeField] private ulong id;
|
||||
[SerializeField] private int defId;
|
||||
[SerializeField] private string type;
|
||||
public string AddressablePath => addressablePath;
|
||||
public ulong Id => id;
|
||||
public int DefId => defId;
|
||||
public string Type => type;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Steamworks.Data;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.Steamwork
|
||||
{
|
||||
public static class SteamExtensions
|
||||
{
|
||||
public static Texture2D Covert( this Image image )
|
||||
{
|
||||
// Create a new Texture2D
|
||||
var avatar = new Texture2D( (int)image.Width, (int)image.Height, TextureFormat.ARGB32, false )
|
||||
{
|
||||
// Set filter type, or else its really blury
|
||||
filterMode = FilterMode.Trilinear
|
||||
};
|
||||
|
||||
// Flip image
|
||||
for ( int x = 0; x < image.Width; x++ )
|
||||
{
|
||||
for ( int y = 0; y < image.Height; y++ )
|
||||
{
|
||||
var p = image.GetPixel( x, y );
|
||||
avatar.SetPixel( x, (int)image.Height - y, new UnityEngine.Color( p.r / 255.0f, p.g / 255.0f, p.b / 255.0f, p.a / 255.0f ) );
|
||||
}
|
||||
}
|
||||
|
||||
avatar.Apply();
|
||||
return avatar;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace BITKit.Steamwork
|
||||
{
|
||||
public class SteamInventoryItemDef : ISteamInventoryItemDef
|
||||
{
|
||||
public string AddressablePath { get; internal set; }
|
||||
public ulong Id { get; internal set;}
|
||||
public int DefId { get; internal set;}
|
||||
public string Type { get; internal set;}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public sealed class UnityInventoryItemDef:ISteamInventoryItemDef
|
||||
{
|
||||
[SerializeField] private Object obj;
|
||||
private ISteamInventoryItemDef _steamInventoryItemDefImplementation=>obj as ISteamInventoryItemDef;
|
||||
public string AddressablePath => _steamInventoryItemDefImplementation.AddressablePath;
|
||||
|
||||
public ulong Id => _steamInventoryItemDefImplementation.Id;
|
||||
|
||||
public int DefId => _steamInventoryItemDefImplementation.DefId;
|
||||
|
||||
public string Type => _steamInventoryItemDefImplementation.Type;
|
||||
}
|
||||
}
|
93
Assets/BITKit/UnityPluginsSupport/Steamwork/SteamService.cs
Normal file
93
Assets/BITKit/UnityPluginsSupport/Steamwork/SteamService.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using Steamworks;
|
||||
using Steamworks.Data;
|
||||
|
||||
namespace BITKit.Steamwork
|
||||
{
|
||||
public class SteamService : MonoBehaviour,ISteamService
|
||||
{
|
||||
internal static SteamService Singleton;
|
||||
[Header(Constant.Header.Settings)]
|
||||
[SerializeField]private uint appId=480;
|
||||
|
||||
[Header(Constant.Header.Settings)]
|
||||
[SerializeField] private TextAsset allowCharacters;
|
||||
|
||||
[Header(Constant.Header.Settings)]
|
||||
[SerializeField] private Optional<UnityInventoryItemDef[]> overrideInventoryItemDefs;
|
||||
|
||||
//接口实现
|
||||
public ulong SteamId => SteamClient.SteamId;
|
||||
public string Name =>SteamClient.IsValid ? SteamClient.Name.Where(x=>allowCharacters.text.Contains(x)).Aggregate("",(current, c) => current+c) : Environment.UserDomainName;
|
||||
public bool IsInitialized=>SteamClient.IsValid&&SteamClient.IsLoggedOn;
|
||||
public async UniTask<Texture2D> GetAvatarAsync(CancellationToken token)
|
||||
{
|
||||
var avatar =await SteamFriends.GetLargeAvatarAsync(SteamClient.SteamId);
|
||||
var texture = new Texture2D(0, 0);
|
||||
return avatar.Value.Covert();
|
||||
}
|
||||
|
||||
public async UniTask<ISteamInventoryItemDef[]> GetInventoryItemDefsAsync(CancellationToken token)
|
||||
{
|
||||
if(overrideInventoryItemDefs.Allow)return overrideInventoryItemDefs.Value;
|
||||
var items = await SteamInventory.GetAllItemsAsync();
|
||||
if(items.HasValue is false)return Array.Empty<ISteamInventoryItemDef>();
|
||||
return items.Value.GetItems().Select(x => new SteamInventoryItemDef()
|
||||
{
|
||||
Id = x.Id,
|
||||
DefId = x.DefId
|
||||
}).Cast<ISteamInventoryItemDef>().ToArray();
|
||||
}
|
||||
|
||||
public int Id => (int)SteamClient.SteamId.AccountId;
|
||||
|
||||
private bool initialized;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Singleton = this;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (SteamClient.IsValid is false)
|
||||
{
|
||||
SteamClient.Init(appId);
|
||||
}
|
||||
initialized = true;
|
||||
BIT4Log.Log<SteamService>("已初始化Steam");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
BIT4Log.Warning<SteamService>("Steam初始化失败,请验证客户端是否运行");
|
||||
Debug.Log(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (initialized)
|
||||
SteamClient.Shutdown();
|
||||
}
|
||||
|
||||
}
|
||||
[Serializable]
|
||||
public class SteamServiceSingleton:ISteamService
|
||||
{
|
||||
private ISteamService _steamServiceImplementation=>SteamService.Singleton;
|
||||
public int Id => _steamServiceImplementation.Id;
|
||||
public ulong SteamId => _steamServiceImplementation.SteamId;
|
||||
public string Name => _steamServiceImplementation.Name;
|
||||
public bool IsInitialized=>_steamServiceImplementation.IsInitialized;
|
||||
public UniTask<Texture2D> GetAvatarAsync(CancellationToken token)=>_steamServiceImplementation.GetAvatarAsync(token);
|
||||
public UniTask<ISteamInventoryItemDef[]> GetInventoryItemDefsAsync(CancellationToken token)=>_steamServiceImplementation.GetInventoryItemDefsAsync(token);
|
||||
}
|
||||
}
|
26
Assets/BITKit/UnityPluginsSupport/Tests/FloatTest.cs
Normal file
26
Assets/BITKit/UnityPluginsSupport/Tests/FloatTest.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using System.Text;
|
||||
using UnityEngine.TestTools;
|
||||
using System.Linq;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public class FloatTest
|
||||
{
|
||||
[Test]
|
||||
public void AddRandom()
|
||||
{
|
||||
float currentValue = 0;
|
||||
for (int i = 0; i < Random.Range(1,4); i++)
|
||||
{
|
||||
float newValue = Random.Range(0, 8f);
|
||||
Debug.Log($"{currentValue}+{newValue} = {currentValue+=newValue}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
30
Assets/BITKit/UnityPluginsSupport/Tests/GenericEventTest.cs
Normal file
30
Assets/BITKit/UnityPluginsSupport/Tests/GenericEventTest.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using Newtonsoft.Json;
|
||||
using System.Reflection;
|
||||
using System.IO;
|
||||
using BITKit.IO;
|
||||
using System.Text;
|
||||
namespace BITKit
|
||||
{
|
||||
public class GenericEventTest
|
||||
{
|
||||
[Test]
|
||||
public void TestInvokeByType()
|
||||
{
|
||||
GenericEvent genericEvent = new();
|
||||
genericEvent.AddListener<string>(OnGetString);
|
||||
|
||||
genericEvent.Invoke<string>("Value 123");
|
||||
genericEvent.Invoke(typeof(string).Name, "Value 321" as object);
|
||||
void OnGetString(string value)
|
||||
{
|
||||
Debug.Log($"事件回调:{value}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
35
Assets/BITKit/UnityPluginsSupport/Tests/IEnumerableTest.cs
Normal file
35
Assets/BITKit/UnityPluginsSupport/Tests/IEnumerableTest.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using Newtonsoft.Json;
|
||||
namespace BITKit
|
||||
{
|
||||
public class IEnumerableTest
|
||||
{
|
||||
[Test]
|
||||
public void AppendIEnumerable()
|
||||
{
|
||||
List<int> list = new();
|
||||
|
||||
list.CreateOrAddIfEmety(list,() => 1);
|
||||
list.Add(2);
|
||||
|
||||
int[] array = new int[0];
|
||||
array.CreateOrAddIfEmety(array,() => 1);
|
||||
|
||||
Debug.Log("Length Should Be 2");
|
||||
Debug.Log($"List:{JsonConvert.SerializeObject(list, Formatting.Indented)}");
|
||||
Debug.Log($"Array:{JsonConvert.SerializeObject(array, Formatting.Indented)}");
|
||||
}
|
||||
[Test]
|
||||
public void 获取所有组合()
|
||||
{
|
||||
List<int> list = new() { 1, 2, 3, 4, 5 };
|
||||
var result = list.GetAllCombination();
|
||||
Debug.Log($"List:{JsonConvert.SerializeObject(list, Formatting.Indented)}");
|
||||
Debug.Log($"Result:{JsonConvert.SerializeObject(result, Formatting.Indented)}");
|
||||
}
|
||||
}
|
||||
}
|
46
Assets/BITKit/UnityPluginsSupport/Tests/MemoryStreamTest.cs
Normal file
46
Assets/BITKit/UnityPluginsSupport/Tests/MemoryStreamTest.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using Newtonsoft.Json;
|
||||
using System.Reflection;
|
||||
using System.IO;
|
||||
using BITKit.IO;
|
||||
using System.Text;
|
||||
namespace BITKit
|
||||
{
|
||||
public class MemoryStreamTest
|
||||
{
|
||||
[Test]
|
||||
public void WriteStringToMemorySteam()
|
||||
{
|
||||
var _str = nameof(MemoryStreamTest);
|
||||
var _int = 256;
|
||||
var _float = 3.1415926;
|
||||
byte[] bytes;
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
using (BinaryWriter writer = new(ms))
|
||||
{
|
||||
writer.Write(_str);
|
||||
writer.Write(_int);
|
||||
writer.Write(_float);
|
||||
}
|
||||
bytes = ms.ToArray();
|
||||
}
|
||||
Debug.Log($"输入:\nstring:{_str}\nint{_int}\nfloat{_float}");
|
||||
using (var ms = new MemoryStream(bytes))
|
||||
{
|
||||
using (var reader = new BinaryReader(ms))
|
||||
{
|
||||
_str = reader.ReadString();
|
||||
_int = reader.ReadInt32();
|
||||
_float = (float)reader.ReadDouble();
|
||||
}
|
||||
}
|
||||
Debug.Log($":\nstring:{_str}\nint{_int}\nfloat{_float}");
|
||||
}
|
||||
}
|
||||
}
|
46
Assets/BITKit/UnityPluginsSupport/Tests/MiscTest.cs
Normal file
46
Assets/BITKit/UnityPluginsSupport/Tests/MiscTest.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using System.Text;
|
||||
using UnityEngine.TestTools;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public class MiscTest
|
||||
{
|
||||
[Test]
|
||||
public static void CheckPath()
|
||||
{
|
||||
var reportBuilder = new StringBuilder();
|
||||
reportBuilder.AppendLine($"{nameof(EditorApplication.applicationPath)}:{EditorApplication.applicationPath}");
|
||||
reportBuilder.AppendLine($"{nameof(Application.dataPath)}:{Application.dataPath}");
|
||||
reportBuilder.AppendLine($"{nameof(Environment.CurrentDirectory)}:{Environment.CurrentDirectory}");
|
||||
reportBuilder.AppendLine($"{nameof(Application.streamingAssetsPath)}:{Application.streamingAssetsPath}");
|
||||
reportBuilder.AppendLine($"{nameof(Application.persistentDataPath)}:{Application.persistentDataPath}");
|
||||
reportBuilder.AppendLine($"{nameof(Application.temporaryCachePath)}:{Application.temporaryCachePath}");
|
||||
reportBuilder.AppendLine($"{nameof(Application.consoleLogPath)}:{Application.consoleLogPath}");
|
||||
reportBuilder.AppendLine($"{nameof(Application.installerName)}:{Application.installerName}");
|
||||
reportBuilder.AppendLine($"{nameof(Application.companyName)}:{Application.companyName}");
|
||||
reportBuilder.AppendLine($"{nameof(Application.productName)}:{Application.productName}");
|
||||
reportBuilder.AppendLine($"{nameof(Application.version)}:{Application.version}");
|
||||
reportBuilder.AppendLine($"{nameof(Application.unityVersion)}:{Application.unityVersion}");
|
||||
reportBuilder.AppendLine($"{nameof(Application.identifier)}:{Application.identifier}");
|
||||
reportBuilder.AppendLine($"{nameof(Application.internetReachability)}:{Application.internetReachability}");
|
||||
reportBuilder.AppendLine($"{nameof(Application.systemLanguage)}:{Application.systemLanguage}");
|
||||
reportBuilder.AppendLine($"{nameof(Application.platform)}:{Application.platform}");
|
||||
reportBuilder.AppendLine($"{nameof(Application.isMobilePlatform)}:{Application.isMobilePlatform}");
|
||||
reportBuilder.AppendLine($"{nameof(Application.isConsolePlatform)}:{Application.isConsolePlatform}");
|
||||
reportBuilder.AppendLine($"{nameof(Application.isEditor)}:{Application.isEditor}");
|
||||
reportBuilder.AppendLine($"{nameof(Application.isFocused)}:{Application.isFocused}");
|
||||
reportBuilder.AppendLine($"{nameof(Application.isPlaying)}:{Application.isPlaying}");
|
||||
reportBuilder.AppendLine($"{nameof(Application.isBatchMode)}:{Application.isBatchMode}");
|
||||
|
||||
Debug.Log(reportBuilder.ToString());
|
||||
}
|
||||
}
|
||||
}
|
30
Assets/BITKit/UnityPluginsSupport/Tests/PointerTest.cs
Normal file
30
Assets/BITKit/UnityPluginsSupport/Tests/PointerTest.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using System.Text;
|
||||
using UnityEngine.TestTools;
|
||||
using System.Linq;
|
||||
namespace BITKit
|
||||
{
|
||||
public class PointerTest
|
||||
{
|
||||
public object value;
|
||||
[Test]
|
||||
public void MakeRefAndRefValue()
|
||||
{
|
||||
value = 64;
|
||||
|
||||
var typedReference = __makeref(value);
|
||||
|
||||
var field = typeof(PointerTest).GetField("value");
|
||||
|
||||
field.SetValueDirect(typedReference,128);
|
||||
|
||||
__refvalue(typedReference,object) = 128;
|
||||
|
||||
Debug.Log("预期值:128,实际值:"+value);
|
||||
}
|
||||
}
|
||||
}
|
142
Assets/BITKit/UnityPluginsSupport/Tests/StringTest.cs
Normal file
142
Assets/BITKit/UnityPluginsSupport/Tests/StringTest.cs
Normal file
@@ -0,0 +1,142 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using System.Text;
|
||||
using UnityEngine.TestTools;
|
||||
using System.Linq;
|
||||
namespace BITKit
|
||||
{
|
||||
public class StringTest
|
||||
{
|
||||
[Test]
|
||||
public void JoinString()
|
||||
{
|
||||
List<string> stringList = new()
|
||||
{
|
||||
"UX",
|
||||
"Test",
|
||||
"Creator"
|
||||
};
|
||||
Debug.Log(string.Join("/",stringList));
|
||||
}
|
||||
[Test]
|
||||
public void SpliteNamespace()
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
List<string> ignoreNamespaces = new()
|
||||
{
|
||||
"System",
|
||||
"UnityEngine",
|
||||
"Unity",
|
||||
"Microsoft",
|
||||
"UnityEditor",
|
||||
"Google",
|
||||
"Mono",
|
||||
"ZXing",
|
||||
"ImmersiveVRTools",
|
||||
"MonKey",
|
||||
"FLib",
|
||||
"Kcp",
|
||||
"Udx",
|
||||
"Sirenix",
|
||||
"TMPro",
|
||||
"RotaryHeart",
|
||||
"Cinemachine",
|
||||
"ParadoxNotion",
|
||||
"Net",
|
||||
"VSCodeEditor",
|
||||
"AOT",
|
||||
"UnityEditorInternal",
|
||||
"UnityEngineInternal",
|
||||
"JetBrains",
|
||||
"Bee",
|
||||
"NotInvited",
|
||||
"HighlightPlus",
|
||||
"DG",
|
||||
"Hierarchy2",
|
||||
"Cysharp",
|
||||
"JetBrains",
|
||||
"Packages",
|
||||
"Newtonsoft_X",
|
||||
"Binding",
|
||||
"NodeCanvas",
|
||||
"SaveDuringPlay",
|
||||
"LimWorks",
|
||||
"MagicaCloth2",
|
||||
"FastScriptReload",
|
||||
"ParrelSync",
|
||||
"KinematicCharacterController",
|
||||
"LimWorksEditor",
|
||||
"BuildComponent",
|
||||
"dnlib",
|
||||
"BigIntegerLibrary",
|
||||
"Ionic",
|
||||
"log4net",
|
||||
"DG",
|
||||
"ImmersiveVrToolsCommon",
|
||||
"NUnit",
|
||||
"HarmonyLib",
|
||||
"MonoMod",
|
||||
"WebDav",
|
||||
"PlasticGui",
|
||||
"Codice",
|
||||
"GluonGui",
|
||||
"PlasticPipe",
|
||||
"XDiffGui",
|
||||
"MacFsWatcher",
|
||||
"MacUI",
|
||||
"PlayerBuildProgramLibrary",
|
||||
"ExCSS",
|
||||
"ScriptCompilationBuildProgram",
|
||||
"BeeBuildProgramCommon",
|
||||
"Accessibility",
|
||||
"CodiceApp",
|
||||
"Newtonsoft",
|
||||
"MergetoolGui",
|
||||
"TreeEditor",
|
||||
"MackySoft",
|
||||
"FullscreenEditor",
|
||||
|
||||
};
|
||||
var allTypes =new List<Type>();
|
||||
var supportTypes=new List<Type>();
|
||||
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
try
|
||||
{
|
||||
allTypes.AddRange(assembly.GetExportedTypes());
|
||||
}
|
||||
catch
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
stringBuilder.AppendLine($"以获取到类型:{allTypes.Count()}个");
|
||||
foreach (var type in allTypes)
|
||||
{
|
||||
var typeName = type.Name;
|
||||
var nameSpace = type.Namespace;
|
||||
var rootNamespace =string.IsNullOrEmpty(nameSpace)?string.Empty : nameSpace.Split(@".").First();
|
||||
var contrast = ignoreNamespaces.Contains(rootNamespace);
|
||||
//stringBuilder.AppendLine($"类型名称:{typeName}\t命名空间{nameSpace}\t根命名空间:{rootNamespace}\t对比结果:{contrast}");
|
||||
if(contrast)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
supportTypes.Add(type);
|
||||
}
|
||||
}
|
||||
stringBuilder.AppendLine($"所有类型{allTypes.Count()}个\t支持类型{supportTypes.Count}");
|
||||
stringBuilder.AppendLine("已支持的命名空间:");
|
||||
foreach (var x in supportTypes.Select(x=>x.Namespace).Distinct())
|
||||
{
|
||||
stringBuilder.AppendLine(x);
|
||||
}
|
||||
Debug.Log(stringBuilder);
|
||||
}
|
||||
}
|
||||
}
|
25
Assets/BITKit/UnityPluginsSupport/Tests/Tests.asmdef
Normal file
25
Assets/BITKit/UnityPluginsSupport/Tests/Tests.asmdef
Normal file
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "Tests",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"UnityEngine.TestRunner",
|
||||
"UnityEditor.TestRunner",
|
||||
"BITKit"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": true,
|
||||
"precompiledReferences": [
|
||||
"nunit.framework.dll",
|
||||
"Newtonsoft.Json.dll"
|
||||
],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [
|
||||
"UNITY_INCLUDE_TESTS"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
16
Assets/BITKit/UnityPluginsSupport/Tests/VectorTest.cs
Normal file
16
Assets/BITKit/UnityPluginsSupport/Tests/VectorTest.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public class Vector : MonoBehaviour
|
||||
{
|
||||
[Test]
|
||||
public void CalculateSqrMagnitude()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "BITKit.Extensions.TranslucentImage",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:6ef4ed8ff60a7aa4bb60a8030e6f4008",
|
||||
"GUID:ff218ee40fe2b8648ab3234d56415557"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [
|
||||
"LeTai_TranslucentImage"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using LeTai.Asset.TranslucentImage;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class TranslucentService : MonoBehaviour
|
||||
{
|
||||
public static RenderTexture BlurredScreen;
|
||||
[SerializeField] private TranslucentImageSource source;
|
||||
[SerializeField] private RenderTexture blurredScreen;
|
||||
private void LateUpdate()
|
||||
{
|
||||
source.Request();
|
||||
BlurredScreen = blurredScreen = source.BlurredScreen;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
|
||||
public class TranslucentVisualElement : VisualElement
|
||||
{
|
||||
public new class UxmlFactory : UxmlFactory<TranslucentVisualElement, UxmlTraits> { }
|
||||
public TranslucentVisualElement()
|
||||
{
|
||||
RegisterCallback<GeometryChangedEvent>(OnGeometryChanged);
|
||||
generateVisualContent += DrawCanvas;
|
||||
}
|
||||
|
||||
private void DrawCanvas(MeshGenerationContext obj)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void OnGeometryChanged(GeometryChangedEvent evt)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (BITAppForUnity.IsPlaying is false) return;
|
||||
#endif
|
||||
if (style.display.value is not DisplayStyle.Flex) return;
|
||||
style.backgroundImage = new StyleBackground(Background.FromRenderTexture(TranslucentService.BlurredScreen));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UXTranslucentService : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Image image;
|
||||
private float alpha;
|
||||
private void Start()
|
||||
{
|
||||
BITAppForUnity.AllowCursor.AddListener(OnCursor);
|
||||
destroyCancellationToken.Register(Dispose);
|
||||
}
|
||||
private void Dispose()
|
||||
{
|
||||
BITAppForUnity.AllowCursor.RemoveListener(OnCursor);
|
||||
}
|
||||
private void OnCursor(bool obj)
|
||||
{
|
||||
image.enabled = obj;
|
||||
if (obj) alpha = 0;
|
||||
}
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (BITAppForUnity.AllowCursor.Allow && alpha is not 1)
|
||||
{
|
||||
alpha = Mathf.Clamp01(alpha + Time.deltaTime*5);
|
||||
image.color = new Color(0, 0, 0, alpha);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "UnitySpline",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:21d1eb854b91ade49bc69a263d12bee2",
|
||||
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
|
||||
"GUID:d8b63aba1907145bea998dd612889d6b",
|
||||
"GUID:709caf8d7fb6ef24bbba0ab9962a3ad0",
|
||||
"GUID:7efac18f239530141802fb139776f333",
|
||||
"GUID:f06555f75b070af458a003d92f9efb00"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [
|
||||
"UnitySplines"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
@@ -0,0 +1,109 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Playables;
|
||||
using UnityEngine.Splines;
|
||||
using UnityEngine.Timeline;
|
||||
|
||||
namespace BITKit.Spline
|
||||
{
|
||||
public class UnitySplineAnimateBehaviour : PlayableBehaviour
|
||||
{
|
||||
public SplineAnimate splineAnimate { get; set; }
|
||||
public SplineContainer splineContainer { get; set; }
|
||||
public Transform additiveTransform { get; set; }
|
||||
public bool isNormalized;
|
||||
|
||||
public override void OnBehaviourPlay(Playable playable, FrameData info)
|
||||
{
|
||||
if (splineAnimate)
|
||||
splineAnimate.Updated += OnSplineAnimateUpdated;
|
||||
}
|
||||
public override void OnBehaviourPause(Playable playable, FrameData info)
|
||||
{
|
||||
if (splineAnimate)
|
||||
splineAnimate.Updated -= OnSplineAnimateUpdated;
|
||||
}
|
||||
private void OnSplineAnimateUpdated(Vector3 position, Quaternion rotation)
|
||||
{
|
||||
if (splineAnimate == null)
|
||||
return;
|
||||
|
||||
if (BITAppForUnity.IsEditor&& BITAppForUnity.IsPlaying is false)
|
||||
{
|
||||
var transform = splineAnimate.transform;
|
||||
var parent = transform.parent;
|
||||
var localPosition = position;
|
||||
var localRotation = rotation;
|
||||
if (parent != null)
|
||||
{
|
||||
localPosition = transform.parent.worldToLocalMatrix.MultiplyPoint3x4(position);
|
||||
localRotation = Quaternion.Inverse(parent.rotation) * localRotation;
|
||||
|
||||
}
|
||||
|
||||
transform.localPosition = localPosition;
|
||||
transform.localRotation = localRotation;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public override void ProcessFrame(Playable playable, FrameData info, object playerData)
|
||||
{
|
||||
splineAnimate = playerData as SplineAnimate;
|
||||
|
||||
if (!splineAnimate)
|
||||
{
|
||||
Debug.LogException(new NullReferenceException("SplineAnimate is null"));
|
||||
return;
|
||||
}
|
||||
|
||||
var time = (float)playable.GetTime();
|
||||
splineAnimate.Container = splineContainer;
|
||||
|
||||
if (BITAppForUnity.IsEditor is false && BITAppForUnity.IsPlaying is false)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isNormalized)
|
||||
{
|
||||
splineAnimate.NormalizedTime =info.deltaTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
splineAnimate.ElapsedTime =time;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[DisplayName("SplineAnimate Clip")]
|
||||
public class UnitySplineAnimateAsset : PlayableAsset,ITimelineClipAsset
|
||||
{
|
||||
private UnitySplineAnimateBehaviour template = new();
|
||||
public ExposedReference<SplineContainer> spline;
|
||||
public AnimationCurve curve;
|
||||
public bool isNormalized;
|
||||
public override Playable CreatePlayable(PlayableGraph graph, GameObject owner)
|
||||
{
|
||||
var playable = ScriptPlayable<UnitySplineAnimateBehaviour>.Create(graph,template);
|
||||
|
||||
var behaviour = playable.GetBehaviour();
|
||||
|
||||
behaviour.splineContainer = spline.Resolve(graph.GetResolver());
|
||||
|
||||
behaviour.isNormalized = isNormalized;
|
||||
|
||||
return playable;
|
||||
}
|
||||
public ClipCaps clipCaps => ClipCaps.None;
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Playables;
|
||||
using UnityEngine.Splines;
|
||||
using UnityEngine.Timeline;
|
||||
|
||||
namespace BITKit.Spline
|
||||
{
|
||||
[TrackBindingType(typeof(SplineAnimate))]
|
||||
[TrackClipType(typeof(UnitySplineAnimateAsset))]
|
||||
public class UnitySplineAnimateTrack : TrackAsset
|
||||
{
|
||||
}
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Splines;
|
||||
namespace BITKit.Spline
|
||||
{
|
||||
public interface ISplineContainer
|
||||
{
|
||||
Transform Position { get; }
|
||||
Transform TangentIn { get; }
|
||||
Transform TangentOut { get; }
|
||||
}
|
||||
[System.Serializable]
|
||||
public class BasicSplineContainer : ISplineContainer
|
||||
{
|
||||
public Transform m_transform;
|
||||
public Transform m_tangentIn;
|
||||
public Transform m_tangentOut;
|
||||
public Transform Position => m_transform;
|
||||
public Transform TangentIn => m_tangentIn;
|
||||
public Transform TangentOut => m_tangentOut;
|
||||
}
|
||||
[ExecuteAlways]
|
||||
public class UnitySplineCreator : MonoBehaviour
|
||||
{
|
||||
[SerializeReference, SubclassSelector] public List<ISplineContainer> splines = new();
|
||||
public SplineContainer container;
|
||||
public SplineExtrude extrude;
|
||||
[Header(Constant.Header.Settings)]
|
||||
public int updateTimes;
|
||||
void Update()
|
||||
{
|
||||
UnityEngine.Splines.Spline spline = new();
|
||||
foreach (var x in splines)
|
||||
{
|
||||
spline.Add(new BezierKnot()
|
||||
{
|
||||
Position = x.Position.position,
|
||||
Rotation = x.Position.rotation,
|
||||
TangentIn = x.TangentIn ? x.TangentIn.position : Vector3.zero,
|
||||
TangentOut = x.TangentOut ? x.TangentOut.position : Vector3.zero,
|
||||
});
|
||||
}
|
||||
container.Spline = spline;
|
||||
extrude.Rebuild();
|
||||
updateTimes++;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Splines;
|
||||
|
||||
namespace BITKit.Entities.Movement
|
||||
{
|
||||
public class UnitySplineMovementComponent : EntityBehavior
|
||||
{
|
||||
[SerializeField] private float speed;
|
||||
[SerializeField] private SplineContainer spline;
|
||||
|
||||
[Inject] private IHealth _health;
|
||||
[Inject] private IEntityMovement _movement;
|
||||
|
||||
private float _currentDistance;
|
||||
public override void OnFixedUpdate(float deltaTime)
|
||||
{
|
||||
base.OnFixedUpdate(deltaTime);
|
||||
if (_health.IsAlive is false) return;
|
||||
var position = spline.EvaluatePosition(_currentDistance+=speed*deltaTime);
|
||||
|
||||
_movement.Position = spline.transform.rotation * position + spline.transform.position;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Splines;
|
||||
namespace BITKit
|
||||
{
|
||||
[ExecuteAlways]
|
||||
public class UnitySplineRebuilder : MonoBehaviour
|
||||
{
|
||||
[Header(Constant.Header.Settings)]
|
||||
[Range(0, 1)]
|
||||
public float elapsedTime;
|
||||
public bool allowAnimate;
|
||||
[Header(Constant.Header.Debug)]
|
||||
public float m_elapsedTime;
|
||||
[Header(Constant.Header.Components)]
|
||||
public SplineContainer container;
|
||||
public SplineExtrude extrude;
|
||||
public SplineAnimate animate;
|
||||
void Update()
|
||||
{
|
||||
extrude?.Rebuild();
|
||||
if (allowAnimate && animate)
|
||||
{
|
||||
animate.ElapsedTime = elapsedTime;
|
||||
}
|
||||
|
||||
m_elapsedTime = elapsedTime;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.Spline
|
||||
{
|
||||
public class UnitySplineWorldElement : MonoBehaviour
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Splines;
|
||||
namespace BITKit
|
||||
{
|
||||
public class UnityWireSplineCreator : MonoBehaviour,IAction
|
||||
{
|
||||
public Mesh mesh;
|
||||
public SplineContainer container;
|
||||
public SplineExtrude extrude;
|
||||
// ReSharper disable Unity.PerformanceAnalysis
|
||||
[ContextMenu(nameof(Execute))]
|
||||
public void Execute()
|
||||
{
|
||||
UnityEngine.Splines.Spline spline = new();
|
||||
var count = 0;
|
||||
// foreach (var vertexes in MathE.Combinations(mesh.vertices))
|
||||
// {
|
||||
// foreach (var vertex in vertexes)
|
||||
// {
|
||||
// spline.Add(new BezierKnot()
|
||||
// {
|
||||
// Position = vertex
|
||||
// });
|
||||
// count++;
|
||||
// }
|
||||
// }
|
||||
foreach (var vertex in mesh.vertices)
|
||||
{
|
||||
spline.Add(new (vertex));
|
||||
count++;
|
||||
}
|
||||
container.Spline = spline;
|
||||
extrude.Rebuild();
|
||||
Debug.Log($"已创建{count}个顶点");
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "BITKit.Extension.ZXing",
|
||||
"rootNamespace": "",
|
||||
"references": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
BIN
Assets/BITKit/UnityPluginsSupport/ZXing/zxing.unity.dll
Normal file
BIN
Assets/BITKit/UnityPluginsSupport/ZXing/zxing.unity.dll
Normal file
Binary file not shown.
Reference in New Issue
Block a user