Skip to content

Instantly share code, notes, and snippets.

View zhenlinyang's full-sized avatar

Zhenlin Yang zhenlinyang

View GitHub Profile
@zhenlinyang
zhenlinyang / StatusHandler.cs
Last active July 15, 2017 10:05
Object Status
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
public static class StatusHandler
{
private static readonly Dictionary<string, BindingFlags> m_BindingFlagsDic =
new Dictionary<string, BindingFlags>
{
@zhenlinyang
zhenlinyang / UnityEngine.Simulation.Object.cs
Created April 4, 2017 12:31
UnityEngine Simulation Object
namespace UnityEngine.Simulation
{
public class Object
{
private static int s_IdCount = 0;
private int m_InstanceID;
private bool m_Alive = true;
@zhenlinyang
zhenlinyang / PathCombine.cs
Last active April 1, 2017 06:37
PathCombine
using System;
using System.Collections.Generic;
using System.IO;
public static class PathCombine
{
public static string Combine(params string[] subPath)
{
if (null == subPath || 0 == subPath.Length)
{
@zhenlinyang
zhenlinyang / Bit.cs
Created December 13, 2016 07:38
Bit Operation
public static class Bit
{
private const int INT_MAX_LENGTH = 32;
private const byte BYTE_MAX_LENGTH = 8;
public static bool Read(int source, int index)
{
Debug.Assert(index >= 0 && index < INT_MAX_LENGTH);
return 0 != (source & (1 << index));
}
@zhenlinyang
zhenlinyang / ZipMng.cs
Created December 6, 2016 13:22
CSharp GZip
public static class ZipMng
{
public static byte[] Compress(byte[] originalData)
{
using (MemoryStream outms = new MemoryStream())
{
using (MemoryStream inms = new MemoryStream(originalData))
{
using (GZipStream gzs = new GZipStream(outms, CompressionMode.Compress))
{
@zhenlinyang
zhenlinyang / AndroidSignCheck.cs
Created December 6, 2016 02:48
AndroidSignCheck
using UnityEngine;
public static class AndroidSignCheck
{
private const string c_PackageName = "com.yangzhenlin.unitydemo";
public static byte[] GetSignature()
{
//Player = new UnityPlayer();
AndroidJavaClass Player = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
@zhenlinyang
zhenlinyang / CopyAndReplaceDirectory.cs
Created November 5, 2016 12:15
CopyAndReplaceDirectory
private static void CopyAndReplaceDirectory(string srcPath, string dstPath)
{
if (Directory.Exists(dstPath))
{
Directory.Delete(dstPath);
}
if (File.Exists(dstPath))
{
File.Delete(dstPath);
@zhenlinyang
zhenlinyang / StreamingAssetsSample.cs
Created October 9, 2016 09:25
Use StreamingAssets in Unity
private IEnumerator CopyVersion()
{
string _Version_txt_streamingAssetsPath = PathConf.VCRoot + "Version.txt";
if (_Version_txt_streamingAssetsPath.Contains("://"))
{
using (WWW www = new WWW(_Version_txt_streamingAssetsPath))
{
yield return www;
if (!string.IsNullOrEmpty(www.error))
{
@zhenlinyang
zhenlinyang / ExtractZipFile.cs
Created September 27, 2016 05:45 — forked from r2d2rigo/ExtractZipFile.cs
Using SharpZipLib to extract zip files from Unity in a coroutine-friendly way
// This sample function uses SharpZipLib (http://icsharpcode.github.io/SharpZipLib/) to extract
// a zip file without blocking Unity's main thread. Remember to call it with StartCoroutine().
// Byte data is passed so a MemoryStream object is created inside the function to prevent it
// from being reclaimed by the garbage collector.
public IEnumerator ExtractZipFile(byte[] zipFileData, string targetDirectory, int bufferSize = 256 * 1024)
{
Directory.CreateDirectory(targetDirectory);
using (MemoryStream fileStream = new MemoryStream())
@zhenlinyang
zhenlinyang / VS2015 Class Template
Last active September 7, 2016 01:49
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ItemTemplates\CSharp\Code\2052\
using System;
using System.Collections.Generic;
$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
$endif$using System.Text;
$if$ ($targetframeworkversion$ >= 4.5)using System.Threading.Tasks;
$endif$
namespace $rootnamespace$
{
class $safeitemrootname$
{