終於抽出時間來做些方便的小工具,其實也是為了要幫助自己快速優化專案的東西。
功能:可以對所有物件上所指定的script 同時替換成另一個script。但是限制是繼承同一個script~(例如NGUISPritePlus(繼承NGUISprite)可以取代NGUISprite)
雜七雜八,程式碼、Unity、還有遊戲
Animator m_FirstAnim, m_SecondAnim;
m_FirstAnim.Play("Loop", 0, 0);
.....
.....
float myTime = 0;
AnimatorStateInfo animationState = m_FirstAnim.GetCurrentAnimatorStateInfo(0);
float newNormalIzedTime = animationState.normalizedTime - (float)System.Math.Truncate(animationState.normalizedTime);
AnimatorClipInfo[] targetAnimatorClip = m_FirstAnim.GetCurrentAnimatorClipInfo(0);
if (targetAnimatorClip.Length > 0)
{
myTime = targetAnimatorClip[0].clip.length * newNormalIzedTime;
}
else
{
myTime = newNormalIzedTime;
}
m_SecondAnim.Play("Loop", 0, myTime);
[CustomEditor(typeof(Tool))]
public class ToolInspecter : Editor
{
protected Tool m_Tool;
///
/// Component每一次顯示在Inspector上就會重新呼叫一次
///
private void OnEnable()
{
//DO init
m_Tool = target as Tool;
}
///
/// Component從Inspector上移除的瞬間執行
///
private void OnDestroy()
{
//Do origin
}
///
/// 該Component每一次有改變就會呼叫一次
///
public override void OnInspectorGUI()
{
//Do Draw GUI
DrawDefaultInspector();
}
var tProp = OverrideCtrl.GetType().GetField("name", BindingFlags.NonPublic | BindingFlags.Instance);
tProp.SetValue(tPorp, "new name value");
public GameObject TargetObject = null;
private void ReplaceObj(){
var tProp = OverrideCtrl.GetType().GetField("monoObject", BindingFlags.NonPublic | BindingFlags.Instance);
tProp.SetValue(OverrideCtrl, TargetObject);
}
Reasons to call ToArray()轉換驗證:
- If the returned value is not meant to be modified, returning it as an array makes that fact a bit clearer.
- If the caller is expected to perform many non-sequential accesses to the data, there can be a performance benefit to an array over a List<>.
- If you know you will need to pass the returned value to a third-party function that expects an array.
- Compatibility with calling functions that need to work with .NET version 1 or 1.1. These versions don't have the List<> type (or any generic types, for that matter).
Reasons not to call ToArray()
- If the caller ever does need to add or remove elements, a List<> is absolutely required.
- The performance benefits are not necessarily guaranteed, especially if the caller is accessing the data in a sequential fashion. There is also the additional step of converting from List<> to array, which takes processing time.
- The caller can always convert the list to an array themselves.
StartCoroutine("Runner", "Text Run"); + StopCoroutine("Runner");
m_Runner = StartCoroutine(Runner("Love")); + StopCoroutine(m_Runner);
StartCoroutine(Runner("Love")); + StopCoroutine("Runner");
StartCoroutine(Runner("Love")); + StopCoroutine(Runner("Love"));