【C#】保守しやすいように書く
1. TODO: を活用する
- プログラマーは、ソースコードにTODOを書こう。 - このブログは証明できない。
- MonodevelopでTODOを活用する - テラシュールブログ
- 【Unity小技】ToDoをエディタ起動時にログ出力させて忘れにくくする - Qiita
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;
【Unity エラー】Android APKビルドできない時
CommandInvokationFailure: Failed to build apk. See the Console for details.
debug certificate expired on
【Unity ライブラリ】Easy Save 2 : DateTime型のデータを保存
EasySave2でDateTime型は保存できないので、string型で保存する。
public string _sCurTimeIsLeft{ get{ if (ES2.Exists ("curTimeIsLeft" + _id)) { return ES2.Load<string> ("curTimeIsLeft" + _id); } else { return null; } } set{ ES2.Save (value, "curTimeIsLeft" + _id); } } public string _sTimeIsClicked{ get{ if (ES2.Exists ("timeIsClicked" + _id)) { return ES2.Load<string> ("timeIsClicked" + _id); } else { return null; } } set{ ES2.Save (value, "timeIsClicked" + _id); } }
呼び出す側で、intやDateTime型に変換してあげる。
void Update () { if(SkillSource._item[_id]._bOnUseSkill){ if( _curTimeIsLeft > 0){ _curTimeIsLeft = Convert.ToInt64(SkillSource._item[_id]._sCurTimeIsLeft); TimeSpan pastTime = DateTime.Now - Convert.ToDateTime(SkillSource._item[_id]._sTimeIsClicked); _curTimeIsLeft = _timeCoolDown - pastTime.Seconds; SkillSource._item[_id]._sCurTimeIsLeft = Convert.ToString(_curTimeIsLeft); UpdateContent(); }else{ SkillSource._item[_id]._bOnUseSkill = false; _curTimeIsLeft = _timeCoolDown; _bIcon.enabled = true; } } } public void SetContent(int id) { List<SkillContents> _item = SkillSource._item; _id = id; _type = _item[_id]._type; _curLevel = _item[_id]._curLevel; _levelRequirement = _item[_id]._stageRequirement; _iSkill.SetSprite ( _item[_id]._spriteName); Utility.ChangeTextMesh(_tName , _item[_id]._name); Utility.ChangeTextMesh(_tDescription, _item[_id]._description); UpdateContent(_id); }
UI エフェクトコンポーネント "outline"
UI エフェクトコンポーネント「outline」を使って、UI をアウトラインする。
【Unity エラー】Inspecterでnullスクリプトがないか確認する
NullReferenceException: Object reference not set to an instance of an object
<原因>
Inspecterで、null(指定していない)スクリプトをコンポーネントに持つオブジェクトが存在する。
NullReferenceException: Object reference not set to an instance of an object UnityEngine.UI.Graphic.OnRebuildRequested () (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Graphic.cs:454) UnityEngine.UI.GraphicRebuildTracker.OnRebuildRequested () (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/GraphicRebuildTracker.cs:33) UnityEngine.CanvasRenderer.RequestRefresh ()