Skip to content

Instantly share code, notes, and snippets.

View unitycoder's full-sized avatar
‏‏‎

mika unitycoder

‏‏‎
View GitHub Profile
@unitycoder
unitycoder / OnGUI_DropDown.cs
Last active September 16, 2015 21:22
Call function if OnGUI() dropdown item was selected
// vars
string[] optionList = new string[] {"Apples", "Oranges", "Androids"};
int index = 0;
// loop
void OnGUI()
{
GUI.changed = false; // not needed if EditorGUILayout.Popup is first in OnGUI
index = EditorGUILayout.Popup("My List",index, optionList);
if (GUI.changed) DoSomething(); // NOTE: gets also called if same item is selected from list
@unitycoder
unitycoder / oculusOnOff.cs
Created September 17, 2015 08:54
Unity Toggle Oculus on/off
using UnityEngine.VR;
// toggle oculus on/off
VRSettings.enabled = !VRSettings.enabled;
@unitycoder
unitycoder / flat_array.cs
Last active November 27, 2022 09:02
Access 2D & 3D Flat Arrays 1D
// 2D array to 1D array
array[x,y] = array[y*width+x]
// 3D array to 1D array
array[x, y, z] = array[x+width*(y+depth*z)]
array[x, y, z] = array[x + HEIGHT* (y + WIDTH* z)]
array[x, y, z] = array[(z * xMax * yMax) + (y * xMax) + x]
@unitycoder
unitycoder / SaveFBX.cs
Last active September 21, 2015 10:42 — forked from mstevenson/SaveFBX.cs
ASCII FBX file exporter for Unity. Extracted from Michal Mandrysz's Unity Summer of Code 2009 external lightmapping project.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using UnityEditor;
using UnityEngine;
/*
@unitycoder
unitycoder / ForceGrassDistanceInEditor.cs
Last active September 21, 2015 21:10
Force Terrain Details DrawDistance over the 250 limit
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class ForceGrassDistanceInEditor : MonoBehaviour {
public float distance=250; // 250 is max in terrain settings, but not here
Terrain terrain;
void Start () {
@unitycoder
unitycoder / gist:1221c532c7485426a75d
Created September 28, 2015 10:55
Mod Odd / Even %
if (value % 2 == 0) print("even");
@unitycoder
unitycoder / MeshSplinesAndExtrusion.cs
Created October 24, 2015 13:02
Snippets : Unite 2015 - A coder's guide to spline-based procedural geometry
/* Code snippets from Unite 2015 - A coder's guide to spline-based procedural geometry */
/* https://www.youtube.com/watch?v=o9RK6O2kOKo */
// Optimized GetPoint
Vector3 GetPoint( Vector3[] pts, float t ) {
float omt = 1f-t;
float omt2 = omt * omt;
float t2 = t * t;
return pts[0] * ( omt2 * omt ) +
pts[1] * ( 3f * omt2 * t ) +
@unitycoder
unitycoder / GetLeapFingers.cs
Created November 3, 2015 22:33
Leap Motion Get Finger Positions In Unity Coordinates
/******************************************************************************\
* Copyright (C) Leap Motion, Inc. 2011-2014. *
* Leap Motion proprietary. Licensed under Apache 2.0 *
* Available at http://www.apache.org/licenses/LICENSE-2.0.html *
\******************************************************************************/
// Original script: "MagneticPinch.cs" modified by unitycoder.com to just get the finger position & directions
using UnityEngine;
using System.Collections;
using Leap;
@unitycoder
unitycoder / UIFadeEffect.cs
Last active November 6, 2021 17:02
UI Image and Text color fade
/* Fade all current object anc child images & texts, code needs cleaning up.. */
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class UIFadeEffect : MonoBehaviour
{
public bool destroyRootAfterFade=false;
@unitycoder
unitycoder / DisableWarnings.cs
Created November 8, 2015 21:36
Disable unused variable warnings
// Add warning number after the disable (can see the error code from the console output)
// examples:
#pragma warning disable 0168 // variable declared but not used.
#pragma warning disable 0219 // variable assigned but not used.
#pragma warning disable 0414 // private field assigned but not used.