Skip to content

Instantly share code, notes, and snippets.

View yangruihan's full-sized avatar
📖
Studying...

Ryan yangruihan

📖
Studying...
  • Tencent
  • Shen Zhen, China
View GitHub Profile
@yangruihan
yangruihan / ConfigHelper.cs
Last active July 16, 2016 12:31
Unity3D 读取文本文件中的配置信息
using UnityEngine;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace ruihanyang.ConfigHelper
{
/// <summary>
/// <para>配置助手</para>
@yangruihan
yangruihan / SmoothCameraFollow.cs
Last active July 25, 2016 08:39
Unity3D 摄像机平滑跟踪某个游戏对象
using UnityEngine;
using System.Collections;
public class SmoothCameraFollow : MonoBehaviour {
static public Transform target;
public float distance = 4.0f;
public float height = 1.0f;
public float smoothLag = 0.2f;
public float maxSpeed = 10.0f;
@yangruihan
yangruihan / TouchIgnore.cs
Created August 10, 2016 03:35
Unity 使UI组件忽略点击事件响应
using UnityEngine;
using System.Collections;
public class TouchIgnore : MonoBehaviour, ICanvasRaycastFilter
{
public bool IsRaycastLocationValid(Vector2 screenPoint, Camera eventCamera)
{
return false;
}
}
@yangruihan
yangruihan / ReadFile.java
Created November 6, 2016 10:06
Java 从文件中读取内容
public class ReadFromFile {
/**
* 以字节为单位读取文件,常用于读二进制文件,如图片、声音、影像等文件。
*/
public static void readFileByBytes(String fileName) {
File file = new File(fileName);
InputStream in = null;
try {
System.out.println("以字节为单位读取文件内容,一次读一个字节:");
// 一次读一个字节
@yangruihan
yangruihan / WriteFile.java
Created November 6, 2016 10:07
Java 写内容到文件中
public class AppendToFile {
/**
* A方法追加文件:使用RandomAccessFile
*/
public static void appendMethodA(String fileName, String content) {
try {
// 打开一个随机访问文件流,按读写方式
RandomAccessFile randomFile = new RandomAccessFile(fileName, "rw");
// 文件长度,字节数
long fileLength = randomFile.length();
@yangruihan
yangruihan / Singleton.cs
Last active February 15, 2019 08:09
单例抽象类
public abstract class Singleton<T> where T : class, new()
{
private static readonly object LockObject = new object();
private static T _instance;
public static T Instance
{
get
{
if (_instance != null) return _instance;
@yangruihan
yangruihan / InstancePool.cs
Last active February 15, 2019 08:07
对象池
using System.Collections.Generic;
/// <summary>
/// 可入对象池接口
/// </summary>
public interface IPoolable
{
void OnAwakeFromPool();
void OnReturnToPool();
@yangruihan
yangruihan / ForeachCharUtil.cs
Created July 28, 2017 08:56
Unity弹字脚本
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.UI;
public class ForeachCharUtil : MonoBehaviour
{
public enum ShowContentStatus
{
@yangruihan
yangruihan / EventDispatcher.cs
Last active February 15, 2019 08:06
Unity EventDispatcher
using System.Collections.Generic;
using UnityEngine;
using System;
public delegate void EventHandler(short type);
public delegate void EventHandler<in T>(short type, T msg);
/// <summary>
/// 事件派发器
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
public class SerializeHelper
{
/// <summary>
/// 序列化
/// </summary>
/// <returns>The message queue.</returns>