From fe555652c3f98fb97d505f9adef1bdb6b3e86645 Mon Sep 17 00:00:00 2001 From: Alexander Filippov Date: Sun, 27 Jun 2021 14:46:18 +0200 Subject: [PATCH] First commit --- Editor.meta | 8 + Editor/Agoxandr.Utils.Editor.asmdef | 18 +++ Editor/Agoxandr.Utils.Editor.asmdef.meta | 7 + Editor/EventManagerEditor.cs | 38 +++++ Editor/EventManagerEditor.cs.meta | 11 ++ Editor/ReadOnlyFieldDrawer.cs | 16 ++ Editor/ReadOnlyFieldDrawer.cs.meta | 11 ++ Editor/ReflectionProbeVolumeEditor.cs | 151 ++++++++++++++++++ Editor/ReflectionProbeVolumeEditor.cs.meta | 11 ++ Editor/SceneViewRotation.cs | 81 ++++++++++ Editor/SceneViewRotation.cs.meta | 11 ++ Runtime.meta | 8 + Runtime/Agoxandr.Utils.asmdef | 13 ++ Runtime/Agoxandr.Utils.asmdef.meta | 7 + Runtime/Array.cs | 24 +++ Runtime/Array.cs.meta | 11 ++ Runtime/DefaultMonoBehaviourEditor.cs | 34 ++++ Runtime/DefaultMonoBehaviourEditor.cs.meta | 11 ++ Runtime/DefaultScriptableObjectEditor.cs | 34 ++++ Runtime/DefaultScriptableObjectEditor.cs.meta | 11 ++ Runtime/EventManager.cs | 46 ++++++ Runtime/EventManager.cs.meta | 11 ++ Runtime/HideScriptField.cs | 7 + Runtime/HideScriptField.cs.meta | 11 ++ Runtime/ReadOnlyFieldAttribute.cs | 5 + Runtime/ReadOnlyFieldAttribute.cs.meta | 11 ++ Runtime/ReflectionProbeVolume.cs | 107 +++++++++++++ Runtime/ReflectionProbeVolume.cs.meta | 11 ++ Runtime/TimeSince.cs | 36 +++++ Runtime/TimeSince.cs.meta | 11 ++ package.json | 15 ++ package.json.meta | 7 + 32 files changed, 794 insertions(+) create mode 100644 Editor.meta create mode 100644 Editor/Agoxandr.Utils.Editor.asmdef create mode 100644 Editor/Agoxandr.Utils.Editor.asmdef.meta create mode 100644 Editor/EventManagerEditor.cs create mode 100644 Editor/EventManagerEditor.cs.meta create mode 100644 Editor/ReadOnlyFieldDrawer.cs create mode 100644 Editor/ReadOnlyFieldDrawer.cs.meta create mode 100644 Editor/ReflectionProbeVolumeEditor.cs create mode 100644 Editor/ReflectionProbeVolumeEditor.cs.meta create mode 100644 Editor/SceneViewRotation.cs create mode 100644 Editor/SceneViewRotation.cs.meta create mode 100644 Runtime.meta create mode 100644 Runtime/Agoxandr.Utils.asmdef create mode 100644 Runtime/Agoxandr.Utils.asmdef.meta create mode 100644 Runtime/Array.cs create mode 100644 Runtime/Array.cs.meta create mode 100644 Runtime/DefaultMonoBehaviourEditor.cs create mode 100644 Runtime/DefaultMonoBehaviourEditor.cs.meta create mode 100644 Runtime/DefaultScriptableObjectEditor.cs create mode 100644 Runtime/DefaultScriptableObjectEditor.cs.meta create mode 100644 Runtime/EventManager.cs create mode 100644 Runtime/EventManager.cs.meta create mode 100644 Runtime/HideScriptField.cs create mode 100644 Runtime/HideScriptField.cs.meta create mode 100644 Runtime/ReadOnlyFieldAttribute.cs create mode 100644 Runtime/ReadOnlyFieldAttribute.cs.meta create mode 100644 Runtime/ReflectionProbeVolume.cs create mode 100644 Runtime/ReflectionProbeVolume.cs.meta create mode 100644 Runtime/TimeSince.cs create mode 100644 Runtime/TimeSince.cs.meta create mode 100644 package.json create mode 100644 package.json.meta diff --git a/Editor.meta b/Editor.meta new file mode 100644 index 0000000..10f6a03 --- /dev/null +++ b/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0eb4eb3df692ded49bdb057b0c58ee5e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Agoxandr.Utils.Editor.asmdef b/Editor/Agoxandr.Utils.Editor.asmdef new file mode 100644 index 0000000..5f40a9c --- /dev/null +++ b/Editor/Agoxandr.Utils.Editor.asmdef @@ -0,0 +1,18 @@ +{ + "name": "Agoxandr.Utils.Editor", + "rootNamespace": "", + "references": [ + "GUID:80ed647da8ce73c45b66c239eba0365a" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Editor/Agoxandr.Utils.Editor.asmdef.meta b/Editor/Agoxandr.Utils.Editor.asmdef.meta new file mode 100644 index 0000000..0abf477 --- /dev/null +++ b/Editor/Agoxandr.Utils.Editor.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 09e6534102d04e24c9f2104acfe90639 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/EventManagerEditor.cs b/Editor/EventManagerEditor.cs new file mode 100644 index 0000000..b4d2361 --- /dev/null +++ b/Editor/EventManagerEditor.cs @@ -0,0 +1,38 @@ +using UnityEditor; +using UnityEngine; + +namespace Agoxandr.Utils +{ + [CustomEditor(typeof(EventManager), true)] + public class EventManagerEditor : Editor + { + public override void OnInspectorGUI() + { + EventManager myTarget = (EventManager)target; + GUILayout.BeginHorizontal(); + GUILayout.Label("Update"); + if (Application.isPlaying) + { + GUILayout.FlexibleSpace(); + GUILayout.Label(myTarget.UpdateLength().ToString()); + } + GUILayout.EndHorizontal(); + GUILayout.BeginHorizontal(); + GUILayout.Label("FixedUpdate"); + if (Application.isPlaying) + { + GUILayout.FlexibleSpace(); + GUILayout.Label(myTarget.FixedUpdateLength().ToString()); + } + GUILayout.EndHorizontal(); + GUILayout.BeginHorizontal(); + GUILayout.Label("LateUpdate"); + if (Application.isPlaying) + { + GUILayout.FlexibleSpace(); + GUILayout.Label(myTarget.LateUpdateLength().ToString()); + } + GUILayout.EndHorizontal(); + } + } +} diff --git a/Editor/EventManagerEditor.cs.meta b/Editor/EventManagerEditor.cs.meta new file mode 100644 index 0000000..93d15f3 --- /dev/null +++ b/Editor/EventManagerEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cfb61866a7759bd468a8da7f1f6583dd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/ReadOnlyFieldDrawer.cs b/Editor/ReadOnlyFieldDrawer.cs new file mode 100644 index 0000000..d0e773e --- /dev/null +++ b/Editor/ReadOnlyFieldDrawer.cs @@ -0,0 +1,16 @@ +using UnityEditor; +using UnityEngine; + +namespace Agoxandr.Utils +{ + [CustomPropertyDrawer(typeof(ReadOnlyFieldAttribute))] + public class ReadOnlyFieldDrawer : PropertyDrawer + { + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + GUI.enabled = false; + EditorGUI.PropertyField(position, property, label, true); + GUI.enabled = true; + } + } +} diff --git a/Editor/ReadOnlyFieldDrawer.cs.meta b/Editor/ReadOnlyFieldDrawer.cs.meta new file mode 100644 index 0000000..ddb4518 --- /dev/null +++ b/Editor/ReadOnlyFieldDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a988db17fd1c9ee4190ccbd3a00f22ae +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/ReflectionProbeVolumeEditor.cs b/Editor/ReflectionProbeVolumeEditor.cs new file mode 100644 index 0000000..43f1980 --- /dev/null +++ b/Editor/ReflectionProbeVolumeEditor.cs @@ -0,0 +1,151 @@ +using UnityEditor; +using UnityEngine; + +namespace Agoxandr.Utils +{ + public class ReflectionProbeVolumeEditor : MonoBehaviour + { + [CustomEditor(typeof(ReflectionProbeVolume), true)] + public class EventManagerEditor : Editor + { + private SerializedProperty resolution; + private SerializedProperty offset; + private SerializedProperty threshold; + + private void OnEnable() + { + resolution = serializedObject.FindProperty("resolution"); + offset = serializedObject.FindProperty("offset"); + threshold = serializedObject.FindProperty("threshold"); + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + EditorGUILayout.PropertyField(resolution); + EditorGUILayout.PropertyField(offset); + EditorGUILayout.PropertyField(threshold); + serializedObject.ApplyModifiedProperties(); + EditorGUILayout.Space(); + if (GUILayout.Button("Place")) + { + Place(); + } + } + + private void Place() + { + var voxelSize = this.resolution.intValue; + var offset = this.offset.floatValue; + var threshold = this.threshold.floatValue; + ReflectionProbeVolume reflectionProbeVolume = (ReflectionProbeVolume)target; + var transform = reflectionProbeVolume.transform; + //Gizmos.DrawWireCube(transform.position, transform.localScale); + var startPos = transform.position + transform.right * transform.localScale.x / 2 + transform.up * transform.localScale.y / 2 + transform.forward * transform.localScale.z / 2; + var xVar = transform.localScale.x / voxelSize / 2f; + var zVar = transform.localScale.z / voxelSize / 2f; + var data = new Vector3[voxelSize, voxelSize]; + //Gizmos.color = Color.blue; + for (int x = 0; x < voxelSize; x++) + { + for (int z = 0; z < voxelSize; z++) + { + var rayPos = startPos - transform.right * xVar - transform.forward * zVar; + if (Physics.Raycast(rayPos, Vector2.down, out RaycastHit hit)) + { + var point = hit.point + Vector3.up * offset; + data[x, z] = point; + } + zVar += transform.localScale.z / voxelSize; + } + xVar += transform.localScale.x / voxelSize; + zVar = transform.localScale.z / voxelSize / 2f; + } + + CheckSquare(data, 5, voxelSize, threshold, transform); + CheckSquare(data, 4, voxelSize, threshold, transform); + CheckSquare(data, 3, voxelSize, threshold, transform); + CheckSquare(data, 2, voxelSize, threshold, transform); + + for (int x = 0; x < voxelSize; x++) + { + for (int z = 0; z < voxelSize; z++) + { + if (data[x, z].x != float.PositiveInfinity) + { + var go = new GameObject("Reflection Probe Size: 1"); + go.transform.SetParent(transform); + go.transform.position = data[x, z]; + var reflectionProbe = go.AddComponent(typeof(ReflectionProbe)) as ReflectionProbe; + reflectionProbe.resolution = 16; + reflectionProbe.center = new Vector3(0f, transform.position.y - data[x, z].y, 0f); + reflectionProbe.size = new Vector3(transform.localScale.x / voxelSize, transform.localScale.y, transform.localScale.z / voxelSize); + } + } + } + } + + private void CheckSquare(Vector3[,] data, int size, int voxelSize, float threshold, Transform transform) + { + for (int x = 0; x < voxelSize; x++) + { + for (int z = 0; z < voxelSize; z++) + { + if (x + size <= voxelSize && z + size <= voxelSize) + { + bool valid = true; + var point = Vector3.zero; + for (int i = 0; i < size; i++) + { + for (int k = 0; k < size; k++) + { + var pos = data[x + i, z + k]; + if (pos != Vector3.positiveInfinity) + { + if (Compare(data[x, z].y, pos.y, threshold)) + { + point += pos; + + } + else + { + valid = false; + } + } + } + } + if (valid) + { + point /= size * size; + + var go = new GameObject("Reflection Probe Size: " + size); + go.transform.SetParent(transform); + go.transform.position = point; + var reflectionProbe = go.AddComponent(typeof(ReflectionProbe)) as ReflectionProbe; + if (size == 2) reflectionProbe.resolution = 16; + else if (size == 3) reflectionProbe.resolution = 32; + else if (size == 4) reflectionProbe.resolution = 32; + else if (size == 5) reflectionProbe.resolution = 64; + reflectionProbe.center = new Vector3(0f, transform.position.y - point.y, 0f); + reflectionProbe.size = new Vector3(transform.localScale.x / voxelSize * size, transform.localScale.y, transform.localScale.z / voxelSize * size); + + for (int i = 0; i < size; i++) + { + for (int k = 0; k < size; k++) + { + data[x + i, z + k] = Vector3.positiveInfinity; + } + } + } + } + } + } + } + + private bool Compare(float arg0, float arg1, float threshold) + { + return Mathf.Abs(arg0 - arg1) < threshold; + } + } + } +} diff --git a/Editor/ReflectionProbeVolumeEditor.cs.meta b/Editor/ReflectionProbeVolumeEditor.cs.meta new file mode 100644 index 0000000..8742fe7 --- /dev/null +++ b/Editor/ReflectionProbeVolumeEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a77b3177fd3b4754cb1b855b831c5424 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/SceneViewRotation.cs b/Editor/SceneViewRotation.cs new file mode 100644 index 0000000..e8f22f4 --- /dev/null +++ b/Editor/SceneViewRotation.cs @@ -0,0 +1,81 @@ +using UnityEditor; +using UnityEngine; + +namespace Agoxandr.Utils +{ + [InitializeOnLoad] + public static class SceneViewRotation + { + private static bool toggleDir; + + static SceneViewRotation() + { + SceneView.duringSceneGui += OnSceneGUI; + } + + private static void OnSceneGUI(SceneView sceneView) + { + if (sceneView.isRotationLocked) + { + return; + } + Event e = Event.current; + switch (e.type) + { + case EventType.KeyDown: + if (e.keyCode == KeyCode.Keypad1) + { + sceneView.rotation = Quaternion.LookRotation(toggleDir ? Vector3.forward : Vector3.back); + } + else if (e.keyCode == KeyCode.Keypad2) + { + var angles = sceneView.rotation.eulerAngles; + sceneView.rotation = Quaternion.Euler(angles.x - 15f, angles.y, angles.z); + } + else if (e.keyCode == KeyCode.Keypad3) + { + sceneView.rotation = Quaternion.LookRotation(toggleDir ? Vector3.left : Vector3.right); + } + else if (e.keyCode == KeyCode.Keypad4) + { + var angles = sceneView.rotation.eulerAngles; + sceneView.rotation = Quaternion.Euler(angles.x, angles.y + 15f, angles.z); + } + else if (e.keyCode == KeyCode.Keypad5) + { + sceneView.orthographic = !sceneView.orthographic; + } + else if (e.keyCode == KeyCode.Keypad6) + { + var angles = sceneView.rotation.eulerAngles; + sceneView.rotation = Quaternion.Euler(angles.x, angles.y - 15f, angles.z); + } + else if (e.keyCode == KeyCode.Keypad7) + { + sceneView.rotation = new Quaternion(0f, toggleDir ? -.7f : .7f, -.7f, 0f); + } + else if (e.keyCode == KeyCode.Keypad8) + { + var angles = sceneView.rotation.eulerAngles; + sceneView.rotation = Quaternion.Euler(angles.x + 15f, angles.y, angles.z); + } + //else if (e.keyCode == KeyCode.Keypad9) + //{ + // //sceneView.rotation = Quaternion.LookRotation(-sceneView.camera.transform.forward); + // sceneView.rotation = Quaternion.Inverse(sceneView.rotation); + //} + else if (e.keyCode == KeyCode.LeftControl) + { + toggleDir = true; + } + break; + case EventType.KeyUp: + if (e.keyCode == KeyCode.LeftControl) + { + toggleDir = false; + } + break; + } + } + } +} diff --git a/Editor/SceneViewRotation.cs.meta b/Editor/SceneViewRotation.cs.meta new file mode 100644 index 0000000..886afb3 --- /dev/null +++ b/Editor/SceneViewRotation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 76a26ed3da43c8e44b991241a3310661 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime.meta b/Runtime.meta new file mode 100644 index 0000000..1cb470f --- /dev/null +++ b/Runtime.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5c341e38fb3e1874bb71cbdaf42dd11f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Agoxandr.Utils.asmdef b/Runtime/Agoxandr.Utils.asmdef new file mode 100644 index 0000000..2a5f5dc --- /dev/null +++ b/Runtime/Agoxandr.Utils.asmdef @@ -0,0 +1,13 @@ +{ + "name": "Agoxandr.Utils", + "references": [], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Runtime/Agoxandr.Utils.asmdef.meta b/Runtime/Agoxandr.Utils.asmdef.meta new file mode 100644 index 0000000..c62fc89 --- /dev/null +++ b/Runtime/Agoxandr.Utils.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 80ed647da8ce73c45b66c239eba0365a +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Array.cs b/Runtime/Array.cs new file mode 100644 index 0000000..a1d03e2 --- /dev/null +++ b/Runtime/Array.cs @@ -0,0 +1,24 @@ +using System; + +namespace Agoxandr.Utils +{ + public static class Array + { + public static T[] Append(this T[] array, T item) + { + if (array == null) + { + return new T[] { item }; + } + + T[] result = new T[array.Length + 1]; + for (int i = 0; i < array.Length; i++) + { + result[i] = array[i]; + } + + result[array.Length] = item; + return result; + } + } +} diff --git a/Runtime/Array.cs.meta b/Runtime/Array.cs.meta new file mode 100644 index 0000000..1737d32 --- /dev/null +++ b/Runtime/Array.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6e14f8172d2e1b345bd36b974bcaeb61 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/DefaultMonoBehaviourEditor.cs b/Runtime/DefaultMonoBehaviourEditor.cs new file mode 100644 index 0000000..89d5882 --- /dev/null +++ b/Runtime/DefaultMonoBehaviourEditor.cs @@ -0,0 +1,34 @@ +#if UNITY_EDITOR +using UnityEditor; +using UnityEngine; + +namespace Agoxandr.Utils +{ + [CustomEditor(typeof(MonoBehaviour), true)] + public class DefaultMonoBehaviourEditor : Editor + { + private bool hideScriptField; + + private void OnEnable() + { + hideScriptField = target.GetType().GetCustomAttributes(typeof(HideScriptField), false).Length > 0; + } + + public override void OnInspectorGUI() + { + if (hideScriptField) + { + serializedObject.Update(); + EditorGUI.BeginChangeCheck(); + DrawPropertiesExcluding(serializedObject, "m_Script"); + if (EditorGUI.EndChangeCheck()) + serializedObject.ApplyModifiedProperties(); + } + else + { + base.OnInspectorGUI(); + } + } + } +} +#endif \ No newline at end of file diff --git a/Runtime/DefaultMonoBehaviourEditor.cs.meta b/Runtime/DefaultMonoBehaviourEditor.cs.meta new file mode 100644 index 0000000..6469c1b --- /dev/null +++ b/Runtime/DefaultMonoBehaviourEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: eb81e1373aff45646b4be5eaacc2d20f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/DefaultScriptableObjectEditor.cs b/Runtime/DefaultScriptableObjectEditor.cs new file mode 100644 index 0000000..f311d1d --- /dev/null +++ b/Runtime/DefaultScriptableObjectEditor.cs @@ -0,0 +1,34 @@ +#if UNITY_EDITOR +using UnityEditor; +using UnityEngine; + +namespace Agoxandr.Utils +{ + [CustomEditor(typeof(ScriptableObject), true)] + public class DefaultScriptableObjectEditor : Editor + { + private bool hideScriptField; + + private void OnEnable() + { + hideScriptField = target.GetType().GetCustomAttributes(typeof(HideScriptField), false).Length > 0; + } + + public override void OnInspectorGUI() + { + if (hideScriptField) + { + serializedObject.Update(); + EditorGUI.BeginChangeCheck(); + DrawPropertiesExcluding(serializedObject, "m_Script"); + if (EditorGUI.EndChangeCheck()) + serializedObject.ApplyModifiedProperties(); + } + else + { + base.OnInspectorGUI(); + } + } + } +} +#endif \ No newline at end of file diff --git a/Runtime/DefaultScriptableObjectEditor.cs.meta b/Runtime/DefaultScriptableObjectEditor.cs.meta new file mode 100644 index 0000000..4abe201 --- /dev/null +++ b/Runtime/DefaultScriptableObjectEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cf2664ad6bca36847b220c7a796fda2f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/EventManager.cs b/Runtime/EventManager.cs new file mode 100644 index 0000000..505ad74 --- /dev/null +++ b/Runtime/EventManager.cs @@ -0,0 +1,46 @@ +using UnityEngine; + +namespace Agoxandr.Utils +{ + public class EventManager : MonoBehaviour + { + public delegate void UpdateAction(); + public static event UpdateAction OnUpdated; + + public delegate void FixedUpdateAction(); + public static event FixedUpdateAction OnFixedUpdated; + + public delegate void LateUpdateAction(); + public static event LateUpdateAction OnLateUpdated; + + private void Update() + { + OnUpdated?.Invoke(); + } + + private void FixedUpdate() + { + OnFixedUpdated?.Invoke(); + } + + private void LateUpdate() + { + OnLateUpdated?.Invoke(); + } + + public int UpdateLength() + { + return (int)OnUpdated?.GetInvocationList().Length; + } + + public int FixedUpdateLength() + { + return (int)OnFixedUpdated?.GetInvocationList().Length; + } + + public int LateUpdateLength() + { + return (int)OnLateUpdated?.GetInvocationList().Length; + } + } +} diff --git a/Runtime/EventManager.cs.meta b/Runtime/EventManager.cs.meta new file mode 100644 index 0000000..3e50f50 --- /dev/null +++ b/Runtime/EventManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0bb08af31d5be794d8b065613bf63318 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/HideScriptField.cs b/Runtime/HideScriptField.cs new file mode 100644 index 0000000..ac027a5 --- /dev/null +++ b/Runtime/HideScriptField.cs @@ -0,0 +1,7 @@ +using System; + +namespace Agoxandr.Utils +{ + [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] + public sealed class HideScriptField : Attribute { } +} \ No newline at end of file diff --git a/Runtime/HideScriptField.cs.meta b/Runtime/HideScriptField.cs.meta new file mode 100644 index 0000000..e81549a --- /dev/null +++ b/Runtime/HideScriptField.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 01070f8d70b500f46bbff0be7295d435 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/ReadOnlyFieldAttribute.cs b/Runtime/ReadOnlyFieldAttribute.cs new file mode 100644 index 0000000..06ef1a8 --- /dev/null +++ b/Runtime/ReadOnlyFieldAttribute.cs @@ -0,0 +1,5 @@ +using UnityEngine; +namespace Agoxandr.Utils +{ + public class ReadOnlyFieldAttribute : PropertyAttribute { } +} diff --git a/Runtime/ReadOnlyFieldAttribute.cs.meta b/Runtime/ReadOnlyFieldAttribute.cs.meta new file mode 100644 index 0000000..ad5bbd1 --- /dev/null +++ b/Runtime/ReadOnlyFieldAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 49159ec7b8dcf764485aa5b141808651 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/ReflectionProbeVolume.cs b/Runtime/ReflectionProbeVolume.cs new file mode 100644 index 0000000..a41580d --- /dev/null +++ b/Runtime/ReflectionProbeVolume.cs @@ -0,0 +1,107 @@ +using System.Diagnostics; +using UnityEngine; + +namespace Agoxandr.Utils +{ + public class ReflectionProbeVolume : MonoBehaviour + { + [Min(1)] + public int resolution = 4; + public float offset = 2; + [Min(0)] + public float threshold = .5f; + + [Conditional("UNITY_EDITOR")] + private void OnDrawGizmosSelected() + { + Gizmos.DrawWireCube(transform.position, transform.localScale); + var startPos = transform.position + transform.right * transform.localScale.x / 2 + transform.up * transform.localScale.y / 2 + transform.forward * transform.localScale.z / 2; + var xVar = transform.localScale.x / resolution / 2f; + var zVar = transform.localScale.z / resolution / 2f; + var data = new Vector3[resolution, resolution]; + Gizmos.color = Color.blue; + for (int x = 0; x < resolution; x++) + { + for (int z = 0; z < resolution; z++) + { + var rayPos = startPos - transform.right * xVar - transform.forward * zVar; + if (Physics.Raycast(rayPos, Vector2.down, out RaycastHit hit)) + { + var point = hit.point + Vector3.up * offset; + data[x, z] = point; + } + zVar += transform.localScale.z / resolution; + } + xVar += transform.localScale.x / resolution; + zVar = transform.localScale.z / resolution / 2f; + } + + CheckSquare(data, 5); + CheckSquare(data, 4); + CheckSquare(data, 3); + CheckSquare(data, 2); + + for (int x = 0; x < resolution; x++) + { + for (int z = 0; z < resolution; z++) + { + if (data[x, z] != Vector3.positiveInfinity) + { + Gizmos.DrawSphere(data[x, z], .1f); + } + } + } + } + + private void CheckSquare(Vector3[,] data, int size) + { + for (int x = 0; x < resolution; x++) + { + for (int z = 0; z < resolution; z++) + { + if (x + size <= resolution && z + size <= resolution) + { + bool valid = true; + var point = Vector3.zero; + for (int i = 0; i < size; i++) + { + for (int k = 0; k < size; k++) + { + var pos = data[x + i, z + k]; + if (pos != Vector3.positiveInfinity) + { + if (Compare(data[x, z].y, pos.y)) + { + point += pos; + + } + else + { + valid = false; + } + } + } + } + if (valid) + { + point /= size * size; + Gizmos.DrawSphere(point, size * .1f); + for (int i = 0; i < size; i++) + { + for (int k = 0; k < size; k++) + { + data[x + i, z + k] = Vector3.positiveInfinity; + } + } + } + } + } + } + } + + private bool Compare(float arg0, float arg1) + { + return Mathf.Abs(arg0 - arg1) < threshold; + } + } +} diff --git a/Runtime/ReflectionProbeVolume.cs.meta b/Runtime/ReflectionProbeVolume.cs.meta new file mode 100644 index 0000000..a5bf09f --- /dev/null +++ b/Runtime/ReflectionProbeVolume.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a740d05cae346654fbd4dc576e6405ab +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/TimeSince.cs b/Runtime/TimeSince.cs new file mode 100644 index 0000000..92d97ef --- /dev/null +++ b/Runtime/TimeSince.cs @@ -0,0 +1,36 @@ +// https://garry.tv/timesince + +//TimeSince ts; + +//void Start() +//{ +// ts = 0; +//} + +//void Update() +//{ +// if (ts > 10) +// { +// DoSomethingAfterTenSeconds(); +// } +//} + +using UnityEngine; + +namespace Agoxandr.Utils +{ + public struct TimeSince + { + private float time; + + public static implicit operator float(TimeSince ts) + { + return Time.time - ts.time; + } + + public static implicit operator TimeSince(float ts) + { + return new TimeSince { time = Time.time - ts }; + } + } +} diff --git a/Runtime/TimeSince.cs.meta b/Runtime/TimeSince.cs.meta new file mode 100644 index 0000000..4559973 --- /dev/null +++ b/Runtime/TimeSince.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8969b6c0535a0984f95d376c95506953 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package.json b/package.json new file mode 100644 index 0000000..9c68bae --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "de.agoxandr.utils", + "version": "2.5.1", + "displayName": "Utils", + "description": "Utility useful for almost any project.", + "keywords": [ + "Utility", + "Utils", + "Agoxandr" + ], + "author": { + "name": "Alexander Filippov", + "email": "agoxandr@gmail.com" + } +} \ No newline at end of file diff --git a/package.json.meta b/package.json.meta new file mode 100644 index 0000000..56c6c31 --- /dev/null +++ b/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 3cea9973e4f0f814ea87aacbfbddcb7a +PackageManifestImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: