Exemplo n.º 1
0
        public bool CreateAnimationDataPlayables(MotionMatchingData data, float time = 0f)
        {
            currentMMData = data;
            if (this.IsValid())
            {
                this.ClearMainMixerInput();
                switch (data.dataType)
                {
                case AnimationDataType.SingleAnimation:
                    AddClipPlayable(data.clips[0], time, 1f);
                    break;

                case AnimationDataType.BlendTree:
                    for (int i = 0; i < data.blendTreeWeights.Length; i++)
                    {
                        AddClipPlayable(data.clips[i], time, data.blendTreeWeights[i]);
                    }
                    break;

                case AnimationDataType.AnimationSequence:
                    asBuffor = new AnimationsSequence("seq");
                    for (int i = 0; i < data.clips.Count; i++)
                    {
                        asBuffor.AddClip(data.clips[i]);
                        asBuffor.neededInfo[i] = data.animationSeqInfos[i];
                    }

                    asBuffor.CreateAnimationsInTime(time, this);
                    break;
                }

                this.Evaluate(0);
                return(true);
            }

            return(false);
        }
        private static void DrawSequence(DataCreator creator, AnimationsSequence seq, int index, float rectWidth)
        {
            if (seq.findPoseInClip.Count != seq.clips.Count)
            {
                for (int i = 0; i < seq.clips.Count; i++)
                {
                    seq.findPoseInClip.Add(true);
                }
            }
            GUILayoutElements.DrawHeader(
                seq.name,
                GUIResources.GetLightHeaderStyle_MD()
                );

            GUILayout.Space(5);

            seq.name = EditorGUILayout.TextField(
                new GUIContent("Animation sequence name"),
                seq.name
                );

            //seq.loop = EditorGUILayout.Toggle(
            //    new GUIContent("Loop"),
            //    seq.loop
            //    );

            seq.findInYourself  = EditorGUILayout.Toggle(new GUIContent("Find in yourself"), seq.findInYourself);
            seq.blendToYourself = EditorGUILayout.Toggle(new GUIContent("Blend to yourself"), seq.blendToYourself);

            GUILayout.Space(5);
            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Add clip"))
            {
                seq.AddClip(null);
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(5);
            float floatWidth  = 60f;
            float buttonWidth = 25f;
            float findPose    = 60f;

            GUILayout.BeginHorizontal();
            GUILayout.Label("Animation");
            GUILayout.Label("Find pose", GUILayout.Width(findPose));
            GUILayout.Label("Start", GUILayout.Width(floatWidth));
            GUILayout.Label("End", GUILayout.Width(floatWidth));
            GUILayout.Label("Blend", GUILayout.Width(floatWidth));
            GUILayout.Space(buttonWidth);
            GUILayout.EndHorizontal();
            for (int i = 0; i < seq.clips.Count; i++)
            {
                GUILayout.BeginHorizontal();
                //GUILayout.Label(string.Format("{0}.", i + 1));
                seq.clips[i] = (AnimationClip)EditorGUILayout.ObjectField(
                    seq.clips[i],
                    typeof(AnimationClip),
                    true
                    );

                seq.findPoseInClip[i] = EditorGUILayout.Toggle(seq.findPoseInClip[i], GUILayout.Width(findPose));

                float x = seq.neededInfo[i].x;
                float y = seq.neededInfo[i].y;
                float z = seq.neededInfo[i].z;

                //GUILayout.Label("Start time");
                x = EditorGUILayout.FloatField(x, GUILayout.Width(floatWidth));
                //GUILayout.Label("Blend start time");
                y = EditorGUILayout.FloatField(y, GUILayout.Width(floatWidth));
                //GUILayout.Label("Blend time");
                z = EditorGUILayout.FloatField(z, GUILayout.Width(floatWidth));

                seq.neededInfo[i] = new Vector3(x, y, z);

                if (GUILayout.Button("X", GUILayout.Width(buttonWidth)))
                {
                    seq.RemoveAnimationsAt(i);
                }
                GUILayout.EndHorizontal();
            }

            GUILayout.Space(10);

            //deltaTimeCaculation = Time.realtimeSinceStartup;

            seq.CalculateLength();
            GUILayout.Label(string.Format("Sequence length: \t {0}", seq.length));


            GUILayout.Space(10);
        }