Linux migration.
This commit is contained in:
@ -1,22 +1,22 @@
|
||||
namespace Utils
|
||||
{
|
||||
public static class ArrayExtensions
|
||||
{
|
||||
public static T[] Append<T>(this T[] array, T item)
|
||||
{
|
||||
if (array == null)
|
||||
{
|
||||
return new T[] { item };
|
||||
}
|
||||
|
||||
var result = new T[array.Length + 1];
|
||||
for (var i = 0; i < array.Length; i++)
|
||||
{
|
||||
result[i] = array[i];
|
||||
}
|
||||
|
||||
result[array.Length] = item;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace Utils
|
||||
{
|
||||
public static class ArrayExtensions
|
||||
{
|
||||
public static T[] Append<T>(this T[] array, T item)
|
||||
{
|
||||
if (array == null)
|
||||
{
|
||||
return new T[] { item };
|
||||
}
|
||||
|
||||
var result = new T[array.Length + 1];
|
||||
for (var i = 0; i < array.Length; i++)
|
||||
{
|
||||
result[i] = array[i];
|
||||
}
|
||||
|
||||
result[array.Length] = item;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,36 +1,36 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace 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
|
@ -1,34 +1,34 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace 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
|
@ -1,58 +1,58 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace 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 static int UpdateLength
|
||||
{
|
||||
get
|
||||
{
|
||||
var list = OnUpdated?.GetInvocationList();
|
||||
return list?.Length ?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static int FixedUpdateLength
|
||||
{
|
||||
get
|
||||
{
|
||||
var list = OnFixedUpdated?.GetInvocationList();
|
||||
return list?.Length ?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static int LateUpdateLength
|
||||
{
|
||||
get
|
||||
{
|
||||
var list = OnLateUpdated?.GetInvocationList();
|
||||
return list?.Length ?? 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
using UnityEngine;
|
||||
|
||||
namespace 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 static int UpdateLength
|
||||
{
|
||||
get
|
||||
{
|
||||
var list = OnUpdated?.GetInvocationList();
|
||||
return list?.Length ?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static int FixedUpdateLength
|
||||
{
|
||||
get
|
||||
{
|
||||
var list = OnFixedUpdated?.GetInvocationList();
|
||||
return list?.Length ?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static int LateUpdateLength
|
||||
{
|
||||
get
|
||||
{
|
||||
var list = OnLateUpdated?.GetInvocationList();
|
||||
return list?.Length ?? 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
|
||||
public sealed class HideScriptField : Attribute { }
|
||||
using System;
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
|
||||
public sealed class HideScriptField : Attribute { }
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
public class ReadOnlyFieldAttribute : PropertyAttribute { }
|
||||
}
|
||||
using UnityEngine;
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
public class ReadOnlyFieldAttribute : PropertyAttribute { }
|
||||
}
|
||||
|
@ -1,108 +1,108 @@
|
||||
using System.Diagnostics;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
public class ReflectionProbeVolume : MonoBehaviour
|
||||
{
|
||||
[Min(1)]
|
||||
public int resolution = 4;
|
||||
public float offset = 2;
|
||||
public float blendDistance = 1;
|
||||
[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;
|
||||
}
|
||||
}
|
||||
}
|
||||
using System.Diagnostics;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
public class ReflectionProbeVolume : MonoBehaviour
|
||||
{
|
||||
[Min(1)]
|
||||
public int resolution = 4;
|
||||
public float offset = 2;
|
||||
public float blendDistance = 1;
|
||||
[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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,36 +1,36 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace 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 };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://garry.tv/timesince
|
||||
|
||||
//TimeSince ts;
|
||||
|
||||
//void Start()
|
||||
//{
|
||||
// ts = 0;
|
||||
//}
|
||||
|
||||
//void Update()
|
||||
//{
|
||||
// if (ts > 10)
|
||||
// {
|
||||
// DoSomethingAfterTenSeconds();
|
||||
// }
|
||||
//}
|
||||
using UnityEngine;
|
||||
|
||||
namespace 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 };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://garry.tv/timesince
|
||||
|
||||
//TimeSince ts;
|
||||
|
||||
//void Start()
|
||||
//{
|
||||
// ts = 0;
|
||||
//}
|
||||
|
||||
//void Update()
|
||||
//{
|
||||
// if (ts > 10)
|
||||
// {
|
||||
// DoSomethingAfterTenSeconds();
|
||||
// }
|
||||
//}
|
||||
|
Reference in New Issue
Block a user