【C#】デリゲート(delegate) 使用例 第一弾

delegate例
例1

public void FacebookShare (int id) {
	
	string msg = BossSource._item[id]._shareHeadline;
	Sprite ShareSprite  = BossSource._item[id]._bossShareSprite;
	*****.Facebook.PostImageWithDialog(msg ,ShareSprite.texture, OnFacebookShareComplete);
}

void OnFacebookShareComplete (*****.Social.IActionResult result)
{
	if(result.IsSuccess){
		ShowModal("Thanks For Posting");
		EventManager.ShareSccessMethod();
	}else{
		ShowModal(result.Error);
	}
	EventManager.onFinishUIShareMethod();
}


例2

public void FacebookShare (int id) {
	
	string msg = BossSource._item[id]._shareHeadline;
	Sprite ShareSprite  = BossSource._item[id]._bossShareSprite;
	*****.Facebook.PostImageWithDialog(msg ,ShareSprite.texture, delegate(*****.Social.IActionResult result) {
		if(result.IsSuccess){
			ShowModal("Thanks For Posting");
			EventManager.ShareSccessMethod();
		}else{
			ShowModal(result.Error);
		}
		EventManager.onFinishUIShareMethod();
	});
}

【Unity エラー】UnityException : Textureの読み書き

デバイスでバグが確認でき、バグの原因がデバイスだけでわからない時、Android Device Monitor を使って確認する。(モニターでのチェックは必須..?)

エラー

03-30 16:13:01.606: I/Unity(3016): UnityException: 
Texture 'frame_share_000' is not readable, the texture memory can not be accessed from scripts. 
You can make the texture readable in the Texture Import Settings.

解決法

  • texture[texture type : advance]をスクリプトから読み書きする時、使用する"Read / Write anabled" を"true"にする必要がある。

【C#】ネーミング まとめ

命名の際に注意すること

  • 名前に数字を利用するのは良くない
  • 略語は出来る限り利用しない。一般的なもののみ利用してもよい。
  • 複数形は利用しない。複数形か単数形かを混同したエラーを避ける。
  • tblやdbなどの接頭語は冗長であり無駄なので使わない
  • ブーリアンのカラム名はisから始める
  • http://gokexn.blog.fc2.com/blog-entry-34.html


Codic

関連記事

【C#】ToString("0.0") : 数値型を小数点1桁の文字列型に変換

小数点1桁

_tCompletePercent.text = _percent.ToString("0.0") + "%";

【C#】保守しやすいように書く

1. TODO: を活用する


2. より簡潔に

private void SetAllButtonToDefault () {
	//一行で書ける。
	btnNormal.color = btnHard.color = btnImpossibru.color = Color.gray;
//	btnNormal.color = Color.gray;
//	btnHard.color = Color.gray;
//	btnImpossibru.color  = Color.gray;
}


参考資料

【Unity】RectTransform : width取得方法

_lengthStageGauge = _giStage.transform.GetComponent<RectTransform>().sizeDelta.x;

関連

Vector3 posStage2 = _iStage2.transform.GetComponent<RectTransform>().anchoredPosition;