public AnimatorControllerExportCollection(IAssetExporter assetExporter, VirtualSerializedFile virtualFile, AnimatorController asset) : base(assetExporter, asset) { ControllerConstant controller = asset.Controller; IReadOnlyList <OffsetPtr <StateMachineConstant> > stateMachinesConst = controller.StateMachineArray; StateMachines = new AnimatorStateMachine[stateMachinesConst.Count]; for (int i = 0; i < stateMachinesConst.Count; i++) { AnimatorStateMachine stateMachine = AnimatorStateMachine.CreateVirtualInstance(virtualFile, asset, i); StateMachines[i] = stateMachine; } for (int i = 0; i < StateMachines.Length; i++) { AnimatorStateMachine stateMachine = StateMachines[i]; StateMachineConstant stateMachineConstant = asset.Controller.StateMachineArray[i].Instance; AddAsset(stateMachine); AddBehaviours(asset, stateMachine.StateMachineBehaviours); foreach (PPtr <AnimatorStateTransition> transitionPtr in stateMachine.AnyStateTransitions) { AnimatorStateTransition transition = transitionPtr.GetAsset(virtualFile); AddAsset(transition); } foreach (PPtr <AnimatorTransition> transitionPtr in stateMachine.EntryTransitions) { AnimatorTransition transition = transitionPtr.GetAsset(virtualFile); AddAsset(transition); } for (int j = 0; j < stateMachine.ChildStates.Length; j++) { PPtr <AnimatorState> statePtr = stateMachine.ChildStates[j].State; AnimatorState state = statePtr.GetAsset(virtualFile); StateConstant stateConstant = stateMachineConstant.StateConstantArray[j].Instance; AddAsset(state); AddBehaviours(asset, state.StateMachineBehaviours); if (state.Motion.IsVirtual) { Motion motion = state.Motion.GetAsset(virtualFile); AddBlendTree(virtualFile, (BlendTree)motion); } for (int k = 0; k < state.Transitions.Length; k++) { PPtr <AnimatorStateTransition> transitionPtr = state.Transitions[k]; AnimatorStateTransition transition = transitionPtr.GetAsset(virtualFile); TransitionConstant transitionConstant = stateConstant.TransitionConstantArray[k].Instance; AddAsset(transition); } } } }
private AnimatorState(AssetInfo assetInfo, AnimatorController controller, int stateMachineIndex, int stateIndex, Vector3f position) : base(assetInfo, 1) { VirtualSerializedFile virtualFile = (VirtualSerializedFile)assetInfo.File; IReadOnlyDictionary <uint, string> TOS = controller.TOS; if (!TOS.ContainsKey(0)) { Dictionary <uint, string> tos = new Dictionary <uint, string>(); tos.Add(0, string.Empty); tos.AddRange(controller.TOS); TOS = tos; } StateMachineConstant stateMachine = controller.Controller.StateMachineArray[stateMachineIndex].Instance; StateConstant state = stateMachine.StateConstantArray[stateIndex].Instance; Name = TOS[state.NameID]; Speed = state.Speed; CycleOffset = state.CycleOffset; m_transitions = new PPtr <AnimatorStateTransition> [state.TransitionConstantArray.Count]; for (int i = 0; i < state.TransitionConstantArray.Count; i++) { TransitionConstant transitionConstant = state.TransitionConstantArray[i].Instance; AnimatorStateTransition transition = AnimatorStateTransition.CreateVirtualInstance(virtualFile, controller, transitionConstant); m_transitions[i] = transition.File.CreatePPtr(transition); } m_stateMachineBehaviours = controller.GetStateBeahviours(stateMachineIndex, stateIndex); Position = position; IKOnFeet = state.IKOnFeet; WriteDefaultValues = state.GetWriteDefaultValues(controller.File.Version); Mirror = state.Mirror; SpeedParameterActive = state.SpeedParamID > 0; MirrorParameterActive = state.MirrorParamID > 0; CycleOffsetParameterActive = state.CycleOffsetParamID > 0; TimeParameterActive = state.TimeParamID > 0; Motion = state.CreateMotion(virtualFile, controller, 0); Tag = TOS[state.TagID]; SpeedParameter = TOS[state.SpeedParamID]; MirrorParameter = TOS[state.MirrorParamID]; CycleOffsetParameter = TOS[state.CycleOffsetParamID]; TimeParameter = TOS[state.TimeParamID]; }
public AnimatorState(VirtualSerializedFile file, AnimatorController controller, int stateMachineIndex, int stateIndex, Vector3f position) : base(file.CreateAssetInfo(ClassIDType.AnimatorState)) { ObjectHideFlags = 1; IReadOnlyDictionary <uint, string> TOS = controller.TOS; StateMachineConstant stateMachine = controller.Controller.StateMachineArray[stateMachineIndex].Instance; StateConstant state = stateMachine.StateConstantArray[stateIndex].Instance; Name = TOS[state.NameID]; Speed = state.Speed; CycleOffset = state.CycleOffset; m_transitions = new PPtr <AnimatorStateTransition> [state.TransitionConstantArray.Count]; for (int i = 0; i < state.TransitionConstantArray.Count; i++) { TransitionConstant transitionConstant = state.TransitionConstantArray[i].Instance; AnimatorStateTransition transition = new AnimatorStateTransition(file, controller, transitionConstant); m_transitions[i] = PPtr <AnimatorStateTransition> .CreateVirtualPointer(transition); } m_stateMachineBehaviours = controller.GetStateBeahviours(stateMachineIndex, stateIndex); Position = position; IKOnFeet = state.IKOnFeet; WriteDefaultValues = state.GetWriteDefaultValues(controller.File.Version); Mirror = state.Mirror; SpeedParameterActive = state.SpeedParamID > 0; MirrorParameterActive = state.MirrorParamID > 0; CycleOffsetParameterActive = state.CycleOffsetParamID > 0; TimeParameterActive = state.TimeParamID > 0; Motion = state.CreateMotion(file, controller, 0); Tag = TOS[state.TagID]; SpeedParameter = TOS[state.SpeedParamID]; MirrorParameter = TOS[state.MirrorParamID]; CycleOffsetParameter = TOS[state.CycleOffsetParamID]; TimeParameter = TOS[state.TimeParamID]; file.AddAsset(this); }
private AnimatorStateTransition(AssetInfo assetInfo, AnimatorController controller, TransitionConstant transition) : base(assetInfo, ClassIDType.AnimatorStateTransition, controller, transition) { TransitionDuration = transition.TransitionDuration; TransitionOffset = transition.TransitionOffset; ExitTime = transition.GetExitTime(controller.File.Version); HasExitTime = transition.GetHasExitTime(controller.File.Version); HasFixedDuration = transition.GetHasFixedDuration(controller.File.Version);; InterruptionSource = transition.GetInterruptionSource(controller.File.Version); OrderedInterruption = transition.OrderedInterruption; CanTransitionToSelf = transition.CanTransitionToSelf; }
public static AnimatorStateTransition CreateVirtualInstance(VirtualSerializedFile virtualFile, AnimatorController controller, TransitionConstant transition, IReadOnlyList <AnimatorState> states) { return(virtualFile.CreateAsset((assetInfo) => new AnimatorStateTransition(assetInfo, controller, transition, states))); }
private AnimatorStateTransition(AssetInfo assetInfo, AnimatorController controller, TransitionConstant transition, IReadOnlyList <AnimatorState> states) : this(assetInfo, controller, transition) { if (!transition.IsExit) { AnimatorState state = states[transition.DestinationState]; DstState = state.File.CreatePPtr(state); } }
public AnimatorStateTransition(VirtualSerializedFile file, AnimatorController controller, TransitionConstant transition) : base(file, ClassIDType.AnimatorStateTransition, controller, transition) { TransitionDuration = transition.TransitionDuration; TransitionOffset = transition.TransitionOffset; ExitTime = transition.GetExitTime(controller.File.Version); HasExitTime = transition.GetHasExitTime(controller.File.Version); HasFixedDuration = transition.GetHasFixedDuration(controller.File.Version);; InterruptionSource = transition.GetInterruptionSource(controller.File.Version); OrderedInterruption = transition.OrderedInterruption; CanTransitionToSelf = transition.CanTransitionToSelf; file.AddAsset(this); }
public AnimatorStateTransition(VirtualSerializedFile file, AnimatorController controller, TransitionConstant transition, IReadOnlyList <AnimatorState> states) : this(file, controller, transition) { if (!transition.IsExit) { DstState = PPtr <AnimatorState> .CreateVirtualPointer(states[transition.DestinationState]); } }
private AnimatorStateMachine(AssetInfo assetInfo, AnimatorController controller, int stateMachineIndex) : base(assetInfo, HideFlags.HideInHierarchy) { VirtualSerializedFile virtualFile = (VirtualSerializedFile)assetInfo.File; LayerConstant layer = controller.Controller.GetLayerByStateMachineIndex(stateMachineIndex); Name = controller.TOS[layer.Binding]; StateMachineConstant stateMachine = controller.Controller.StateMachineArray[stateMachineIndex].Instance; int stateCount = stateMachine.StateConstantArray.Count; int stateMachineCount = 0; int count = stateCount + stateMachineCount; int side = (int)Math.Ceiling(Math.Sqrt(count)); List <AnimatorState> states = new List <AnimatorState>(); m_childStates = new ChildAnimatorState[stateCount]; for (int y = 0, stateIndex = 0; y < side && stateIndex < stateCount; y++) { for (int x = 0; x < side && stateIndex < stateCount; x++, stateIndex++) { Vector3f position = new Vector3f(x * StateOffset, y * StateOffset, 0.0f); AnimatorState state = AnimatorState.CreateVirtualInstance(virtualFile, controller, stateMachineIndex, stateIndex, position); ChildAnimatorState childState = new ChildAnimatorState(state, position); m_childStates[stateIndex] = childState; states.Add(state); } } #warning TODO: child StateMachines m_childStateMachines = new ChildAnimatorStateMachine[stateMachineCount]; // set destination state for transitions here because all states has become valid only now for (int i = 0; i < stateMachine.StateConstantArray.Count; i++) { AnimatorState state = states[i]; StateConstant stateConstant = stateMachine.StateConstantArray[i].Instance; PPtr <AnimatorStateTransition>[] transitions = new PPtr <AnimatorStateTransition> [stateConstant.TransitionConstantArray.Count]; for (int j = 0; j < stateConstant.TransitionConstantArray.Count; j++) { TransitionConstant transitionConstant = stateConstant.TransitionConstantArray[j].Instance; AnimatorStateTransition.Parameters parameters = new AnimatorStateTransition.Parameters { StateMachine = stateMachine, States = states, TOS = controller.TOS, Transition = transitionConstant, Version = controller.File.Version, }; AnimatorStateTransition transition = AnimatorStateTransition.CreateVirtualInstance(virtualFile, parameters); transitions[j] = transition.File.CreatePPtr(transition); } state.Transitions = transitions; } m_anyStateTransitions = new PPtr <AnimatorStateTransition> [stateMachine.AnyStateTransitionConstantArray.Count]; for (int i = 0; i < stateMachine.AnyStateTransitionConstantArray.Count; i++) { TransitionConstant transitionConstant = stateMachine.AnyStateTransitionConstantArray[i].Instance; AnimatorStateTransition.Parameters parameters = new AnimatorStateTransition.Parameters { StateMachine = stateMachine, States = states, TOS = controller.TOS, Transition = transitionConstant, Version = controller.File.Version, }; AnimatorStateTransition transition = AnimatorStateTransition.CreateVirtualInstance(virtualFile, parameters); m_anyStateTransitions[i] = transition.File.CreatePPtr(transition); } StateMachineConstant.Parameters stateParameters = new StateMachineConstant.Parameters { ID = layer.Binding, States = states, TOS = controller.TOS, Version = controller.File.Version, }; m_entryTransitions = stateMachine.CreateEntryTransitions(virtualFile, stateParameters); m_stateMachineBehaviours = Array.Empty <PPtr <MonoBehaviour> >(); AnyStatePosition = new Vector3f(0.0f, -StateOffset, 0.0f); EntryPosition = new Vector3f(StateOffset, -StateOffset, 0.0f); ExitPosition = new Vector3f(2.0f * StateOffset, -StateOffset, 0.0f); ParentStateMachinePosition = new Vector3f(0.0f, -2.0f * StateOffset, 0.0f); DefaultState = ChildStates.Count > 0 ? ChildStates[stateMachine.DefaultState].State : default; }
protected AnimatorTransitionBase(AssetInfo assetInfo, ClassIDType classID, AnimatorController controller, TransitionConstant transition) : this(assetInfo, classID, controller, transition.ConditionConstantArray) { Name = controller.TOS[transition.UserID]; IsExit = transition.IsExit; }
public AnimatorStateMachine(VirtualSerializedFile file, AnimatorController controller, int stateMachineIndex) : base(file.CreateAssetInfo(ClassIDType.AnimatorStateMachine)) { ObjectHideFlags = 1; LayerConstant layer = controller.Controller.GetLayerByStateMachineIndex(stateMachineIndex); Name = controller.TOS[layer.Binding]; StateMachineConstant stateMachine = controller.Controller.StateMachineArray[stateMachineIndex].Instance; int stateCount = stateMachine.StateConstantArray.Count; int stateMachineCount = 0; int count = stateCount + stateMachineCount; int side = (int)Math.Ceiling(Math.Sqrt(count)); List <AnimatorState> states = new List <AnimatorState>(); m_childStates = new ChildAnimatorState[stateCount]; for (int y = 0, stateIndex = 0; y < side && stateIndex < stateCount; y++) { for (int x = 0; x < side && stateIndex < stateCount; x++, stateIndex++) { Vector3f position = new Vector3f(x * StateOffset, y * StateOffset, 0.0f); AnimatorState state = new AnimatorState(file, controller, stateMachineIndex, stateIndex, position); ChildAnimatorState childState = new ChildAnimatorState(state, position); m_childStates[stateIndex] = childState; states.Add(state); } } m_childStateMachines = new ChildAnimatorStateMachine[stateMachineCount]; // set destination state for transitions here because all states has become valid only now for (int i = 0; i < stateMachine.StateConstantArray.Count; i++) { AnimatorState state = states[i]; StateConstant stateConstant = stateMachine.StateConstantArray[i].Instance; for (int j = 0; j < stateConstant.TransitionConstantArray.Count; j++) { long stateTransitionPath = state.Transitions[j].PathID; AnimatorStateTransition transition = (AnimatorStateTransition)file.GetAsset(stateTransitionPath); TransitionConstant transitionConstant = stateConstant.TransitionConstantArray[j].Instance; if (!transitionConstant.IsExit) { AnimatorState destState = states[transitionConstant.DestinationState]; transition.DstState = PPtr <AnimatorState> .CreateVirtualPointer(destState); } } } m_anyStateTransitions = new PPtr <AnimatorStateTransition> [stateMachine.AnyStateTransitionConstantArray.Count]; for (int i = 0; i < stateMachine.AnyStateTransitionConstantArray.Count; i++) { TransitionConstant transitionConstant = stateMachine.AnyStateTransitionConstantArray[i].Instance; AnimatorStateTransition transition = new AnimatorStateTransition(file, controller, transitionConstant, states); m_anyStateTransitions[i] = PPtr <AnimatorStateTransition> .CreateVirtualPointer(transition); } m_entryTransitions = stateMachine.GetEntryTransitions(file, controller, layer.Binding, states); m_stateMachineBehaviours = new PPtr <MonoBehaviour> [0]; AnyStatePosition = new Vector3f(0.0f, -StateOffset, 0.0f); EntryPosition = new Vector3f(StateOffset, -StateOffset, 0.0f); ExitPosition = new Vector3f(2.0f * StateOffset, -StateOffset, 0.0f); ParentStateMachinePosition = new Vector3f(0.0f, -2.0f * StateOffset, 0.0f); DefaultState = ChildStates.Count > 0 ? ChildStates[stateMachine.DefaultState].State : default; file.AddAsset(this); }
private void TryInitialize(ProjectAssetContainer container) { if (m_initialized) { return; } AnimatorController asset = (AnimatorController)Asset; ControllerConstant controller = asset.Controller; IReadOnlyList <OffsetPtr <StateMachineConstant> > stateMachinesConst = controller.StateMachineArray; m_stateMachines = new AnimatorStateMachine[stateMachinesConst.Count]; for (int i = 0; i < stateMachinesConst.Count; i++) { StateMachineConstant stateMachineConstant = stateMachinesConst[i].Instance; AnimatorStateMachine stateMachine = new AnimatorStateMachine(container.VirtualFile, asset, i); m_stateMachines[i] = stateMachine; } for (int i = 0; i < StateMachines.Count; i++) { AnimatorStateMachine stateMachine = StateMachines[i]; StateMachineConstant stateMachineConstant = asset.Controller.StateMachineArray[i].Instance; AddAsset(stateMachine); foreach (PPtr <AnimatorStateTransition> transitionPtr in stateMachine.AnyStateTransitions) { AnimatorStateTransition transition = transitionPtr.GetAsset(container.VirtualFile); AddAsset(transition); } foreach (PPtr <AnimatorTransition> transitionPtr in stateMachine.EntryTransitions) { AnimatorTransition transition = transitionPtr.GetAsset(container.VirtualFile); AddAsset(transition); } for (int j = 0; j < stateMachine.ChildStates.Count; j++) { PPtr <AnimatorState> statePtr = stateMachine.ChildStates[j].State; AnimatorState state = statePtr.GetAsset(container.VirtualFile); StateConstant stateConstant = stateMachineConstant.StateConstantArray[j].Instance; AddAsset(state); if (state.Motion.IsVirtual) { AddBlendTree(container.VirtualFile, state.Motion.CastTo <BlendTree>()); } for (int k = 0; k < state.Transitions.Count; k++) { PPtr <AnimatorStateTransition> transitionPtr = state.Transitions[k]; AnimatorStateTransition transition = transitionPtr.GetAsset(container.VirtualFile); TransitionConstant transitionConstant = stateConstant.TransitionConstantArray[k].Instance; AddAsset(transition); } } } m_initialized = true; }
protected AnimatorTransitionBase(VirtualSerializedFile file, ClassIDType classID, AnimatorController controller, TransitionConstant transition) : this(file, classID, controller, transition.ConditionConstantArray) { Name = controller.TOS[transition.UserID]; IsExit = transition.IsExit; }