Skip to content

Instantly share code, notes, and snippets.

View demonixis's full-sized avatar

Yannick Comte demonixis

View GitHub Profile
@demonixis
demonixis / GetScreenInch.cs
Created October 15, 2015 12:46
A static method to retrieve the screen inch of an Android device in Unity
public static int GetScreenInch()
{
#if UNITY_ANDROID
var displayMetrics = new AndroidJavaObject("android.util.DisplayMetrics");
var heightPixels = displayMetrics.Get<int>("heightPixels");
var widthPixels = displayMetrics.Get<int>("widthPixels");
var xdpi = displayMetrics.Get<float>("xdpi");
var ydpi = displayMetrics.Get<float>("ydpi");
var x = widthPixels / xdpi;
var y = heightPixels / ydpi;
@demonixis
demonixis / ArrayResize.js
Created April 15, 2015 13:51
Resize an array with JavaScript is easy
var array = [1, 2, 3, 4, 5];
console.log(array.length); // 5
array.length--;
console.log(array.length); // 4
array.length += 15;
console.log(array.length); // 19
@demonixis
demonixis / VRMobileDemo.html
Created February 24, 2015 16:18
This is the minimum code you need to write to have a VR application running on a web browser and using THREE.js. The code contains a fallback to use an OrbitController on PC.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"/>
<title>VR Sandbox 3D</title>
<style>
body {
margin: 0; padding: 0; overflow: hidden;
}
@demonixis
demonixis / ES6-LiveTest.html
Last active August 29, 2015 14:13
Thanks to Traceur, an ECMAScript 6 compiler, we can write ES6 code directly into a web page without compilation. Use it for testing purpose only because it's not very fast for middle and large applications.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>ECMAScript 6 - Demos</title>
</head>
<body>
<script src="https://google.github.io/traceur-compiler/bin/traceur.js"></script>
<script src="https://google.github.io/traceur-compiler/src/bootstrap.js"></script>
<script type="module">
@demonixis
demonixis / loop.js
Created December 18, 2014 14:46
Loop test
var start = new Date().getTime(); for (var i = 0; i < 1000000; i++) { "foo"; } console.log("Original Loop:", (new Date().getTime() - start))
var start = new Date().getTime(); for (var i = 0; i < 1000000; i++) { "foo"; } console.log("Original Loop:", (new Date().getTime() - start))
var start = new Date().getTime(); for (var i = 0; i < 1000000; i++) { "foo"; } console.log("Original Loop:", (new Date().getTime() - start))
var start = new Date().getTime(); for (var i = -1; ++i < 1000000; ) { "foo"; } console.log("New Loop:", (new Date().getTime() - start))
var start = new Date().getTime(); for (var i = -1; ++i < 1000000; ) { "foo"; } console.log("New Loop:", (new Date().getTime() - start))
var start = new Date().getTime(); for (var i = -1; ++i < 1000000; ) { "foo"; } console.log("New Loop:", (new Date().getTime() - start))
@demonixis
demonixis / LaveShader.shader
Created October 25, 2014 09:23
A lave Shader for Unity
Shader "Demonixis/LavaShader" {
Properties {
_MainTexture ("Lava texture", 2D) = "white" {}
_BumpTexture ("Bump texture", 2D) = "white" {}
_DiffuseColor ("Diffuse Color", Color) = (1, 1, 1, 1)
_EmissiveColor ("Emissive Color", Color) = (0, 0, 0, 1)
_Tiling ("Texture tiling", Vector) = (1, 1, 0)
_Offset ("Texture offset", Vector) = (0, 0, 0)
_WeaveSpeed ("_WeaveSpeed", float) = 1
}
@demonixis
demonixis / MobileVRCamera.js
Created October 3, 2014 14:51
A mobile VR compatible class to use with Babylon.js
var MobileVRCamera = (function() {
var mobileVR = function(position, scene) {
BABYLON.OculusCamera.call(this, "MobileVR Component", position, scene);
this.vrEnabled = false;
this.screenOrientation = 0;
this.deviceOrientation = {
alpha: 0,
beta: 0,
@demonixis
demonixis / OculusRiftCamera.js
Created October 2, 2014 14:00
A camera for Babylon.js which use the WebVR API.
var OculusRiftCamera = (function () {
var camRift = function (position, scene) {
BABYLON.OculusCamera.call(this, "OculusRiftCamera", position, scene);
this._startVR = this._startVR.bind(this);
};
camRift.prototype = Object.create(BABYLON.OculusCamera.prototype);
camRift.prototype.attachControl = function (element, noPreventDefault) {
BABYLON.OculusCamera.prototype.attachControl.call(this, element, noPreventDefault);
@demonixis
demonixis / LevelManager.cs
Last active November 11, 2016 00:29
LevelManager script used in my tutorial about Networking with Unity (in French @ http://www.demonixis.net/blog). It's used for spawing players in the level.
using UnityEngine;
using System.Collections;
public class LevelManager : MonoBehaviour
{
public CameraFollow playerCam;
public GameObject playerPrefab;
public SpawnPoint[] spawnPoints;
void Start ()
@demonixis
demonixis / NetworkManager.cs
Last active August 29, 2015 14:07
NetworkManager script used in my tutorial about Networking with Unity (in French @ http://www.demonixis.net/blog). It's used to show a menu for create or join a network game.
using UnityEngine;
using System.Collections;
public class NetworkManager : MonoBehaviour
{
public const string TypeName = "MyGameTitle";
public static string GameName = "GameName";
public static HostData GameToJoin = null;
private Rect _startBtnRect;