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 override void OnInspectorGUI() { GameEditorUtility util = (GameEditorUtility)this.target; if (GUILayout.Button("Save As")) { util.SaveToFile(); } if (GUILayout.Button("Clear All")) { util.Clear(); } if (GUILayout.Button("Copy to Clipboard")) { util.SaveToClipboard(); } DrawDefaultInspector(); }
private void DrawActionList() { Texture2D blackTexture = new Texture2D(1, 1); blackTexture.SetPixel(0, 0, Color.black); blackTexture.Apply(); GUI.DrawTexture(new Rect(leftBarWidth, 16, 1f, Screen.height - 16), blackTexture); actionListScroll = GUILayout.BeginScrollView(actionListScroll, GUILayout.Width(leftBarWidth), GUILayout.ExpandHeight(true)); bool delete = false; for (int i = 0; i < allAction.Count; i++) { SpriteAnimationData.ActionData actionData = allAction[i]; if (actionData == null) { continue; } bool highlight = selection == actionData.name; 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(actionData.name, "OL TextField", GUILayout.Height(20f))) { selection = actionData.name; CurActionData = actionData; settingView.Draw(); timeLineView.Draw(); } if (mDelNames.Contains(actionData.name)) { GUI.backgroundColor = Color.red; if (GUILayout.Button("删除", GUILayout.Width(60f))) { delete = true; } GUI.backgroundColor = Color.green; if (GUILayout.Button("X", GUILayout.Width(22f))) { mDelNames.Remove(actionData.name); delete = false; } GUI.backgroundColor = Color.white; } else { // If we have not yet selected a sprite for deletion, show a small "X" button if (GUILayout.Button("X", GUILayout.Width(22f))) { mDelNames.Add(actionData.name); } } GUILayout.EndHorizontal(); } if (delete) { for (int i = allAction.Count - 1; i >= 0; i--) { SpriteAnimationData.ActionData actionData = allAction[i]; if (actionData != null && mDelNames.Contains(actionData.name)) { allAction.RemoveAt(i); if (CurActionData == actionData) { CurActionData = null; settingView.Draw(); timeLineView.Draw(); } } } mDelNames.Clear(); } GUILayout.EndScrollView(); Rect viewRect = GUILayoutUtility.GetLastRect(); leftBarWidth = (int)GameEditorUtility.DragableHandle(4819283, viewRect, leftBarWidth, GameEditorUtility.DragDirection.Horizontal); }
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(); }
private void DrawSpriteList() { Rect rect = new Rect(0, 0, leftBarWidth, Screen.height); if (rect.Contains(Event.current.mousePosition)) { switch (Event.current.type) { case EventType.DragUpdated: if (IsValidDragPayload()) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; } else { DragAndDrop.visualMode = DragAndDropVisualMode.None; } break; case EventType.DragPerform: var droppedObjectsList = new List <Object>(); for (int i = 0; i < DragAndDrop.objectReferences.Length; ++i) { var type = DragAndDrop.objectReferences[i].GetType(); if (type == typeof(Texture2D)) { droppedObjectsList.Add(DragAndDrop.objectReferences[i]); } else if (type == typeof(Object) && System.IO.Directory.Exists(DragAndDrop.paths[i])) { droppedObjectsList.AddRange(AddTexturesInPath(DragAndDrop.paths[i])); } } deferredDroppedObjects = droppedObjectsList.ToArray(); Repaint(); break; } } if (Event.current.type == EventType.Layout && deferredDroppedObjects != null) { HandleDroppedPayload(deferredDroppedObjects); deferredDroppedObjects = null; } if (_spriteAtlasProxy != null) { if (_spriteAtlasProxy.Empty) { GUILayout.BeginVertical(GUILayout.Width(leftBarWidth), GUILayout.ExpandHeight(true)); GUILayout.FlexibleSpace(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.Label("拖动贴图到这里"); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); GUILayout.EndVertical(); return; } } else { return; } //line Texture2D blackTexture = new Texture2D(1, 1); blackTexture.SetPixel(0, 0, Color.black); blackTexture.Apply(); GUI.DrawTexture(new Rect(leftBarWidth, 16, 1f, Screen.height - 16), blackTexture); //Handles.DrawLine(new Vector3(leftBarWidth, 0), new Vector3(leftBarWidth,)); spriteListScroll = GUILayout.BeginScrollView(spriteListScroll, GUILayout.Width(leftBarWidth), GUILayout.ExpandHeight(true)); bool delete = false; for (int spriteIndex = 0; spriteIndex < _spriteAtlasProxy.spriteDataList.Count; ++spriteIndex) { var sprite = _spriteAtlasProxy.spriteDataList[spriteIndex]; var spriteSourceTexture = GetTexture(sprite.name);; if (spriteSourceTexture == null && sprite.name.Length == 0) { continue; } bool highlight = selection == sprite.name; 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(spriteIndex.ToString(), GUILayout.Width(24f)); if (GUILayout.Button(sprite.name, "OL TextField", GUILayout.Height(20f))) { selection = sprite.name; textureView.CurTexture = spriteSourceTexture; } if (mDelNames.Contains(sprite.name)) { GUI.backgroundColor = Color.red; if (GUILayout.Button("删除", GUILayout.Width(60f))) { delete = true; } GUI.backgroundColor = Color.green; if (GUILayout.Button("X", GUILayout.Width(22f))) { mDelNames.Remove(sprite.name); delete = false; } GUI.backgroundColor = Color.white; } else { // If we have not yet selected a sprite for deletion, show a small "X" button if (GUILayout.Button("X", GUILayout.Width(22f))) { mDelNames.Add(sprite.name); } } GUILayout.EndHorizontal(); } if (delete) { for (int spriteIndex = _spriteAtlasProxy.spriteDataList.Count - 1; spriteIndex >= 0; spriteIndex--) { var sprite = _spriteAtlasProxy.spriteDataList[spriteIndex]; var spriteSourceTexture = GetTexture(sprite.name); if (spriteSourceTexture == null && sprite.name.Length == 0) { continue; } if (mDelNames.Contains(sprite.name)) { _spriteAtlasProxy.spriteDataList.RemoveAt(spriteIndex); if (textureView.CurTexture == spriteSourceTexture) { textureView.CurTexture = null; textureView.Draw(); } } } mDelNames.Clear(); } GUILayout.EndScrollView(); Rect viewRect = GUILayoutUtility.GetLastRect(); leftBarWidth = (int)GameEditorUtility.DragableHandle(4819283, viewRect, leftBarWidth, GameEditorUtility.DragDirection.Horizontal); }