Version: 2022.3
언어: 한국어

AnimatorController.CreateStateMachineBehaviour

매뉴얼로 전환
public static int CreateStateMachineBehaviour (MonoScript script);

파라미터

script MonoScript class to instantiate.

반환

int Returns instance id of created object, returns 0 if something is not valid.

설명

This function will create a StateMachineBehaviour instance based on the class define in this script.

This function will validate that the monoscript is a valid statemachine behaviour, the class must be a sub class of StateMachineBehaviour and shouldn't be a generic. See Also: StateMachineBehaviour.

using UnityEditor;
using UnityEditor.Animations;
using UnityEngine;

public class AddSMB { public void DoAddStateMachineBehaviour(UnityEditor.Animations.AnimatorState state, MonoScript monoScript) { if (state == null) return;

int instanceID = AnimatorController.CreateStateMachineBehaviour(monoScript); if (instanceID == 0) { Debug.LogError("Could not create state machine behaviour " + monoScript.name); return; }

state.AddStateMachineBehaviour(monoScript.GetClass());

var obj = EditorUtility.InstanceIDToObject(instanceID); if (obj == null) Debug.LogError("No object could be found with instance id: " + instanceID); else AssetDatabase.AddObjectToAsset(obj, state.ToString()); } }