chore: initial commit
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace PathBerserker2d
|
||||
{
|
||||
internal class IconHandle2D
|
||||
{
|
||||
private static readonly int controlHashIcon = "IconHandle2D_icon".GetHashCode();
|
||||
|
||||
public static void DrawHandle(Vector3 position, Texture icon, float size, Object objectToSelect)
|
||||
{
|
||||
int iconId = EditorGUIUtility.GetControlID(controlHashIcon, FocusType.Passive);
|
||||
|
||||
var e = Event.current;
|
||||
switch (e.type)
|
||||
{
|
||||
case EventType.MouseDown:
|
||||
if (e.button == 0 && HandleUtility.nearestControl == iconId)
|
||||
{
|
||||
Selection.activeObject = objectToSelect;
|
||||
e.Use();
|
||||
}
|
||||
|
||||
break;
|
||||
case EventType.Layout:
|
||||
float distance = HandleUtility.DistanceToRectangle(position, Camera.current.transform.rotation, size);
|
||||
HandleUtility.AddControl(iconId, distance);
|
||||
break;
|
||||
case EventType.Repaint:
|
||||
Vector3 up = Camera.current.transform.up * size;
|
||||
float aspectRatio = (float)icon.width / (float)icon.height;
|
||||
Vector3 right = Camera.current.transform.right * size * aspectRatio;
|
||||
SharedMaterials.UnlitTexture.SetTexture("_MainTex", icon);
|
||||
SharedMaterials.UnlitTexture.SetPass(0);
|
||||
GL.Begin(GL.QUADS);
|
||||
{
|
||||
GL.TexCoord2(1, 1);
|
||||
GL.Vertex(position + right + up);
|
||||
GL.TexCoord2(1, 0);
|
||||
GL.Vertex(position + right - up);
|
||||
GL.TexCoord2(0, 0);
|
||||
GL.Vertex(position - right - up);
|
||||
GL.TexCoord2(0, 1);
|
||||
GL.Vertex(position - right + up);
|
||||
}
|
||||
GL.End();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 99480f75d87fac34c9ad4d0125d7a2e5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e5d17af10e083841ac8d81ba70fd984
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,73 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace PathBerserker2d
|
||||
{
|
||||
internal static class MyGUI
|
||||
{
|
||||
public static string nameSeed = "aWJhcmFraQ==";
|
||||
public static string nameSeed2 = "aWJhcl9ha2k=";
|
||||
static GUIStyle horizontalLine;
|
||||
|
||||
static MyGUI()
|
||||
{
|
||||
horizontalLine = new GUIStyle();
|
||||
horizontalLine.normal.background = EditorGUIUtility.whiteTexture;
|
||||
horizontalLine.margin = new RectOffset(0, 0, 4, 4);
|
||||
horizontalLine.fixedHeight = 1;
|
||||
}
|
||||
|
||||
// utility method
|
||||
public static void HorizontalLine(Color color)
|
||||
{
|
||||
var c = GUI.color;
|
||||
GUI.color = color;
|
||||
GUILayout.Box(GUIContent.none, horizontalLine);
|
||||
GUI.color = c;
|
||||
}
|
||||
|
||||
public static void Header(string text)
|
||||
{
|
||||
EditorGUILayout.LabelField(text, EditorStyles.boldLabel);
|
||||
}
|
||||
|
||||
public static void DrawNavTagLayout(SerializedProperty spNavTag)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
spNavTag.intValue = EditorGUILayout.Popup("NavTag", spNavTag.intValue, PathBerserker2dSettings.NavTags);
|
||||
if (GUILayout.Button("+", EditorStyles.miniButtonRight, GUILayout.Width(17)))
|
||||
{
|
||||
SettingsService.OpenProjectSettings(PathBerserker2dSettingsProvider.WindowPath);
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
public static void DrawNavTagColorPickerLayout(SerializedProperty spNavTag)
|
||||
{
|
||||
int tag = spNavTag.intValue;
|
||||
if (tag == 0)
|
||||
GUI.enabled = false;
|
||||
|
||||
PathBerserker2dSettings.SetNavTagColor(tag, EditorGUILayout.ColorField("NavTag Color", PathBerserker2dSettings.GetNavTagColor(tag)));
|
||||
|
||||
GUI.enabled = true;
|
||||
}
|
||||
|
||||
public static void ProVersionOnlyLabelLayout()
|
||||
{
|
||||
EditorGUILayout.LabelField(ProVersionOnly);
|
||||
}
|
||||
|
||||
public static void ProVersionLinkTypeLabelLayout()
|
||||
{
|
||||
EditorGUILayout.LabelField("Custom link types are limited to the pro-version.");
|
||||
}
|
||||
|
||||
public static GUIContent AddProVersionOnlyToolTipp(string label)
|
||||
{
|
||||
return new GUIContent(label, ProVersionOnly);
|
||||
}
|
||||
|
||||
public const string ProVersionOnly = "This is a pro-version only feature";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 88926f52dae6ae348a100721fd59f003
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,137 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace PathBerserker2d
|
||||
{
|
||||
internal class PositionHandle2D
|
||||
{
|
||||
private Vector3 startPos;
|
||||
private Vector2 currentMousePos;
|
||||
private Vector2 startMousePos;
|
||||
public Color primary;
|
||||
public Color hover;
|
||||
public Color selected;
|
||||
|
||||
private int hash;
|
||||
|
||||
public PositionHandle2D(Color primary, Color hover, Color selected)
|
||||
{
|
||||
this.primary = primary;
|
||||
this.hover = hover;
|
||||
this.selected = selected;
|
||||
|
||||
hash = GetHashCode();
|
||||
}
|
||||
|
||||
public Vector2 DrawHandle(Vector2 position)
|
||||
{
|
||||
int controlIdXArrow = EditorGUIUtility.GetControlID(hash, FocusType.Passive);
|
||||
int controlIdYArrow = EditorGUIUtility.GetControlID(hash, FocusType.Passive);
|
||||
int controlIdRect = EditorGUIUtility.GetControlID(hash, FocusType.Passive);
|
||||
|
||||
bool selectedXArrow = GUIUtility.hotControl == controlIdXArrow;
|
||||
bool hoveredXArrow = HandleUtility.nearestControl == controlIdXArrow;
|
||||
|
||||
bool selectedYArrow = GUIUtility.hotControl == controlIdYArrow;
|
||||
bool hoveredYArrow = HandleUtility.nearestControl == controlIdYArrow;
|
||||
|
||||
bool selectedRect = GUIUtility.hotControl == controlIdRect;
|
||||
bool hoveredRect = HandleUtility.nearestControl == controlIdRect;
|
||||
|
||||
var e = Event.current;
|
||||
|
||||
switch (e.type)
|
||||
{
|
||||
case EventType.MouseDown:
|
||||
if (e.button == 0 && GUIUtility.hotControl == 0 && !e.alt)
|
||||
{
|
||||
if (HandleUtility.nearestControl == controlIdXArrow)
|
||||
{
|
||||
GUIUtility.hotControl = controlIdXArrow;
|
||||
}
|
||||
else if (HandleUtility.nearestControl == controlIdYArrow)
|
||||
{
|
||||
GUIUtility.hotControl = controlIdYArrow;
|
||||
}
|
||||
else if (HandleUtility.nearestControl == controlIdRect)
|
||||
{
|
||||
GUIUtility.hotControl = controlIdRect;
|
||||
}
|
||||
|
||||
|
||||
if (HandleUtility.nearestControl == controlIdXArrow ||
|
||||
HandleUtility.nearestControl == controlIdYArrow ||
|
||||
HandleUtility.nearestControl == controlIdRect)
|
||||
{
|
||||
startPos = position;
|
||||
currentMousePos = e.mousePosition;
|
||||
startMousePos = e.mousePosition;
|
||||
e.Use();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case EventType.MouseUp:
|
||||
if (e.button == 0 || e.button == 2)
|
||||
{
|
||||
if (GUIUtility.hotControl == controlIdXArrow || GUIUtility.hotControl == controlIdYArrow || GUIUtility.hotControl == controlIdRect)
|
||||
{
|
||||
GUIUtility.hotControl = 0;
|
||||
e.Use();
|
||||
selectedXArrow = false;
|
||||
selectedYArrow = false;
|
||||
selectedRect = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case EventType.MouseDrag:
|
||||
|
||||
if (GUIUtility.hotControl == controlIdXArrow || GUIUtility.hotControl == controlIdYArrow || GUIUtility.hotControl == controlIdRect)
|
||||
{
|
||||
currentMousePos += new Vector2(e.delta.x, -e.delta.y) * EditorGUIUtility.pixelsPerPoint;
|
||||
|
||||
Vector3 screenPos = Camera.current.WorldToScreenPoint(Handles.matrix.MultiplyPoint(startPos));
|
||||
screenPos += (Vector3)(currentMousePos - startMousePos);
|
||||
Vector2 newPos = Handles.inverseMatrix.MultiplyPoint(Camera.current.ScreenToWorldPoint(screenPos));
|
||||
|
||||
if (selectedXArrow)
|
||||
{
|
||||
newPos.y = startPos.y;
|
||||
}
|
||||
else if (selectedYArrow)
|
||||
{
|
||||
newPos.x = startPos.x;
|
||||
}
|
||||
|
||||
if (newPos != position)
|
||||
{
|
||||
position = newPos;
|
||||
GUI.changed = true;
|
||||
}
|
||||
|
||||
e.Use();
|
||||
}
|
||||
break;
|
||||
}
|
||||
Handles.color = selectedRect || selectedXArrow ? selected : (hoveredXArrow ? hover : primary);
|
||||
Handles.ArrowHandleCap(controlIdXArrow, position, Quaternion.Euler(0, 90, 0), HandleUtility.GetHandleSize(position), e.type);
|
||||
|
||||
Handles.color = selectedRect || selectedYArrow ? selected : (hoveredYArrow ? hover : primary);
|
||||
Handles.ArrowHandleCap(controlIdYArrow, position, Quaternion.Euler(-90, 0, 0), HandleUtility.GetHandleSize(position), e.type);
|
||||
|
||||
Handles.color = selectedRect ? selected : (hoveredRect ? hover : primary);
|
||||
float rectSize = HandleUtility.GetHandleSize(position) * 0.14f;
|
||||
|
||||
Vector2 rectPos = position + Vector2.one * rectSize;
|
||||
if (e.type == EventType.Repaint)
|
||||
Handles.DrawSolidRectangleWithOutline(new Rect(position, new Vector2(rectSize, rectSize) * 2f), new Color(1, 1, 1, 0.2f), new Color(1, 1, 1, 1));
|
||||
|
||||
rectPos = Handles.Slider2D(rectPos, Vector3.forward, Vector3.right, Vector3.up, rectSize, Handles.RectangleHandleCap, 0);
|
||||
position = rectPos - Vector2.one * rectSize;
|
||||
|
||||
|
||||
|
||||
return position;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 38d3d3506e06653448c052e8936eb8dc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user