Initial commit

This commit is contained in:
2026-05-19 13:55:16 +01:00
commit f650f6da3c
99 changed files with 7189 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
using PashaBibko.Pacore.Attributes;
using System.Collections.Generic;
using System.Reflection;
using System;
namespace PashaBibko.Pacore.Editor.Caches
{
public static class InspectorCallableCache
{
public struct AttributeInfo
{
public InspectorCallableAttribute Attribute;
public MethodInfo AttachedMethod;
}
private const BindingFlags BINDING_FLAGS =
BindingFlags.Public |
BindingFlags.NonPublic |
BindingFlags.Instance;
private static Dictionary<Type, AttributeInfo[]> Cache { get; } = new();
public static AttributeInfo[] GetAllAttributesOfType(Type type)
{
/* Checks the cache for the type */
if (Cache.TryGetValue(type, out AttributeInfo[] attributes))
{
return attributes;
}
/* Finds all the functions with the attribute */
MethodInfo[] methods = type.GetMethods(BINDING_FLAGS);
List<AttributeInfo> buttons = new();
foreach (MethodInfo method in methods)
{
InspectorCallableAttribute attribute
= method.GetCustomAttribute<InspectorCallableAttribute>();
if (attribute != null)
{
AttributeInfo info = new()
{
Attribute = attribute,
AttachedMethod = method,
};
buttons.Add(info);
}
}
/* Adds it to the cache before returning */
AttributeInfo[] array = buttons.ToArray();
Cache.Add(type, array);
return array;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0d386b13b5ef4284d98d5a9f6c9af20e

View File

@@ -0,0 +1,34 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using System;
namespace PashaBibko.Pacore.Editor.Caches
{
public static class MonoScriptCache
{
private static Dictionary<string, MonoScript> Cache { get; } = new();
static MonoScriptCache()
{
/* Finds all MonoScripts and adds them to the dictionary by name */
MonoScript[] scripts = Resources.FindObjectsOfTypeAll<MonoScript>();
foreach (MonoScript script in scripts)
{
Type scriptType = script.GetClass();
if (scriptType is not null)
{
string name = scriptType.FullName;
Cache.TryAdd(name, script);
}
}
}
public static MonoScript Get(string name)
{
/* Fetches the value (if there is one) without creating a default val */
Cache.TryGetValue(name, out MonoScript script);
return script;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 63ede88d28b04fb4cb18f55c0b7babef