Version: 2017.1

AnimatorController.CreateStateMachineBehaviour

Cambiar al Manual
public static int CreateStateMachineBehaviour (MonoScript script);

Parámetros

script MonoScript class to instantiate.

Valor de retorno

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

Descripción

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: UnityEngine.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()); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961