private void AddNewParticleState(JTimelineParticle line, JParticleTrack track, float time, string stateName)
        {
            // var clipData = ScriptableObject.CreateInstance<JParticleClipData>();
            JParticleClipData clipData = new JParticleClipData();

            clipData.TargetObject     = line.AffectedObject.gameObject;
            clipData.StartTime        = time;
            clipData.ParticleName     = stateName;
            clipData.EffectDuration   = line.GetEffectDuration(stateName); // ParticleSystemUtility.GetParticleDuration(stateName, line.AffectedObject.gameObject);
            clipData.PlaybackDuration = clipData.EffectDuration;
            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);
            }
        }
 private void AddRenderDataForParticle(JTimelineBase timeline)
 {
     if (timeline is JTimelineParticle)
     {
         JTimelineParticle      particleline = (JTimelineParticle)timeline;
         List <JClipRenderData> list         = new List <JClipRenderData>();
         for (int i = 0; i < particleline.ParticleTracks.Count; i++)
         {
             JParticleTrack track = particleline.ParticleTracks[i];
             if (track)
             {
                 for (int j = 0; j < track.TrackClips.Count; j++)
                 {
                     JParticleClipData ClipData = track.TrackClips[j];
                     var cachedData             = ScriptableObject.CreateInstance <JClipRenderData>();
                     cachedData.ClipData = ClipData;
                     list.Add(cachedData);
                 }
                 if (!timelineClipRenderDataMap.ContainsKey(track))
                 {
                     timelineClipRenderDataMap.Add(track, list);
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
        public void RemoveClip(JParticleClipData clipData)
        {
            if (!trackClipList.Contains(clipData))
            {
                throw new Exception("Track doesn't contains Clip");
            }

            trackClipList.Remove(clipData);
        }
Ejemplo n.º 4
0
 public void AddClip(JParticleClipData clipData)
 {
     if (trackClipList.Contains(clipData))
     {
         throw new Exception("Track already contains Clip");
     }
     clipData.Track = this;
     trackClipList.Add(clipData);
 }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            var serializedProperty = serializedObject.GetIterator();

            serializedProperty.Next(true);

            while (serializedProperty.NextVisible(true))
            {
                if (serializedProperty.name == "effectDuration")
                {
                    GUI.enabled = false;
                    EditorGUILayout.PropertyField(serializedProperty);
                    GUI.enabled = true;
                }
                else
                {
                    EditorGUILayout.PropertyField(serializedProperty);
                }
            }
            //if (serializedProperty.name == "effectConfig")
            {
                JParticleClipData             ss     = (JParticleClipData)target;
                CySkillEditor.EffectConfigure effect = ss.EffectConfig;
                EditorDrawUtility.DrawEffectConfigure(effect);
            }
            var particleTrack    = serializedObject.FindProperty("track").objectReferenceValue as JParticleTrack;
            var targetObject     = serializedObject.FindProperty("targetObject").objectReferenceValue;
            var targetGameObject = targetObject as GameObject;

            if (!particleTrack)
            {
                return;
            }

            if (!targetGameObject)
            {
                return;
            }


            if (serializedObject.ApplyModifiedProperties())
            {
                JWindow[] windows = Resources.FindObjectsOfTypeAll <JWindow>();
                foreach (var window in windows)
                {
                    window.Repaint();
                }
            }
        }
        private void RemoveParticleClip(JClipRenderData clip)
        {
            var clipdata = clip.ClipData;

            if (clipdata is JParticleClipData)
            {
                JParticleClipData anidata = (JParticleClipData)clipdata;
                if (timelineClipRenderDataMap.ContainsKey(anidata.Track))
                {
                    if (timelineClipRenderDataMap[anidata.Track].Contains(clip))
                    {
                        timelineClipRenderDataMap[anidata.Track].Remove(clip);
                    }
                }
                anidata.Track.RemoveClip(anidata);
            }
        }
 private void ProcessDraggingParticleClip(JClipRenderData clip, Vector2 mouseDelta)
 {
     if (SourcePositions.ContainsKey(clip))
     {
         UnityEngine.Object selected = clip.ClipData;
         if (selected is JParticleClipData)
         {
             JParticleClipData particleClipData   = selected as JParticleClipData;
             float             mousePosOnTimeline = ContentXToTime(mouseDelta.x + FloatingWidth);
             float             newTime            = SourcePositions[clip] + mousePosOnTimeline;
             newTime = Mathf.Clamp(newTime, 0.0f, CurrentSequence.Duration - particleClipData.PlaybackDuration);
             particleClipData.StartTime = newTime;
             if (SelectedObjects.Count == 1)
             {
                 Selection.activeObject = particleClipData;
             }
         }
     }
 }
        private void ParticleGUI(JTimelineParticle Particleline, JParticleTrack linetrack, JClipRenderData[] renderDataList)
        {
            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];
                JParticleClipData particleClipData = (JParticleClipData)renderdata.ClipData;
                JParticleTrack    track            = particleClipData.Track;
                if (linetrack != track)
                {
                    continue;
                }
                var startX      = ConvertTimeToXPos(particleClipData.StartTime);
                var endX        = ConvertTimeToXPos(particleClipData.StartTime + particleClipData.PlaybackDuration);
                var transitionX = ConvertTimeToXPos(particleClipData.StartTime + particleClipData.TransitionDuration);
                var handleWidth = 2.0f;

                float posy   = DisplayArea.y;
                float height = DisplayArea.height;

                Rect renderRect     = new Rect(startX, posy, endX - startX, height);
                Rect transitionRect = new Rect(startX, posy, transitionX - startX, height);
                Rect leftHandle     = new Rect(startX, posy, handleWidth * 2.0f, height);
                Rect rightHandle    = new Rect(endX - (handleWidth * 2.0f), posy, handleWidth * 2.0f, 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(163 / 255.0f, 237 / 255.0f, 116 / 255.0f, 1);
                if (SelectedObjects.Contains(renderdata))
                {
                    GUI.color = ColorTools.SelectColor;
                }
                GUI.Box(renderRecttemp, "", USEditorUtility.NormalWhiteOutLineBG);

                if (particleClipData.CrossFade)
                {
                    GUI.Box(transitionRecttemp, "");
                }

                GUI.Box(leftHandletemp, "");
                GUI.Box(rightHandletemp, "");

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

                renderdata.renderRect     = renderRect;
                renderdata.labelRect      = renderRect;
                renderdata.renderPosition = new Vector2(startX, height);
                renderdata.transitionRect = transitionRect;
                renderdata.leftHandle     = leftHandle;
                renderdata.rightHandle    = rightHandle;
                renderdata.ClipData       = particleClipData;

                if (particleClipData.CrossFade)
                {
                    labelRect.x = labelRect.x + (transitionX - startX);
                }
                else
                {
                    labelRect.x += 4.0f; // Nudge this along a bit so it isn't flush with the side.
                }
                GUI.color = Color.black;
                GUI.Label(labelRect, particleClipData.FriendlyName);

                GUI.color = Color.white;

                if (isContext && renderRecttemp.Contains(UnityEngine.Event.current.mousePosition))
                {
                    hasBox = true;
                    contextMenu.AddItem(new GUIContent("DeleteClip"),
                                        false, (obj) => RemoveParticleClip(((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 = Particleline.gameObject;
                EditorGUIUtility.PingObject(Particleline.gameObject);
            }
            if (!hasBox && isContext && DisplayAreaTemp.Contains(UnityEngine.Event.current.mousePosition))
            {
                contextMenu = MenuForParticleTimeLine(Particleline, linetrack);
            }
            if (!hasBox && isContext && DisplayAreaTemp.Contains(UnityEngine.Event.current.mousePosition))
            {
                UnityEngine.Event.current.Use();
                contextMenu.ShowAsContext();
            }
        }
Ejemplo n.º 9
0
        public override void Process(float sequenceTime, float playbackRate)
        {
            allClips.Clear();
            for (int index = 0; index < ParticleTracks.Count; index++)
            {
                var track = ParticleTracks[index];
                if (track != null && 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      = JSequencer.SequenceUpdateRate;
            var runningTotalTime = previousTime + runningTime;

            if (timelinePlayingInReverse)
            {
                ResetParticle();
                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 (!JParticleClipData.IsClipRunning(runningTotalTime, clip) && !clip.Looping)
                        {
                            if (clip.active)
                            {
                                clip.Reset();
                            }
                            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];
                        clip.Init();
                        clip.OnUpdate(runningTime);

                        /* if (ParticleDict.ContainsKey(clip.ParticleName))
                         * {
                         *   List<string> p = ParticleDict[clip.ParticleName];
                         *   foreach (var pp in RootParticleList)
                         *   {
                         *       foreach (var ppp in p)
                         *       {
                         *           if (pp.name == ppp)
                         *           {
                         *               //float playtime = Mathf.Clamp(clip.EffectDuration * (runningTotalTime - clip.StartTime) / clip.PlaybackDuration, 0, clip.EffectDuration);
                         *               //float speed = clip.EffectDuration / clip.PlaybackDuration;
                         *               pp.Simulate(runningTime, true, false);
                         *
                         *               if (JParticleClipData.IsClipFinished(runningTotalTime+runningTime, clip))
                         *               {
                         *                   pp.Stop(true);
                         *                   pp.Simulate(0, true, true);
                         *                   pp.Clear(true);
                         *               }
                         *           }
                         *       }
                         *   }
                         * }*/
                    }
                    absDeltaTime -= JSequencer.SequenceUpdateRate;
                    if (!Mathf.Approximately(absDeltaTime, Mathf.Epsilon) && absDeltaTime < JSequencer.SequenceUpdateRate)
                    {
                        runningTime = absDeltaTime;
                    }
                    runningTotalTime += runningTime;
                }
            }
            previousTime = sequenceTime;
        }
Ejemplo n.º 10
0
 public static bool IsClipFinished(float sequencerTime, JParticleClipData clipData)
 {
     return(sequencerTime >= clipData.EndTime);
 }
Ejemplo n.º 11
0
 public static bool IsClipRunning(float sequencerTime, JParticleClipData clipData)
 {
     return(sequencerTime > clipData.StartTime && sequencerTime < clipData.EndTime);
 }