Legacy Documentation: Version 2017.2 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Sampler.GetRecorder

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public method GetRecorder(): Profiling.Recorder;
public Profiling.Recorder GetRecorder();

Returns

Recorder Recorder object associated with the Sampler.

Description

Returns Recorder associated with the Sampler.

Each Sampler has only one recorder. Multiple calls to GetRecorder return references that control the same native Recorder object. If Sampler object is invalid, it returns invalid Recorder object as well.

#pragma strict
var behaviourUpdateRecorder: Recorder;
function Start() {
	var sampler: var = Sampler.Get("BehaviourUpdate");
	behaviourUpdateRecorder = sampler.GetRecorder();
	if (behaviourUpdateRecorder.isValid)
		behaviourUpdateRecorder.enabled = true;
}
function Update() {
	if (behaviourUpdateRecorder.isValid)
		Debug.Log("BehaviourUpdate time: " + behaviourUpdateRecorder.elapsedNanoseconds);
}
using UnityEngine;
using UnityEngine.Profiling;

public class ExampleClass : MonoBehaviour { Recorder behaviourUpdateRecorder; void Start() { var sampler = Sampler.Get("BehaviourUpdate"); behaviourUpdateRecorder = sampler.GetRecorder(); if (behaviourUpdateRecorder.isValid) behaviourUpdateRecorder.enabled = true; }

void Update() { if (behaviourUpdateRecorder.isValid) Debug.Log("BehaviourUpdate time: " + behaviourUpdateRecorder.elapsedNanoseconds); } }

Note: At the moment Samplers are available only in the Editor and Development Players. Use Sampler.isValid to verify if Sampler can be used to create a valid Recorder.

See Also: Sampler.isValid, Recorder, Recorder.isValid.

对文档有任何疑问,请移步至开发者社区提问,我们将尽快为您解答