private void timeLineSelectHandle(EventX e) { SkillPointVO data = e.data as SkillPointVO; if (data != null) { propertyWindow.show(data); } }
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); }
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; }
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; }
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; } }
public void show(SkillPointVO vo) { this.vo = vo; updateView(); }
private void genericMenuEditorCallBack(Vector2 v, string cmd) { if (_currentSkillTimeLineVo == null) { return; } int row = (int)v.y; int col = (int)v.x; int toIndex = 0; SkillLineVO lineVo; SkillPointVO pointVo; switch (cmd) { case "Remove": lineVo = _currentSkillTimeLineVo.lines[row]; if (lineVo != null) { if (EditorUtility.DisplayDialog("Delete", "确定删除?", "确定", "取消")) { _currentSkillTimeLineVo.removeLine(lineVo); } } break; case "Up": toIndex = row - 1; if (toIndex < 0) { return; } lineVo = _currentSkillTimeLineVo.lines[row]; if (lineVo != null) { _currentSkillTimeLineVo.removeLine(lineVo); _currentSkillTimeLineVo.lines.Insert(toIndex, lineVo); } break; case "Down": toIndex = row + 1; if (toIndex > _currentSkillTimeLineVo.lines.Count - 1) { return; } lineVo = _currentSkillTimeLineVo.lines[row]; if (lineVo != null) { _currentSkillTimeLineVo.removeLine(lineVo); _currentSkillTimeLineVo.lines.Insert(toIndex, lineVo); } break; case "AddPointer": lineVo = _currentSkillTimeLineVo.lines[row]; if (lineVo != null) { lineVo.insert(col, new SkillPointVO()); refreashLineVO(lineVo); } break; case "RemovePointer": lineVo = _currentSkillTimeLineVo.lines[row]; if (lineVo != null) { pointVo = lineVo.points[col]; lineVo.removePoint(pointVo); refreashLineVO(lineVo); } break; case "Copy": lineVo = _currentSkillTimeLineVo.lines[row]; if (lineVo != null) { pointVo = lineVo.points[col]; if (pointVo != null) { timeLinePointCopy = new ByteArray(); timeLinePointCopy.WriteObject(pointVo); timeLinePointCopy.Position = 0; } } break; case "Parse": if (timeLinePointCopy != null) { timeLinePointCopy.Position = 0; } SkillPointVO pointVoCopy = null; try { pointVoCopy = timeLinePointCopy.ReadObject() as SkillPointVO; } catch (Exception ex) { ShowNotification("粘贴数据非事件点数据:" + ex.Message); } if (pointVoCopy != null) { lineVo = _currentSkillTimeLineVo.lines[row]; if (lineVo != null) { pointVo = lineVo.points[col]; SkillEvent skillEvent = pointVoCopy.evt; if (skillEvent != null) { pointVo.addEvent(skillEvent); } } } break; } updateView(_currentSkillTimeLineVo); }