2021-01-03 12:38:02 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2022-02-27 12:40:44 +00:00
|
|
|
namespace Popcron
|
2021-01-03 12:38:02 +00:00
|
|
|
{
|
2022-02-27 12:40:44 +00:00
|
|
|
public abstract class Drawer
|
2022-02-25 06:04:54 +00:00
|
|
|
{
|
2022-02-27 12:40:44 +00:00
|
|
|
private static Dictionary<Type, Drawer> typeToDrawer = null;
|
2021-01-03 12:38:02 +00:00
|
|
|
|
2022-02-27 12:40:44 +00:00
|
|
|
public abstract int Draw(ref Vector3[] buffer, params object[] args);
|
2021-01-03 12:38:02 +00:00
|
|
|
|
2022-02-27 12:40:44 +00:00
|
|
|
public Drawer()
|
2021-01-04 17:31:58 +00:00
|
|
|
{
|
2022-02-25 06:04:54 +00:00
|
|
|
|
2021-01-04 17:31:58 +00:00
|
|
|
}
|
2022-02-25 06:04:54 +00:00
|
|
|
|
2022-02-27 12:40:44 +00:00
|
|
|
public static Drawer Get<T>() where T : class
|
|
|
|
{
|
|
|
|
//find all drawers
|
|
|
|
if (typeToDrawer == null)
|
|
|
|
{
|
|
|
|
typeToDrawer = new Dictionary<Type, Drawer>
|
|
|
|
{
|
|
|
|
|
|
|
|
//add defaults
|
|
|
|
{ typeof(CubeDrawer), new CubeDrawer() },
|
|
|
|
{ typeof(LineDrawer), new LineDrawer() },
|
|
|
|
{ typeof(PolygonDrawer), new PolygonDrawer() },
|
|
|
|
{ typeof(SquareDrawer), new SquareDrawer() },
|
|
|
|
{ typeof(FrustumDrawer), new FrustumDrawer() }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return typeToDrawer.TryGetValue(typeof(T), out var drawer)
|
|
|
|
? drawer
|
|
|
|
: null;
|
|
|
|
}
|
2021-01-04 17:31:58 +00:00
|
|
|
}
|
2022-02-25 06:04:54 +00:00
|
|
|
}
|