2013年11月14日木曜日

Unityでビットマップフォントを使用する [Unity Orthello C#]

Orthelloのインポートとビットマップフォントの作成は終了している状態で進めます

※Orthelloのインポートはこちらから
※ビットマップフォントの作成はこちらから

1.Projectの「Assets」「Orthello」「Objects」「Sprites」「SpriteAtlas」「SpriteAtlas-Cocos2D-fnt」を「Hierarchy」にドラッグ&ドロップします


この部分が追加されます
「StatusFnt」に変更





















2. 「Assets」-「Orthello」-「Objects」-「Sprites」-「TextSprite」を「Hierarchy」にドラッグ&ドロップ













この部分が追加されます
「StatusSprite」に変更



















3.作成した「xxxx.txt」と「xxxx.png」を適当な場所に移動する
  ここでは「Assets」に「status.txt」と「status.png」を作成

4. 「StatusFnt」-「Inspector」の「Texture」を作成した「xxxx.png」に変更する





















5. 「StatusSprite」-「Inspector」の「Sprite Container」に「StatusFnt」を設定
  ※フォントカラーを変更したい場合は「TinColor」で色を選択























6.ステータス値の出力
  「Status.cs」を作成し、下記プログラムを書き込む

public class status: MonoBehaviour {
  OTTextSprite text;
  // Use this for initialization
  void Start () {
  text = GetComponent<OTTextSprite>();
  }
  int tick = 100;
  // Update is called once per frame
  void Update () {
  if (tick > 0) {
  tick -= 1;
  text.text = (tick) + "/100" ;
  }
  }
}

「Status.cs」を「StatusSprite」にドラッグ&ドロップ
実行すると「100/100」から「0/100」にカウントダウンする



Unityにデータ保存 [Unity C#]

1.保存
  EditorPrefs.SetInt("名前", 数値);

2.取得
  EditorPrefs.GetInt("名前", 0);

3.削除

  指定削除 EditorPrefs.DeleteKey("削除する名前");
  全件削除 EditorPrefs. DeleteAll();



※他にも[Bool][String][Float]があるようです
詳しくはこちらを参照。