Created
March 2, 2025 23:42
-
-
Save baobao/4d5b45c6a82ef1cacf0808ef400a03c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.Profiling; | |
public enum TransformAccessType | |
{ | |
transformAccess, | |
GetComponentAccess, | |
CachedTransform, | |
} | |
public class ComponentPerformanceTest : MonoBehaviour | |
{ | |
// インスペクタから切り替えて負荷確認 | |
public TransformAccessType type; | |
Transform t; | |
void Update () | |
{ | |
if (t == null) | |
{ | |
t = transform; | |
} | |
Profiler.BeginSample ("### Check Transform ###"); | |
for (int i = 0; i < 10000; i++) { | |
if (type == TransformAccessType.CachedTransform) | |
{ | |
// Transformをキャッシュして使用 | |
t.localPosition = Vector3.zero; | |
} | |
else if (type == TransformAccessType.GetComponentAccess) | |
{ | |
// GetComponentを使用 | |
GetComponent<Transform> ().localPosition = Vector3.zero; | |
} | |
else | |
{ | |
// transformアクセス | |
transform.localPosition = Vector3.zero; | |
} | |
} | |
Profiler.EndSample (); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment