Exemple #1
0
        private void deleteHandle(EventX e)
        {
            bool b = EditorUtility.DisplayDialog("提示", "确定要删除", "是", "否");

            if (b)
            {
                EditorButton eui       = e.target as EditorButton;
                SkillEvent   skilEvent = eui.data as SkillEvent;

                if (vo != null)
                {
                    vo.removeEvent(skilEvent);
                }

                Undo.RecordObject(this.window, "delete SkillEvent");
                updateView();
            }
        }
Exemple #2
0
        public override void onRender()
        {
            if (_dataProvider == null)
            {
                return;
            }
            int timeLineCount = _dataProvider.Count;

            if (timeLineCount < 1)
            {
                return;
            }

            if (bgTex == null)
            {
                load(null);
            }

            float w = 0;

            if (propertyWindow.numChildren > 0)
            {
                w = 300;
            }

            Rect rect = GUILayoutUtility.GetRect(0, this.stage.stageWidth - w, 0, this.stage.stageHeight - 60);

            GUI.BeginGroup(rect);

            viewRect = new Rect(0, 0, rect.width, rect.height);

            fullRect       = new Rect(0, 0, TACK_5FRAME_WIDTH * 70, timeLineCount * TACK_FRAME_HEIGHT + TACK_FRAME_TEXT_HEIGHT);
            scrollPosition = GUI.BeginScrollView(viewRect, scrollPosition, fullRect);

            int startIndex  = (int)(scrollPosition.x / TACK_5FRAME_WIDTH);
            int repeatCount = (int)((rect.width - linePadX) / TACK_5FRAME_WIDTH);
            int drawOffset  = 3;//1;
            int endIndex    = startIndex + repeatCount + drawOffset;

            float yPos = 0;

            for (int i = 0; i < timeLineCount; i++)
            {
                yPos = i * TACK_FRAME_HEIGHT + TACK_FRAME_TEXT_HEIGHT;
                for (int j = startIndex; j < endIndex; j++)
                {
                    Rect r = new Rect(linePadX + j * TACK_5FRAME_WIDTH, yPos, TACK_5FRAME_WIDTH, TACK_FRAME_HEIGHT - 2);
                    if (frameTex != null)
                    {
                        GUI.DrawTexture(r, frameTex, ScaleMode.ScaleAndCrop, false);
                    }
                }
                SkillLineVO         lineVo        = _dataProvider[i];
                List <SkillPointVO> skillPointVos = lineVo.points;
                ITrack track = getSackByLine(lineVo);
                int    plen  = Mathf.Min(skillPointVos.Count, endIndex * 5);
                for (int k = startIndex * 5; k < plen; k++)
                {
                    SkillPointVO skillPointVo = skillPointVos[k];
                    if (skillPointVo.isEmpty == false)
                    {
                        Rect r = new Rect(linePadX + k * TACK_FRAME_WIDTH + 3, yPos + 8, 10, 10);
                        if (whitePointTex != null)
                        {
                            track.drawPoint(skillPointVo, lineVo, r, whitePointTex);
                        }
                    }
                }
            }

            //时间轴范围;
            timeLineBound.x      = rect.x;
            timeLineBound.y      = rect.y + TACK_FRAME_TEXT_HEIGHT;
            timeLineBound.width  = rect.width;
            timeLineBound.height = rect.height - TACK_FRAME_TEXT_HEIGHT;

            GUI.DrawTexture(new Rect(linePadX, scrollPosition.y, fullRect.width, TACK_FRAME_TEXT_HEIGHT), bgTex);
            GUI.Label(new Rect(linePadX, scrollPosition.y, 10, TACK_FRAME_TEXT_HEIGHT), (startIndex + 1).ToString());
            for (int i = startIndex + 1; i < endIndex; i++)
            {
                string frameCountStr = (i * 5).ToString();
                Rect   r             = new Rect(linePadX + i * TACK_5FRAME_WIDTH - TACK_FRAME_WIDTH, scrollPosition.y + 2,
                                                frameCountStr.Length * 10,
                                                TACK_FRAME_TEXT_HEIGHT);
                GUI.Label(r, frameCountStr);
            }
            //绘制红色的当前帧位置
            Rect rrr = new Rect(linePadX + (cursorPos + 0.5f) * TACK_FRAME_WIDTH, scrollPosition.y, 1, timeLineBound.height);

            if (tickTex != null)
            {
                GUI.DrawTexture(rrr, tickTex);
            }

            for (int i = 0; i < timeLineCount; i++)
            {
                Rect        rr     = new Rect(scrollPosition.x, (i * TACK_FRAME_HEIGHT) + TACK_FRAME_TEXT_HEIGHT, linePadX, TACK_FRAME_HEIGHT - 2);
                SkillLineVO lineVo = _dataProvider[i];
                ITrack      track  = getSackByLine(lineVo);
                track.OnGUI(rr, lineVo, i);
            }

            GUI.EndScrollView();

            if (GUI.Button(new Rect(0, 0, 20, 20), "+", EditorStyles.miniButton))
            {
                GenericMenu menu = new GenericMenu();

                Type[] types = ReflectionTools.GetDerivedTypesOf(typeof(BaseTrack));
                foreach (Type type in types)
                {
                    string name = type.FullName;
                    menu.AddItem(new GUIContent(type.Name), false, (object userData) =>
                    {
                        addMenuEditorCallBack((string)userData);
                    }, name);
                }

                menu.ShowAsContext();
            }
            GUI.EndGroup();

            Event   currentEvent  = Event.current;
            Vector2 mousePosition = currentEvent.mousePosition;

            if (timeLineBound.Contains(mousePosition) == false)
            {
                return;
            }

            SkillPointVO vo;
            Vector2      v = Vector2.zero;

            switch (currentEvent.type)
            {
            case EventType.MouseDown:
                v  = getTimeLineFrame(mousePosition);
                vo = getSkillPointVoByPosition(v);
                willDraggerDownPosition = mousePosition;

                currentEvent.Use();
                simpleDispatch(EventX.SELECT, vo);
                break;

            case EventType.MouseUp:
                v  = getTimeLineFrame(mousePosition);
                vo = getSkillPointVoByPosition(v);

                if (willDraggerDownPosition != Vector2.zero && vo != null)
                {
                    Vector2 distance = mousePosition - willDraggerDownPosition;
                    if (distance.y * distance.y < TACK_FRAME_HEIGHT * TACK_FRAME_HEIGHT &&
                        distance.x * distance.x > TACK_FRAME_WIDTH * TACK_FRAME_WIDTH)
                    {
                        v = getTimeLineFrame(willDraggerDownPosition, false);
                        SkillPointVO moveVO = getSkillPointVoByPosition(v);

                        if (moveVO != null && moveVO.isEmpty == false && vo.isEmpty == true)
                        {
                            SkillEvent moveEvent = moveVO.evt;
                            moveVO.removeEvent(moveEvent);
                            vo.addEvent(moveEvent);
                            currentEvent.Use();
                        }
                    }
                }
                willDraggerDownPosition = Vector2.zero;

                break;

            case EventType.ContextClick:

                v  = getTimeLineFrame(mousePosition);
                vo = getSkillPointVoByPosition(v);

                currentEvent.Use();
                if (vo != null)
                {
                    SkillLineVO lineVo = getSkillLineVOByPosition(v);
                    GenericMenu menu   = new GenericMenu();

                    if (vo.isEmpty)
                    {
                        menu = propertyWindow.getGenericMenu(lineVo, vo, v);
                        menu.AddItem(new GUIContent("加点+"), false, () =>
                        {
                            genericMenuEditorCallBack(v, "AddPointer");
                        });

                        menu.AddItem(new GUIContent("减点-"), false, () =>
                        {
                            genericMenuEditorCallBack(v, "RemovePointer");
                        });

                        menu.AddItem(new GUIContent("粘贴"), false, () =>
                        {
                            genericMenuEditorCallBack(v, "Parse");
                        });
                    }
                    else
                    {
                        menu.AddItem(new GUIContent("复制"), false, () =>
                        {
                            genericMenuEditorCallBack(v, "Copy");
                        });
                    }

                    menu.ShowAsContext();
                }
                else if (v.y < _dataProvider.Count && v.x < 0)
                {
                    GenericMenu menu = GenericMenuEditor(v);
                    menu.ShowAsContext();
                }
                break;

            case EventType.MouseMove:
                getTimeLineFrame(currentEvent.mousePosition);
                break;

            case EventType.MouseDrag:
                getTimeLineFrame(currentEvent.mousePosition);
                this.window.Repaint();
                break;

            case EventType.KeyDown:

                v  = getTimeLineFrame(mousePosition);
                vo = getSkillPointVoByPosition(v);
                if (vo != null && vo.isEmpty)
                {
                    if (currentEvent.keyCode == KeyCode.Equals || currentEvent.keyCode == KeyCode.Plus)
                    {
                        currentEvent.Use();
                        genericMenuEditorCallBack(v, "AddPointer");
                        this.window.Repaint();
                    }
                    else if (currentEvent.keyCode == KeyCode.Minus)
                    {
                        currentEvent.Use();
                        genericMenuEditorCallBack(v, "RemovePointer");
                        this.window.Repaint();
                    }
                }
                break;
            }
        }