Skip to content

Instantly share code, notes, and snippets.

View Naphier's full-sized avatar
🐲

Sean Mann Naphier

🐲
View GitHub Profile
using UnityEngine;
// Displays lines for the Local Axis of a game object evenwhen the object is not selected.
public class ShowLocalAxis : MonoBehaviour
{
// This is used by the CustomTransformComponent class
// and the custom inspector for this class so that we can tag the script component
// for deletion at the proper time. We're hiding it in the inspector since it shouldn't
// be modified by the user, but needs to be publically accessible by other classes.
[HideInInspector]
using UnityEngine;
using UnityEditor;
// This custom Inspector just shows the default inspector and
// then, at the correct time, destroys the component if it has
// been flagged for destruction.
[CustomEditor(typeof(ShowLocalAxis))]
public class ShowLocalAxisInspector : Editor
{
public override void OnInspectorGUI()
public enum AlignToType { lastSelected, firstSelected }
public enum AxisFlag { X = 1, Y = 2, Z = 4 }
// First we need an enum for a dropdown to select what to align to (first or last selected).
public AlignToType alignTo = AlignToType.lastSelected;
// We also need an enum to flag what axes we want to align on.
public AxisFlag alignmentAxis;
// This method will display the Alignment options and execution button.
private void AlignmentInspector()
{
// Start off with a nice bold label to help section off the area.
using UnityEngine;
using UnityEditor;
using UnityEditor.AnimatedValues;
[CustomEditor(typeof(Transform))]
[CanEditMultipleObjects]
public class MyTransformComponent : Editor
{
private Transform _transform;
private AnimBool m_showExtraFields;
@Naphier
Naphier / SimpleCSVDebug.cs
Created November 19, 2015 03:11
Simple class to log output to file for debugging.
using System.IO;
using System;
using System.Text;
public class SimpleCSVDebug
{
string GetPathFile()
{
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string file = "output.csv";
@Naphier
Naphier / TestSimpleCSVDebug.cs
Last active November 19, 2015 03:21
Test script for SimpleCSVDebug.cs for Unity
using UnityEngine;
public class TestSimpleCSVDebug : MonoBehaviour
{
// Construct an instance of the SimpleCSVDebug class to use.
private SimpleCSVDebug simpleCSVDebug = new SimpleCSVDebug();
void Start()
{
@Naphier
Naphier / StrategyPatternStructure.cs
Created December 30, 2015 17:11
Strategy Design Pattern Structure
using System;
namespace StrategyPattern.structure
{
abstract class Strategy
{
public abstract void AlgorithmInterface();
}
class ConcreteStrategyA : Strategy
@Naphier
Naphier / OutputStrategy.cs
Created December 30, 2015 17:32
Strategy Pattern Example - String Output - IOutputStrategy
public interface IOutputStrategy
{
string Output(string input);
}
@Naphier
Naphier / OutputStrategy.cs
Last active December 30, 2015 17:45
Strategy Pattern Example - String Output - CSVOutput
public class CSVOutput : IOutputStrategy
{
char delimiter = ' ';
public CSVOutput(char delimiter)
{
this.delimiter = delimiter;
}
public string Output(string input)
{