Skip to content

Instantly share code, notes, and snippets.

@johnsoncodehk
johnsoncodehk / CloneExtension.cs
Last active March 24, 2017 06:55
Unity GameObject Clone Extension
/*
* https://gist.github.com/johnsoncodehk/6da46453ce2f870b6f87f431bb267b9c
*/
using UnityEngine;
public static class CloneExtension {
public static GameObject Clone (this GameObject gameObject) {
GameObject newGameObject = Object.Instantiate (gameObject);
@johnsoncodehk
johnsoncodehk / RigidbodyPause.cs
Last active September 9, 2017 01:37
[Unity] Pause Rigidbody Component
/*
* https://gist.github.com/johnsoncodehk/783295c6aa06593badfce037c810c7b2
*/
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class RigidbodyPause : MonoBehaviour {
[System.Serializable]
@johnsoncodehk
johnsoncodehk / aspect-ratio.css
Created April 24, 2018 17:19
CSS自適應長寬比
/* aspect-ratio */
/* <div class="aspect-ratio" style="--width: 16; --height: 9;"> */
.aspect-ratio {
position: relative;
box-sizing: border-box;
}
.aspect-ratio > * {
position: absolute;
top: 0;
right: 0;
@johnsoncodehk
johnsoncodehk / AspectRatioFitter.js
Created August 20, 2018 07:11
AspectRatioFitter for CocosCreator
let AspectMode = cc.Enum({
None: 0,
WidthControlsHeight: 1,
HeightControlsWidth: 2,
FitInParent: 3,
EnvelopeParent: 4,
});
cc.Class({
extends: cc.Component,
@johnsoncodehk
johnsoncodehk / YieldReturnExtension.cs
Last active October 2, 2018 16:51
Unity Coroutine -> Callback
/*
* https://gist.github.com/johnsoncodehk/17f05ebbeb1b7966efc4d5a176dd0bd8
*/
using UnityEngine;
using System;
using System.Collections;
public static class YieldReturnExtension
{
del /s /q /f /a .DS_STORE
del /s /q /f /a ._*
del /s /q /f /a *DS_STORE
pause
@johnsoncodehk
johnsoncodehk / Unity.gitignore
Created December 1, 2018 21:09
.gitignore for Unity
/*
/*/
!/Assets/
!/Packages/
!/ProjectSettings/
!.gitignore
@johnsoncodehk
johnsoncodehk / ScreenCaptureMenu.cs
Last active January 28, 2019 08:34
Unity capture screenshot to file
#if UNITY_EDITOR
using System;
using UnityEngine;
using UnityEditor;
public static class ScreenCaptureMenu {
[MenuItem("ScreenCapture/CaptureScreenshot")]
public static void Cap() {
string filename = Convert.ToInt32(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds).ToString() + ".png";
@johnsoncodehk
johnsoncodehk / gscc.js
Last active June 6, 2019 21:56
GameSparks Cloud Code - (CommonJS)TypeScript to Cloud Code
/**
* Obsolete! Use https://github.com/johnsoncodehk/ts2gamesparks
*/
var path = require('path'), fs = require('fs');
var outDir = "./dist/";
function findAllTsFiles(startPath, paths = []) {
if (!fs.existsSync(startPath)) {
@johnsoncodehk
johnsoncodehk / trim-trailing-slash.js
Last active November 16, 2019 17:20
Remove URL trailing slash
window.history.replaceState("", "", window.location.href.replace(new RegExp("/(?!.*/)"), ""))