예제 #1
0
        public static AnimatorState CloneDeep(this AnimatorState source)
        {
            var dest = new AnimatorState
            {
                cycleOffset                = source.cycleOffset,
                cycleOffsetParameter       = source.cycleOffsetParameter,
                cycleOffsetParameterActive = source.cycleOffsetParameterActive,
                iKOnFeet              = source.iKOnFeet,
                mirror                = source.mirror,
                mirrorParameter       = source.mirrorParameter,
                mirrorParameterActive = source.mirrorParameterActive,
                motion                = source.motion,
                speed                = source.speed,
                speedParameter       = source.speedParameter,
                speedParameterActive = source.speedParameterActive,
                tag                 = source.tag,
                timeParameter       = source.timeParameter,
                timeParameterActive = source.timeParameterActive,
                writeDefaultValues  = source.writeDefaultValues,
                name                = source.name,
                hideFlags           = source.hideFlags
            };

            foreach (var sourceTransition in source.transitions.Where(w => w.isExit))
            {
                var transition = dest.AddExitTransition(false);
                sourceTransition.ApplyTo(transition);

                InstanceCache <AnimatorStateTransition> .SafeRegister(sourceTransition.GetInstanceID(), transition);
            }

            foreach (var sourceTransition in source.transitions.Where(w => !w.isExit))
            {
                AnimatorStateTransition transition = null;
                if (sourceTransition.destinationStateMachine != null)
                {
                    transition = dest.AddTransition(InstanceCache <AnimatorStateMachine> .FindOrCreate(sourceTransition.destinationStateMachine, w => w.CloneDeep()));
                }

                if (sourceTransition.destinationState != null)
                {
                    transition = dest.AddTransition(InstanceCache <AnimatorState> .FindOrCreate(sourceTransition.destinationState, w => w.CloneDeep()));
                }

                if (transition == null)
                {
                    throw new ArgumentNullException(nameof(transition));
                }

                sourceTransition.ApplyTo(transition);

                InstanceCache <AnimatorStateTransition> .SafeRegister(sourceTransition.GetInstanceID(), transition);
            }

            foreach (var sourceBehaviour in source.behaviours)
            {
                var behaviour = dest.AddStateMachineBehaviour(sourceBehaviour.GetType());
                sourceBehaviour.ApplyTo(behaviour);

                InstanceCache <StateMachineBehaviour> .SafeRegister(behaviour.GetInstanceID(), behaviour);
            }

            return(dest);
        }
        public static AnimatorStateMachine CloneDeep(this AnimatorStateMachine source)
        {
            var dest = new AnimatorStateMachine
            {
                defaultState               = InstanceCache <AnimatorState> .FindOrCreate(source.defaultState, w => w.CloneDeep()),
                anyStatePosition           = source.anyStatePosition,
                entryPosition              = source.entryPosition,
                exitPosition               = source.exitPosition,
                parentStateMachinePosition = source.parentStateMachinePosition,
                hideFlags = source.hideFlags,
                name      = source.name
            };

            foreach (var sourceState in source.states)
            {
                dest.AddState(InstanceCache <AnimatorState> .FindOrCreate(sourceState.state, w => w.CloneDeep()), sourceState.position);
            }

            foreach (var sourceTransition in source.anyStateTransitions)
            {
                AnimatorStateTransition transition = null;
                if (sourceTransition.destinationStateMachine != null)
                {
                    transition = dest.AddAnyStateTransition(InstanceCache <AnimatorStateMachine> .FindOrCreate(sourceTransition.destinationStateMachine, w => w.CloneDeep()));
                }

                if (sourceTransition.destinationState != null)
                {
                    transition = dest.AddAnyStateTransition(InstanceCache <AnimatorState> .FindOrCreate(sourceTransition.destinationState, w => w.CloneDeep()));
                }

                if (transition == null)
                {
                    throw new ArgumentNullException(nameof(transition));
                }

                sourceTransition.ApplyTo(transition);

                InstanceCache <AnimatorStateTransition> .SafeRegister(sourceTransition.GetInstanceID(), transition);
            }

            foreach (var sourceTransition in source.entryTransitions)
            {
                AnimatorTransition transition = null;
                if (sourceTransition.destinationStateMachine != null)
                {
                    transition = dest.AddEntryTransition(InstanceCache <AnimatorStateMachine> .FindOrCreate(sourceTransition.destinationStateMachine, w => w.CloneDeep()));
                }

                if (sourceTransition.destinationState != null)
                {
                    transition = dest.AddEntryTransition(InstanceCache <AnimatorState> .FindOrCreate(sourceTransition.destinationState, w => w.CloneDeep()));
                }

                if (transition == null)
                {
                    throw new ArgumentNullException(nameof(transition));
                }

                sourceTransition.ApplyTo(transition);

                InstanceCache <AnimatorTransition> .SafeRegister(sourceTransition.GetInstanceID(), transition);
            }

            foreach (var sourceBehaviour in source.behaviours)
            {
                var behaviour = dest.AddStateMachineBehaviour(sourceBehaviour.GetType());
                sourceBehaviour.ApplyTo(behaviour);

                InstanceCache <StateMachineBehaviour> .SafeRegister(behaviour.GetInstanceID(), behaviour);
            }

            foreach (var sourceStateMachine in source.stateMachines)
            {
                dest.AddStateMachine(InstanceCache <AnimatorStateMachine> .FindOrCreate(sourceStateMachine.stateMachine, w => w.CloneDeep()), sourceStateMachine.position);
            }

            return(dest);
        }