Skip to content

Instantly share code, notes, and snippets.

View Naphier's full-sized avatar
🐲

Sean Mann Naphier

🐲
View GitHub Profile
@Naphier
Naphier / NaplandCamera.cs
Created April 28, 2016 19:18
Gets screen bounds based on camera.
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Camera))]
public class NaplandCamera : MonoBehaviour {
#pragma warning disable 0414
public static float minX;
public static float maxX;
@Naphier
Naphier / InputDetector.cs
Created March 19, 2016 04:32
A little helper that to figure out your inputs.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System;
public class InputDetector : MonoBehaviour
{
public enum TestType { joystickButtons, keys, axis, mouse, touch }
public TestType testType = TestType.joystickButtons;
public bool logMessages = true;
@Naphier
Naphier / ComponentCache.cs
Last active February 1, 2016 09:36
CacheBehaviour alternative
using UnityEngine;
using System.Collections.Generic;
public class ComponentCache
{
public enum LogMessageLevel { all, error, none}
LogMessageLevel logMessageLevel = LogMessageLevel.error;
private GameObject _gameObject;
private List<Component> _components = new List<Component>();
@Naphier
Naphier / OutputStrategyController.cs
Created December 30, 2015 18:14
Strategy Pattern Example - String Output
public class OutputStrategyController : MonoBehaviour
{
public string input = "This is some arbitrary input string";
void Start()
{
OutputContext context = new OutputContext(new CSVOutput(' '));
Debug.Log("This is the CSV output:\n" + context.GetOutput(input));
//Easily change the context!
@Naphier
Naphier / OutputStrategy.cs
Created December 30, 2015 18:00
Strategy Pattern Example - String Output - OutputContext
public class OutputContext
{
IOutputStrategy outputStrategy;
public OutputContext(IOutputStrategy outputStrategy)
{
this.outputStrategy = outputStrategy;
}
public string GetOutput(string input)
{
@Naphier
Naphier / OutputStrategy.cs
Created December 30, 2015 17:51
Strategy Pattern Example - String Output - EncryptedOutput
public class EncryptedOutput : IOutputStrategy
{
public string Output(string input)
{
char[] array = input.ToCharArray();
for (int i = 0; i < array.Length; i++)
{
int number = (int)array[i];
if (number >= 'a' && number <= 'z')
@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)
{
@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 / 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 / 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()
{