Linux migration.

This commit is contained in:
2022-05-20 22:58:25 +02:00
parent 029e02fd2f
commit 14bbae67e5
16 changed files with 698 additions and 698 deletions

View File

@ -1,38 +1,38 @@
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
namespace Utils namespace Utils
{ {
[CustomEditor(typeof(EventManager), true)] [CustomEditor(typeof(EventManager), true)]
public class EventManagerEditor : Editor public class EventManagerEditor : Editor
{ {
public override void OnInspectorGUI() public override void OnInspectorGUI()
{ {
var eventManager = (EventManager)target; var eventManager = (EventManager)target;
GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal();
GUILayout.Label("Update"); GUILayout.Label("Update");
if (Application.isPlaying) if (Application.isPlaying)
{ {
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();
GUILayout.Label(EventManager.UpdateLength.ToString()); GUILayout.Label(EventManager.UpdateLength.ToString());
} }
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal();
GUILayout.Label("FixedUpdate"); GUILayout.Label("FixedUpdate");
if (Application.isPlaying) if (Application.isPlaying)
{ {
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();
GUILayout.Label(EventManager.FixedUpdateLength.ToString()); GUILayout.Label(EventManager.FixedUpdateLength.ToString());
} }
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal();
GUILayout.Label("LateUpdate"); GUILayout.Label("LateUpdate");
if (Application.isPlaying) if (Application.isPlaying)
{ {
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();
GUILayout.Label(EventManager.LateUpdateLength.ToString()); GUILayout.Label(EventManager.LateUpdateLength.ToString());
} }
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
} }
} }
} }

View File

@ -1,51 +1,51 @@
using System.IO; using System.IO;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
namespace Utils namespace Utils
{ {
public class PackgeUpdater public class PackgeUpdater
{ {
private static string ManifestPath private static string ManifestPath
{ {
get get
{ {
var projectPath = Directory.GetParent(Application.dataPath).FullName; var projectPath = Directory.GetParent(Application.dataPath).FullName;
var manifestPath = Path.Combine(projectPath, "Packages", "manifest.json"); var manifestPath = Path.Combine(projectPath, "Packages", "manifest.json");
return manifestPath; return manifestPath;
} }
} }
public static string GetIdentifier(string input, char charFrom, char charTo) public static string GetIdentifier(string input, char charFrom, char charTo)
{ {
var first = input.IndexOf(charFrom); var first = input.IndexOf(charFrom);
var second = input.IndexOf(charTo, first + 1); var second = input.IndexOf(charTo, first + 1);
var posFrom = input.IndexOf(charFrom, second + 1); var posFrom = input.IndexOf(charFrom, second + 1);
if (posFrom != -1) //if found char if (posFrom != -1) //if found char
{ {
var posTo = input.IndexOf(charTo, posFrom + 1); var posTo = input.IndexOf(charTo, posFrom + 1);
if (posTo != -1) //if found char if (posTo != -1) //if found char
{ {
return input.Substring(posFrom + 1, posTo - posFrom - 1); return input.Substring(posFrom + 1, posTo - posFrom - 1);
} }
} }
return string.Empty; return string.Empty;
} }
[MenuItem("Assets/Update Git Packages", false, 1000)] [MenuItem("Assets/Update Git Packages", false, 1000)]
private static void UpdateGitPackages() private static void UpdateGitPackages()
{ {
var lines = File.ReadAllLines(ManifestPath); var lines = File.ReadAllLines(ManifestPath);
foreach (var line in lines) foreach (var line in lines)
{ {
if (line.Contains("git")) if (line.Contains("git"))
{ {
var identifier = GetIdentifier(line, '"', '"'); var identifier = GetIdentifier(line, '"', '"');
Debug.Log("Checking for updates " + identifier); Debug.Log("Checking for updates " + identifier);
UnityEditor.PackageManager.Client.Add(identifier); UnityEditor.PackageManager.Client.Add(identifier);
} }
} }
} }
} }
} }

View File

@ -1,16 +1,16 @@
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
namespace Utils namespace Utils
{ {
[CustomPropertyDrawer(typeof(ReadOnlyFieldAttribute))] [CustomPropertyDrawer(typeof(ReadOnlyFieldAttribute))]
public class ReadOnlyFieldDrawer : PropertyDrawer public class ReadOnlyFieldDrawer : PropertyDrawer
{ {
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{ {
GUI.enabled = false; GUI.enabled = false;
EditorGUI.PropertyField(position, property, label, true); EditorGUI.PropertyField(position, property, label, true);
GUI.enabled = true; GUI.enabled = true;
} }
} }
} }

View File

@ -1,168 +1,168 @@
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
namespace Utils namespace Utils
{ {
public class ReflectionProbeVolumeEditor : MonoBehaviour public class ReflectionProbeVolumeEditor : MonoBehaviour
{ {
[CustomEditor(typeof(ReflectionProbeVolume), true)] [CustomEditor(typeof(ReflectionProbeVolume), true)]
public class EventManagerEditor : Editor public class EventManagerEditor : Editor
{ {
private SerializedProperty resolution; private SerializedProperty resolution;
private SerializedProperty offset; private SerializedProperty offset;
private SerializedProperty threshold; private SerializedProperty threshold;
private SerializedProperty blendDistance; private SerializedProperty blendDistance;
private void OnEnable() private void OnEnable()
{ {
resolution = serializedObject.FindProperty("resolution"); resolution = serializedObject.FindProperty("resolution");
offset = serializedObject.FindProperty("offset"); offset = serializedObject.FindProperty("offset");
threshold = serializedObject.FindProperty("threshold"); threshold = serializedObject.FindProperty("threshold");
blendDistance = serializedObject.FindProperty("blendDistance"); blendDistance = serializedObject.FindProperty("blendDistance");
} }
public override void OnInspectorGUI() public override void OnInspectorGUI()
{ {
serializedObject.Update(); serializedObject.Update();
EditorGUILayout.PropertyField(resolution); EditorGUILayout.PropertyField(resolution);
EditorGUILayout.PropertyField(offset); EditorGUILayout.PropertyField(offset);
EditorGUILayout.PropertyField(threshold); EditorGUILayout.PropertyField(threshold);
EditorGUILayout.PropertyField(blendDistance); EditorGUILayout.PropertyField(blendDistance);
serializedObject.ApplyModifiedProperties(); serializedObject.ApplyModifiedProperties();
EditorGUILayout.Space(); EditorGUILayout.Space();
if (GUILayout.Button("Place")) if (GUILayout.Button("Place"))
{ {
Place(); Place();
} }
} }
private void Place() private void Place()
{ {
var voxelSize = resolution.intValue; var voxelSize = resolution.intValue;
var offset = this.offset.floatValue; var offset = this.offset.floatValue;
var threshold = this.threshold.floatValue; var threshold = this.threshold.floatValue;
var blendDistance = this.blendDistance.floatValue; var blendDistance = this.blendDistance.floatValue;
ReflectionProbeVolume reflectionProbeVolume = (ReflectionProbeVolume)target; ReflectionProbeVolume reflectionProbeVolume = (ReflectionProbeVolume)target;
var transform = reflectionProbeVolume.transform; var transform = reflectionProbeVolume.transform;
//Gizmos.DrawWireCube(transform.position, transform.localScale); //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 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 xVar = transform.localScale.x / voxelSize / 2f;
var zVar = transform.localScale.z / voxelSize / 2f; var zVar = transform.localScale.z / voxelSize / 2f;
var data = new Vector3[voxelSize, voxelSize]; var data = new Vector3[voxelSize, voxelSize];
//Gizmos.color = Color.blue; //Gizmos.color = Color.blue;
for (int x = 0; x < voxelSize; x++) for (int x = 0; x < voxelSize; x++)
{ {
for (int z = 0; z < voxelSize; z++) for (int z = 0; z < voxelSize; z++)
{ {
var rayPos = startPos - transform.right * xVar - transform.forward * zVar; var rayPos = startPos - transform.right * xVar - transform.forward * zVar;
if (Physics.Raycast(rayPos, Vector2.down, out RaycastHit hit)) if (Physics.Raycast(rayPos, Vector2.down, out RaycastHit hit))
{ {
var point = hit.point + Vector3.up * offset; var point = hit.point + Vector3.up * offset;
data[x, z] = point; data[x, z] = point;
} }
zVar += transform.localScale.z / voxelSize; zVar += transform.localScale.z / voxelSize;
} }
xVar += transform.localScale.x / voxelSize; xVar += transform.localScale.x / voxelSize;
zVar = transform.localScale.z / voxelSize / 2f; zVar = transform.localScale.z / voxelSize / 2f;
} }
CheckSquare(data, 5, voxelSize, threshold, blendDistance, transform); CheckSquare(data, 5, voxelSize, threshold, blendDistance, transform);
CheckSquare(data, 4, voxelSize, threshold, blendDistance, transform); CheckSquare(data, 4, voxelSize, threshold, blendDistance, transform);
CheckSquare(data, 3, voxelSize, threshold, blendDistance, transform); CheckSquare(data, 3, voxelSize, threshold, blendDistance, transform);
CheckSquare(data, 2, voxelSize, threshold, blendDistance, transform); CheckSquare(data, 2, voxelSize, threshold, blendDistance, transform);
for (int x = 0; x < voxelSize; x++) for (int x = 0; x < voxelSize; x++)
{ {
for (int z = 0; z < voxelSize; z++) for (int z = 0; z < voxelSize; z++)
{ {
if (data[x, z].x != float.PositiveInfinity) if (data[x, z].x != float.PositiveInfinity)
{ {
var go = new GameObject("Reflection Probe Size: 1"); var go = new GameObject("Reflection Probe Size: 1");
go.transform.SetParent(transform); go.transform.SetParent(transform);
go.transform.position = data[x, z]; go.transform.position = data[x, z];
var reflectionProbe = go.AddComponent(typeof(ReflectionProbe)) as ReflectionProbe; var reflectionProbe = go.AddComponent(typeof(ReflectionProbe)) as ReflectionProbe;
reflectionProbe.resolution = 16; reflectionProbe.resolution = 16;
reflectionProbe.center = new Vector3(0f, transform.position.y - data[x, z].y, 0f); reflectionProbe.center = new Vector3(0f, transform.position.y - data[x, z].y, 0f);
reflectionProbe.size = new Vector3(transform.localScale.x / voxelSize + blendDistance, transform.localScale.y, transform.localScale.z / voxelSize + blendDistance); reflectionProbe.size = new Vector3(transform.localScale.x / voxelSize + blendDistance, transform.localScale.y, transform.localScale.z / voxelSize + blendDistance);
} }
} }
} }
} }
private void CheckSquare(Vector3[,] data, int size, int voxelSize, float threshold, float blendDistance, Transform transform) private void CheckSquare(Vector3[,] data, int size, int voxelSize, float threshold, float blendDistance, Transform transform)
{ {
for (int x = 0; x < voxelSize; x++) for (int x = 0; x < voxelSize; x++)
{ {
for (int z = 0; z < voxelSize; z++) for (int z = 0; z < voxelSize; z++)
{ {
if (x + size <= voxelSize && z + size <= voxelSize) if (x + size <= voxelSize && z + size <= voxelSize)
{ {
bool valid = true; bool valid = true;
var point = Vector3.zero; var point = Vector3.zero;
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
for (int k = 0; k < size; k++) for (int k = 0; k < size; k++)
{ {
var pos = data[x + i, z + k]; var pos = data[x + i, z + k];
if (pos != Vector3.positiveInfinity) if (pos != Vector3.positiveInfinity)
{ {
if (Compare(data[x, z].y, pos.y, threshold)) if (Compare(data[x, z].y, pos.y, threshold))
{ {
point += pos; point += pos;
} }
else else
{ {
valid = false; valid = false;
} }
} }
} }
} }
if (valid) if (valid)
{ {
point /= size * size; point /= size * size;
var go = new GameObject("Reflection Probe Size: " + size); var go = new GameObject("Reflection Probe Size: " + size);
go.transform.SetParent(transform); go.transform.SetParent(transform);
go.transform.position = point; go.transform.position = point;
var reflectionProbe = go.AddComponent(typeof(ReflectionProbe)) as ReflectionProbe; var reflectionProbe = go.AddComponent(typeof(ReflectionProbe)) as ReflectionProbe;
if (size == 2) if (size == 2)
{ {
reflectionProbe.resolution = 16; reflectionProbe.resolution = 16;
} }
else if (size == 3) else if (size == 3)
{ {
reflectionProbe.resolution = 32; reflectionProbe.resolution = 32;
} }
else if (size == 4) else if (size == 4)
{ {
reflectionProbe.resolution = 32; reflectionProbe.resolution = 32;
} }
else if (size == 5) else if (size == 5)
{ {
reflectionProbe.resolution = 64; reflectionProbe.resolution = 64;
} }
reflectionProbe.center = new Vector3(0f, transform.position.y - point.y, 0f); reflectionProbe.center = new Vector3(0f, transform.position.y - point.y, 0f);
reflectionProbe.size = new Vector3(transform.localScale.x / voxelSize * size + blendDistance, transform.localScale.y, transform.localScale.z / voxelSize * size + blendDistance); reflectionProbe.size = new Vector3(transform.localScale.x / voxelSize * size + blendDistance, transform.localScale.y, transform.localScale.z / voxelSize * size + blendDistance);
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
for (int k = 0; k < size; k++) for (int k = 0; k < size; k++)
{ {
data[x + i, z + k] = Vector3.positiveInfinity; data[x + i, z + k] = Vector3.positiveInfinity;
} }
} }
} }
} }
} }
} }
} }
private bool Compare(float arg0, float arg1, float threshold) private bool Compare(float arg0, float arg1, float threshold)
{ {
return Mathf.Abs(arg0 - arg1) < threshold; return Mathf.Abs(arg0 - arg1) < threshold;
} }
} }
} }
} }

View File

@ -1,81 +1,81 @@
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
namespace Utils namespace Utils
{ {
[InitializeOnLoad] [InitializeOnLoad]
public static class SceneViewRotation public static class SceneViewRotation
{ {
private static bool toggleDir; private static bool toggleDir;
static SceneViewRotation() static SceneViewRotation()
{ {
SceneView.duringSceneGui += OnSceneGUI; SceneView.duringSceneGui += OnSceneGUI;
} }
private static void OnSceneGUI(SceneView sceneView) private static void OnSceneGUI(SceneView sceneView)
{ {
if (sceneView.isRotationLocked) if (sceneView.isRotationLocked)
{ {
return; return;
} }
Event e = Event.current; Event e = Event.current;
switch (e.type) switch (e.type)
{ {
case EventType.KeyDown: case EventType.KeyDown:
if (e.keyCode == KeyCode.Keypad1) if (e.keyCode == KeyCode.Keypad1)
{ {
sceneView.rotation = Quaternion.LookRotation(toggleDir ? Vector3.forward : Vector3.back); sceneView.rotation = Quaternion.LookRotation(toggleDir ? Vector3.forward : Vector3.back);
} }
else if (e.keyCode == KeyCode.Keypad2) else if (e.keyCode == KeyCode.Keypad2)
{ {
var angles = sceneView.rotation.eulerAngles; var angles = sceneView.rotation.eulerAngles;
sceneView.rotation = Quaternion.Euler(angles.x - 15f, angles.y, angles.z); sceneView.rotation = Quaternion.Euler(angles.x - 15f, angles.y, angles.z);
} }
else if (e.keyCode == KeyCode.Keypad3) else if (e.keyCode == KeyCode.Keypad3)
{ {
sceneView.rotation = Quaternion.LookRotation(toggleDir ? Vector3.left : Vector3.right); sceneView.rotation = Quaternion.LookRotation(toggleDir ? Vector3.left : Vector3.right);
} }
else if (e.keyCode == KeyCode.Keypad4) else if (e.keyCode == KeyCode.Keypad4)
{ {
var angles = sceneView.rotation.eulerAngles; var angles = sceneView.rotation.eulerAngles;
sceneView.rotation = Quaternion.Euler(angles.x, angles.y + 15f, angles.z); sceneView.rotation = Quaternion.Euler(angles.x, angles.y + 15f, angles.z);
} }
else if (e.keyCode == KeyCode.Keypad5) else if (e.keyCode == KeyCode.Keypad5)
{ {
sceneView.orthographic = !sceneView.orthographic; sceneView.orthographic = !sceneView.orthographic;
} }
else if (e.keyCode == KeyCode.Keypad6) else if (e.keyCode == KeyCode.Keypad6)
{ {
var angles = sceneView.rotation.eulerAngles; var angles = sceneView.rotation.eulerAngles;
sceneView.rotation = Quaternion.Euler(angles.x, angles.y - 15f, angles.z); sceneView.rotation = Quaternion.Euler(angles.x, angles.y - 15f, angles.z);
} }
else if (e.keyCode == KeyCode.Keypad7) else if (e.keyCode == KeyCode.Keypad7)
{ {
sceneView.rotation = new Quaternion(0f, toggleDir ? -.7f : .7f, -.7f, 0f); sceneView.rotation = new Quaternion(0f, toggleDir ? -.7f : .7f, -.7f, 0f);
} }
else if (e.keyCode == KeyCode.Keypad8) else if (e.keyCode == KeyCode.Keypad8)
{ {
var angles = sceneView.rotation.eulerAngles; var angles = sceneView.rotation.eulerAngles;
sceneView.rotation = Quaternion.Euler(angles.x + 15f, angles.y, angles.z); sceneView.rotation = Quaternion.Euler(angles.x + 15f, angles.y, angles.z);
} }
//else if (e.keyCode == KeyCode.Keypad9) //else if (e.keyCode == KeyCode.Keypad9)
//{ //{
// //sceneView.rotation = Quaternion.LookRotation(-sceneView.camera.transform.forward); // //sceneView.rotation = Quaternion.LookRotation(-sceneView.camera.transform.forward);
// sceneView.rotation = Quaternion.Inverse(sceneView.rotation); // sceneView.rotation = Quaternion.Inverse(sceneView.rotation);
//} //}
else if (e.keyCode == KeyCode.LeftControl) else if (e.keyCode == KeyCode.LeftControl)
{ {
toggleDir = true; toggleDir = true;
} }
break; break;
case EventType.KeyUp: case EventType.KeyUp:
if (e.keyCode == KeyCode.LeftControl) if (e.keyCode == KeyCode.LeftControl)
{ {
toggleDir = false; toggleDir = false;
} }
break; break;
} }
} }
} }
} }

View File

@ -1,21 +1,21 @@
MIT License MIT License
Copyright (c) 2021 Alexander Filippov Copyright (c) 2021 Alexander Filippov
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software. copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.

View File

@ -1,13 +1,13 @@
# Utils # Utils
Unity package with utility useful for almost any project. Unity package with utility useful for almost any project.
## Features ## Features
* Hide the script field. * Hide the script field.
* C# Event based Event Manager * C# Event based Event Manager
* Call Update, FixedUpdate and LateUpdate from anywhere. * Call Update, FixedUpdate and LateUpdate from anywhere.
* Better performance than Unity methods. * Better performance than Unity methods.
* Automatic volume based reflection probe placer. * Automatic volume based reflection probe placer.
* Check how much time has passed with the Time Since struct. * Check how much time has passed with the Time Since struct.
* Camera Blender controls in the scene view. * Camera Blender controls in the scene view.
* Package Manager Git updater. * Package Manager Git updater.
* Append to an array. * Append to an array.

View File

@ -1,22 +1,22 @@
namespace Utils namespace Utils
{ {
public static class ArrayExtensions public static class ArrayExtensions
{ {
public static T[] Append<T>(this T[] array, T item) public static T[] Append<T>(this T[] array, T item)
{ {
if (array == null) if (array == null)
{ {
return new T[] { item }; return new T[] { item };
} }
var result = new T[array.Length + 1]; var result = new T[array.Length + 1];
for (var i = 0; i < array.Length; i++) for (var i = 0; i < array.Length; i++)
{ {
result[i] = array[i]; result[i] = array[i];
} }
result[array.Length] = item; result[array.Length] = item;
return result; return result;
} }
} }
} }

View File

@ -1,36 +1,36 @@
#if UNITY_EDITOR #if UNITY_EDITOR
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
namespace Utils namespace Utils
{ {
[CustomEditor(typeof(MonoBehaviour), true)] [CustomEditor(typeof(MonoBehaviour), true)]
public class DefaultMonoBehaviourEditor : Editor public class DefaultMonoBehaviourEditor : Editor
{ {
private bool hideScriptField; private bool hideScriptField;
private void OnEnable() private void OnEnable()
{ {
hideScriptField = target.GetType().GetCustomAttributes(typeof(HideScriptField), false).Length > 0; hideScriptField = target.GetType().GetCustomAttributes(typeof(HideScriptField), false).Length > 0;
} }
public override void OnInspectorGUI() public override void OnInspectorGUI()
{ {
if (hideScriptField) if (hideScriptField)
{ {
serializedObject.Update(); serializedObject.Update();
EditorGUI.BeginChangeCheck(); EditorGUI.BeginChangeCheck();
DrawPropertiesExcluding(serializedObject, "m_Script"); DrawPropertiesExcluding(serializedObject, "m_Script");
if (EditorGUI.EndChangeCheck()) if (EditorGUI.EndChangeCheck())
{ {
serializedObject.ApplyModifiedProperties(); serializedObject.ApplyModifiedProperties();
} }
} }
else else
{ {
base.OnInspectorGUI(); base.OnInspectorGUI();
} }
} }
} }
} }
#endif #endif

View File

@ -1,34 +1,34 @@
#if UNITY_EDITOR #if UNITY_EDITOR
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
namespace Utils namespace Utils
{ {
[CustomEditor(typeof(ScriptableObject), true)] [CustomEditor(typeof(ScriptableObject), true)]
public class DefaultScriptableObjectEditor : Editor public class DefaultScriptableObjectEditor : Editor
{ {
private bool hideScriptField; private bool hideScriptField;
private void OnEnable() private void OnEnable()
{ {
hideScriptField = target.GetType().GetCustomAttributes(typeof(HideScriptField), false).Length > 0; hideScriptField = target.GetType().GetCustomAttributes(typeof(HideScriptField), false).Length > 0;
} }
public override void OnInspectorGUI() public override void OnInspectorGUI()
{ {
if (hideScriptField) if (hideScriptField)
{ {
serializedObject.Update(); serializedObject.Update();
EditorGUI.BeginChangeCheck(); EditorGUI.BeginChangeCheck();
DrawPropertiesExcluding(serializedObject, "m_Script"); DrawPropertiesExcluding(serializedObject, "m_Script");
if (EditorGUI.EndChangeCheck()) if (EditorGUI.EndChangeCheck())
serializedObject.ApplyModifiedProperties(); serializedObject.ApplyModifiedProperties();
} }
else else
{ {
base.OnInspectorGUI(); base.OnInspectorGUI();
} }
} }
} }
} }
#endif #endif

View File

@ -1,58 +1,58 @@
using UnityEngine; using UnityEngine;
namespace Utils namespace Utils
{ {
public class EventManager : MonoBehaviour public class EventManager : MonoBehaviour
{ {
public delegate void UpdateAction(); public delegate void UpdateAction();
public static event UpdateAction OnUpdated; public static event UpdateAction OnUpdated;
public delegate void FixedUpdateAction(); public delegate void FixedUpdateAction();
public static event FixedUpdateAction OnFixedUpdated; public static event FixedUpdateAction OnFixedUpdated;
public delegate void LateUpdateAction(); public delegate void LateUpdateAction();
public static event LateUpdateAction OnLateUpdated; public static event LateUpdateAction OnLateUpdated;
private void Update() private void Update()
{ {
OnUpdated?.Invoke(); OnUpdated?.Invoke();
} }
private void FixedUpdate() private void FixedUpdate()
{ {
OnFixedUpdated?.Invoke(); OnFixedUpdated?.Invoke();
} }
private void LateUpdate() private void LateUpdate()
{ {
OnLateUpdated?.Invoke(); OnLateUpdated?.Invoke();
} }
public static int UpdateLength public static int UpdateLength
{ {
get get
{ {
var list = OnUpdated?.GetInvocationList(); var list = OnUpdated?.GetInvocationList();
return list?.Length ?? 0; return list?.Length ?? 0;
} }
} }
public static int FixedUpdateLength public static int FixedUpdateLength
{ {
get get
{ {
var list = OnFixedUpdated?.GetInvocationList(); var list = OnFixedUpdated?.GetInvocationList();
return list?.Length ?? 0; return list?.Length ?? 0;
} }
} }
public static int LateUpdateLength public static int LateUpdateLength
{ {
get get
{ {
var list = OnLateUpdated?.GetInvocationList(); var list = OnLateUpdated?.GetInvocationList();
return list?.Length ?? 0; return list?.Length ?? 0;
} }
} }
} }
} }

View File

@ -1,7 +1,7 @@
using System; using System;
namespace Utils namespace Utils
{ {
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
public sealed class HideScriptField : Attribute { } public sealed class HideScriptField : Attribute { }
} }

View File

@ -1,6 +1,6 @@
using UnityEngine; using UnityEngine;
namespace Utils namespace Utils
{ {
public class ReadOnlyFieldAttribute : PropertyAttribute { } public class ReadOnlyFieldAttribute : PropertyAttribute { }
} }

View File

@ -1,108 +1,108 @@
using System.Diagnostics; using System.Diagnostics;
using UnityEngine; using UnityEngine;
namespace Utils namespace Utils
{ {
public class ReflectionProbeVolume : MonoBehaviour public class ReflectionProbeVolume : MonoBehaviour
{ {
[Min(1)] [Min(1)]
public int resolution = 4; public int resolution = 4;
public float offset = 2; public float offset = 2;
public float blendDistance = 1; public float blendDistance = 1;
[Min(0)] [Min(0)]
public float threshold = .5f; public float threshold = .5f;
[Conditional("UNITY_EDITOR")] [Conditional("UNITY_EDITOR")]
private void OnDrawGizmosSelected() private void OnDrawGizmosSelected()
{ {
Gizmos.DrawWireCube(transform.position, transform.localScale); 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 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 xVar = transform.localScale.x / resolution / 2f;
var zVar = transform.localScale.z / resolution / 2f; var zVar = transform.localScale.z / resolution / 2f;
var data = new Vector3[resolution, resolution]; var data = new Vector3[resolution, resolution];
Gizmos.color = Color.blue; Gizmos.color = Color.blue;
for (int x = 0; x < resolution; x++) for (int x = 0; x < resolution; x++)
{ {
for (int z = 0; z < resolution; z++) for (int z = 0; z < resolution; z++)
{ {
var rayPos = startPos - transform.right * xVar - transform.forward * zVar; var rayPos = startPos - transform.right * xVar - transform.forward * zVar;
if (Physics.Raycast(rayPos, Vector2.down, out RaycastHit hit)) if (Physics.Raycast(rayPos, Vector2.down, out RaycastHit hit))
{ {
var point = hit.point + Vector3.up * offset; var point = hit.point + Vector3.up * offset;
data[x, z] = point; data[x, z] = point;
} }
zVar += transform.localScale.z / resolution; zVar += transform.localScale.z / resolution;
} }
xVar += transform.localScale.x / resolution; xVar += transform.localScale.x / resolution;
zVar = transform.localScale.z / resolution / 2f; zVar = transform.localScale.z / resolution / 2f;
} }
CheckSquare(data, 5); CheckSquare(data, 5);
CheckSquare(data, 4); CheckSquare(data, 4);
CheckSquare(data, 3); CheckSquare(data, 3);
CheckSquare(data, 2); CheckSquare(data, 2);
for (int x = 0; x < resolution; x++) for (int x = 0; x < resolution; x++)
{ {
for (int z = 0; z < resolution; z++) for (int z = 0; z < resolution; z++)
{ {
if (data[x, z] != Vector3.positiveInfinity) if (data[x, z] != Vector3.positiveInfinity)
{ {
Gizmos.DrawSphere(data[x, z], .1f); Gizmos.DrawSphere(data[x, z], .1f);
} }
} }
} }
} }
private void CheckSquare(Vector3[,] data, int size) private void CheckSquare(Vector3[,] data, int size)
{ {
for (int x = 0; x < resolution; x++) for (int x = 0; x < resolution; x++)
{ {
for (int z = 0; z < resolution; z++) for (int z = 0; z < resolution; z++)
{ {
if (x + size <= resolution && z + size <= resolution) if (x + size <= resolution && z + size <= resolution)
{ {
bool valid = true; bool valid = true;
var point = Vector3.zero; var point = Vector3.zero;
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
for (int k = 0; k < size; k++) for (int k = 0; k < size; k++)
{ {
var pos = data[x + i, z + k]; var pos = data[x + i, z + k];
if (pos != Vector3.positiveInfinity) if (pos != Vector3.positiveInfinity)
{ {
if (Compare(data[x, z].y, pos.y)) if (Compare(data[x, z].y, pos.y))
{ {
point += pos; point += pos;
} }
else else
{ {
valid = false; valid = false;
} }
} }
} }
} }
if (valid) if (valid)
{ {
point /= size * size; point /= size * size;
Gizmos.DrawSphere(point, size * .1f); Gizmos.DrawSphere(point, size * .1f);
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
for (int k = 0; k < size; k++) for (int k = 0; k < size; k++)
{ {
data[x + i, z + k] = Vector3.positiveInfinity; data[x + i, z + k] = Vector3.positiveInfinity;
} }
} }
} }
} }
} }
} }
} }
private bool Compare(float arg0, float arg1) private bool Compare(float arg0, float arg1)
{ {
return Mathf.Abs(arg0 - arg1) < threshold; return Mathf.Abs(arg0 - arg1) < threshold;
} }
} }
} }

View File

@ -1,36 +1,36 @@
using UnityEngine; using UnityEngine;
namespace Utils namespace Utils
{ {
public struct TimeSince public struct TimeSince
{ {
private float time; private float time;
public static implicit operator float(TimeSince ts) public static implicit operator float(TimeSince ts)
{ {
return Time.time - ts.time; return Time.time - ts.time;
} }
public static implicit operator TimeSince(float ts) public static implicit operator TimeSince(float ts)
{ {
return new TimeSince { time = Time.time - ts }; return new TimeSince { time = Time.time - ts };
} }
} }
} }
// https://garry.tv/timesince // https://garry.tv/timesince
//TimeSince ts; //TimeSince ts;
//void Start() //void Start()
//{ //{
// ts = 0; // ts = 0;
//} //}
//void Update() //void Update()
//{ //{
// if (ts > 10) // if (ts > 10)
// { // {
// DoSomethingAfterTenSeconds(); // DoSomethingAfterTenSeconds();
// } // }
//} //}

View File

@ -1,7 +1,7 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 3cea9973e4f0f814ea87aacbfbddcb7a guid: 3cea9973e4f0f814ea87aacbfbddcb7a
PackageManifestImporter: PackageManifestImporter:
externalObjects: {} externalObjects: {}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant: