Skip to content

Instantly share code, notes, and snippets.

View CoffeeVampir3's full-sized avatar

Z CoffeeVampir3

View GitHub Profile
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Linq;
using System.Reflection;
namespace BW {
[CustomPropertyDrawer(typeof(ExpandSO)), CanEditMultipleObjects]
public class ExpandSOPropDrawer : PropertyDrawer {
//Example use would be Damage (source) to Health (target)
//which would lookup the sources Damage stat and deal that much damage to the target's Health stat.
public abstract class ScriptableStatInteractor : ScriptableObject
{
[SerializeField]
protected ModularStat sourceStat = null;
[SerializeField]
protected ModularStat targetStat = null;
public abstract int Apply(StatBlock sourceBlock, StatBlock targetBlock);
@CoffeeVampir3
CoffeeVampir3 / TTFParser.cs
Last active October 12, 2020 18:46
True Text Font peicewise encapsulator
public class TTFParser
{
private string unparsedString;
private int textLength;
private int cursorPosition = 0;
private string currentString;
private const char openingTag = '<';
private const char tagCancel = '/';
using Sirenix.OdinInspector;
using UnityEngine;
namespace VisualNovelFramework
{
public class VNDialogueController : MonoBehaviour
{
[SerializeField]
private TMPShakeParser shakeParser = null;
[SerializeField]
using UnityEngine.UIElements;
namespace VisualNovelFramework.Elements.Utils
{
/// <summary>
/// A dynamic button which is directly added the the ModularLists frame.
/// </summary>
public class DynamicButton
{
protected Button button;
[TypeSelect(typeof(Component))]
public SerializedType componentType;
@CoffeeVampir3
CoffeeVampir3 / AutoDrawer.cs
Last active April 7, 2021 08:12
Unity UITK Auto Drawer
public static class FieldFactory
{
private delegate VisualElement CreationDelegate(Type t, object o);
private static readonly Dictionary<Type, CreationDelegate> creationDictionary =
new Dictionary<Type, CreationDelegate>();
private static readonly List<Type> creationTypes = new List<Type>();
private static bool initialized = false;
@CoffeeVampir3
CoffeeVampir3 / EffectSystem.cs
Last active June 2, 2021 02:52
Overcomplicated Command Thingy
public static class EffectsSystem
{
private static readonly Dictionary<Type, List<IEffectRule>> allRules = new();
public static void RegisterRule<T>(this IEffectRule<T> rule, Type ruleType)
where T : IEffect
{
if(!allRules.TryGetValue(ruleType, out var specificRules))
{
specificRules = new List<IEffectRule>();
allRules.Add(ruleType, specificRules);
@CoffeeVampir3
CoffeeVampir3 / IRule.cs
Created June 12, 2021 02:47
Non-Academic Rule Engine
public interface IRule<in Ruleable> : IRule
where Ruleable : IRuleable
{
/// <summary>
/// Tries to run this specific rule.
/// </summary>
/// <returns>Returns true if the rule ran on this command.</returns>
bool RunIfValid(Ruleable ruleable);
}
@CoffeeVampir3
CoffeeVampir3 / CardDraggingState.cs
Last active October 30, 2022 18:17
Example of a real State Machine
using System;
using UnityEngine;
namespace Vampire.CG
{
[Serializable]
public class CardDraggingState : IState
{
[SerializeField]
private Transform transform;