示例#1
0
        public void AddSkillAtom(MetaAtom metaAtom)
        {
            if (_curMetaStage == null)
            {
                return;
            }
            if (metaAtom == null)
            {
                return;
            }
            if (rClickInfo.y >= 0)
            {
                metaAtom.Index = (int)rClickInfo.y;
            }
            MetaFrame frame = null;

            foreach (MetaFrame frm in _curMetaStage.FrameList)
            {
                if (frm.Index != (int)rClickInfo.x)
                {
                    continue;
                }
                frame = frm;
            }
            if (frame == null)
            {
                frame       = new MetaFrame();
                frame.Index = (int)rClickInfo.x;
                _curMetaStage.FrameList.Add(frame);

                _curMetaStage.FrameList = _curMetaStage.FrameList.OrderBy(frm => frm.Index).ToList();
            }
            frame.MetaAtomList.Add(metaAtom);
            selectedAtom = metaAtom;
        }
示例#2
0
        public void RemoveSkillAtom(MetaAtom metaAtom)
        {
            if (_curMetaStage == null)
            {
                return;
            }
            MetaFrame frame = null;

            foreach (MetaFrame frm in _curMetaStage.FrameList)
            {
                if (!frm.MetaAtomList.Contains(metaAtom))
                {
                    continue;
                }
                frame = frm;
            }
            if (frame == null)
            {
                return;
            }
            frame.MetaAtomList.Remove(metaAtom);
            if (frame.MetaAtomList.Count == 0)
            {
                _curMetaStage.FrameList.Remove(frame);
            }
            selectedAtom = null;
        }
示例#3
0
        public MetaStage Clone()
        {
            MetaStage skillStage = new MetaStage();

            foreach (MetaFrame sfi in this.FrameList)
            {
                MetaFrame newsfi = new MetaFrame();
                newsfi.Index        = sfi.Index;
                newsfi.MetaAtomList = new List <MetaAtom>();
                foreach (MetaAtom sa in sfi.MetaAtomList)
                {
                    MetaAtom newsa = null;
                    if (sa != null)
                    {
                        newsa = sa.Clone();
                    }
                    newsfi.MetaAtomList.Add(newsa);
                }
                skillStage.FrameList.Add(newsfi);
            }
            return(skillStage);
        }
示例#4
0
 public void CopySkillAtom(MetaAtom metaAtom)
 {
     cacheAtom = metaAtom.Clone();
 }
示例#5
0
        void EditorEventListener()
        {
            if (Event.current.type == EventType.mouseDown)
            {
                if (cursorChangeRect.Contains(Event.current.mousePosition))
                {
                    resize = true;
                }
                else
                {
                    if (frameSliderRect.Contains(Event.current.mousePosition))
                    {
                        selectFrame = (int)Math.Round((Event.current.mousePosition.x + horScrollVal - gridRect.x - gridOffset) / pixPerRuller);
                    }
                    if (gridRect.Contains(Event.current.mousePosition))
                    {
                        int   localSelectFrame = (int)Math.Round((Event.current.mousePosition.x + horScrollVal - gridRect.x - gridOffset) / pixPerRuller);
                        int   index            = (int)((Event.current.mousePosition.y - gridHeightOffset) / gridHeight);
                        float fValue           = (Event.current.mousePosition.y - gridHeightOffset) % gridHeight;
                        if (fValue > (gridHeight / 2 - circleRadius))
                        {
                            selectedAtom = GetMetaAtom(localSelectFrame, index);
                        }
                        else
                        {
                            selectedAtom = null;
                        }
                        if (selectedAtom != null)
                        {
                            selectedKey = new Vector2(localSelectFrame, index);
                        }
                        else
                        {
                            selectedKey = new Vector2(-1.0f, -1.0f);
                        }
                    }
                }
                if (Event.current.button == 1)
                {
                    if (Event.current.mousePosition.x > gridRect.x && !frameSliderRect.Contains(Event.current.mousePosition))
                    {
                        showMenu = true;
                    }
                    else
                    {
                        showListMenu = true;
                    }
                    int frameX = (int)Math.Round((Event.current.mousePosition.x + horScrollVal - gridRect.x - gridOffset) / pixPerRuller);
                    int rowY   = (int)((Event.current.mousePosition.y - gridHeightOffset) / gridHeight);
                    rClickInfo = new Vector2(frameX, rowY);
                }

                dragFrame = false;
                dragKey   = false;
            }
            if (Event.current.type == EventType.mouseDrag)
            {
                if (Event.current.button == 2)
                {
                    //horScrollVal -= (Event.current.mousePosition - middlePos).x;
                    //verScrollVal += (Event.current.mousePosition - middlePos).y;
                }
                else
                {
                    if (frameSliderRect.Contains(Event.current.mousePosition))
                    {
                        if (GetFrameInfo(selectFrame) != null)
                        {
                            dragFrame = true;
                        }
                    }
                    if (gridRect.Contains(Event.current.mousePosition))
                    {
                        if (selectedKey.x > -1)
                        {
                            dragKey = true;
                        }
                    }
                }
            }
            if (resize)
            {
                cursorChangeRect.Set(Event.current.mousePosition.x, 0, 2, position.height);
            }
            if (Event.current.type == EventType.MouseUp)
            {
                if (resize)
                {
                    resize = false;
                }
                else
                {
                }
                if (dragFrame)
                {
                    int dstFrame = (int)Math.Round((Event.current.mousePosition.x + horScrollVal - gridRect.x - gridOffset) / pixPerRuller);
                    if (GetFrameInfo(dstFrame) == null) //不能再根据第一个元素来判断是否为空帧了!
                    {
                        ChangeFrame(selectFrame, dstFrame);
                        selectFrame = dstFrame;
                    }
                }
                dragFrame = false;
                if (dragKey)
                {
                    int dstFrame = (int)Math.Round((Event.current.mousePosition.x + horScrollVal - gridRect.x - gridOffset) / pixPerRuller);
                    dstFrame = dstFrame < 0 ? 0 : dstFrame;
                    int     dstRow = (int)((Event.current.mousePosition.y - gridHeightOffset) / gridHeight);
                    Vector2 dstKey = new Vector2(dstFrame, dstRow);
                    if (GetMetaAtom(dstFrame, dstRow) == null)
                    {
                        ChangeKey(selectedKey, dstKey);
                        selectedKey = dstKey;
                    }
                }
                dragKey = false;
            }
        }
示例#6
0
        void ShowGridMenu()
        {
            if (showMenu)
            {
                showMenu = false;
                if (selectedAtom == null)
                {
                    GenericMenu.MenuFunction2 Selected = delegate(System.Object obj)
                    {
                        if (obj as String == "paste")
                        {
                            AddSkillAtom(cacheAtom);
                        }
                        else
                        {
                            Type tp = obj as Type;
                            if (tp == null)
                            {
                                return;
                            }
                            MetaAtom atom = Activator.CreateInstance(tp) as MetaAtom;
                            atom.Owner = _curMetaStage != null ? _curMetaStage.Owner : null;
                            if (atom is PlayEffctAtom)
                            {
                                PlayEffctAtom ea = atom as PlayEffctAtom;
                                ea.FlagIndex = atom.Owner != null?atom.Owner.GetFlagIndex() : 0;
                            }
                            else if (atom is PlaySoundAtom)
                            {
                                PlaySoundAtom sa = atom as PlaySoundAtom;
                                sa.FlagIndex = atom.Owner != null?atom.Owner.GetFlagIndex() : 0;
                            }
                            AddSkillAtom(atom);
                        }
                    };

                    GenericMenu menu = new GenericMenu();


                    var scriptInfos = Utility.GetAllScriptsOfTypeCategorized(typeof(MetaAtom));


                    foreach (Utility.ScriptInfo script in scriptInfos)
                    {
                        if (string.IsNullOrEmpty(script.category))
                        {
                            menu.AddItem(new GUIContent(script.name), false, Selected, script.type);
                        }
                    }


                    foreach (Utility.ScriptInfo script in scriptInfos)
                    {
                        if (!string.IsNullOrEmpty(script.category))
                        {
                            menu.AddItem(new GUIContent(script.category + "/" + script.name), false, Selected, script.type);
                        }
                    }
                    menu.AddSeparator("/");
                    menu.AddItem(new GUIContent("粘贴"), false, Selected, "paste");
                    menu.ShowAsContext();
                }
                else
                {
                    GenericMenu.MenuFunction2 Selected = delegate(object selectedType)
                    {
                        if (selectedType.ToString() == "delete")
                        {
                            RemoveSkillAtom(selectedAtom);
                        }
                        else if (selectedType.ToString() == "copy")
                        {
                            CopySkillAtom(selectedAtom);
                        }
                    };
                    GenericMenu menu = new GenericMenu();
                    menu.AddItem(new GUIContent("删除"), false, Selected, "delete");
                    menu.AddItem(new GUIContent("复制"), false, Selected, "copy");
                    menu.ShowAsContext();
                }
                Event.current.Use();
            }
        }
示例#7
0
        public void OnGUI()
        {
            refreshRect();

            GUILayout.BeginArea(skillListRct);
            GUILayout.BeginHorizontal(EditorStyles.toolbar);
            GUI.backgroundColor = new Color(1f, 1f, 1f, 0.5f);
            if (GUILayout.Button("S", EditorStyles.toolbarButton, GUILayout.Width(20)))
            {
                SaveAll();
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("▲", EditorStyles.toolbarButton, GUILayout.Width(20)))
            {
                playStage();
            }
            if (GUILayout.Button("ㄖ", EditorStyles.toolbarButton, GUILayout.Width(20)))
            {
                UnityEditor.EditorApplication.isPaused = !UnityEditor.EditorApplication.isPaused;
            }
            if (GUILayout.Button("■", EditorStyles.toolbarButton, GUILayout.Width(20)))
            {
                UnityEditor.EditorApplication.isPlaying = false;
            }
            GUILayout.EndHorizontal();

            OnGUISkillList();
            GUILayout.EndArea();
            Handles.color = Color.gray;
            Handles.DrawLine(new Vector3(cursorChangeRect.x, cursorChangeRect.y, 0), new Vector3(cursorChangeRect.x, cursorChangeRect.height, 0));
            EditorGUIUtility.AddCursorRect(cursorChangeRect, MouseCursor.ResizeHorizontal);

            //绘制编辑区
            GUILayout.BeginArea(gridRect);
            //绘制标尺
            GUILayout.BeginHorizontal(EditorStyles.toolbar);
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();


            GUILayout.BeginHorizontal(EditorStyles.toolbar);
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            float offset = gridOffset - horScrollVal;
            //int iStart = horScrollVal - gridOffset;
            int iCnt      = (int)((gridRect.width - (gridOffset - horScrollVal)) / pixPerRuller);
            int iStartFrm = 0;

            if (horScrollVal - gridOffset > 0)
            {
                iStartFrm = (int)((horScrollVal - gridOffset) / pixPerRuller);
            }

            for (int i = iStartFrm; i < iCnt; ++i)
            {
                if ((gridOffset - horScrollVal) + i * pixPerRuller < 0.0f)
                {
                    continue;
                }
                if (i % 5 == 0)
                {
                    Handles.Label(new Vector3((gridOffset - horScrollVal) + i * pixPerRuller + 2, 0, 0), string.Format("{0,3:F}", i * 0.01f));
                    Drawing.DrawLine(new Vector2((gridOffset - horScrollVal) + i * pixPerRuller, 5), new Vector2((gridOffset - horScrollVal) + i * pixPerRuller, 18), selectFrame == i ? Color.red : Color.grey, 0.5f, true);
                    Drawing.DrawLine(new Vector2((gridOffset - horScrollVal) + i * pixPerRuller, 7), new Vector2((gridOffset - horScrollVal) + i * pixPerRuller, gridRect.height - 17), selectFrame == i ? Color.red : Color.gray, 0.5f, true);
                }
                else
                {
                    Drawing.DrawLine(new Vector2((gridOffset - horScrollVal) + i * pixPerRuller, 15), new Vector2((gridOffset - horScrollVal) + i * pixPerRuller, 18), selectFrame == i ? Color.red : new Color(0.3f, 0.3f, 0.3f), 0.5f, true);
                    Drawing.DrawLine(new Vector2((gridOffset - horScrollVal) + i * pixPerRuller, gridHeightOffset), new Vector2((gridOffset - horScrollVal) + i * pixPerRuller, gridRect.height - 17), selectFrame == i ? Color.red : new Color(0.3f, 0.3f, 0.3f), 0.5f, true);
                }
            }
            iCnt = (int)((gridRect.height - gridHeightOffset) / gridHeight);
            for (int i = 0; i < iCnt; ++i)
            {
                Handles.DrawLine(new Vector3(0, gridHeightOffset + i * gridHeight, 0), new Vector3(gridRect.width - 17, gridHeightOffset + i * gridHeight, 0));
            }

            if (_curMetaStage != null)
            {
                foreach (MetaFrame frm in _curMetaStage.FrameList)
                {
                    if (frm.Index < iStartFrm)
                    {
                        continue;
                    }
                    for (int j = 0; j < frm.MetaAtomList.Count; ++j)
                    {
                        if (selectedAtom == frm.MetaAtomList[j])
                        {
                            Handles.color = Color.red;
                        }
                        else
                        {
                            Handles.color = Color.black;
                        }
                        MetaAtom currSkillAtom = frm.MetaAtomList[j];
                        if (currSkillAtom != null) //空白帧不绘制
                        {
                            float fHeight = ((gridHeightOffset + currSkillAtom.Index * gridHeight) + (gridHeightOffset + (currSkillAtom.Index + 1) * gridHeight)) / 2;
                            //优先绘制外框
                            Handles.DrawSolidDisc(new Vector3((gridOffset - horScrollVal) + frm.Index * pixPerRuller, fHeight, 0), Vector3.forward, 5);
                        }
                    }
                }
            }

            horScrollVal = GUI.HorizontalScrollbar(new Rect(0, gridRect.height - 17, gridRect.width - 17, 14), horScrollVal, 100, 0, 27000);
            verScrollVal = GUI.VerticalScrollbar(new Rect(gridRect.width - 17, 37, 14, gridRect.height - 37 - 17), verScrollVal, 100, 0, 27000);
            GUILayout.EndArea();


            if (selectedAtom != null)
            {
                NameAttribute nameAttribute = selectedAtom.GetType().GetCustomAttributes(typeof(NameAttribute), false).FirstOrDefault() as NameAttribute;
                BeginWindows();
                windowRect = GUI.Window(1, windowRect, DoProperty, nameAttribute != null ? nameAttribute.name : "属性面板");
                EndWindows();
            }

            ShowGridMenu();
            ShowListMenu();
            EditorEventListener();
            Repaint();
        }