Skip to content

Instantly share code, notes, and snippets.

@grimmdev
grimmdev / TextureFlip.cs
Last active April 11, 2022 14:52
Texture Invert-er for Unity converted to C#, Original from GirlsCanCode! https://girlscancode.wordpress.com/2015/03/02/unity3d-flipping-a-texture/
// Converted to C#, originally from https://girlscancode.wordpress.com/2015/03/02/unity3d-flipping-a-texture/
Texture2D FlipText(Texture2D original)
{
// We create a new texture so we don't change the old one!
Texture2D flip = new Texture2D(original.width,original.height);
// These for loops are for running through each individual pixel and then replacing them in the new texture.
for(int i=0; i < flip.width; i++) {
for(int j=0; j < flip.height; j++) {
flip.SetPixel(flip.width-i-1, j, original.GetPixel(i,j));
@grimmdev
grimmdev / SocketClient.cs
Last active August 29, 2015 14:25
WebSocket Client/Server in Unity using Websocket-Sharp, read the comments below to get started!
using System;
using UnityEngine;
using WebSocketSharp;
using System.Collections;
public class SocketClient : MonoBehaviour {
// Public Variables
public string ConnectionString = "ws://echo.websocket.org";
public string Message = "Hello World!";
@grimmdev
grimmdev / QT_Trigger.cs
Last active November 2, 2019 18:52
Quick-Time Events for Unity, I made this with just a small amount of time, I plan to expand it but I wanted to give an example of how a QuickTime Event would work, as I'm building mine around my own solution and project. This also works for multiple Quick-Time Events.
using System.Collections;
using System.Collections.Generic;
// using this for Text Demonstration
using UnityEngine.UI;
public class QT_Trigger : MonoBehaviour {
// We could probably gut the Done State but I use it for my purpose.
public enum QTState { Ready, Delay, Ongoing, Done };
public QTState qtState = QTState.Ready;
// an enum for a possible response!
@grimmdev
grimmdev / Logger.cs
Created August 24, 2015 06:38
Made a Debug Logger Class for managing important Information!
using System;
using UnityEngine;
public class Logger {
private static string CUSTOM_MESSAGE = "CUSTOM LOGS: ";
private static bool PrintLog()
{
return true;
}
@grimmdev
grimmdev / AlphaAnimator.cs
Created August 24, 2015 07:44
Animates the Alpha on a Renderer
using System;
using UnityEngine;
[ExecuteInEditMode]
public class AlphaAnimator : MonoBehaviour
{
[Range(0f, 1f), SerializeField]
private float m_alpha;
private Renderer m_renderer;
private MaterialPropertyBlock m_propBlock;
@grimmdev
grimmdev / ArrayHelper.cs
Created August 24, 2015 07:50
I made this to help with dealing in Arrays!
using System;
using UnityEngine;
public static class ArrayHelper
{
public static T AddArrayElement<T>(ref T[] array) where T : new()
{
return ArrayHelper.AddArrayElement<T>(ref array, (default(T) == null) ? Activator.CreateInstance<T>() : default(T));
}
@grimmdev
grimmdev / FPSCounter.cs
Created August 24, 2015 08:13
Crack at my own FPS Counter
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FPSCounter : MonoBehaviour
{
[SerializeField]
public Text m_label;
@grimmdev
grimmdev / GameObjectExtension.cs
Created August 24, 2015 08:18
Some useful functions that extends Unity's GameObject
using System;
using System.Collections.Generic;
using UnityEngine;
public static class GameObjectExtension
{
public static T GetComponentInParents<T>(this Component self) where T : Component
{
return self.transform.GetComponentInParents<T>();
}
@grimmdev
grimmdev / AdditiveProtocol.cs
Last active August 31, 2015 10:24
Custom PowerUI Protocols for Unity3D for some savory and simple functions.
using PowerUI.Css;
using UnityEngine;
namespace PowerUI{
/// <summary>
/// This additive:// protocol enables a link to point to another scene.
/// E.g. href="additive://sceneName" will load the scene additive called 'sceneName' when clicked.
/// </summary>
@grimmdev
grimmdev / DroidScriptFunctions.js
Created September 1, 2015 02:55
DroidScript/Javascript Functions
String.format = function() {
// The string containing the format items (e.g. "{0}")
// will and always has to be the first argument.
var theString = arguments[0];
// start with the second argument (i = 1)
for (var i = 1; i < arguments.length; i++) {
// "gm" = RegEx options for Global search (more than one instance)
// and for Multiline search
var regEx = new RegExp("\\{" + (i - 1) + "\\}", "gm");