internal void AddBehaviour(MonoScript stateMachineBehaviour) { UnityEngine.Object[] targets = AddStateMachineBehaviourComponentWindow.targets; for (int i = 0; i < targets.Length; i++) { UnityEngine.Object @object = targets[i]; AnimatorState animatorState = @object as AnimatorState; AnimatorStateMachine animatorStateMachine = @object as AnimatorStateMachine; if (animatorState || animatorStateMachine) { int num = AnimatorController.CreateStateMachineBehaviour(stateMachineBehaviour); if (num == 0) { Debug.LogError("Could not create state machine behaviour " + stateMachineBehaviour.name); return; } string format = "Add Behaviour '{0}' to state '{1}'"; if (animatorState != null) { if (AddStateMachineBehaviourComponentWindow.controller != null) { Undo.RegisterCompleteObjectUndo(AddStateMachineBehaviourComponentWindow.controller, string.Format(format, stateMachineBehaviour.name, animatorState.name)); Undo.RegisterCompleteObjectUndo(animatorState, string.Format(format, stateMachineBehaviour.name, animatorState.name)); AddStateMachineBehaviourComponentWindow.controller.AddStateEffectiveBehaviour(animatorState, AddStateMachineBehaviourComponentWindow.layerIndex, num); } else { Undo.RegisterCompleteObjectUndo(animatorState, string.Format(format, stateMachineBehaviour.name, animatorState.name)); animatorState.AddBehaviour(num); } AssetDatabase.AddInstanceIDToAssetWithRandomFileId(num, animatorState, true); } else if (animatorStateMachine != null) { Undo.RegisterCompleteObjectUndo(animatorStateMachine, string.Format(format, stateMachineBehaviour.name, animatorStateMachine.name)); animatorStateMachine.AddBehaviour(num); AssetDatabase.AddInstanceIDToAssetWithRandomFileId(num, animatorStateMachine, true); } } } }
internal void AddBehaviour(MonoScript stateMachineBehaviour) { foreach (UnityEngine.Object obj2 in targets) { AnimatorState objectToUndo = obj2 as AnimatorState; AnimatorStateMachine machine = obj2 as AnimatorStateMachine; if ((objectToUndo != null) || (machine != null)) { int instanceID = AnimatorController.CreateStateMachineBehaviour(stateMachineBehaviour); if (instanceID == 0) { Debug.LogError("Could not create state machine behaviour " + stateMachineBehaviour.name); break; } string format = "Add Behaviour '{0}' to state '{1}'"; if (objectToUndo != null) { if (controller != null) { Undo.RegisterCompleteObjectUndo(controller, string.Format(format, stateMachineBehaviour.name, objectToUndo.name)); Undo.RegisterCompleteObjectUndo(objectToUndo, string.Format(format, stateMachineBehaviour.name, objectToUndo.name)); controller.AddStateEffectiveBehaviour(objectToUndo, layerIndex, instanceID); } else { Undo.RegisterCompleteObjectUndo(objectToUndo, string.Format(format, stateMachineBehaviour.name, objectToUndo.name)); objectToUndo.AddBehaviour(instanceID); } AssetDatabase.AddInstanceIDToAssetWithRandomFileId(instanceID, objectToUndo, true); } else if (machine != null) { Undo.RegisterCompleteObjectUndo(machine, string.Format(format, stateMachineBehaviour.name, machine.name)); machine.AddBehaviour(instanceID); AssetDatabase.AddInstanceIDToAssetWithRandomFileId(instanceID, machine, true); } } } }