Esempio n. 1
0
        private JSingleLineTrajectory[] SingleLineFacyory(JTrajectoryClipData clip)
        {
            if (clip.skillunit.launchType != JSkillUnit.LaunchType.SINGLELINE)
            {
                return(null);
            }
            List <JSingleLineTrajectory> list = new List <JSingleLineTrajectory>();
            SkillLine line = (SkillLine)clip.skillunit.skillObj;

            if (line.waves == 0)
            {
                line.waves = 1;
            }
            for (int i = 0; i < line.waves; i++)
            {
                JSingleLineTrajectory sg = new JSingleLineTrajectory();
                sg.TargetObject = clip.TargetObject;
                sg.skillunit    = clip.skillunit;
                sg.effectunit   = clip.effectunit;
                sg._originDir   = clip.TargetObject.transform.forward;
                sg._delayBegin  = i * line.waveDelay;
                list.Add(sg);
            }
            if (clip.skillunit.guidePolicy != null)
            {
                clip.PlaybackDuration = (line.waveDelay * line.waves + line.moveTime + clip.skillunit.guidePolicy.guideTime + clip.skillunit.guidePolicy.guidingTime) / 1000f;
            }
            else
            {
                clip.PlaybackDuration = (line.waveDelay * line.waves + line.moveTime) / 1000f;
            }

            return(list.ToArray());
        }
        private void AddRenderDataForTrajectory(JTimelineBase timeline)
        {
            if (timeline is JTimelineTrajectory)
            {
                JTimelineTrajectory tline = (JTimelineTrajectory)timeline;
                for (int k = 0; k < tline.TrajectoryTracks.Count; k++)
                {
                    List <JClipRenderData> list  = new List <JClipRenderData>();
                    JTrajectoryTrack       track = tline.TrajectoryTracks[k];
                    for (int l = 0; l < track.TrackClips.Count; l++)
                    {
                        JTrajectoryClipData key = track.TrackClips[l];
                        var cachedData          = ScriptableObject.CreateInstance <JClipRenderData>();
                        cachedData.ClipData = key;
                        list.Add(cachedData);
                    }

                    if (!timelineClipRenderDataMap.ContainsKey(track))
                    {
                        timelineClipRenderDataMap.Add(track, list);
                    }
                    else
                    {
                        timelineClipRenderDataMap[track] = list;
                    }
                }
            }
        }
Esempio n. 3
0
        public override void OnInspectorGUI()
        {
            JTrajectoryClipData clip = (JTrajectoryClipData)target;
            var serializedProperty   = serializedObject.FindProperty("Target");

            EditorGUILayout.PropertyField(serializedProperty);

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

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

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

            EditorGUILayout.PropertyField(serializedlooping);

            EditorDrawUtility.DrawSkillEffectUnit(clip.effectunit);
            EditorDrawUtility.DrawSkillUnit(clip.skillunit);

            if (serializedObject.ApplyModifiedProperties())
            {
                JWindow[] windows = Resources.FindObjectsOfTypeAll <JWindow>();
                foreach (var window in windows)
                {
                    window.Repaint();
                }
            }
        }
        public void RemoveClip(JTrajectoryClipData clipData)
        {
            if (!trackClipList.Contains(clipData))
            {
                throw new Exception("Track doesn't contains Clip");
            }

            trackClipList.Remove(clipData);
        }
 public void AddClip(JTrajectoryClipData clipData)
 {
     if (trackClipList.Contains(clipData))
     {
         throw new Exception("Track already contains Clip");
     }
     clipData.Track = this;
     trackClipList.Add(clipData);
 }
 private void RemoveTrajectoryClip(JClipRenderData clip)
 {
     if (clip.ClipData is JTrajectoryClipData)
     {
         JTrajectoryClipData anidata = (JTrajectoryClipData)clip.ClipData;
         if (timelineClipRenderDataMap.ContainsKey(anidata.Track))
         {
             if (timelineClipRenderDataMap[anidata.Track].Contains(clip))
             {
                 timelineClipRenderDataMap[anidata.Track].Remove(clip);
             }
         }
         anidata.Track.RemoveClip(anidata);
     }
 }
        //拖动
        private void ProcessDraggingTrajectoryClip(JClipRenderData clip, Vector2 mouseDelta)
        {
            if (SourcePositions.ContainsKey(clip))
            {
                ScriptableObject selected = (ScriptableObject)clip.ClipData;
                if (selected is JTrajectoryClipData)
                {
                    JTrajectoryClipData animationClipData = selected as JTrajectoryClipData;

                    //float newTime = ((newPosition.x / DisplayArea.width) * AnimationTimeline.Sequence.Duration) / XScale;
                    // newTime = Mathf.Clamp(newTime, 0.0f, AnimationTimeline.Sequence.Duration);

                    float mousePosOnTimeline = ContentXToTime(FloatingWidth + mouseDelta.x);
                    float newTime            = SourcePositions[clip] + mousePosOnTimeline;
                    newTime = Mathf.Clamp(newTime, 0.0f, CurrentSequence.Duration - animationClipData.PlaybackDuration);
                    animationClipData.StartTime = newTime;
                    animationClipData.effectunit.artEffect.beginTime = (int)(newTime * 1000f);
                    if (SelectedObjects.Count == 1)
                    {
                        Selection.activeObject = animationClipData;
                    }
                }
            }
        }
Esempio n. 8
0
        public override void Process(float sequenceTime, float playbackRate)
        {
            allClips.Clear();

            for (int index = 0; index < TrajectoryTracks.Count; index++)
            {
                var track = TrajectoryTracks[index];
                if (track.Enable)
                {
                    for (int trackClipIndex = 0; trackClipIndex < track.TrackClips.Count; trackClipIndex++)
                    {
                        var trackClip = track.TrackClips[trackClipIndex];
                        allClips.Add(trackClip);
                    }
                }
            }

            var totalDeltaTime           = sequenceTime - previousTime;
            var absDeltaTime             = Mathf.Abs(totalDeltaTime);
            var timelinePlayingInReverse = totalDeltaTime < 0.0f;
            var runningTime      = SequenceUpdateRate;
            var runningTotalTime = previousTime + runningTime;

            if (timelinePlayingInReverse)
            {
                previousTime = 0.0f;
                Process(sequenceTime, playbackRate);
            }
            else
            {
                while (absDeltaTime > 0.0f)
                {
                    cachedRunningClips.Clear();
                    for (int allClipIndex = 0; allClipIndex < allClips.Count; allClipIndex++)
                    {
                        var clip = allClips[allClipIndex];
                        if (JTrajectoryClipData.IsClipFinished(runningTotalTime, clip))
                        {
                            for (int i = 0; i < clip.TrajectoryList.Length; i++)
                            {
                                if (clip.TrajectoryList[i]._active)
                                {
                                    clip.TrajectoryList[i].Reset();
                                }
                            }
                            //   if (clip.Trajectory._active)
                            //   {
                            //       clip.Trajectory.Reset();
                            //    }
                        }
                        if (!JTrajectoryClipData.IsClipRunning(runningTotalTime, clip) && !clip.Looping)
                        {
                            continue;
                        }

                        cachedRunningClips.Add(clip);
                    }

                    cachedRunningClips.Sort((x, y) => x.StartTime.CompareTo(y.StartTime));

                    for (int runningClipIndex = 0; runningClipIndex < cachedRunningClips.Count; runningClipIndex++)
                    {
                        var clip = cachedRunningClips[runningClipIndex];
                        if (Restart)
                        {
                            if (clip.skillunit.launchType == JSkillUnit.LaunchType.SINGLELINE)
                            {
                                clip.TrajectoryList = SingleLineFacyory(clip);
                            }
                            if (clip.skillunit.launchType == JSkillUnit.LaunchType.MULLINE)
                            {
                                clip.TrajectoryList = MultiLineFacyory(clip);
                            }
                            Restart = false;
                        }
                        if (clip.TrajectoryList != null)
                        {
                            for (int i = 0; i < clip.TrajectoryList.Length; i++)
                            {
                                if (!clip.TrajectoryList[i]._active)
                                {
                                    clip.TrajectoryList[i].Begin();
                                }
                                clip.TrajectoryList[i].DoUpdate(Time.realtimeSinceStartup);
                            }
                        }
                    }

                    absDeltaTime -= SequenceUpdateRate;
                    if (!Mathf.Approximately(absDeltaTime, Mathf.Epsilon) && absDeltaTime < SequenceUpdateRate)
                    {
                        runningTime = absDeltaTime;
                    }

                    runningTotalTime += runningTime;
                }
            }

            previousTime = sequenceTime;
        }
Esempio n. 9
0
        private JSingleLineTrajectory[] MultiLineFacyory(JTrajectoryClipData clip)
        {
            if (clip.skillunit.launchType != JSkillUnit.LaunchType.MULLINE)
            {
                return(null);
            }
            List <JSingleLineTrajectory> list = new List <JSingleLineTrajectory>();
            SkillMultiLine line = (SkillMultiLine)clip.skillunit.skillObj;

            if (line.shape.area == SkillShape.Area.CIRCLE)
            {
                float   angle = 360f / line.unitCount;
                Vector3 dir   = clip.TargetObject.transform.forward;
                for (int i = 0; i < line.unitCount; i++)
                {
                    Vector3 ndir = RotateRound(dir, new Vector3(0, 1, 0), i * angle);
                    if (line.waves == 0)
                    {
                        line.waves = 1;
                    }
                    for (int j = 0; j < line.waves; j++)
                    {
                        JSingleLineTrajectory sg = new JSingleLineTrajectory();
                        sg.TargetObject = clip.TargetObject;
                        sg._originDir   = ndir;
                        sg.skillunit    = clip.skillunit;
                        sg.effectunit   = clip.effectunit;
                        sg._delayBegin  = j * line.waveDelay;
                        list.Add(sg);
                    }
                }
            }
            if (line.shape.area == SkillShape.Area.QUADRATE)
            {
                Vector3 dir  = clip.TargetObject.transform.forward;
                Vector3 ndir = RotateRound(dir, new Vector3(0, 1, 0), 90);
                if (line.unitCount > 1)
                {
                    ndir = ndir * line.shape.param2 / (line.unitCount - 1);
                }
                Vector3 beginPos = -ndir * (line.unitCount - 1) / 2f;
                for (int i = 0; i < line.unitCount; i++)
                {
                    if (line.waves == 0)
                    {
                        line.waves = 1;
                    }
                    for (int j = 0; j < line.waves; j++)
                    {
                        JSingleLineTrajectory sg = new JSingleLineTrajectory();
                        sg.TargetObject     = clip.TargetObject;
                        sg._originDir       = dir;
                        sg._originPosOffset = beginPos + ndir * i;
                        sg.skillunit        = clip.skillunit;
                        sg.effectunit       = clip.effectunit;
                        sg._delayBegin      = j * line.waveDelay;
                        list.Add(sg);
                    }
                }
            }
            if (line.shape.area == SkillShape.Area.SECTOR)
            {
                float   angle      = line.shape.param3 / (line.unitCount - 1);
                float   beginAngle = -angle * (line.unitCount - 1) / 2;
                Vector3 dir        = clip.TargetObject.transform.forward;
                for (int i = 0; i < line.unitCount; i++)
                {
                    Vector3 ndir = RotateRound(dir, new Vector3(0, 1, 0), beginAngle + i * angle);
                    if (line.waves == 0)
                    {
                        line.waves = 1;
                    }
                    for (int j = 0; j < line.waves; j++)
                    {
                        JSingleLineTrajectory sg = new JSingleLineTrajectory();
                        sg.TargetObject     = clip.TargetObject;
                        sg._originDir       = ndir;
                        sg._originPosOffset = ndir * line.shape.param1;
                        sg.skillunit        = clip.skillunit;
                        sg.effectunit       = clip.effectunit;
                        sg._delayBegin      = j * line.waveDelay;
                        list.Add(sg);
                    }
                }
            }
            if (line.shape.area == SkillShape.Area.TRIANGLE)
            {
                Vector3 dir  = clip.TargetObject.transform.forward;
                Vector3 ndir = RotateRound(dir, new Vector3(0, 1, 0), 90);
                if (line.unitCount > 1)
                {
                    ndir = ndir * line.shape.param2 / (line.unitCount - 1) / 2;
                }
                Vector3 beginPos = Vector3.zero;
                if (line.shape.param3 == 1)
                {
                    beginPos = -ndir * (line.unitCount - 1) / 2f;
                }
                if (line.shape.param3 == 2)
                {
                    beginPos = dir * line.shape.param1 - ndir * (line.unitCount - 1) / 2f;
                }
                Vector3 launchPos = Vector3.zero;
                Vector3 pdir      = Vector3.zero;
                for (int i = 0; i < line.unitCount; i++)
                {
                    if (line.shape.param3 == 1)
                    {
                        launchPos = beginPos + i * ndir;
                        Vector3 tempPos = dir * line.shape.param1;
                        pdir = (tempPos - launchPos).normalized;
                    }
                    else
                    if (line.shape.param3 == 2)
                    {
                        Vector3 tempPos = beginPos + i * ndir;
                        pdir = (tempPos - launchPos).normalized;
                    }

                    if (line.waves == 0)
                    {
                        line.waves = 1;
                    }
                    for (int j = 0; j < line.waves; j++)
                    {
                        JSingleLineTrajectory sg = new JSingleLineTrajectory();
                        sg._originPosOffset = launchPos;
                        sg._originDir       = pdir;
                        sg.TargetObject     = clip.TargetObject;
                        sg.skillunit        = clip.skillunit;
                        sg.effectunit       = clip.effectunit;
                        sg._delayBegin      = j * line.waveDelay;
                        list.Add(sg);
                    }
                }
            }
            if (clip.skillunit.guidePolicy != null)
            {
                clip.PlaybackDuration = (line.waveDelay * line.waves + line.moveTime + clip.skillunit.guidePolicy.guideTime + clip.skillunit.guidePolicy.guidingTime) / 1000f;
            }
            else
            {
                clip.PlaybackDuration = (line.waveDelay * line.waves + line.moveTime) / 1000f;
            }

            return(list.ToArray());
        }
        private void TrajectoryGUI(JTimelineBase timeline, JTrajectoryTrack track, JClipRenderData[] renderDataList)
        {
            if (timeline is JTimelineTrajectory)
            {
                JTimelineTrajectory trajectoryline = (JTimelineTrajectory)timeline;

                GenericMenu contextMenu = new GenericMenu();
                ///event 右键点击
                bool isContext       = UnityEngine.Event.current.type == EventType.MouseDown && UnityEngine.Event.current.button == 1;
                bool isChoose        = UnityEngine.Event.current.type == EventType.MouseDown && UnityEngine.Event.current.button == 0 && UnityEngine.Event.current.clickCount == 1;
                bool hasBox          = false;
                Rect DisplayAreaTemp = DisplayArea;
                DisplayAreaTemp.x = 0;
                DisplayAreaTemp.y = 0;
                for (int j = 0; j < renderDataList.Length; j++)
                {
                    JClipRenderData     renderdata         = renderDataList[j];
                    JTrajectoryClipData trajectoryClipData = (JTrajectoryClipData)renderdata.ClipData;
                    JTrajectoryTrack    linetrack          = trajectoryClipData.Track;
                    if (linetrack != track)
                    {
                        continue;
                    }
                    var startX      = ConvertTimeToXPos(trajectoryClipData.StartTime);
                    var endX        = ConvertTimeToXPos(trajectoryClipData.StartTime + trajectoryClipData.PlaybackDuration);
                    var transitionX = ConvertTimeToXPos(trajectoryClipData.StartTime + trajectoryClipData.PlaybackDuration);
                    var handleWidth = 2.0f;

                    Rect renderRect     = new Rect(startX, DisplayArea.y, endX - startX, DisplayArea.height);
                    Rect transitionRect = new Rect(startX, DisplayArea.y, transitionX - startX, DisplayArea.height);
                    Rect leftHandle     = new Rect(startX, DisplayArea.y, handleWidth * 2.0f, DisplayArea.height);
                    Rect rightHandle    = new Rect(endX - (handleWidth * 2.0f), DisplayArea.y, handleWidth * 2.0f, DisplayArea.height);
                    Rect labelRect      = new Rect();

                    Rect renderRecttemp = renderRect;
                    renderRecttemp.x -= DisplayArea.x;
                    renderRecttemp.y  = 0;
                    Rect transitionRecttemp = transitionRect;
                    transitionRecttemp.y  = 0;
                    transitionRecttemp.x -= DisplayArea.x;
                    Rect leftHandletemp = leftHandle;
                    leftHandletemp.y  = 0;
                    leftHandletemp.x -= DisplayArea.x;
                    Rect rightHandletemp = rightHandle;
                    rightHandletemp.x -= DisplayArea.x;
                    rightHandletemp.y  = 0;

                    GUI.color = new Color(156 / 255.0f, 11 / 255.0f, 11 / 255.0f, 1);
                    if (SelectedObjects.Contains(renderdata))
                    {
                        GUI.color = ColorTools.SelectColor;
                    }

                    GUI.Box(renderRecttemp, "", USEditorUtility.NormalWhiteOutLineBG);
                    GUI.Box(leftHandletemp, "");
                    GUI.Box(rightHandletemp, "");

                    labelRect       = renderRecttemp;
                    labelRect.width = DisplayArea.width;

                    renderdata.renderRect     = renderRect;
                    renderdata.labelRect      = renderRect;
                    renderdata.renderPosition = new Vector2(startX, DisplayArea.y);
                    renderdata.transitionRect = transitionRect;
                    renderdata.leftHandle     = leftHandle;
                    renderdata.rightHandle    = rightHandle;
                    renderdata.ClipData       = trajectoryClipData;


                    labelRect.x += 4.0f;  // Nudge this along a bit so it isn't flush with the side.

                    GUI.color = Color.black;
                    GUI.Label(labelRect, trajectoryClipData.FriendlyName);

                    GUI.color = Color.white;

                    if (isContext && renderRecttemp.Contains(UnityEngine.Event.current.mousePosition))
                    {
                        hasBox = true;
                        contextMenu.AddItem(new GUIContent("DeleteClip"),
                                            false, (obj) => RemoveTrajectoryClip(((JClipRenderData)((object[])obj)[0])),
                                            new object[] { renderdata });
                    }
                    if (isContext && renderRecttemp.Contains(UnityEngine.Event.current.mousePosition))
                    {
                        UnityEngine.Event.current.Use();
                        contextMenu.ShowAsContext();
                    }
                }

                if (!hasBox && isChoose && DisplayAreaTemp.Contains(UnityEngine.Event.current.mousePosition) && (UnityEngine.Event.current.control || UnityEngine.Event.current.command))
                {
                    //代码选中hierarchy中的对象 显示inspector 按住Ctrl or command
                    //GameObject go = GameObject.Find(Animationline.gameObject.name);
                    Selection.activeGameObject = trajectoryline.gameObject;
                    EditorGUIUtility.PingObject(trajectoryline.gameObject);
                }
                if (!hasBox && isContext && DisplayAreaTemp.Contains(UnityEngine.Event.current.mousePosition))
                {
                    contextMenu = MenuForTrajectoryTimeLine(trajectoryline, track);
                }
                if (!hasBox && isContext && DisplayAreaTemp.Contains(UnityEngine.Event.current.mousePosition))
                {
                    UnityEngine.Event.current.Use();
                    contextMenu.ShowAsContext();
                }
            }
        }
 public static bool IsClipFinished(float sequencerTime, JTrajectoryClipData clipData)
 {
     return(sequencerTime >= clipData.EndTime);
 }
 public static bool IsClipRunning(float sequencerTime, JTrajectoryClipData clipData)
 {
     return(sequencerTime > clipData.StartTime && sequencerTime < clipData.EndTime);
 }