mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 14:29:25 +00:00
Initial Upload
it working and not nuking fps... wow
This commit is contained in:
parent
cb280bdf00
commit
29060f71c1
23 changed files with 1905 additions and 0 deletions
70
CVRGizmos/Gizmo/Drawer.cs
Normal file
70
CVRGizmos/Gizmo/Drawer.cs
Normal file
|
@ -0,0 +1,70 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Popcron
|
||||
{
|
||||
public abstract class Drawer
|
||||
{
|
||||
private static Dictionary<Type, Drawer> typeToDrawer = null;
|
||||
|
||||
public abstract int Draw(ref Vector3[] buffer, params object[] args);
|
||||
|
||||
public Drawer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static Drawer Get<T>() where T : class
|
||||
{
|
||||
//find all drawers
|
||||
if (typeToDrawer == null)
|
||||
{
|
||||
typeToDrawer = new Dictionary<Type, Drawer>();
|
||||
|
||||
//add defaults
|
||||
typeToDrawer.Add(typeof(CubeDrawer), new CubeDrawer());
|
||||
typeToDrawer.Add(typeof(LineDrawer), new LineDrawer());
|
||||
typeToDrawer.Add(typeof(PolygonDrawer), new PolygonDrawer());
|
||||
typeToDrawer.Add(typeof(SquareDrawer), new SquareDrawer());
|
||||
|
||||
//find extras
|
||||
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
foreach (Assembly assembly in assemblies)
|
||||
{
|
||||
Type[] types = assembly.GetTypes();
|
||||
foreach (Type type in types)
|
||||
{
|
||||
if (type.IsAbstract)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (type.IsSubclassOf(typeof(Drawer)) && !typeToDrawer.ContainsKey(type))
|
||||
{
|
||||
try
|
||||
{
|
||||
Drawer value = (Drawer)Activator.CreateInstance(type);
|
||||
typeToDrawer[type] = value;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError($"couldnt register drawer of type {type} because {e.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (typeToDrawer.TryGetValue(typeof(T), out Drawer drawer))
|
||||
{
|
||||
return drawer;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue