Beispiel #1
0
        //添加动作片段
        private void AddNewAnimationState(JTimelineAnimation line, JAnimationTrack track, float time, string stateName)
        {
            var clipData = ScriptableObject.CreateInstance <JAnimationClipData>();

            clipData.TargetObject     = line.AffectedObject.gameObject;
            clipData.StartTime        = time;
            clipData.StateName        = stateName;
            clipData.StateDuration    = MecanimAnimationUtility.GetStateDuration(stateName, line.AffectedObject.gameObject);
            clipData.PlaybackDuration = clipData.StateDuration;
            clipData.Track            = track;
            track.AddClip(clipData);
            if (timelineClipRenderDataMap.ContainsKey(track))
            {
                var cachedData = ScriptableObject.CreateInstance <JClipRenderData>();
                cachedData.ClipData = clipData;
                timelineClipRenderDataMap[track].Add(cachedData);
            }
            else
            {
                var cachedData = ScriptableObject.CreateInstance <JClipRenderData>();
                cachedData.ClipData = clipData;
                List <JClipRenderData> list = new List <JClipRenderData>();
                list.Add(cachedData);
                timelineClipRenderDataMap.Add(track, list);
            }
        }
        public void AddClipWithState(string stateName, float startTime)
        {
            var clipData = ScriptableObject.CreateInstance <JAnimationClipData>();

            clipData.TargetObject     = TimeLine.AffectedObject.gameObject;
            clipData.StartTime        = startTime;
            clipData.StateName        = stateName;
            clipData.StateDuration    = MecanimAnimationUtility.GetStateDuration(stateName, TimeLine.AffectedObject.gameObject);
            clipData.PlaybackDuration = clipData.StateDuration;
            clipData.Track            = this;
            AddClip(clipData);
        }
Beispiel #3
0
        //加载动作
        private void LoadAnimationState(bool force = true)
        {
            SkillArt skillart  = EditorDataContainer.currentskillAssetData.skillArt;
            string   modelName = "";

            modelName = skillart.modelName;
            RuntimeAnimatorController controller0 = AssetUtility.GetAnimationCtl(skillart.modelType, skillart.modelName, skillart.animationController);

            if (skillart.animationControllerObj == null && controller0 != null)
            {
                skillart.animationControllerObj = controller0;
            }
            RuntimeAnimatorController controller = skillart.animationControllerObj;// AssetUtility.GetAnimationCtl(skillart.modelType, modelName, skillart.animationController);

            if (force && controller == null)
            {
                Debug.Log("Error! Error animationController Not Found");
            }
            if (controller != null)
            {
                if (force)
                {
                    stateNamelist = new List <string>();
                    stateNamelist = MecanimAnimationUtility.GetAllStateNamesWithController(controller);
                }
                else
                {
                    if (stateNamelist == null)
                    {
                        stateNamelist = new List <string>();
                        stateNamelist = MecanimAnimationUtility.GetAllStateNamesWithController(controller);
                    }
                }
            }
            else if (stateNamelist == null)
            {
                stateNamelist = new List <string>();
            }
            else if (stateNamelist != null)
            {
                stateNamelist.Clear();
            }
        }
Beispiel #4
0
        //时间线右键点击的菜单
        private GenericMenu MenuForAnimationTimeLine(JTimelineAnimation Animationline, JAnimationTrack linetrack)
        {
            GenericMenu   contextMenu     = new GenericMenu();
            List <string> allStates       = new List <string>();
            var           animationLayers = MecanimAnimationUtility.GetAllLayerNames(Animationline.AffectedObject.gameObject);

            contextMenu.AddItem(new GUIContent("AddNewTrack"),
                                false, (obj) => AddNewAnimationTrack(((JTimelineBase)((object[])obj)[0])),
                                new object[] { Animationline });

            foreach (var animationLayer in animationLayers)
            {
                int           layer          = MecanimAnimationUtility.LayerNameToIndex(Animationline.AffectedObject.gameObject, animationLayer);
                List <string> layerallStates = MecanimAnimationUtility.GetAllStateNames(Animationline.AffectedObject.gameObject, layer);
                foreach (var statename in layerallStates)
                {
                    string Addstate = "Layer/{0}/{1}";
                    allStates.Add(string.Format(Addstate, animationLayer, statename));
                }
            }
            float newTime = (((UnityEngine.Event.current.mousePosition.x + XScroll) / DisplayArea.width) * Animationline.Sequence.Duration) / XScale;

            foreach (var state in allStates)
            {
                contextMenu.AddItem(
                    new GUIContent(state),
                    false,
                    (obj) => AddNewAnimationState(((JTimelineAnimation)((object[])obj)[0]), ((JAnimationTrack)((object[])obj)[1]), ((float)((object[])obj)[2]), ((string)((object[])obj)[3])),
                    new object[] { Animationline, linetrack, newTime, state.Split('/')[2] }
                    );
            }
            //删除时间线
            contextMenu.AddItem(new GUIContent("DeleteAnimationLine"),
                                false, (obj) => RemoveAnimationTimeline(((JTimelineAnimation)((object[])obj)[0]), ((JAnimationTrack)((object[])obj)[1])),
                                new object[] { Animationline, linetrack });
            return(contextMenu);
        }
Beispiel #5
0
        public override void OnInspectorGUI()
        {
            JEffectClipData clip = (JEffectClipData)target;
            var             serializedProperty = serializedObject.FindProperty("effectType");

            EditorGUILayout.PropertyField(serializedProperty);

            var startTime = serializedObject.FindProperty("startTime");

            EditorGUILayout.PropertyField(startTime);
            var playbackDuration = serializedObject.FindProperty("playbackDuration");

            EditorGUILayout.PropertyField(playbackDuration);
            var serializedlooping = serializedObject.FindProperty("looping");

            EditorGUILayout.PropertyField(serializedlooping);

            float starttime = 0.5f;
            float phasetime = 0.5f;

            if (clip.effectType == EffectType.Particle || clip.effectType == EffectType.Trajectory)
            {
                starttime = clip.effectunit.artEffect.beginTime / 1000f;
                phasetime = clip.effectunit.artEffect.phaseTime / 1000f;
            }
            else
            if (clip.effectType == EffectType.Camera)
            {
                starttime = clip.cameraAction.delay;
                phasetime = clip.cameraAction.phaseTime;
            }

            bool apply = serializedObject.ApplyModifiedProperties();

            if (apply)
            {
                clip.PlaybackDuration = serializedObject.FindProperty("playbackDuration").floatValue;
                clip.StartTime        = serializedObject.FindProperty("startTime").floatValue;
            }
            if (clip.effectType == EffectType.Particle)
            {
                EditorDrawUtility.DrawSkillEffectUnit(clip.effectunit);
                if (clip.effectunit.artEffect.beginTime / 1000f != starttime || clip.effectunit.artEffect.phaseTime / 1000f != phasetime)
                {
                    clip.PlaybackDuration = (clip.effectunit.artEffect.phaseTime / 1000f);
                    clip.StartTime        = (clip.effectunit.artEffect.beginTime / 1000f);
                    apply = true;
                }
            }
            if (clip.effectType == EffectType.Camera)
            {
                var TargetCamera = serializedObject.FindProperty("TargetCamera");
                EditorGUILayout.PropertyField(TargetCamera);
                EditorDrawUtility.DrawCameraAction(clip.cameraAction);
                if (clip.cameraAction.delay != starttime || clip.cameraAction.phaseTime != phasetime)
                {
                    clip.PlaybackDuration = clip.cameraAction.phaseTime;
                    clip.StartTime        = clip.cameraAction.delay;
                    apply = true;
                }
            }
            if (clip.effectType == EffectType.Trajectory)
            {
                var Target = serializedObject.FindProperty("Target");
                EditorGUILayout.PropertyField(Target);
                var targetObject = serializedObject.FindProperty("targetObject");
                EditorGUILayout.PropertyField(targetObject);
                EditorDrawUtility.DrawSkillEffectUnit(clip.effectunit);
                EditorDrawUtility.DrawSkillUnit(clip.skillunit);
                if (clip.effectunit.artEffect.beginTime / 1000f != starttime || clip.effectunit.artEffect.phaseTime / 1000f != phasetime)
                {
                    clip.PlaybackDuration = clip.effectunit.artEffect.phaseTime / 1000f;
                    clip.StartTime        = clip.effectunit.artEffect.beginTime / 1000f;
                    apply = true;
                }
            }
            if (clip.effectType == EffectType.Sound)
            {
                var sound = serializedObject.FindProperty("sound");
                EditorGUILayout.PropertyField(sound);
                if ((AudioClip)sound.objectReferenceValue != null)
                {
                    EditorGUILayout.FloatField("Duration", ((AudioClip)sound.objectReferenceValue).length);
                }
                var targetObject = serializedObject.FindProperty("targetObject");
                EditorGUILayout.PropertyField(targetObject);

                if (serializedObject.ApplyModifiedProperties())
                {
                    serializedObject.ApplyModifiedProperties();
                    serializedObject.FindProperty("playbackDuration").floatValue = ((AudioClip)sound.objectReferenceValue).length;
                    apply = true;
                }
            }
            if (clip.effectType == EffectType.Animation)
            {
                var targetObject      = serializedObject.FindProperty("targetObject");
                var animController    = serializedObject.FindProperty("animController");
                var stateNameProperty = serializedObject.FindProperty("stateName");
                var layer             = serializedObject.FindProperty("layer");

                GameObject targetObj = (GameObject)targetObject.objectReferenceValue;
                apply = EditorGUILayout.PropertyField(targetObject);
                RuntimeAnimatorController anim0 = (RuntimeAnimatorController)animController.objectReferenceValue;
                Animator anim = targetObj.GetComponent <Animator>();
                if (anim != null)
                {
                    if (anim0 != null)
                    {
                        anim.runtimeAnimatorController = anim0;
                    }
                    if (anim0 == null && anim.runtimeAnimatorController != null)
                    {
                        animController.objectReferenceValue = anim.runtimeAnimatorController;
                    }
                    apply = true;
                }
                EditorGUILayout.PropertyField(animController);

                var availableLayerNames = MecanimAnimationUtility.GetAllLayerNames(targetObj);
                var olayer = EditorGUILayout.Popup("Layer", layer.intValue, availableLayerNames.ToArray());
                if (olayer != layer.intValue)
                {
                    layer.intValue = olayer;
                }
                var availableStateNames = MecanimAnimationUtility.GetAllStateNames(targetObj, layer.intValue);
                var existingState       = -1;
                var existingStateName   = stateNameProperty.stringValue;
                if (availableStateNames.Contains(existingStateName))
                {
                    existingState = availableStateNames.IndexOf(existingStateName);
                }
                var newState = EditorGUILayout.Popup("StateName", existingState, availableStateNames.ToArray());
                if (newState != existingState)
                {
                    stateNameProperty.stringValue = availableStateNames[newState];
                    float duration = MecanimAnimationUtility.GetStateDurationWithAnimatorController(stateNameProperty.stringValue, (RuntimeAnimatorController)animController.objectReferenceValue);
                    clip.PlaybackDuration = duration;
                    serializedObject.FindProperty("playbackDuration").floatValue = duration;
                    apply = true;
                }
            }
            if (apply)
            {
                JWindow[] windows = Resources.FindObjectsOfTypeAll <JWindow>();
                foreach (var window in windows)
                {
                    window.Repaint();
                }
            }
        }
        //生成序列
        public static JSequencer GenerateSequence(SkillAssetData skillart)
        {
            //id 名称
            string SkillId = EditorDataContainer.GetSkillStringById(skillart.skillArt.id);
            //模型名称
            string ModelName = skillart.skillArt.modelName;
            //起始动作
            string guideAction = skillart.skillArt.guideAction;
            //持续动作
            string guidingAction = skillart.skillArt.guidingAction;
            //结束动作
            string endAction = skillart.skillArt.endAction;
            //animator名称
            string animatorName = skillart.skillArt.animationController;
            RuntimeAnimatorController animationControllerObj = skillart.skillArt.animationControllerObj;
            //模型类型 主角  NPC
            ModelTargetType modelType = skillart.skillArt.modelType;
            //技能列表
            List <SkillEffectUnit> beginEffect = skillart.skillArt.beginEffect;
            //技能列表
            List <SkillEffectUnit> unitEffect = skillart.skillArt.unitEffect;
            //技能列表
            List <SkillEffectUnit> tipEffect = skillart.skillArt.tipEffect;
            //技能列表
            List <SkillEffectUnit> hitEffect = skillart.skillArt.hitEffect;

            GameObject ShowRoot = new GameObject("ShowRoot_" + SkillId);
            //获取模型 实例化
            GameObject PlayerModel = AssetUtility.GetFBXAsset(modelType, ModelName);
            GameObject Player      = null;

            if (PlayerModel != null)
            {
                Player                  = UnityEngine.Object.Instantiate(PlayerModel) as GameObject;
                Player.name             = ModelName;
                Player.transform.parent = ShowRoot.transform;
            }
            else
            {
                Player = new GameObject(ModelName);
                Player.transform.parent = ShowRoot.transform;
            }
            //获取animator 赋值
            RuntimeAnimatorController controll = animationControllerObj;// AssetUtility.GetAnimationCtl(modelType, ModelName, animatorName);

            if (controll != null)
            {
                if (Player.GetComponent <Animator>() == null)
                {
                    Player.AddComponent <Animator>();
                }
                Player.GetComponent <Animator>().runtimeAnimatorController = controll;
            }

            //新建队列
            GameObject newSequence = new GameObject("Sequence_" + ModelName);
            JSequencer sequence    = newSequence.AddComponent <JSequencer>();

            JTimelineContainer ccontainer = sequence.CreateNewTimelineContainer(Player.transform);

            JTimelineEffect effectline = (JTimelineEffect)ccontainer.AddNewTimeline(TimeLineType.Effect);

            if (guideAction != "-1")
            {
                JEffectTrack track = effectline.AddNewTrack();
                track.name = SkillNames.EffectNames[(int)SkillNames.Effect.GuideAction];
                JEffectClipData clip = ScriptableObject.CreateInstance <JEffectClipData>();
                clip.effectType       = EffectType.Animation;
                clip.TargetObject     = effectline.AffectedObject.gameObject;
                clip.animController   = controll;
                clip.StateName        = guideAction;
                clip.PlaybackDuration = MecanimAnimationUtility.GetStateDurationWithAnimatorController(guideAction, controll);
                clip.StartTime        = 0;
                track.AddClip(clip);
            }
            if (guidingAction != "-1")
            {
                JEffectTrack track = effectline.AddNewTrack();
                track.name = SkillNames.EffectNames[(int)SkillNames.Effect.GuidingAction];
                JEffectClipData clip = ScriptableObject.CreateInstance <JEffectClipData>();
                clip.effectType       = EffectType.Animation;
                clip.TargetObject     = effectline.AffectedObject.gameObject;
                clip.animController   = controll;
                clip.StateName        = guidingAction;
                clip.PlaybackDuration = MecanimAnimationUtility.GetStateDurationWithAnimatorController(guidingAction, controll);
                float t = guidingAction == "-1" ? 0 : MecanimAnimationUtility.GetStateDurationWithAnimatorController(guideAction, controll);
                clip.StartTime = t;
                track.AddClip(clip);
            }
            if (endAction != "-1")
            {
                JEffectTrack track = effectline.AddNewTrack();
                track.name = SkillNames.EffectNames[(int)SkillNames.Effect.EndAction];
                float           t1   = guideAction == "-1" ? 0 : MecanimAnimationUtility.GetStateDurationWithAnimatorController(guideAction, controll);
                float           t    = guidingAction == "-1" ? 0 : MecanimAnimationUtility.GetStateDurationWithAnimatorController(guidingAction, controll);
                JEffectClipData clip = ScriptableObject.CreateInstance <JEffectClipData>();
                clip.effectType       = EffectType.Animation;
                clip.TargetObject     = effectline.AffectedObject.gameObject;
                clip.animController   = controll;
                clip.StateName        = endAction;
                clip.PlaybackDuration = MecanimAnimationUtility.GetStateDurationWithAnimatorController(endAction, controll);
                clip.StartTime        = t1 + t;
                track.AddClip(clip);
            }

            if (beginEffect != null)
            {
                //一个特效 一条轨道
                foreach (SkillEffectUnit effect in beginEffect)
                {
                    //特效名称
                    JEffectTrack track = effectline.AddNewTrack();
                    int          index = beginEffect.IndexOf(effect);
                    if (index > 2)
                    {
                        index = 2;
                    }
                    track.name = SkillNames.EffectNames[(int)SkillNames.Effect.BeginEffect0 + index];
                    JEffectClipData clip = ScriptableObject.CreateInstance <JEffectClipData>();
                    clip.effectType       = EffectType.Particle;
                    clip.effectunit       = effect.Copy();
                    clip.TargetObject     = effectline.AffectedObject.gameObject;
                    clip.PlaybackDuration = (float)effect.artEffect.phaseTime / 1000.0f;
                    clip.StartTime        = (float)effect.artEffect.beginTime / 1000.0f;
                    track.AddClip(clip);
                }
            }
            if (unitEffect != null)
            {
                //一个特效 一条轨道
                foreach (SkillEffectUnit effect in unitEffect)
                {
                    //特效名称
                    JEffectTrack track = effectline.AddNewTrack();
                    track.name = SkillNames.EffectNames[(int)SkillNames.Effect.UnitEffect];
                    JEffectClipData clip = ScriptableObject.CreateInstance <JEffectClipData>();
                    clip.effectType       = EffectType.Trajectory;
                    clip.effectunit       = effect.Copy();
                    clip.skillunit        = skillart.skillUnit.Copy();
                    clip.TargetObject     = effectline.AffectedObject.gameObject;
                    clip.PlaybackDuration = (float)effect.artEffect.phaseTime / 1000.0f;
                    clip.StartTime        = (float)effect.artEffect.beginTime / 1000.0f;
                    track.AddClip(clip);
                }
            }
            if (tipEffect != null)
            {
                //一个特效 一条轨道
                foreach (SkillEffectUnit effect in tipEffect)
                {
                    //特效名称
                    JEffectTrack track = effectline.AddNewTrack();
                    track.name = SkillNames.EffectNames[(int)SkillNames.Effect.TipEffect];
                    JEffectClipData clip = ScriptableObject.CreateInstance <JEffectClipData>();
                    clip.effectType       = EffectType.Particle;
                    clip.effectunit       = effect.Copy();
                    clip.TargetObject     = effectline.AffectedObject.gameObject;
                    clip.PlaybackDuration = (float)effect.artEffect.phaseTime / 1000.0f;
                    clip.StartTime        = (float)effect.artEffect.beginTime / 1000.0f;
                    track.AddClip(clip);
                }
            }
            if (hitEffect != null)
            {
                //一个特效 一条轨道
                foreach (SkillEffectUnit effect in hitEffect)
                {
                    //特效名称
                    JEffectTrack track = effectline.AddNewTrack();
                    track.name = SkillNames.EffectNames[(int)SkillNames.Effect.HitEffect];
                    JEffectClipData clip = ScriptableObject.CreateInstance <JEffectClipData>();
                    clip.effectType       = EffectType.Particle;
                    clip.effectunit       = effect.Copy();
                    clip.TargetObject     = effectline.AffectedObject.gameObject;
                    clip.PlaybackDuration = (float)effect.artEffect.phaseTime / 1000.0f;
                    clip.StartTime        = (float)effect.artEffect.beginTime / 1000.0f;
                    track.AddClip(clip);
                    //    track.AddClip(effectName, (float)effect.artEffect.beginTime / 1000.0f, (float)effect.artEffect.phaseTime / 1000.0f, effectPrefab, effect.configure);
                }
            }
            if (skillart.skillArt.beginCameraAction != null)
            {
                //一个特效 一条轨道
                foreach (SkillCameraAction effect in skillart.skillArt.beginCameraAction)
                {
                    JEffectTrack track = effectline.AddNewTrack();
                    track.name = SkillNames.EffectNames[(int)SkillNames.Effect.BeginCameraAction];
                    JEffectClipData clip = ScriptableObject.CreateInstance <JEffectClipData>();
                    clip.effectType       = EffectType.Camera;
                    clip.cameraAction     = effect.Copy();
                    clip.TargetCamera     = Camera.main;
                    clip.TargetObject     = effectline.AffectedObject.gameObject;
                    clip.PlaybackDuration = (float)effect.phaseTime;
                    clip.StartTime        = (float)effect.delay;
                    track.AddClip(clip);
                }
            }
            if (skillart.skillArt.moveCameraAction != null)
            {
                foreach (SkillCameraAction effect in skillart.skillArt.moveCameraAction)
                {
                    JEffectTrack track = effectline.AddNewTrack();
                    track.name = SkillNames.EffectNames[(int)SkillNames.Effect.MoveCameraAction];
                    JEffectClipData clip = ScriptableObject.CreateInstance <JEffectClipData>();
                    clip.effectType       = EffectType.Camera;
                    clip.cameraAction     = effect.Copy();
                    clip.TargetCamera     = Camera.main;
                    clip.TargetObject     = effectline.AffectedObject.gameObject;
                    clip.PlaybackDuration = (float)effect.phaseTime;
                    clip.StartTime        = (float)effect.delay;
                    track.AddClip(clip);
                }
            }
            if (skillart.skillArt.hitCameraAction != null)
            {
                foreach (SkillCameraAction effect in skillart.skillArt.hitCameraAction)
                {
                    JEffectTrack track = effectline.AddNewTrack();
                    track.name = SkillNames.EffectNames[(int)SkillNames.Effect.HitCameraAction];
                    JEffectClipData clip = ScriptableObject.CreateInstance <JEffectClipData>();
                    clip.effectType       = EffectType.Camera;
                    clip.cameraAction     = effect.Copy();
                    clip.TargetCamera     = Camera.main;
                    clip.TargetObject     = effectline.AffectedObject.gameObject;
                    clip.PlaybackDuration = (float)effect.phaseTime;
                    clip.StartTime        = (float)effect.delay;
                    track.AddClip(clip);
                }
            }
            return(sequence);
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            var serializedProperty = serializedObject.GetIterator();

            serializedProperty.Next(true);

            while (serializedProperty.NextVisible(true))
            {
                if (serializedProperty.name == "stateDuration")
                {
                    GUI.enabled = false;
                    EditorGUILayout.PropertyField(serializedProperty);
                    GUI.enabled = true;
                }
                else
                {
                    EditorGUILayout.PropertyField(serializedProperty);
                }
            }
            var stateNameProperty = serializedObject.FindProperty("stateName");
            var animationTrack    = serializedObject.FindProperty("track").objectReferenceValue as JAnimationTrack;
            var targetObject      = serializedObject.FindProperty("targetObject").objectReferenceValue;
            var targetGameObject  = targetObject as GameObject;

            if (!animationTrack)
            {
                return;
            }

            if (!targetGameObject)
            {
                return;
            }

            var availableStateNames = MecanimAnimationUtility.GetAllStateNames(targetGameObject, animationTrack.Layer);

            var existingState     = -1;
            var existingStateName = stateNameProperty.stringValue;

            for (int clipIndex = 0; clipIndex < availableStateNames.Count; clipIndex++)
            {
                if (availableStateNames[clipIndex] == existingStateName)
                {
                    existingState = clipIndex;
                }
            }

            var newState = EditorGUILayout.Popup("Clip", existingState, availableStateNames.ToArray());

            if (newState != existingState)
            {
                stateNameProperty.stringValue = availableStateNames[newState];
            }

            if (serializedObject.ApplyModifiedProperties())
            {
                JWindow[] windows = Resources.FindObjectsOfTypeAll <JWindow>();
                foreach (var window in windows)
                {
                    window.Repaint();
                }
            }
        }