summaryrefslogtreecommitdiff
path: root/Erika/Assets/Tools/WorkflowVisualizer/Editor/GUIHelper.cs
blob: cb56f4112241b567861d6a15b936e933b7bb6bfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

namespace Workflow
{

	public static class GUIHelper
	{

		static GUIHelper()
		{
		}

		public static bool DropdownButton(string name, float width)
		{
			return GUILayout.Button(name, EditorStyles.toolbarDropDown, GUILayout.Width(width));
		}


		public static void DrawPortHandle(Rect rect, Color backgroundColor, Color typeColor)
		{
			Color col = GUI.color;
			GUI.color = backgroundColor;
			GUI.DrawTexture(rect, Res.tex_dot_outer);
			GUI.color = typeColor;
			GUI.DrawTexture(rect, Res.tex_dot);
			GUI.color = col;
		}

		/// <summary>
		/// 从start的右中点到end的左中
		/// </summary>
		/// <param name="start"></param>
		/// <param name="end"></param>
		public static void DrawNodeCurve(Rect start, Rect end)
		{
			Vector3 startPos = new Vector3(start.x + start.width, start.y + start.height / 2, 0);
			Vector3 endPos = new Vector3(end.x, end.y + end.height / 2, 0);
			Vector3 startTan = startPos + Vector3.right * 50;
			Vector3 endTan = endPos + Vector3.left * 50;
			Color shadowCol = new Color(0, 0, 0, 0.06f);
			for (int i = 0; i < 3; i++) // Draw a shadow
				Handles.DrawBezier(startPos, endPos, startTan, endTan, shadowCol, null, (i + 1) * 5);
			Handles.DrawBezier(startPos, endPos, startTan, endTan, Color.black, null, 1);
		}

	}


	public static class Utils
	{
		public static IEnumerable<Type> GetAllSubclassOf(Type parent)
		{
			foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
				foreach (var t in a.GetTypes())
					if (t.IsSubclassOf(parent)) yield return t;
		}

		public static T GetAttribute<T>(Type classType) where T : Attribute
		{
			T[] attrs = classType.GetCustomAttributes(typeof(T), true) as T[];
			if (attrs == null || attrs.Length == 0)
				return null;
			return attrs[0];
		}

	}

}