Skip to content

Instantly share code, notes, and snippets.

@ApprenticeGC
ApprenticeGC / DescribeNumber.fs
Created November 3, 2012 06:54
Pattern Matching Sample
let isOdd x = (x % 2 = 1)
let describeNumber x =
match isOdd x with
| true -> printfn "x is odd"
| false -> printfn "x is even"
@ApprenticeGC
ApprenticeGC / PostprocessModel.cs
Created November 30, 2012 05:48
Post-process model removing Model from animation kind of file.
using UnityEditor;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
public class PostprocessModel : AssetPostprocessor
{
void OnPostprocessModel(GameObject rootGameObject)
@ApprenticeGC
ApprenticeGC / StoreKitGUIManager.cs
Created December 8, 2012 04:10
Partial code in StoreKitGUIManager
public class StoreKitGUIManager : MonoBehaviour
{
//
void OnGUI()
{
//
if( GUI.Button( new Rect( xPos, yPos += heightPlus, width, height ), "Get Product Data" ) )
{
// array of product ID's from iTunesConnect. MUST match exactly what you have there!
string[] productIdentifiers = {
@ApprenticeGC
ApprenticeGC / PlatformCheck.cs
Created December 12, 2012 10:12
Code snippet to show how to get device(iPhone, iPad) by using resolution.
public class PlatformCheck
{
public static EPlatformType GetPlatform()
{
// Variable declartion.
if (widthToHeightAspect == aspect960_640 || widthToHeightAspect == aspect640_960)
{
if ((Screen.width == 960 && Screen.height == 640) ||
(Screen.width == 640 && Screen.height == 960))
public class BuildAssetBundleUtility
{
public static void BuildAssetBundle(string outPath, List<UnityEngine.Object> objectCollection)
{
BuildPipeline.BuildAssetBundle(
// Main object
objectCollection[0],
// A collection of objects to be packed
objectCollection.ToArray(),
// The output location
public class AssetBundleLoader : UnityEngine.MonoBehaviour
{
private WWW _www;
private IEnumerator WaitLoadingBundle()
{
string assetBundleName = "BundleName";
// One folder level up of Application.dataPath.
// This is the same level as Assets in Editor(platform).
// For iPhone, this is just one group(XCode term) called AssetBundles created
// same as Classes.
public DBLoader : MonoBehaviour
{
public string DBLocation;
public string DBFile;
private SQLiteDB _mainDB = null;
// Assume there is a DB which contains a table named player_info at the
// specified location.
private void UpdatePlayerDB(string playerName, int moneyAmount)
{
@ApprenticeGC
ApprenticeGC / TestHello.sc
Created April 25, 2013 10:00
Partial code
def my = 1 + 2
def your = my + 10
println {
"this is cool."
}
@ApprenticeGC
ApprenticeGC / CreateNDataBindingCode.cs
Last active December 17, 2015 18:29
Code snippet showing how to create NData binding code.
private void AddEzDataTypeCode(CodeTypeDeclaration generatedClass)
{
generatedClass.Members.Add(CreatePrivateField(typeof(EZData.Property<int>), "FpsValue"));
generatedClass.Members.Add(CreateIntermediateProperty(typeof(EZData.Property<int>), "FpsValue"));
generatedClass.Members.Add(CreateActualProperty(typeof(int), "FpsValue"));
}
private CodeMemberField CreatePrivateField(Type ezDataType, string fieldName)
{
string ezDataTypeName = ezDataType.FullName;
@ApprenticeGC
ApprenticeGC / CreatePlayMakerState.cs
Created June 2, 2013 12:41
This code snippet illustrate the core of generating actions in PlayMaker programmatically. It is only dealing DebugLog action. Other actions that have event as the fields may need different approach. Besides, the code is not cleaned up yet.
// Just a method of the class
void TestAddProcess()
{
if (_theGameObject != null)
{
_theGameObject.AddComponent<PlayMakerFSM>();
PlayMakerFSM pmFsm = _theGameObject.GetComponent<PlayMakerFSM>();
if (pmFsm != null)
{
// Need to select fsm first