Skip to content

Instantly share code, notes, and snippets.

View sugi-cho's full-sized avatar
😪
zzz

Hironori Sugino sugi-cho

😪
zzz
View GitHub Profile
@sugi-cho
sugi-cho / vertWorldPos.shader
Last active August 29, 2015 14:12
world position to frag matrix example
v2f vert(Input v) {
float4 posWorld = mul(_Object2World, v.vertex);
posWorld.xyz += _POS;
v2f o;
o.vertex = mul(UNITY_MATRIX_P, mul(UNITY_MATRIX_V, posWorld));
o.uv = v.uv;
return o;
}
@sugi-cho
sugi-cho / Actionの使い方
Created January 19, 2015 08:27
System.Action、デリゲート
using System;
void Test(string t){
Debug.Log(t);
}
void Main(){
Action<string> a = Test;
a("test");
}
@sugi-cho
sugi-cho / qmul
Created January 26, 2015 04:54
memo! Quaternion
// Quaternion multiplication.
// http://mathworld.wolfram.com/Quaternion.html
float4 qmul(float4 q1, float4 q2)
{
return float4(
q2.xyz * q1.w + q1.xyz * q2.w + cross(q1.xyz, q2.xyz),
q1.w * q2.w - dot(q1.xyz, q2.xyz)
);
}
Shader "Custom/QuaternionTest" {
Properties {
_AX("axis", Vector) = (0,0,0,0)
_TH("theta", Float) = 0
}
CGINCLUDE
#include "UnityCG.cginc"
#define PI 3.1416
using UnityEngine;
using UnityEditor;
using System.Collections;
public class CreateTex3D : EditorWindow
{
[MenuItem("sugi.cho/Window/CreatePerlin3DTexture")]
public static void Init ()
{
EditorWindow window = EditorWindow.GetWindow (typeof(CreateTex3D));
using UnityEngine;
using UnityEditor;
using System.Collections;
public class BakeTransformToMesh
{
[MenuItem("sugi.cho/Mesh/Bake Transform")]
public static void BakeTransform ()
{
@sugi-cho
sugi-cho / Example
Created June 8, 2015 12:18
event Action に アクションを足していく
public event System.Action<int> OnJoin;
void Init(){
this.OnJoin += JoinAction;
}
void JoinAction(int id){
list.Add(id);
}
<iframe width="420" height="315" src="https://www.youtube.com/embed/--fKAwlUUAM" frameborder="0" allowfullscreen></iframe> ##ポイント - `using UnityEngine.Networking;` - ネットワークで同期させる変数、モノは、全てServer側で動かす - ClientからServer側の関数を呼ぶときは`[Command]`Attributeをつける。 - 同期させる変数には`[sync]`Attributeを付け、ServerからClientに同期される。`[sync]`の変数がClient側で変化した時に呼ばれる関数も指定できる。`[sync(hook="SomeFunc")]` - `if(NetworkServer.active)`Serverとして動作しているとき - `if(NetworkClient.active)`
var manager = GetComponent<NetworkManager>();
manager.StartServer(); //server
manager.StartClient(); //client
manager.StartHost(); //serverかつclient
manager.StopServer();
using UnityEngine;
using UnityEngine.Networking;
public class MyNetManager:NetworkManager{
public override void OnStartClient(NetworkClient client){
base.OnStartClient(client);
//処理
}
public override void OnClientConnect(NetworkConnection conn){
//.....