예제 #1
0
 public void SourceListToTimeLabels(List <TimeLabelData> sourcesList)
 {
     _labels.Clear();
     _rectWasChanged = true;
     foreach (TimeLabelData data in sourcesList)
     {
         TimeLabel newTimeLabel = new TimeLabel(this, data);
         newTimeLabel.TimeEnter += ((TimedData timeLabelData) =>
         {
             if (LabelTimeEnter != null)
             {
                 LabelTimeEnter.Invoke(timeLabelData as TimeLabelData);
             }
         });
         newTimeLabel.TimeExit += ((timeLabelData) =>
         {
             if (LabelTimeExit != null)
             {
                 LabelTimeExit.Invoke(timeLabelData as TimeLabelData);
             }
         });
         _labels.Add(newTimeLabel);
     }
 }
예제 #2
0
        private void HandleLabelAdd(object obj)
        {
            TimeSpan coursorTime = _timeLineEngine.Time;
            TimeSpan duration    = new TimeSpan(0, 0, 10);

            if (obj != null && obj is TimeLabelData)
            {
                duration = (obj as TimeLabelData).Duration;
            }
            foreach (TimeLabel timeLabel in _labels)
            {
                if (coursorTime >= timeLabel.SourceData.Start && coursorTime < timeLabel.SourceData.End)
                {
                    EditorUtility.DisplayDialog("Error!", "You cannot add time label on the occupied time.", "Ok");
                    return;
                }
                if (coursorTime < timeLabel.SourceData.Start && coursorTime + duration > timeLabel.SourceData.Start)
                {
                    TimeSpan gap = timeLabel.SourceData.Start - coursorTime;
                    if (gap < duration)
                    {
                        duration = gap;
                    }
                }
            }
            if (coursorTime + duration > _timeLineEngine.Duration)
            {
                duration = _timeLineEngine.Duration - coursorTime;
            }
            TimeLabelData data;

            if (obj != null && obj is TimeLabelData)
            {
                data = new TimeLabelData(obj as TimeLabelData);
            }
            else
            {
                data = new TimeLabelData()
                {
                    Name  = "Time label",
                    Color = Color.cyan
                };
            }
            data.Start = coursorTime;
            data.End   = coursorTime + duration;
            TimeLabel newTimeLabel = new TimeLabel(this, data);

            newTimeLabel.TimeEnter += ((TimedData timeLabelData) =>
            {
                if (LabelTimeEnter != null)
                {
                    LabelTimeEnter.Invoke(timeLabelData as TimeLabelData);
                }
            });
            newTimeLabel.TimeExit += ((TimedData timeLabelData) =>
            {
                if (LabelTimeExit != null)
                {
                    LabelTimeExit.Invoke(timeLabelData as TimeLabelData);
                }
            });
            _labels.Add(newTimeLabel);
            if (LabelCreate != null)
            {
                LabelCreate.Invoke(data);
            }
        }