Skip to content

Instantly share code, notes, and snippets.

View Ashwinning's full-sized avatar

Ashwin Sinha Ashwinning

View GitHub Profile
@Ashwinning
Ashwinning / Singletons.md
Last active March 31, 2020 15:18
A copy of the post on Singletons in Unity/C# as it appeared on UnityPatterns.com

Singletons

Original post by David Laskey on UnityPatterns

As you develop in Unity, you’ll often find that it’s handy to have just single instances of certain objects. For example, let’s say we have a single GameObject, “MusicManager”, that’s in charge of our music. It might look like this:

using UnityEngine;
 
@Ashwinning
Ashwinning / LazySingleton.cs
Last active December 3, 2015 02:56
How to use Lazy Singletons in C#
public class MusicManager : MonoBehaviour
{
//We make a static variable to our MusicManager instance
public static MusicManager instance { get; private set; }
//When the object awakens, we assign the static variable
void Awake()
{
instance = this;
}
@Ashwinning
Ashwinning / FloatToVector3Array.md
Last active December 3, 2015 02:54
Convert an array of floats to an array of Vector3. (Also serialize a vector 3 array to string, just for fun)

##Converting an array of floats to string

using System.Collections.Generic;

//...

	Vector3[] ConvertToVector3Array (float[] floats)
	{
 List vector3List = new List();
@Ashwinning
Ashwinning / CPP-Unity-String-Transfer.md
Last active January 25, 2016 03:32
C++ plugin getting a string back from a function
@Ashwinning
Ashwinning / FirmwareUpdate.md
Last active December 21, 2017 14:04
How to force update the RealSense R200 firmware

tl;dr : run FWUpdateR200.exe with the -force flag

I use this to fix the faulty R200 when it doesn't show up in Unity3D. Force updating the firware helps.

Start installing the SDK/DCM

Search for FWUpdateR200.exe

It was found in C:\Windows.old\Users\%User%\AppData\Local\Temp\%SomeGibberishID%\plugins\FWUpdateR200\Bin

@Ashwinning
Ashwinning / VerticallyCentered.html
Created February 2, 2016 22:43
Use this code to vertically and horizontally center something on a web page.
<html>
<head>
<title>This page is under construction</title>
<style>
.outer {
display: table;
@Ashwinning
Ashwinning / FindChildrenWithTag.md
Created February 7, 2016 23:29
FindChildrenWithTag : An extension method that finds all children of a Transform with a specified tag, and returns an array. transform.FindChildrenWithTag("SpecifiedTag")
	/// <summary>
	/// Extension method for UnityEngine.Transform.
	/// Finds the children with tag.
	/// Returns an array.
	/// </summary>
	/// <returns>The children with tag.</returns>
	/// <param name="tag">Tag.</param>
	public static Transform[] FindChildrenWithTag(this Transform trans, string tag)
	{
@Ashwinning
Ashwinning / IsBetween.md
Created February 7, 2016 23:34
IsBetween : C# extension method for `float` which checks whether that float is between a min and max value.
	/// <summary>
	/// Determines if is between the specified float is between two given floats.
	/// </summary>
	/// <returns><c>true</c> if the float is between the specified num lower upper inclusive; otherwise, <c>false</c>.</returns>
	/// <param name="num">Number.</param>
	/// <param name="lower">Lower.</param>
	/// <param name="upper">Upper.</param>
	/// <param name="inclusive">If set to <c>true</c> inclusive.</param>
	public static bool IsBetween (this float num, float lower, float upper, bool inclusive = false)
@Ashwinning
Ashwinning / RaycastFromCenter.md
Created February 8, 2016 21:53
Raycast from center : re
	RaycastHit RaycastFromCenter()
	{
		// Determine if we hit anything
		Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0));
		RaycastHit hit;
		if (Physics.Raycast (ray, out hit)) 
		{	
			return hit;
 }
@Ashwinning
Ashwinning / RaycastFromCenter.md
Last active February 9, 2016 23:58
Raycast from center - Raycasts to infinity from the center of the screen - Returns RaycastHit object if something is hit, or null if nothing is hit.
	/// <summary>
	/// Raycasts from center.
	/// </summary>
	/// <returns>RaycastHit if something is hit, or null if nothing is hit.</returns>
	/// https://gist.github.com/Ashwinning/d87e014cce668411adb9
	RaycastHit RaycastFromCenter
	{
		get
 {