-
Notifications
You must be signed in to change notification settings - Fork 1
t furu/add WorldItemReferenceListTracer #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d681f60
fe7afd5
40b3d05
89aa98b
a83efad
bbe6f0c
c14e5db
4b61fd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| using UnityEngine; | ||
|
|
||
| namespace CCKProcessTracer.Editor.WorldItemReferenceListTracer | ||
| { | ||
| public sealed class Button | ||
| { | ||
| readonly IButton parent; | ||
| public IButton Owner => parent; | ||
| public Rect rect; | ||
| public string text; | ||
| public Button(IButton parent) | ||
| { | ||
| ButtonDrawer.buttons.Add(this); | ||
| this.parent = parent; | ||
| } | ||
|
|
||
| public void OnPress() | ||
| { | ||
| if (parent != null) parent.OnPress(); | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| namespace CCKProcessTracer.Editor.WorldItemReferenceListTracer | ||
| { | ||
| public sealed class DisplayUpdater | ||
| { | ||
| public static void Update() | ||
| { | ||
| ButtonDrawer.Clear(); | ||
| ObjectFrameDrawer.Clear(); | ||
|
|
||
| RefObjectFactory.RebuildAndAlign(); | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| using UnityEngine; | ||
|
|
||
| namespace CCKProcessTracer.Editor.WorldItemReferenceListTracer | ||
| { | ||
| public static class DragController | ||
| { | ||
| public static RefObject draggingObject { get; private set; } | ||
| private static Vector2 dragStartOffset; | ||
|
|
||
| public static void Control() | ||
| { | ||
| Event e = Event.current; | ||
| if (e == null) return; | ||
|
|
||
| Vector2 mousePos = e.mousePosition; | ||
| Vector2 canvasMousePos = View.ScreenToCanvasPosition(mousePos); | ||
|
|
||
| if (e.type == EventType.MouseDown && e.button == 0) | ||
| { | ||
| RefObject foundObject = null; | ||
| for (int i = ObjectFrameDrawer.objectFrames.Count - 1; i >= 0; i--) | ||
| { | ||
| var frame = ObjectFrameDrawer.objectFrames[i]; | ||
| if (frame == null || frame.refObject == null) continue; | ||
|
|
||
| if (frame.nameButtonRect.Contains(canvasMousePos)) | ||
| { | ||
| foundObject = frame.refObject; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (foundObject != null) | ||
| { | ||
| draggingObject = foundObject; | ||
| dragStartOffset = canvasMousePos - new Vector2(foundObject.objectFrame.nameButtonRect.x, foundObject.objectFrame.nameButtonRect.y); | ||
| e.Use(); | ||
| } | ||
| } | ||
| else if (e.type == EventType.MouseDrag && e.button == 0) | ||
| { | ||
| if (draggingObject != null) | ||
| { | ||
| Vector2 basePos = new Vector2(draggingObject.objectFrame.nameButtonRect.x, draggingObject.objectFrame.nameButtonRect.y) - draggingObject.dragOffset; | ||
| Vector2 targetPos = canvasMousePos - dragStartOffset; | ||
| draggingObject.dragOffset = targetPos - basePos; | ||
|
|
||
| DisplayUpdater.Update(); | ||
| e.Use(); | ||
| } | ||
| } | ||
| else if (e.type == EventType.MouseUp && e.button == 0) | ||
| { | ||
| if (draggingObject != null) | ||
| { | ||
| draggingObject = null; | ||
| e.Use(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| using UnityEngine; | ||
|
|
||
| namespace CCKProcessTracer.Editor.WorldItemReferenceListTracer | ||
| { | ||
| public sealed class ArrowDrawer | ||
| { | ||
| public static void Draw() | ||
| { | ||
| Color color = UnityEditor.EditorGUIUtility.isProSkin | ||
| ? new Color(0.5f, 0.62f, 0.7f, 0.8f) | ||
| : new Color(0.12f, 0.22f, 0.28f, 0.6f); | ||
| float thickness = Mathf.Max(1f, 2.5f * View.scale); | ||
|
|
||
| foreach (var connect in RefObjectFactory.connects) | ||
| { | ||
| if (connect == null || connect.from == null || connect.to == null) continue; | ||
|
|
||
| Vector2 from = connect.from.arrowSendPosition; | ||
| Vector2 to = connect.to.arrowReceivePosition; | ||
|
|
||
| DrawArrow(from, to, connect.highlight ? new Color(1f, 0.78f, 0.2f, 1.0f) : color, connect.highlight ? Mathf.Max(1.5f, 4f * View.scale) : thickness); | ||
| } | ||
| } | ||
|
|
||
| static void DrawArrow(Vector2 from, Vector2 to, Color color, float thickness) | ||
| { | ||
| Vector2 p1 = (Quaternion.AngleAxis(135, Vector3.forward) * (to - from)).normalized * 10; | ||
| Vector2 p2 = (Quaternion.AngleAxis(-135, Vector3.forward) * (to - from)).normalized * 10; | ||
|
|
||
| LineDrawer.Draw(from, to, color, thickness); | ||
| LineDrawer.Draw(to + p1, to, color, thickness); | ||
| LineDrawer.Draw(to + p2, to, color, thickness); | ||
| LineDrawer.Draw(to + p1, to + p2, color, thickness); | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
|
|
||
| namespace CCKProcessTracer.Editor.WorldItemReferenceListTracer | ||
| { | ||
| public sealed class ButtonDrawer | ||
| { | ||
| public static List<Button> buttons = new List<Button>(); | ||
|
|
||
| public static void Clear() | ||
| { | ||
| buttons = new List<Button>(); | ||
| } | ||
|
|
||
| public static void Draw() | ||
| { | ||
| foreach (var button in buttons) | ||
| { | ||
| if (button == null || button.Owner == null) continue; | ||
|
|
||
| var scaledRect = new Rect(); | ||
| var pos = View.ProcessViewPosition(new Vector2(button.rect.x, button.rect.y)); | ||
| scaledRect.x = pos.x; | ||
| scaledRect.y = pos.y; | ||
| scaledRect.width = button.rect.width * View.scale; | ||
| scaledRect.height = button.rect.height * View.scale; | ||
|
|
||
| var style = new GUIStyle(); | ||
| style.alignment = TextAnchor.MiddleLeft; | ||
| style.padding = new RectOffset((int)(10 * View.scale), (int)(10 * View.scale), 0, 0); | ||
| style.fontSize = (int)(12 * View.scale); | ||
| if (style.fontSize < 8) style.fontSize = 8; | ||
|
|
||
| if (button.Owner is ObjectFrame) | ||
| { | ||
| style.fontStyle = FontStyle.Bold; | ||
| style.normal.textColor = new Color(0.12f, 0.22f, 0.28f, 1.0f); | ||
| style.hover.textColor = new Color(0.2f, 0.35f, 0.45f, 1.0f); | ||
|
|
||
| if (scaledRect.Contains(Event.current.mousePosition)) | ||
| { | ||
| Color hoverBgColor = new Color(0.12f, 0.22f, 0.28f, 0.08f); | ||
| UnityEditor.EditorGUI.DrawRect(scaledRect, hoverBgColor); | ||
| } | ||
| } | ||
| else if (button.Owner is Node) | ||
| { | ||
| style.fontStyle = FontStyle.Bold; | ||
| style.normal.textColor = new Color(0.12f, 0.22f, 0.28f, 1.0f); | ||
| style.hover.textColor = new Color(0.2f, 0.35f, 0.45f, 1.0f); | ||
|
|
||
| if (scaledRect.Contains(Event.current.mousePosition)) | ||
| { | ||
| Color hoverBgColor = new Color(0.12f, 0.22f, 0.28f, 0.05f); | ||
| UnityEditor.EditorGUI.DrawRect(scaledRect, hoverBgColor); | ||
| } | ||
| } | ||
| else if (button.Owner is Key) | ||
| { | ||
| style.fontStyle = FontStyle.Normal; | ||
| style.normal.textColor = new Color(0.15f, 0.25f, 0.3f, 1.0f); | ||
| style.hover.textColor = new Color(0.3f, 0.5f, 0.6f, 1.0f); | ||
|
|
||
| if (scaledRect.Contains(Event.current.mousePosition)) | ||
| { | ||
| Color hoverBgColor = new Color(0.12f, 0.22f, 0.28f, 0.05f); | ||
| UnityEditor.EditorGUI.DrawRect(scaledRect, hoverBgColor); | ||
| } | ||
| } | ||
|
|
||
| if (GUI.Button(scaledRect, button.text, style)) | ||
| { | ||
| button.OnPress(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| using UnityEditor; | ||
| using UnityEngine; | ||
|
|
||
| namespace CCKProcessTracer.Editor.WorldItemReferenceListTracer | ||
| { | ||
| public sealed class LineDrawer | ||
| { | ||
| public static void Draw(Vector2 from, Vector2 to, Color color, float thickness = 2f) | ||
| { | ||
| Handles.color = color; | ||
| Vector3[] points = new Vector3[] { View.ProcessViewPosition(from), View.ProcessViewPosition(to) }; | ||
| Handles.DrawAAPolyLine(thickness, points); | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| using System.Linq; | ||
| using UnityEditor; | ||
| using UnityEngine; | ||
|
|
||
| namespace CCKProcessTracer.Editor.WorldItemReferenceListTracer | ||
| { | ||
| public sealed class NodeDrawer | ||
| { | ||
| public static void Draw() | ||
| { | ||
| foreach (var node in RefObjectFactory.refObjects.SelectMany(o => o.nodes)) | ||
| { | ||
| if (node == null || node.refObject == null) continue; | ||
|
|
||
| Vector2 upLeft = View.ProcessViewPosition(new Vector2(node.rect.xMin, node.rect.yMin)); | ||
| Vector2 downRight = View.ProcessViewPosition(new Vector2(node.rect.xMax, node.rect.yMax)); | ||
|
|
||
| Rect scaledRect = new Rect(upLeft.x, upLeft.y, downRight.x - upLeft.x, downRight.y - upLeft.y); | ||
|
|
||
| float radius = 8f * View.scale; | ||
| if (radius < 1f) radius = 1f; | ||
|
|
||
| ObjectFrameDrawer.DrawRoundedRectFill(scaledRect, radius, Color.white); | ||
|
|
||
| Color borderColor = new Color(0.12f, 0.22f, 0.28f, 1.0f); | ||
| ObjectFrameDrawer.DrawRoundedRectBorder(scaledRect, radius, borderColor, Mathf.Max(1f, 1.5f * View.scale)); | ||
|
|
||
| float scaledHeaderHeight = Node.nameHeight * View.scale; | ||
| float borderY = scaledRect.yMin + scaledHeaderHeight; | ||
| if (borderY < scaledRect.yMax) | ||
| { | ||
| Handles.color = borderColor; | ||
| Handles.DrawLine(new Vector2(scaledRect.xMin, borderY), new Vector2(scaledRect.xMax, borderY)); | ||
| } | ||
|
|
||
| float keyHeight = Node.keyHeight; | ||
| for (int i = 0; i < node.useKeys.Count; i++) | ||
| { | ||
| float keyBorderY = borderY + (keyHeight * (i + 1)) * View.scale; | ||
| if (keyBorderY < scaledRect.yMax) | ||
| { | ||
| Handles.color = borderColor; | ||
| Handles.DrawLine(new Vector2(scaledRect.xMin, keyBorderY), new Vector2(scaledRect.xMax, keyBorderY)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.