Skip to content

Instantly share code, notes, and snippets.

View zhenlinyang's full-sized avatar

Zhenlin Yang zhenlinyang

View GitHub Profile
@zhenlinyang
zhenlinyang / UnityEventSample.cs
Created July 26, 2016 02:28
Unity Event Sample
using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class UnityEventSample : Graphic, IPointerUpHandler, IPointerDownHandler
{
[Serializable]
public class EventNone : UnityEvent
@zhenlinyang
zhenlinyang / MakeThreadSafeCallsToWindowsFormsControls.cs
Created July 7, 2016 02:21
Make Thread-Safe Calls to Windows Forms Controls
public delegate void LogCallback(string str, Color color);
private void LogHandler(string str, Color color)
{
if (LogRichTextBox.InvokeRequired)
{
LogCallback logCallback = LogCallbackFunction;
Invoke(logCallback, new object[] {str, color});
}
@zhenlinyang
zhenlinyang / CustomYieldInstructionSample.cs
Created July 6, 2016 09:05
Unity5.3 CustomYieldInstruction Sample
public class CustomYieldInstructionSample : MonoBehaviour
{
IEnumerator TheCoroutine()
{
TheLock theLock = new TheLock();
yield return new WaitTheFinish(theLock.GetLockState);
}
}
public class WaitTheFinish : CustomYieldInstruction
@zhenlinyang
zhenlinyang / ReferenceToValue.cs
Created July 5, 2016 11:38
Reference to Value
public class Name
{
#region Field
public readonly string FirstName;
public readonly string LastName;
#endregion
public Name(string firstName, string lastName)
@zhenlinyang
zhenlinyang / LitJsonSample.cs
Created July 4, 2016 09:36
LitJson Sample for Unity3D
public static Param GetParam(string jsonPath)
{
UnityEngine.Object asset = Resources.Load(jsonPath);
TextAsset textAsset = (TextAsset)asset;
string json = textAsset.text;
JsonReader jsonReader = new JsonReader(json);
JsonData jsonData = JsonMapper.ToObject(jsonReader);
Param param = new Param();
@zhenlinyang
zhenlinyang / ActivatorSample.cs
Last active July 1, 2016 02:40
Activator Sample
private ConfigDataBase CreateConfigData(Type configType)
{
var configData = Activator.CreateInstance(configType) as ConfigDataBase;
return configData;
}
public void LoadConfig()
{
foreach (Type type in ConfigList.AllConfigTypeList)
{
string path = "../../Resources/Config/" + type.Name.Replace("Config", ".bytes");
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None))
{
byte[] binary = new byte[fs.Length];
fs.Read(binary, 0, Convert.ToInt32(fs.Length));
m_configDic.Add(type, BinaryParse(binary, type));