マテリアルのシェーダーは Transparent/Diffuse を使用
| TestGL2_b.cs |
|---|
|
マテリアルのシェーダーは Transparent/Diffuse を使用
| TestGL2_b.cs |
|---|
|
| TestGL2.cs |
|---|
|
GL.LINESでライン描画
空オブジェクトにスクリプトを追加、インスペクター上で、描画するメッシュを選択
| TestGL1.cs |
|---|
|
UnityのWWWで、ローカルホストにアクセスするテスト
サーバーにAIMLを実装したJ-Aliceを使用
ボット同士の会話
| TestWWW2.cs |
|---|
|
空のゲームオブジェクトにTestGizmo.csを追加
ギズモを選択、編集タイプに応じて移動、サイズ変更がシーンウィンドウで行える
| Assets/Script/TestGizmo.cs |
|---|
|
| Assets/Editor/EditorTestGizmo.cs |
|---|
|
using UnityEngine;
using UnityEditor;
public class EditWindowD : EditorWindow {
Material m_Material; // マテリアル
Vector2 [] m_VecArray; // 頂点の配列
int m_VecNum = 3; // 頂点数
// メニューに追加
[MenuItem ("Window/EditWindowD")]
static void Init() {
EditWindowD window = (EditWindowD)EditorWindow.GetWindow( typeof (EditWindowD) );
window.Show();
}
// スクリプトのロード時に呼ばれる ScriptableObject.OnEnable()
void OnEnable() {
CreateVertexArray();
CreateMaterial();
}
// エディタウィンドウのGUI処理をここに記述 EditorWindow.OnGUI()
void OnGUI() {
// 再描画イベント時に描画処理を行う
if (EventType.Repaint != Event.current.type) return;
// 実行するとウィンドウが真っ白
//GL.Clear(false, true, Color.white);
m_Material.SetPass(0);
DrawLine();
}
// マテリアルの作成
void CreateMaterial() {
m_Material = new Material( "Shader \"Lines/Colored_Blended\" {" +
"SubShader { Pass { " +
" Blend SrcAlpha OneMinusSrcAlpha " +
" ZWrite Off Cull Off Fog { Mode Off } " +
" BindChannels {" +
" Bind \"vertex\", vertex" +
" Bind \"color\", color" +
"} } } }" );
m_Material.hideFlags = HideFlags.HideAndDontSave;
m_Material.shader.hideFlags = HideFlags.HideAndDontSave;
}
// 頂点の配列を作成
void CreateVertexArray() {
m_VecArray = new Vector2[m_VecNum];
m_VecArray[0] = new Vector2(50, 10);
m_VecArray[1] = new Vector2(10, 60);
m_VecArray[2] = new Vector2(90, 60);
}
// 線分の描画
void DrawLine() {
GL.Color(Color.blue);
GL.Begin( GL.LINES );
for(int i = 0; i < m_VecNum; i++) {
int idx0 = i;
int idx1 = (i == m_VecNum - 1) ? 0 : idx0 + 1;
GL.Vertex(m_VecArray[idx0]);
GL.Vertex(m_VecArray[idx1]);
}
GL.End();
}
}
using System;
using System.Collections.Generic;
using System.Collections;
using UnityEngine;
class TestObject {
int n;
string name;
public TestObject() {
n = 0;
name = "abc";
}
}
// テスト用のクラス
public class TestClass : MonoBehaviour {
const int ArrayNum = 5000; // 配列数
float fBaseTime = 0.0f;
float fCurTime = 0.0f;
int [] array; // 配列
System.Collections.ArrayList al0;
System.Collections.ArrayList al1;
System.Collections.ArrayList al2;
System.Collections.ArrayList al3;
void Start() {
TestArray();
}
void Update() {
if(Input.GetKeyDown(KeyCode.Alpha1)) {
StartCoroutine( WaitFunc(1.0F) );
}
if(Input.GetKeyDown(KeyCode.Alpha2)) {
StartCoroutine( WaitFunc(1.5F) );
}
if(Input.GetKeyDown(KeyCode.Alpha4)) {
TestArray();
}
}
// 配列のテスト
void TestArray() {
// 配列の作成
array = new int [ ArrayNum ];
al0 = new ArrayList();
al1 = new ArrayList();
al2 = new ArrayList();
al3 = new ArrayList();
// Test1 何もしない
fBaseTime = Time.realtimeSinceStartup;
fCurTime = Time.realtimeSinceStartup;
Debug.Log("Test1 time = " + ((fCurTime - fBaseTime) * 1000.0f).ToString()+"(ms)");
// Test2 配列に値セット
fBaseTime = Time.realtimeSinceStartup;
for(int i = 0; i < ArrayNum; i++) {
array[i] = i;
}
fCurTime = Time.realtimeSinceStartup;
Debug.Log("Test2 time = " + ((fCurTime - fBaseTime) * 1000.0f).ToString()+"(ms)");
// Test3 配列に整数を追加
fBaseTime = Time.realtimeSinceStartup;
for(int i = 0; i < ArrayNum; i++) {
al0.Add( i );
}
fCurTime = Time.realtimeSinceStartup;
Debug.Log("Test3 time = " + ((fCurTime-fBaseTime) * 1000.0f).ToString()+"(ms)");
Debug.Log("al0.Count = " + al0.Count);
// Test4 配列に整数を追加
fBaseTime = Time.realtimeSinceStartup;
for(int i = 0; i < ArrayNum; i++) {
al1.Add( 9876 );
}
fCurTime = Time.realtimeSinceStartup;
Debug.Log("Test4 time = " + ((fCurTime-fBaseTime) * 1000.0f).ToString()+"(ms)");
// Test5 配列に文字列を追加
fBaseTime = Time.realtimeSinceStartup;
for(int i = 0; i < ArrayNum; i++) {
al2.Add( "abcdefghijklmnopqrstu" );
}
fCurTime = Time.realtimeSinceStartup;
Debug.Log("Test5 time = " + ((fCurTime-fBaseTime) * 1000.0f).ToString()+"(ms)");
// Test5 配列にクラスを追加
fBaseTime = Time.realtimeSinceStartup;
for(int i = 0; i < ArrayNum; i++) {
TestObject o = new TestObject();
al3.Add( o );
}
fCurTime = Time.realtimeSinceStartup;
Debug.Log("Test6 time = " + ((fCurTime-fBaseTime) * 1000.0f).ToString()+"(ms)");
}
IEnumerator WaitFunc(float t) {
fBaseTime = Time.realtimeSinceStartup;
yield return new WaitForSeconds( t );
fCurTime = Time.realtimeSinceStartup;
Debug.Log("Test6 time = " + ((fCurTime-fBaseTime) * 1000.0f).ToString()+"(ms)");
}
}
private var nArrayNum : int = 5000;
private var numArray : int[];
private var arr0 : Array;
private var fBaseTime : float = 0.0f;
private var fCurTime : float = 0.0f;
function Start() {
TestArray();
}
function Update() {
if(Input.GetKeyDown(KeyCode.Keypad4)) {
TestArray();
}
}
// 配列のテスト
function TestArray() {
var i : int = 0;
numArray = new int[ nArrayNum ];
arr0 = new Array();
// Test1
fBaseTime = Time.realtimeSinceStartup;
for(i = 0; i < nArrayNum; i++) {
numArray[i] = i;
}
fCurTime = Time.realtimeSinceStartup;
Debug.Log("Test1 time = " + ((fCurTime - fBaseTime) * 1000.0f).ToString() + "(ms)");
// Test2
fBaseTime = Time.realtimeSinceStartup;
for(i = 0; i < nArrayNum; i++) {
arr0.Push( i );
}
fCurTime = Time.realtimeSinceStartup;
Debug.Log("Test2 time = " + ((fCurTime - fBaseTime) * 1000.0f).ToString() + "(ms)");
}
(笑)の略ではなくWorld Wide Web
System.Web.HttpUtility.UrlEncodeが使えない
WWW.EscapeURL()の結果がおかしい?
指定したurlにアクセスして受信結果をテキストファイルに保存するテスト
using System;
using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Text;
//using System.Web; // ERROR System.Webが無い
using UnityEngine;
public class TestWWW : MonoBehaviour
{
public IEnumerator Start() {
// URLエンコードを行う 結果が"abc+123"
print(WWW.EscapeURL("abc 123"));
string url = "http://www.google.co.jp/";
WWW www = new WWW(url);
yield return www;
// ShiftJisのエンコーディングを取得
int codepage = 932;
Encoding enc = Encoding.GetEncoding( codepage );
// 受信結果をファイルに保存 ファイルはプロジェクトフォルダにある
StreamWriter sw = new StreamWriter("./result.html", false, enc);
// sw.Write(www.text); // 文字化けしている
// wwwのバイト配列から文字列を取得
string strShiftJis = enc.GetString( www.bytes );
sw.Write(strShiftJis);
sw.Close();
print("Start() end");
}
}
MonoBehaviour.LateUpdate()内で
変更処理を実行すると描画に反映される
/*
ボーンのTransform
インスペクタ上で変更するボーンを指定
or GameObject.Find("...")でボーンを取得
*/
public Transform testBone;
/*
MonoBehaviour.LateUpdate
MonoBehaviour.Update 後に呼ばれる
*/
public void LateUpdate () {
/*
ボーンの位置を変更
子のボーンにも変更が適用される
*/
testBone.position = new Vector3(0.0f, 0.5f, 0.0f);
}
// 空のアニメーションカーブを作成
AnimationCurve animCurve = new AnimationCurve();
// キーフレームの追加
animCurve.AddKey( new Keyframe(0.0f, 1.0f) );
animCurve.AddKey( new Keyframe(2.0f, 0.1f) );
// アニメーションカーブの値を取得
print(animCurve.Evaluate(0.0f)); // 1.0
print(animCurve.Evaluate(1.25f)); // 0.3847657
print(animCurve.Evaluate(2.0f)); // 0.1
print(animCurve.Evaluate(2.5f)); // 0.1
KeyframeのinTangentとoutTangentの値は0