public void Draw() { if (editorDisplayScale <= 1.0f) { editorDisplayScale = 1.0f; } GUILayout.BeginVertical(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); Rect rect = GUILayoutUtility.GetRect(128.0f, 128.0f, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); TextureGrid.Draw(rect); if (CurTexture != null) { // middle mouse drag and scroll zoom if (rect.Contains(Event.current.mousePosition)) { if (Event.current.type == EventType.MouseDrag && Event.current.button == 2) { textureScrollPos -= Event.current.delta * editorDisplayScale; Event.current.Use(); HandleUtility.Repaint(); } if (Event.current.type == EventType.ScrollWheel) { editorDisplayScale -= Event.current.delta.y * 0.03f; Event.current.Use(); HandleUtility.Repaint(); } } bool alphaBlend = true; textureScrollPos = GUI.BeginScrollView(rect, textureScrollPos, new Rect(0, 0, textureBorderPixels * 2 + (CurTexture.width) * editorDisplayScale, textureBorderPixels * 2 + (CurTexture.height) * editorDisplayScale)); Rect textureRect = new Rect(textureBorderPixels, textureBorderPixels, CurTexture.width * editorDisplayScale, CurTexture.height * editorDisplayScale); CurTexture.filterMode = FilterMode.Point; GUI.DrawTexture(textureRect, CurTexture, ScaleMode.ScaleAndCrop, alphaBlend); GameEditorUtility.DrawOutline(textureRect, Color.green); GUI.EndScrollView(); GUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true)); GUILayout.Label(string.Format("Name:{0} W: {1} H: {2}", CurTexture.name, CurTexture.width, CurTexture.height)); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); }
public void Draw() { CurActionData = this.host.CurActionData; clipScrollbar = GUILayout.BeginScrollView(clipScrollbar, GUILayout.Height(100), GUILayout.ExpandWidth(true)); GUILayout.BeginVertical(); //time GUILayout.Box("", EditorStyles.toolbar, GUILayout.ExpandWidth(true)); Rect r = GUILayoutUtility.GetLastRect(); float t = 0.0f; float x = r.x; float fps = CurActionData != null ? CurActionData.fps : 30; while (x < r.x + r.width) { GUI.Label(new Rect(x, r.y, r.width, r.height), t.ToString("0.00"), EditorStyles.miniLabel); x += widthPerTick; t += 1 / fps; } //frame GUILayout.BeginHorizontal(); if (CurActionData != null) { for (int i = 0; i < CurActionData.FrameList.Length; i++) { SpriteAnimationData.FrameData frameData = CurActionData.FrameList[i]; DrawFrame(i, frameData); } GUI.color = Color.red; if (GUILayout.Button("+", "button", GUILayout.Height(60), GUILayout.Width(widthPerTick))) { AddFrame(); } GUI.color = Color.white; // Keyboard shortcuts Event ev = Event.current; int controlId = "Animation.TimeLineView".GetHashCode(); if (ev.type == EventType.KeyDown && GUIUtility.keyboardControl == 0 && selectedFrame != -1) { int newFrame = selectedFrame; switch (ev.keyCode) { case KeyCode.LeftArrow: case KeyCode.Comma: newFrame--; break; case KeyCode.RightArrow: case KeyCode.Period: newFrame++; break; case KeyCode.Home: newFrame = 0; break; case KeyCode.End: newFrame = CurActionData.FrameList.Length - 1; break; case KeyCode.Escape: selectedFrame = -1; HandleUtility.Repaint(); ev.Use(); break; } if (ev.type != EventType.Used && CurActionData.FrameList.Length > 0) { newFrame = Mathf.Clamp(newFrame, 0, CurActionData.FrameList.Length - 1); if (newFrame != selectedFrame) { selectedFrame = newFrame; HandleUtility.Repaint(); ev.Use(); } } } if (ev.type == EventType.KeyDown && (GUIUtility.hotControl == controlId || GUIUtility.keyboardControl == 0) && CurActionData.FrameList.Length > 0 && selectedFrame != -1) { //delete if ((ev.keyCode == KeyCode.Delete || ev.keyCode == KeyCode.Backspace)) { List <SpriteAnimationData.FrameData> list = CurActionData.FrameList.ToList(); list.RemoveAt(selectedFrame); CurActionData.FrameList = list.ToArray(); GUIUtility.hotControl = 0; HandleUtility.Repaint(); } else if (ev.keyCode == KeyCode.Insert) { List <SpriteAnimationData.FrameData> list = CurActionData.FrameList.ToList(); SpriteAnimationData.FrameData tempData = list[selectedFrame]; list.Insert(this.selectedFrame + 1, tempData); this.selectedFrame = this.selectedFrame + 1; CurActionData.FrameList = list.ToArray(); HandleUtility.Repaint(); } } if (ev.type == EventType.MouseDown || GUIUtility.hotControl == controlId) { switch (ev.GetTypeForControl(controlId)) { case EventType.MouseDown: int selectFrame = Mathf.Max(0, (int)Mathf.Floor(ev.mousePosition.x / widthPerTick)); this.selectedFrame = selectFrame; GUIUtility.keyboardControl = 0; GUIUtility.hotControl = controlId; HandleUtility.Repaint(); break; case EventType.MouseUp: if (this.dragSelectFrame != -1 && this.selectedFrame != -1) { List <SpriteAnimationData.FrameData> list = CurActionData.FrameList.ToList(); SpriteAnimationData.FrameData tempData = list[selectedFrame]; list.RemoveAt(selectedFrame); list.Insert(this.dragSelectFrame, tempData); CurActionData.FrameList = list.ToArray(); this.selectedFrame = this.dragSelectFrame; this.dragSelectFrame = -1; HandleUtility.Repaint(); } GUIUtility.keyboardControl = 0; GUIUtility.hotControl = 0; break; case EventType.MouseDrag: dragSelectFrame = Mathf.Max(0, (int)Mathf.Floor(ev.mousePosition.x / widthPerTick)); dragSelectFrame = Mathf.Clamp(dragSelectFrame, 0, CurActionData.FrameList.Length - 1); HandleUtility.Repaint(); break; } } if (selectedFrame != -1 && this.CurActionData != null && this.CurActionData.FrameList.Length > 0) { selectedFrame = Mathf.Clamp(selectedFrame, 0, this.CurActionData.FrameList.Length - 1); string spriteName = this.CurActionData.FrameList[selectedFrame].SpriteName; this.host.textureView.CurTexture = this.host.GetTexture(spriteName); } else { this.host.textureView.CurTexture = null; } } GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.EndScrollView(); Rect rect = GUILayoutUtility.GetLastRect(); GameEditorUtility.DrawOutline(rect, Color.gray); }
//大图绘制 public void Draw() { if (editorDisplayScale <= 1.0f) { editorDisplayScale = 1.0f; } GUILayout.BeginVertical(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); Rect rect = GUILayoutUtility.GetRect(128.0f, 128.0f, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); //在给定矩形内裁剪或平铺图像 TextureGrid.Draw(rect); if (CurTexture != null) { // middle mouse drag and scroll zoom if (rect.Contains(Event.current.mousePosition)) { if (Event.current.type == EventType.MouseDrag && Event.current.button == 2) { textureScrollPos -= Event.current.delta * editorDisplayScale; Event.current.Use(); HandleUtility.Repaint(); } if (Event.current.type == EventType.ScrollWheel) { editorDisplayScale -= Event.current.delta.y * 0.03f; Event.current.Use(); HandleUtility.Repaint(); } } bool alphaBlend = true; Rect scrollViewRect = new Rect(0, 0, textureBorderPixels * 2 + rect.width * editorDisplayScale, textureBorderPixels * 2 + rect.height * editorDisplayScale); Vector2 anchorPointInView = new Vector2(scrollViewRect.center.x + _spriteAtlasProxy.anchorPointInEditor.x, scrollViewRect.yMax - _spriteAtlasProxy.anchorPointInEditor.y); textureScrollPos = GUI.BeginScrollView(rect, textureScrollPos, scrollViewRect); Rect textureRect = new Rect(0, 0, CurTexture.width * editorDisplayScale, CurTexture.height * editorDisplayScale); textureRect.x = anchorPointInView.x - (textureRect.width * 0.5f + _spriteAtlasProxy.anchorPointInImage.x); textureRect.y = anchorPointInView.y - (textureRect.height - _spriteAtlasProxy.anchorPointInImage.y); CurTexture.filterMode = FilterMode.Point; GUI.DrawTexture(textureRect, CurTexture, ScaleMode.ScaleAndCrop, alphaBlend); GameEditorUtility.DrawOutline(textureRect, Color.green); GameEditorUtility.DrawOutline(scrollViewRect, Color.blue); // 编辑器中的锚点 Handles.color = new Color(1, 1, 0, 0.5f); Handles.DrawLine(new Vector2(scrollViewRect.x + 10, anchorPointInView.y), new Vector2(scrollViewRect.x + scrollViewRect.width - 10, anchorPointInView.y)); Handles.DrawLine(new Vector2(anchorPointInView.x, scrollViewRect.yMin + 10), new Vector2(anchorPointInView.x, scrollViewRect.yMax - 10)); // 图片上的锚点 Handles.color = new Color(0, 1, 0, 0.5f); Handles.DrawLine(new Vector2(textureRect.center.x - 10, textureRect.yMax - _spriteAtlasProxy.anchorPointInImage.y), new Vector2(textureRect.center.x + 10, textureRect.yMax - _spriteAtlasProxy.anchorPointInImage.y)); Handles.DrawLine(new Vector2(textureRect.center.x, textureRect.yMax - _spriteAtlasProxy.anchorPointInImage.y - 10), new Vector2(textureRect.center.x, textureRect.yMax - _spriteAtlasProxy.anchorPointInImage.y + 10)); GUI.EndScrollView(); GUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true)); GUILayout.Label(string.Format("Name:{0} W: {1} H: {2}", CurTexture.name, CurTexture.width, CurTexture.height)); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); }
private void DrawTextureSettings() { CurActionData = this.host.CurActionData; if (CurActionData == null) { return; } GUI.color = Color.white; BeginHeader("动作设置"); string changedName = EditorGUILayout.TextField("动作名", CurActionData.name).Trim(); if (changedName != CurActionData.name && changedName.Length > 0) { CurActionData.name = changedName; HandleUtility.Repaint(); } float fps = EditorGUILayout.FloatField("帧率", CurActionData.fps); if (fps > 0) { CurActionData.fps = fps; } float clipTime = CurActionData.FrameList.Length / fps; float newClipTime = EditorGUILayout.FloatField("时长", clipTime); if (newClipTime > 0 && newClipTime != clipTime) { CurActionData.fps = CurActionData.FrameList.Length / newClipTime; } EndHeader(); BeginHeader("图集设置"); if (SpriteAnimationData.SpriteAtlasData != null) { string atlasName = SpriteAnimationData.SpriteAtlasData.name; EditorGUILayout.LabelField("图集名", atlasName); int iwidth = 256; int iheight = 256; Rect rect = GUILayoutUtility.GetRect(iwidth, iheight, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); TextureGrid.Draw(rect); GameEditorUtility.DrawOutline(rect, Color.gray); if (CurTexture != null) { iwidth = (int)rect.width; iheight = (int)rect.height; if (CurTexture.width / CurTexture.height >= iwidth / iheight) { if (CurTexture.width > iwidth) { rect.width = iwidth; rect.height = (CurTexture.height * iwidth) / CurTexture.width; } else { rect.width = CurTexture.width; rect.height = CurTexture.height; } } else { if (CurTexture.height > iheight) { rect.height = iheight; rect.width = (CurTexture.width * iheight) / CurTexture.height; } else { rect.width = CurTexture.width; rect.height = CurTexture.height; } } rect.x += (iwidth - rect.width) / 2; rect.y += (iheight - rect.height) / 2; GUI.DrawTexture(rect, CurTexture); } GUILayout.Space(1); spriteListScroll = GUILayout.BeginScrollView(spriteListScroll, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); for (int i = 0; i < SpriteAnimationData.SpriteAtlasData.spriteDataList.Length; i++) { SpriteAtlasData.SpriteData spriteData = SpriteAnimationData.SpriteAtlasData.spriteDataList[i]; if (spriteData == null) { continue; } bool highlight = selection == spriteData; GUI.backgroundColor = highlight ? Color.green : new Color(0.8f, 0.8f, 0.8f); GUILayout.BeginHorizontal("AS TextArea", GUILayout.MinHeight(20f)); GUI.backgroundColor = Color.white; GUILayout.Label(i.ToString(), GUILayout.Width(24f)); if (GUILayout.Button(spriteData.name, "OL TextField", GUILayout.Height(20f))) { selection = spriteData; } GUI.backgroundColor = Color.green; if (GUILayout.Button("<+", GUILayout.Width(26f))) { selection = spriteData; host.timeLineView.InsertFrame(selection.name, -1); } if (GUILayout.Button("+>", GUILayout.Width(26f))) { selection = spriteData; host.timeLineView.InsertFrame(selection.name, +1); } if (selection != null) { CurTexture = this.host.GetTexture(selection.name); } else { CurTexture = null; } HandleUtility.Repaint(); GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); } else { GUILayout.Label("请先创建图集,在创建动画!"); } EndHeader(); }