Skip to content

Instantly share code, notes, and snippets.

View mandarinx's full-sized avatar

Thomas Viktil mandarinx

View GitHub Profile
@mandarinx
mandarinx / as3_remove_all_children
Created April 30, 2012 08:54
Remove all children (AS3)
while (this.numChildren > 0)
{
removeChild(this.getChildAt(0));
}
// Remove children as part of an event handler
private function eventHandler(e:Event):void
{
e.target.parent.removeChild(e.target);
#if UNITY_EDITOR
void SingleComponentCheck() {
var components = gameObject.GetComponents(this.GetType());
foreach (var component in components) {
if (component == this) continue;
UnityEditor.EditorUtility.DisplayDialog("Can't add the same component multiple times!",
string.Format("The component {0} can't be added because {1} already contains the same component.", this.GetType(), gameObject.name),
"Cancel");
// You can switch to a regular Update() loop
// if you comment out this line. (makes debugging easier)
#define COROUTINE
//
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using UnityEngine;
using Debug = UnityEngine.Debug;
@mandarinx
mandarinx / starstruck.js
Created October 13, 2014 10:26
Phaser 2.1.0 removeTile()
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
var map;
var tileset;
var layer;
var player;
var facing = 'left';
var jumpTimer = 0;
var cursors;
var jumpButton;
@mandarinx
mandarinx / portforwarding.md
Last active August 29, 2015 14:07
Port forwarding on OS X

Edit the hosts file

sudo nano /etc/hosts

Add this line somewhere after 127.0.0.1 localhost:

127.0.0.1       your.domain.com

Save and exit (Ctrl + O, Ctrl + X). Flush the DNS cache:

@mandarinx
mandarinx / CamExtenstions.cs
Created November 26, 2014 12:46
Unity3D Camera culling mask
// Copyright 2014 Jarrah Technology (http://www.jarrahtechnology.com). All Rights Reserved.
// http://www.jarrahtechnology.com/2014/04/01/Culling-Mask-Tip/
using UnityEngine;
public static class CameraExtensions {
public static void LayerCullingShow(this Camera cam, int layerMask) {
cam.cullingMask |= layerMask;
}
@mandarinx
mandarinx / FindMissingComponentRefs.cs
Created December 11, 2014 08:49
Find Missing Component References
using UnityEditor;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class FindMissingComponentRefs : System.Object {
[MenuItem("Tools/Find Missing Component References")]
public static void FindMissingRefs() {
bool found = false;
@mandarinx
mandarinx / FSMState.cs
Last active October 21, 2022 23:54
Unity3D Simple Finite State Machine
using MyGame;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MyGame.FSM {
public abstract class FSMState {
@mandarinx
mandarinx / Bool.cs
Created December 28, 2014 13:09
Listen for changes on int, float and bool variables
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace MyGame.Core {
[System.Serializable]
public class Bool : System.Object {
public delegate void UpdateDelegate(bool val);
public UpdateDelegate OnUpdate;
@mandarinx
mandarinx / SceneTools.cs
Created January 9, 2015 10:42
Unity scene tools
using UnityEngine;
using UnityEditor;
using System;
using System.Collections;
using System.Collections.Generic;
public class SceneTools : EditorWindow {
public delegate void ButtonCallback();