Beispiel #1
0
        private void refreashLineVO(SkillLineVO lineVo)
        {
            int i = 0;

            foreach (SkillPointVO pointVo in lineVo.points)
            {
                pointVo.startTime = i * frameTime;
                i++;
            }
        }
Beispiel #2
0
        private void addMenuEditorCallBack(string cmd)
        {
            if (_currentSkillTimeLineVo == null)
            {
                return;
            }
            SkillLineVO lineVo = new SkillLineVO();

            lineVo.typeFullName = cmd;
            _currentSkillTimeLineVo.addLine(lineVo);

            updateView(_currentSkillTimeLineVo);
        }
Beispiel #3
0
        public SkillLineVO getSkillLineVOByPosition(Vector2 v)
        {
            if (v.y >= _dataProvider.Count || v.x < 0)
            {
                return(null);
            }
            SkillLineVO skillLineVo = _dataProvider[(int)v.y];

            if (skillLineVo == null)
            {
                return(null);
            }
            return(skillLineVo);
        }
Beispiel #4
0
        private void newHandle(EventX obj)
        {
            _currentFilePath = null;
            SkillTimeLineVO skillTimeLineVo = new SkillTimeLineVO();

            SkillLineVO vo = new SkillLineVO();

            vo.typeFullName = typeof(AnimatorTrack).FullName;
            skillTimeLineVo.addLine(vo);

            updateView(skillTimeLineVo);

            setEditFileFullPath("新创文件");
        }
Beispiel #5
0
        public SkillPointVO getSkillPointVoByPosition(Vector2 v)
        {
            SkillLineVO skillLineVo = getSkillLineVOByPosition(v);

            if (skillLineVo == null)
            {
                return(null);
            }

            if (v.x >= skillLineVo.points.Count)
            {
                return(null);
            }
            return(skillLineVo.points[(int)v.x]);
        }
Beispiel #6
0
        public GenericMenu getGenericMenu(SkillLineVO lineVo, SkillPointVO pointVo, Vector2 v)
        {
            //List<Type> list = new List<Type>();
            GenericMenu menu     = new GenericMenu();
            Type        lineType = foundation.ObjectFactory.Locate(lineVo.typeFullName);

            Type[] types = ReflectionTools.GetDerivedTypesOf(typeof(IEventUI));

            refEventUIlist.Clear();
            foreach (Type type in types)
            {
                object[] stackAttributes = type.GetCustomAttributes(typeof(EventStackAttribute), false);
                if (stackAttributes == null || stackAttributes.Length == 0)
                {
                    continue;
                }
                EventStackAttribute eventStackAttribute = (EventStackAttribute)stackAttributes[0];
                if (eventStackAttribute.types.Contains(lineType))
                {
                    object[] eventUIAttributes = type.GetCustomAttributes(typeof(EventUIAttribute), false);
                    if (stackAttributes == null || stackAttributes.Length == 0)
                    {
                        continue;
                    }
                    RefEventUISort sortItem = new RefEventUISort(Activator.CreateInstance(type) as IEventUI, (EventUIAttribute)eventUIAttributes[0]);
                    refEventUIlist.Add(sortItem);
                }
            }
            refEventUIlist.Sort((a, b) =>
            {
                return(a.attribute.priority.CompareTo(b.attribute.priority));
            });

            foreach (RefEventUISort sortItem in refEventUIlist)
            {
                menu.AddItem(new GUIContent(sortItem.ui.label), false, (object userData) =>
                {
                    Type eType            = userData as Type;
                    SkillEvent skillEvent = Activator.CreateInstance(eType) as SkillEvent;
                    pointVo.addEvent(skillEvent);
                    show(pointVo);
                }, sortItem.attribute.type);
            }


            return(menu);
        }
Beispiel #7
0
        public SkillTimeLineVO getRuntimeSkillVO(bool isEditorUse = false)
        {
            SkillTimeLineVO    skillTimeLineVo = new SkillTimeLineVO();
            List <SkillLineVO> lines           = timeLine.dataProvider;

            if (lines == null)
            {
                return(null);
            }

            int len = lines.Count;

            for (int i = 0; i < len; i++)
            {
                SkillLineVO         lineVO   = lines[i];
                List <SkillPointVO> pointVos = lineVO.points as List <SkillPointVO>;
                if (pointVos == null)
                {
                    continue;
                }

                List <SkillPointVO> resultPointVos = new List <SkillPointVO>();
                foreach (SkillPointVO pointVo in pointVos)
                {
                    if (pointVo.isEmpty == false)
                    {
                        resultPointVos.Add(pointVo);
                    }
                }

                if (resultPointVos.Count > 0)
                {
                    SkillLineVO newLineVO = new SkillLineVO();
                    newLineVO.copyFrom(lineVO);
                    newLineVO.points = resultPointVos;
                    if (newLineVO.enabled == false && isEditorUse)
                    {
                        continue;
                    }
                    skillTimeLineVo.addLine(newLineVO);
                }
            }
            return(skillTimeLineVo);
        }
Beispiel #8
0
        public void updateView(SkillTimeLineVO value)
        {
            timeLine.Clear();

            _currentSkillTimeLineVo = new SkillTimeLineVO();
            foreach (SkillLineVO lineVO in value.lines)
            {
                List <SkillPointVO> points = new List <SkillPointVO>();

                for (int i = 0; i < totalFrame; i++)
                {
                    SkillPointVO pointVo = new SkillPointVO();
                    pointVo.startTime = i * frameTime;
                    points.Add(pointVo);
                }

                int len = Math.Min(lineVO.points.Count, totalFrame);
                for (int i = 0; i < len; i++)
                {
                    SkillPointVO pointVo = lineVO.points[i];
                    int          index   = (int)(pointVo.startTime / frameTime);

                    if (index >= totalFrame)
                    {
                        this.ShowNotification("超出时间线:" + index + "被修正:" + totalFrame);
                        index             = totalFrame - 1;
                        pointVo.startTime = index * frameTime;
                    }

                    points[index] = pointVo;
                }

                SkillLineVO newLineVo = new SkillLineVO();
                newLineVo.copyFrom(lineVO);
                newLineVo.points = points;
                _currentSkillTimeLineVo.addLine(newLineVo);
            }

            timeLine.dataProvider = _currentSkillTimeLineVo.lines;
        }
Beispiel #9
0
        public virtual void drawPoint(SkillPointVO pointVo, SkillLineVO lineVo, Rect r, Texture2D texture2D)
        {
            ISkillEvent e = pointVo.evt;

            if (pointVo.evt is EmptyEvent)
            {
                GUI.color = Color.red;
            }
            else
            {
                if (e.enabled == false || lineVo.enabled == false)
                {
                    GUI.color = Color.gray;
                }
                else
                {
                    GUI.color = defaultPointColor;
                }
            }
            GUI.DrawTexture(r, texture2D);
            GUI.color = Color.white;
        }
Beispiel #10
0
        public void OnGUI(Rect rr, SkillLineVO lineVo, int i)
        {
            if (lineVo.enabled == false)
            {
                GUI.color = Color.gray;
            }
            else
            {
                GUI.color = stackColor;
            }

            GUI.DrawTexture(rr, EditorGUIUtility.whiteTexture);
            GUI.color = Color.white;
            string name = lineVo.name;

            if (string.IsNullOrEmpty(name))
            {
                name = this.GetType().Name;
            }
            GUI.BeginGroup(rr);

            rr             = new Rect(5, 3, 20, (int)rr.height - 8);
            lineVo.enabled = EditorGUI.ToggleLeft(rr, "", lineVo.enabled);
            rr.x          += 20;
            rr.width       = 120;
            lineVo.name    = EditorGUI.TextField(rr, name);

            rr.x             += 120;
            rr.width          = 60;
            lineVo.targetType = (EventTargetType)EditorGUI.EnumPopup(rr, lineVo.targetType);

            rr.x    += 60;
            rr.width = 60;

            lineVo.playCount = EditorGUI.IntPopup(rr, lineVo.playCount, playCountString, playCountInt);

            GUI.EndGroup();
        }
Beispiel #11
0
        private ITrack getSackByLine(SkillLineVO lineVo)
        {
            ITrack track        = null;
            string typeFullName = lineVo.typeFullName;

            if (stackCaches.TryGetValue(typeFullName, out track) == false)
            {
                Type type = foundation.ObjectFactory.Locate(typeFullName);
                if (type == null)
                {
                    track = new BaseTrack();
                }
                else
                {
                    track = Activator.CreateInstance(type) as ITrack;
                    if (track == null)
                    {
                        track = new BaseTrack();
                    }
                }
                stackCaches.Add(typeFullName, track);
            }
            return(track);
        }
Beispiel #12
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;
            }
        }