試してみたところ、Arrayに格納し、UpdateMeというメソッドを10000回呼んだところ、10倍程度早かったですよ。
ここを参考にしました
https://blogs.unity3d.com/jp/2015/12/23/1k-update-calls/
計測の仕方ですが、下記のようにして行いましたか?
最初のUpdateが実行された時にStopwatchを起動 (Script Execution Order で設定)、
LateUpdateでStopwatchを停止、
数分間のあいだ計測を続け、平均を出す。
一応計測用スクリプトを。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
class TestScript : MonoBehaviour
{
int i;
public void UpdateMe()
{
i++;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
class TestScript2 : MonoBehaviour
{
float time;
TestScript[] scriptList;
List<float> timeList = new List<float>();
private void Awake()
{
var gos = GameObject.FindGameObjectsWithTag("Test");
scriptList = gos.Select(x => x.GetComponent<TestScript>()).ToArray();
}
void Update()
{
time = Time.realtimeSinceStartup;
foreach (TestScript s in scriptList)
{
s.UpdateMe();
}
}
private void LateUpdate()
{
float lapTime = Time.realtimeSinceStartup - time;
timeList.Add(lapTime);
if(timeList.Count > 60)
{
Debug.Log( timeList.Average() );
timeList.Clear();
}
}
}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/15 09:44 編集