2014年5月14日 星期三

[C#] money string 數字轉成金錢的字串 (插入逗號)

因為專案需要,所以要把數字每三位數插入一個逗號,
之前再寫as3時還傻傻自己寫了一個程式來轉換
這次寫C#遇到同樣的問題
本來打算也寫一隻轉換程式
後來才發現C#內建好了
參考微軟官網

程式的範例

uint playerCoin = 2369000;

playerCoin.ToString("N0");

輸出結果 => 2,369,000

稍微說明一下 ToString("N0")

裡面的N表示輸出的格式為 Number

其他的格式選擇請參考微軟官網

後面的0表示要到小數點第幾位

因為我不需要小數點以後的數字
所以就打0

剩下的就自行參考官網囉^^


2014年5月13日 星期二

[Unity3D] 遊戲暫停時 動畫與音樂的處理

節錄官方範例的script裡的method

private List<Animation> animationComponents;
private List<AudioSource> audioSourceComponents;

void HandleGamePauseRtGame(){ _GamePausePanel.SetActive(false); StartCoroutine(Pause (false)); } void HandleGamePauseOnPress(){ _GamePausePanel.SetActive(true); //_GamePausePanel.transform.position = new Vector3(0,0,0); StartCoroutine(Pause (true)); }

IEnumerator Pause (bool pause) {
// Pause/unpause time
Time.timeScale = (pause ? 0 : 1);
// Unlock/Lock cursor
Screen.lockCursor = !pause;

if (pause == true) {
Object[] objects = FindObjectsOfType(typeof(Animation));
animationComponents = new List<Animation>();
foreach (Object obj in objects) {
Animation anim = (Animation)obj;
if (anim != null && anim.enabled) {
animationComponents.Add(anim);
anim.enabled = false;
}
}
objects = FindObjectsOfType(typeof(AudioSource));
audioSourceComponents = new List<AudioSource>();
foreach (Object obj in objects) {
AudioSource source = (AudioSource)obj;
if (source != null && source.enabled /*&& source.isPlaying*/) {
audioSourceComponents.Add(source);
source.Pause();
}
}
}
else {
// If unpausing, wait one frame before we enable animation component.
// Procedural adjustments are one frame delayed because first frame
// after being paused has deltaTime of 0.
yield return 0;
foreach (Animation anim in animationComponents)
anim.enabled = true;
foreach (AudioSource source in audioSourceComponents)
source.Play();
animationComponents = null;
}
}