示例#1
0
 public int ShouldTransitionBegin(
     float currentAnimLocalTime,
     float currentAnimGlobalTime,
     int animationIndex,
     MotionMatching motionMatchingComponent,
     MotionMatchingStateType currentStateType,
     MotionMatchingData data
     )
 {
     for (int i = 0; i < options.Count; i++)
     {
         if (options[i].ShouldTranistionFromThisOption(
                 currentAnimLocalTime,
                 currentAnimGlobalTime,
                 animationIndex,
                 motionMatchingComponent,
                 currentStateType,
                 data
                 ))
         {
             return(i);
         }
     }
     return(-1);
 }
        public void UpdateFromOther(MotionMatchingData newData, string newName)
        {
            this.name            = newName;
            this.clips           = newData.clips;
            this.frameRate       = newData.frameRate;
            this.frameTime       = newData.frameTime;
            this.animationLength = newData.animationLength;
            this.isLooping       = newData.isLooping;
            this.dataType        = newData.dataType;
            //this.endLocalPosition = newData.endLocalPosition;
            //this.deltaRotStartEnd = newData.deltaRotStartEnd;
            //this.startLocalPosition = newData.startLocalPosition;
            //this.deltaRotEndStart = newData.deltaRotEndStart;
            //this.curves = newData.curves;
            this.frames           = newData.frames;
            this.usedFrameCount   = newData.numberOfFrames;
            this.blendTreeWeights = newData.blendTreeWeights;
            this.sections         = newData.sections;
            this.blendToYourself  = newData.blendToYourself;
            findInYourself        = newData.findInYourself;

            this.animationSeqInfos = newData.animationSeqInfos;

            this.neverChecking         = newData.neverChecking;
            this.trajectoryPointsTimes = newData.trajectoryPointsTimes;

            FrameData bufforFrame;

            for (int frameIndex = 0; frameIndex < frames.Count; frameIndex++)
            {
                bufforFrame = frames[frameIndex];
                for (int sectionIndex = 0; sectionIndex < sections.Count; sectionIndex++)
                {
                    for (int intervalIndex = 0; intervalIndex < sections[sectionIndex].timeIntervals.Count; intervalIndex++)
                    {
                        if (bufforFrame.localTime >= sections[sectionIndex].timeIntervals[intervalIndex].x &&
                            bufforFrame.localTime <= sections[sectionIndex].timeIntervals[intervalIndex].y)
                        {
                            bufforFrame.sections.SetSection(sectionIndex, true);
                        }
                        else
                        {
                            bufforFrame.sections.SetSection(sectionIndex, false);
                        }
                    }
                }
                frames[frameIndex] = bufforFrame;
            }

            //for (int i = 0; i < newCreatedAsset.frames.Count; i++)
            //{
            //    loadedAsset.frames.Add(newCreatedAsset.frames[i]);
            //}
        }
        public static void CopyNeverLookingForNewPoseTimeIntervals(MotionMatchingData from, MotionMatchingData to)
        {
            if (!from || !to)
            {
                Debug.LogWarning("Cannont copy NeverLookingForNewPose time intervals from or to null MotionMatchingData!");
                return;
            }

            to.notLookingForNewPose = from.notLookingForNewPose;

            EditorUtility.SetDirty(to);
        }
示例#4
0
        public bool ShouldTranistionFromThisOption(
            float currentAnimLocalTime,
            float currentAnimGlobalTime,
            int animationIndex,
            MotionMatching motionMatchingComponent,
            MotionMatchingStateType currentStateType,
            MotionMatchingData data
            )
        {
            if (currentStateType != MotionMatchingStateType.MotionMatching)
            {
                if (
                    (currentAnimLocalTime < this.whenCanCheckingTransition[animationIndex].x || currentAnimLocalTime > this.whenCanCheckingTransition[animationIndex].y)
                    )
                {
                    if (
                        (startOnExitTime && currentAnimGlobalTime < (data.animationLength - (blendTime))) ||
                        !startOnExitTime
                        )
                    {
                        return(false);
                    }
                }
            }

            for (int conditionIndex = 0; conditionIndex < floatConditions.Count; conditionIndex++)
            {
                if (!floatConditions[conditionIndex].CalculateCondition(motionMatchingComponent))
                {
                    return(false);
                }
            }

            for (int conditionIndex = 0; conditionIndex < intConditions.Count; conditionIndex++)
            {
                if (!intConditions[conditionIndex].CalculateCondition(motionMatchingComponent))
                {
                    return(false);
                }
            }

            for (int conditionIndex = 0; conditionIndex < boolConditions.Count; conditionIndex++)
            {
                if (!boolConditions[conditionIndex].CalculateCondition(motionMatchingComponent))
                {
                    return(false);
                }
            }

            return(true);
        }
示例#5
0
        public void CreateSingleAnimation(
            MotionMatchingData data,
            AnimationMixerPlayable stateMixer,
            double localTime,
            float newInputStartWeight,
            List <LogicAnimationsSequence> animationsSequences,
            bool passIK,
            bool passFootIK,
            float speedMulti = 1f
            )
        {
            switch (data.dataType)
            {
            case AnimationDataType.SingleAnimation:
                AnimationClipPlayable playable_1 = AnimationClipPlayable.Create(graph, data.clips[0]);
                playable_1.SetApplyPlayableIK(passIK);
                playable_1.SetApplyFootIK(passIK);
                playable_1.SetTime(localTime - Time.deltaTime);
                playable_1.SetTime(localTime);
                playable_1.SetSpeed(speedMulti);
                stateMixer.AddInput(playable_1, 0, newInputStartWeight);
                break;

            case AnimationDataType.BlendTree:
                AnimationMixerPlayable mixerPlayable = AnimationMixerPlayable.Create(this.graph);
                stateMixer.AddInput(mixerPlayable, 0, newInputStartWeight);
                for (int i = 0; i < data.clips.Count; i++)
                {
                    AnimationClipPlayable playable_2 = AnimationClipPlayable.Create(this.graph, data.clips[i]);
                    playable_2.SetApplyPlayableIK(passIK);
                    playable_2.SetApplyFootIK(passIK);
                    playable_2.SetTime(localTime - Time.deltaTime);
                    playable_2.SetTime(localTime);
                    playable_2.SetSpeed(speedMulti);
                    mixerPlayable.AddInput(playable_2, 0, data.blendTreeWeights[i]);
                }
                break;

            case AnimationDataType.AnimationSequence:
                animationsSequences.Add(new LogicAnimationsSequence(data, -1));
                int new_ASIndex = animationsSequences.Count - 1;
                animationsSequences[new_ASIndex].mixer = AnimationMixerPlayable.Create(this.graph);
                stateMixer.AddInput(animationsSequences[new_ASIndex].mixer, 0, newInputStartWeight);
                animationsSequences[new_ASIndex].CreateAnimationsInTime((float)localTime, this, passIK, passFootIK);
                break;
            }
        }
        public void UpdateSectionDependecesInMMData(MotionMatchingData data)
        {
            int curretSectionsCount = data.sections.Count;

            for (int i = 1; i < this.sectionSettings.Count; i++)
            {
                if (curretSectionsCount == MotionMatchingData.maxSectionsCounts && data.sections[i].sectionName != this.sectionSettings[i].name)
                {
                    data.sections[i].sectionName = this.sectionSettings[i].name;
                }
                else if (i >= data.sections.Count)
                {
                    data.sections.Add(new MM_DataSection(sectionSettings[i].name));
                }
                else if (data.sections[i].sectionName != this.sectionSettings[i].name)
                {
                    data.sections[i].sectionName = this.sectionSettings[i].name;
                }
            }
        }
示例#7
0
        public void AddMotionMatchingData(MotionMatchingData data, MotionDataGroup group)
        {
            group.animationData.Add(data);

            switch (this.stateType)
            {
            case MotionMatchingStateType.MotionMatching:
                break;

            case MotionMatchingStateType.SingleAnimation:
                break;

            case MotionMatchingStateType.ContactAnimationState:
                whereCanFindingNextPose.Add(new float2(
                                                0f,
                                                data.contactPoints.Count > 0 ? data.contactPoints[0].startTime : data.animationLength * 0.5f
                                                ));
                break;
            }

            UpdateTransitions();
        }
 public static void CopyNeverCheckingTimeIntervals(MotionMatchingData from, MotionMatchingData to)
 {
 }
 public static void CopyDataSectionTimeIntervals(MotionMatchingData from, MotionMatchingData to, int sectionIndex)
 {
 }
示例#10
0
        public void CreateBlendMotionMatchingAnimation(
            MotionMatchingData data,
            int dataIndex,
            AnimationMixerPlayable stateMixer,
            double localTime,
            float blendTime,
            List <float> blendingSpeeds,
            List <float> currentWeights,
            List <LogicAnimationsSequence> animationsSequences,
            bool passIK,
            bool passFootIK,
            float newInputStartWeight = 0f,
            float minWeightToAchive   = 0f,
            float speedMulti          = 1f
            )
        {
            if (stateMixer.GetInputCount() > 0)
            {
                if (currentWeights[currentWeights.Count - 1] >= minWeightToAchive)
                {
                    blendingSpeeds[blendingSpeeds.Count - 1] = -(stateMixer.GetInputWeight(stateMixer.GetInputCount() - 1) / blendTime);
                }
            }
            currentWeights.Add(newInputStartWeight);
            blendingSpeeds.Add(1f / blendTime);

            switch (data.dataType)
            {
            case AnimationDataType.SingleAnimation:
                AnimationClipPlayable playable_SA = AnimationClipPlayable.Create(graph, data.clips[0]);
                playable_SA.SetApplyPlayableIK(passIK);
                playable_SA.SetApplyFootIK(passFootIK);
                playable_SA.SetTime(localTime - Time.deltaTime);
                playable_SA.SetTime(localTime);
                playable_SA.SetSpeed(speedMulti);
                stateMixer.AddInput(playable_SA, 0, newInputStartWeight);
                break;

            case AnimationDataType.BlendTree:
                AnimationMixerPlayable mixerPlayable = AnimationMixerPlayable.Create(this.graph);
                stateMixer.AddInput(mixerPlayable, 0, newInputStartWeight);

                for (int i = 0; i < data.clips.Count; i++)
                {
                    AnimationClipPlayable playable_BT = AnimationClipPlayable.Create(this.graph, data.clips[i]);
                    playable_BT.SetApplyPlayableIK(passIK);
                    playable_BT.SetApplyFootIK(passFootIK);
                    playable_BT.SetTime(localTime - Time.deltaTime);
                    playable_BT.SetTime(localTime);
                    playable_BT.SetSpeed(speedMulti);
                    mixerPlayable.AddInput(playable_BT, 0, data.blendTreeWeights[i]);
                }
                break;

            case AnimationDataType.AnimationSequence:
                animationsSequences.Add(new LogicAnimationsSequence(data, dataIndex));
                int new_ASIndex = animationsSequences.Count - 1;
                animationsSequences[new_ASIndex].mixer = AnimationMixerPlayable.Create(this.graph);
                stateMixer.AddInput(animationsSequences[new_ASIndex].mixer, 0, newInputStartWeight);
                animationsSequences[new_ASIndex].CreateAnimationsInTime((float)localTime, this, passIK, passFootIK);
                break;
            }
        }
 public LogicAnimationsSequence(MotionMatchingData data, int dataIndex)
 {
     this.data      = data;
     this.dataIndex = dataIndex;
 }