Example #1
0
 private void Awake()
 {
     m_rt = (RectTransform)transform;
     if (m_pointer == null)
     {
         m_pointer = GetComponentInParent <TimelinePointer>();
     }
 }
        protected override void Awake()
        {
            base.Awake();
            if (!Application.isPlaying)
            {
                return;
            }

            if (m_textPanel == null)
            {
                m_textPanel = GetComponentInChildren <TimelineTextPanel>(true);
            }

            if (m_pointer == null)
            {
                m_pointer = GetComponentInChildren <TimelinePointer>(true);
            }

            m_scrollRect = GetComponentInChildren <ScrollRect>(true);
            m_scrollRect.scrollSensitivity = 0;
            m_scrollRect.onValueChanged.AddListener(OnInitScrollRectValueChanged);

            m_hScrollbarListener          = m_scrollRect.horizontalScrollbar.GetComponentInChildren <DragAndDropListener>(true);
            m_vScrollbarListener          = m_scrollRect.verticalScrollbar.GetComponentInChildren <DragAndDropListener>(true);
            m_hScrollbarListener.Drop    += OnHorizontalScrollbarDrop;
            m_hScrollbarListener.EndDrag += OnHorizontalScrollbarDrop;
            m_vScrollbarListener.Drop    += OnVerticalScrolbarDrop;
            m_vScrollbarListener.EndDrag += OnVerticalScrolbarDrop;

            if (FixedHeight > -1)
            {
                ScrollbarResizer[] resizers = m_scrollRect.verticalScrollbar.GetComponentsInChildren <ScrollbarResizer>(true);
                for (int i = 0; i < resizers.Length; ++i)
                {
                    resizers[i].gameObject.SetActive(false);
                }
            }

            m_rtListener = m_scrollRect.gameObject.AddComponent <RectTransformChangeListener>();
            m_rtListener.RectTransformChanged += OnRectTransformChanged;

            if (m_output == null)
            {
                m_output = m_scrollRect.content.GetComponentInChildren <RawImage>(true);
            }

            GameObject cameraGo = RenderCameraPrefab != null?Instantiate(RenderCameraPrefab) : new GameObject();

            cameraGo.name = "TimelineGraphicsCamera";
            cameraGo.SetActive(false);

#if USE_RTE
            IRTE editor = IOC.Resolve <IRTE>();
            cameraGo.transform.SetParent(editor.Root, false);
#endif
            m_camera = cameraGo.GetComponent <Camera>();
            if (m_camera == null)
            {
                m_camera = cameraGo.AddComponent <Camera>();
            }
            m_camera.enabled          = false;
            m_camera.orthographic     = true;
            m_camera.orthographicSize = 0.5f;
            m_camera.clearFlags       = CameraClearFlags.SolidColor;
            m_camera.backgroundColor  = m_backgroundColor;
            m_camera.cullingMask      = 0;

            m_rtCamera            = cameraGo.AddComponent <RenderTextureCamera>();
            m_rtCamera.Fullscreen = false;
            m_rtCamera.Output     = m_output;

            cameraGo.SetActive(true);
            m_rtCamera.enabled = false;

            if (m_timelineGridParams == null)
            {
                CreateDefaultTimelineGridParams();
                m_timelineGridParams.HorLines          = 1;
                m_timelineGridParams.HorLinesSecondary = 2;
            }

            m_timelineGrid = m_output.GetComponent <TimelineGrid>();
            if (m_timelineGrid == null)
            {
                m_timelineGrid = m_output.gameObject.AddComponent <TimelineGrid>();
            }
            m_timelineGrid.Init(m_camera);


            m_dopesheet = m_output.gameObject.GetComponent <Dopesheet>();
            if (m_dopesheet == null)
            {
                m_dopesheet = m_output.gameObject.AddComponent <Dopesheet>();
            }
            m_dopesheet.Init(m_camera);
            SetTimelineGridParameters();

            Clip = new Dopesheet.DsAnimationClip();

            m_pointer.SampleChanged += OnTimelineSampleChanged;
            m_pointer.PointerDown   += OnTimlineClick;
            m_pointer.BeginDrag     += OnTimelineBeginDrag;
            m_pointer.Drag          += OnTimelineDrag;
            m_pointer.Drop          += OnTimelineDrop;

            if (m_boxSelection == null)
            {
                m_boxSelection = GetComponentInChildren <TimelineBoxSelection>();
            }

            if (m_boxSelection != null)
            {
                m_boxSelection.BeginSelection += OnBeginBoxSelection;
                m_boxSelection.Selection      += OnBoxSelection;
            }

            RenderGraphics();
        }