【C#】ジェネリック引数付きコンストラクタ

C#では テンプレート型のコンストラクタに引数が渡せません using System; public class Foo<T> where T : new() { public Foo() { new T(1); } } `T': cannot provide arguments when creating an instance of a variable type 詳細:Compiler Error CS0417 Ty</t>…

【Unity】構造体属性

C#では union がなかったが、似ている機能があります StructLayout属性 構造体のレイアウトを指定可能にします FieldOffset属性 変数を指定位置に配置します [FieldOffset(バイト)] 例 ARGBを保持するクラスを作成します using System.Runtime.InteropServic…

【C#】Action と Funcメモ

C#

ActionとFuncの違いは戻り値あるかどうかですAction:戻り値なし Func:戻り値あり両方とも パラメーター 16 個まで用意されます

【C++】 クラスの呼び方

C++

クラスの継承関係ではいろんな呼び方があります 1. class 子クラス : 親クラス {}; 2. class 派生クラス : 基底クラス {}; 3. class サブクラス : スーパークラス {}; D&E本では2番目を使用されます 自分も 派生クラス/基底クラス に 統一しようと思い…

【雑記】Googleドキュメント

資料をまとめようだが、自宅のPCにはMicrosoft Officeをインストールしてなかった Chromeは結構前から使っていまして、Googleドキュメントは初めて起動したささやかなことにニールセン博士の記事を思い出した ユーザーの知識は低いレベルで停滞する新たな発…

【C#】演算子のオーバーロードメモ

C#

public static 戻り値型 operator 演算子 (パラメータリスト) サンプル class Foo { public int X {get;set;} public Foo(int x){ X = x; } public static Foo operator + (Foo lhs,Foo rhs) { return new Foo(lhs.X+rhs.X); } }

【C#】 Enum メソッド

C#

C#にはEnumを配列に変換するメソッドが用意されています例えば、以下の enum を定義されます enum Type { X = 10, Y = 20, Z = 30, } Enum -> string[] string[] names = Enum.GetNames(typeof(Type)); Enum -> Array int[] values = (int[])Enum.GetValues(…

【Unity】ユニットテスト:UUnit

UUnitはUnityIDE内実行できるユニットテストフレームワークです 何種類のユニットテストフレームワークを試してみて、 UUnitは一番使い勝手いいと思ったので導入方法を紹介します ダウンロード先 http://wiki.unity3d.com/index.php?title=UUnit 最新バージ…

【Unity】文字列プルダウンメニュー

Inspectorに文字列プルダウンメニューを表示する PulldownAttribute // PulldownAttribute.cs using UnityEngine; public class PulldownAttribute : PropertyAttribute { public string[] names; public PulldownAttribute(params string[] names) { this.n…

【Unity】 HideInInspector

スクリプトのpublic変数をInspectorに表示したくない場合 HideInInspectorを使用すればいい public class Foo: MonoBehaviour { { [HideInInspector] public int bar; }

【Unity】 自作Attributeでコメント表示

練習としてパラメータにマウスオーバーしたら コメント表示用Attributeを作成してみます CommentAttribute PropertyAttributeを継承して、コメント保存用クラスを作成します // CommentAttribute.cs using UnityEngine; public class CommentAttribute : Pro…

【C#】名前付き引数を覚えた

void func(int width,int height) { // do something } void bar() { func(height:10,width:20); } 1.引数の順番を気にしなくかける 2.呼び出すコードを見ただけで引数の意味が分かる void bar() { func(/*width*/20,/*height*/10); } C++では名前付き引数を…

【Unity】DontDestroyOnLoad

Unity には シーンを変更時、古いシーンに生成されたオブジェクトを破棄されます シーンを跨いでオブジェクトを使用したい場合 スクリプトのAwakeが呼ばれたら、DontDestroyOnLoadを使えばいいです public class Example : MonoBehaviour { void Awake() { D…

【Unity】RangeAttribute

Inspectorにはスクリプトから公開された変数を調整できる public class SpinScript : MonoBehaviour { public float spin; } 有効範囲を設定したい時、RangeAttributeを使えばいい public class SpinScript : MonoBehaviour { [Range(0,10)] public float sp…

【Unity】Delegates 勉強した

C# delegate の使い方をメモします デリゲート class Foo { delegate void MyDelegate(int num); // delegateの要求形式を記述 MyDelegate myDelegate; public Foo() { myDelegate = PrintNum; myDelegate(10); myDelegate = PrintDoubleNum; myDelegate(10)…

【Unity】GameAnalytics SDK for Unity

データ集計&解析ツール GameAnalytics SDK for UnityUnityのAssertStoreに無料公開中です

【C++】std::bitset のoperator[]

C++

使ってみて少し迷いました #include <bitset> #include <vector> #include <iostream> int main() { std::bitset<4> bit(0b1000); std::vector<int> v = {1,0,0,0}; if(v[0] == bit[0]) std::cout << "true" << std::endl; else std::cout << "false" << std::endl; } false 違和感があった</int></iostream></vector></bitset>…

【Unity】拡張メソッド(Extension Methods)

Transform クラスをリセットするメソッドを追加したい場合*1 // こんな感じで呼び出したい transform.ResetTransformation(); 拡張クラスを書く // ExtensionMethods.cs using UnityEngine; using System.Collections; // 拡張メソッド. このクラスは static…

【雑記】 CodeIQの問題挑戦!

アルゴリズム:日付の2進数変換 を挑戦してみた考えすぎたのかな~

【Unity】 Sprite Animation (セルアニメ) セットアップメモ

Sprite Animation (セルアニメ) 一番簡単なセットアップ方法 1.[ツールバー] -> [GameObject] -> [Create Empty] 2.[Assets]内セルアニメに使用したい画像を複数を選択 3.[1]に生成した GameObject にドラック&ドロップ 4.ダイアログが表示され指示通りに保…

【Unity】Polygon Collider 2D メモ

Polygon Collider 2D の 操作 座標編集( Shiftキー ) 移動したい頂点をドラッグ&ドロップ 頂点追加( Shiftキー ) 追加したい場所にクリック 頂点削除( Ctrlキー ) 削除したい頂点をクリック

Unity 4.3 がリリースされました

Unity Technologies Blogより、 Unity4.3がリリースされることが報告されました Unity - What's new in Unity 4.3 気になる点をハイライトします 2D toolset:2Dゲーム支援の拡張 Sprite追加 2D物理エンジン追加 Animation blendshapes(morph targets) ani…

std::fill のメモ書き

C++

std::fill でポインタ配列初期化時 #include <vector> int main(void) { Foo* foo[10]; std::fill(foo,foo+10,NULL); } error C2440: '=' : 'const int' から 'xxx' に変換できません。 とエラーが表示されます。NULLの定義は 0 だったので std::fill(foo,foo+10,(Fo</vector>…

Clang - (draft) C++14

C++

Clang is (draft) C++14 feature-complete!言語拡張と標準ライブラリ両方を含め Clang は (draft) C++14 の対応を完了しました

std::rotate を調べた

C++

コンテナの要素を回転するアルゴリズムです #include <iostream> #include <vector> #include <algorithm> // std::rotate int main(void) { std::vector<int> v{1,2,3,4,5,6,7}; std::cout << "before: "; for(auto i:v) std::cout << i << " "; std::cout << std::endl; std::rotate(v.begin(</int></algorithm></vector></iostream>…

std::unique_copy で余分なスペースを削除

C++

余分のスペースを削除します*1 #include <iostream> #include <string> #include <algorithm> int main(void) { std::string s = "This is a unique_copy sample!!"; std::cout << "before:" << s << std::endl; auto result = std::unique_copy(s.begin(),s.end(),s.begin(), [](char c1,</algorithm></string></iostream>…

std::tuple と std::tie と std::ignore を調べた

C++

複数の型の値を保存するクラス : std::tuple #include <tuple> #include <string> #include <iostream> int main(void) { std::tuple<int,float,std::string> t(1,2.5,"Hello"); std::cout << "0:" << std::get<0>(t) << std::endl; std::cout << "1:" << std::get<1>(t) << std::endl; std::cout << "2:" << </int,float,std::string></iostream></string></tuple>…

std::transform を調べた

C++

std::transform は 範囲内の要素に関数を適用してくれる機能です4引数バージョン // 小文字 -> 大文字 #include <string> #include <algorithm> #include <iostream> int main() { std::string s("hello"); std::transform(s.begin(), s.end(),s.begin(),toupper); std::cout << s; } HEL</iostream></algorithm></string>…

std::mem_fn を調べた

C++

std::mem_fn はメンバー関数への呼び出し用ラッパーを作成してくれる機能です使い方: #include <functional> class Foo { public: void set(int val){val_=val;} private: int val_; }; int main(void) { Foo foo; auto setter = std::mem_fn(&Foo::set); setter(foo,20)</functional>…

std::ref と std::cref を調べた

C++

std::ref は 変数への参照tを保持するreference_wrapperオブジェクトを生成する std::cref は const版です #include <functional> #include <iostream> void f(int& n1, int& n2, const int& n3) { std::cout << "In function: " << n1 << ' ' << n2 << ' ' << n3 << std::endl; ++</iostream></functional>…