Skip to content

Instantly share code, notes, and snippets.

View Ashwinning's full-sized avatar

Ashwin Sinha Ashwinning

View GitHub Profile
@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 / 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 / CPP-Unity-String-Transfer.md
Last active January 25, 2016 03:32
C++ plugin getting a string back from a function
@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
 {
/// <summary>
/// Rotates the point around a pivot.
/// </summary>
/// <returns>The rotated point.</returns>
/// <param name="point">Point.</param>
/// <param name="pivot">Pivot.</param>
/// <param name="rotation">Rotation.</param>
public Vector3 RotatePointAroundPivot (Vector3 point, Vector3 pivot, Quaternion rotation)
{
Vector3 direction = point - pivot; //Get point's direction relative to the pivot
@Ashwinning
Ashwinning / PointCloudSavingExample.cs
Created April 19, 2016 22:33
The following example saves a Vector 3 List to a '.cloud' file.
using UnityEngine;
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
/// <summary>
/// The following example saves a Vector 3 List to a '.cloud' file.
/// </summary>