Skip to content

Instantly share code, notes, and snippets.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
/* Author @jpsarda
* A drawing class.
*
* Examples :
*
public abstract class SingletonBehaviour<Interface> : MonoBehaviour
where Interface : class
{
private static Interface _instance = null;
public static Interface instance { get { return _instance; } }
void Awake()
{
System.Diagnostics.Debug.Assert(this is Interface);
@cnsoft
cnsoft / LevelEditor.cs
Created December 18, 2013 05:40
An example of Level Editor works on Unity engine.
using System.Linq;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
using System.Collections;
using System;
using gui = UnityEngine.GUILayout;
using System.Collections.Generic;
@cnsoft
cnsoft / minesweep.py
Created December 11, 2013 13:01
minesweep.py
import random
class Cell(object):
def __init__(self, is_mine, is_visible=False, is_flagged=False):
self.is_mine = is_mine
self.is_visible = is_visible
self.is_flagged = is_flagged
def show(self):
/**
Converts Mobile Touch to the default Mouse Click
## invoked these method in Mobile too
OnMouseDown
OnMouseDrag
OnMouseUp
## only called in touch screen
wwdc 2013 sessions video 下载快速通道. https://gist.github.com/cnsoft/7744005
地址 + 百度离线 = 秒下
@cnsoft
cnsoft / HD.txt
Created December 2, 2013 02:26 — forked from lexrus/HD.txt
http://devstreaming.apple.com/videos/wwdc/2013/710xfx3xn8197k4i9s2rvyb/710/710-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/202xdx2x47ezp1wein/202/202-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/200xdx2x35e1pxiinm/200/200-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/413xdx5x97itb5ek4yex3r7/413/413-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/612xax4xx65z1ervy5np1qb/612/612-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/221xex4xxohbllf4hblyngt/221/221-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/220xbx4xipaxfd1tggxuoib/220/220-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/711xcx4x8yuutk8sady6t9f/711/711-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/404xbx2xvp1eaaqonr8zokm/404/404-HD.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2013/505xbx4xrgmhwby4oiwkrpp/505/505-HD.mov?dl=1
@cnsoft
cnsoft / 鼠标拖动物体.js
Created November 28, 2013 08:59
鼠标拖动物体.js
var mouseOverColor = Color.blue;//声明变量为蓝色
private var originalColor : Color;//声明变量存储本来颜色
function Start () {
originalColor = renderer.sharedMaterial.color;//开始时得到物体本来着色
}
function OnMouseEnter () {
renderer.material.color = mouseOverColor;//当鼠标滑过时改变物体颜色为蓝色
}
function OnMouseExit () {
@cnsoft
cnsoft / PunEvent.cs
Last active December 29, 2015 01:39
Pun是如何处理 RPC的 通过 RaiseEvent 消息. 筛选接收者.(按id group ) NetworkPeer.onSerializedRead() > // Use incoming data according to observed type if (view.observed is MonoBehaviour) { object[] contents = data[(byte)1] as object[]; PhotonStream pStream = new PhotonStream(false, contents); PhotonMessageInfo info = new PhotonMessageInfo(sender, networkTime, view…
case PunEvent.RPC:
//ts: each event now contains a single RPC. execute this
this.ExecuteRPC(photonEvent[ParameterCode.Data] as Hashtable, originatingPlayer);
break;
case PunEvent.SendSerialize:
case PunEvent.SendSerializeReliable:
Hashtable serializeData = (Hashtable)photonEvent[ParameterCode.Data];
//Debug.Log(serializeData.ToStringFull());
@cnsoft
cnsoft / NetworkInterpolatedTransform.cs
Created November 22, 2013 02:41
> CoreTech 这部分应该才是核心的点. 插槽式同步. 客户端预测.服务器端纠正. >发送过来的都进缓冲.带时间戳. 本地更新时 依次取有效缓冲点,做Lerp 插值. 延迟太高的话, 服务器发过来的会直接把一些过时的插槽去掉. 客户端更新时依旧是Lerp. 可以拉回到某位置.不会超出太多.
using UnityEngine;
using System.Collections;
public class NetworkInterpolatedTransform : Photon.MonoBehaviour
{
//
// NOTE: Network interpolation is afffected by the network sendRate.
// By default this is 10 times/second for OnSerialize. (See PhotonNetwork.sendIntervalOnSerialize)
// Raise the sendrate if you want to lower the interpolationBackTime.