Compare commits
2 Commits
0dc0896291
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| 5fba35a0a2 | |||
| 102b4fb7bf |
@@ -2,7 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using UnityEngine;
|
||||
|
||||
namespace PashaBibko.Pacore
|
||||
@@ -10,15 +9,6 @@ namespace PashaBibko.Pacore
|
||||
public static class ClassAttributeCache
|
||||
{
|
||||
private static Dictionary<Type, List<Type>> AttributeCache { get; set; }
|
||||
private static DelegateFunction OnCacheInstantiated = LogCacheInformation;
|
||||
|
||||
private static int AttributeCount;
|
||||
private static int ClassCount;
|
||||
private static long TimeTaken;
|
||||
|
||||
private static void LogCacheInformation()
|
||||
{
|
||||
}
|
||||
|
||||
public static ReadOnlyCollection<Type> GetAttributesOf<T>()
|
||||
{
|
||||
@@ -30,8 +20,6 @@ namespace PashaBibko.Pacore
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)]
|
||||
private static void ScanAllAssemblies()
|
||||
{
|
||||
Stopwatch timer = Stopwatch.StartNew();
|
||||
|
||||
/* Fetches all the class types in all loaded assemblies */
|
||||
Type[] classes = AppDomain.CurrentDomain.GetAssemblies() // Assembly[]
|
||||
.SelectMany(assembly => assembly.GetTypes()) // IEnumerable<Type>
|
||||
@@ -64,14 +52,6 @@ namespace PashaBibko.Pacore
|
||||
AttributeCache[type].Add(current);
|
||||
}
|
||||
}
|
||||
|
||||
/* Stores all relevant info for logging */
|
||||
TimeTaken = timer.ElapsedMilliseconds;
|
||||
AttributeCount = AttributeCache.Count;
|
||||
ClassCount = classes.Length;
|
||||
|
||||
/* Calls the delegate function for any dependencies */
|
||||
OnCacheInstantiated.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
namespace PashaBibko.Pacore
|
||||
{
|
||||
public delegate void DelegateFunction();
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 627efc92baea4fec9e576642408e796c
|
||||
timeCreated: 1769701523
|
||||
8
Assets/Pacore/Runtime/MemUtil.meta
Normal file
8
Assets/Pacore/Runtime/MemUtil.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9b64dde6eaaefc498098e1b5641cb52
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
82
Assets/Pacore/Runtime/MemUtil/Unique.cs
Normal file
82
Assets/Pacore/Runtime/MemUtil/Unique.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using Unity.Collections.LowLevel.Unsafe;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Diagnostics;
|
||||
using Unity.Collections;
|
||||
using System;
|
||||
|
||||
namespace PashaBibko.Pacore.MemUtil
|
||||
{
|
||||
public unsafe struct Unique<T> : IDisposable
|
||||
where T : unmanaged
|
||||
{
|
||||
private T* mPtr;
|
||||
|
||||
public bool IsValid
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => mPtr != null;
|
||||
}
|
||||
|
||||
public T Value
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
DebugOnly_CheckValid();
|
||||
return *mPtr;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
set
|
||||
{
|
||||
DebugOnly_CheckValid();
|
||||
*mPtr = value;
|
||||
}
|
||||
}
|
||||
|
||||
public ref T Ref
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
DebugOnly_CheckValid();
|
||||
return ref *mPtr;
|
||||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Unique<T> Create(T val = default)
|
||||
{
|
||||
T* ptr = (T*)UnsafeUtility.Malloc
|
||||
(
|
||||
sizeof(T),
|
||||
UnsafeUtility.SizeOf<T>(),
|
||||
Allocator.Persistent
|
||||
);
|
||||
*ptr = val;
|
||||
|
||||
return new Unique<T> { mPtr = ptr };
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Dispose()
|
||||
{
|
||||
if (IsValid)
|
||||
{
|
||||
UnsafeUtility.Free(mPtr, Allocator.Persistent);
|
||||
}
|
||||
}
|
||||
|
||||
[Conditional("UNITY_EDITOR")]
|
||||
private void DebugOnly_CheckValid()
|
||||
{
|
||||
if (!IsValid)
|
||||
{
|
||||
throw new InvalidOperationException
|
||||
(
|
||||
$"Owned<{nameof(T)}> was expected to be valid."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Pacore/Runtime/MemUtil/Unique.cs.meta
Normal file
11
Assets/Pacore/Runtime/MemUtil/Unique.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4ac012a56e2aa9429ff4f33c5554e7d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -4,7 +4,7 @@
|
||||
"references": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"allowUnsafeCode": true,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "com.pashabibko.pacore",
|
||||
"displayName": "Pacore",
|
||||
"version": "1.0.0",
|
||||
"version": "1.1.1-alpha",
|
||||
"unity": "2022.3",
|
||||
"description" : "Small Unity Util library",
|
||||
"keywords": [ "tool", "script", "runtime" ],
|
||||
|
||||
Reference in New Issue
Block a user