diff --git a/DevelopmentUtilities.meta b/DevelopmentUtilities.meta new file mode 100644 index 0000000..2ce1997 --- /dev/null +++ b/DevelopmentUtilities.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: cf36ba91f22a17e44aa9069b5dd55922 +folderAsset: yes +timeCreated: 1505419550 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/DevelopmentUtilities/Editor.meta b/DevelopmentUtilities/Editor.meta new file mode 100644 index 0000000..36336d3 --- /dev/null +++ b/DevelopmentUtilities/Editor.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 4703e560073f94443811e277ed07e219 +folderAsset: yes +timeCreated: 1505419559 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/DevelopmentUtilities/Editor/BuiltInResourcesWindow.cs b/DevelopmentUtilities/Editor/BuiltInResourcesWindow.cs new file mode 100644 index 0000000..e155295 --- /dev/null +++ b/DevelopmentUtilities/Editor/BuiltInResourcesWindow.cs @@ -0,0 +1,205 @@ +using System; +using UnityEditor; +using UnityEngine; +using System.Collections.Generic; + +public class BuiltInResourcesWindow : EditorWindow { + [MenuItem("Window/Built-in styles and icons")] + public static void ShowWindow() { + BuiltInResourcesWindow w = (BuiltInResourcesWindow)EditorWindow.GetWindow(); + w.Show(); + } + + private struct Drawing { + public Rect Rect; + public Action Draw; + } + + private List Drawings; + + private List _objects; + private float _scrollPos; + private float _maxY; + private Rect _oldPosition; + + private bool _showingStyles = true; + private bool _showingIcons = false; + + private string _search = ""; + + void OnGUI() { + if (position.width != _oldPosition.width && Event.current.type == EventType.Layout) { + Drawings = null; + _oldPosition = position; + } + + GUILayout.BeginHorizontal(); + + if (GUILayout.Toggle(_showingStyles, "Styles", EditorStyles.toolbarButton) != _showingStyles) { + _showingStyles = !_showingStyles; + _showingIcons = !_showingStyles; + Drawings = null; + } + + if (GUILayout.Toggle(_showingIcons, "Icons", EditorStyles.toolbarButton) != _showingIcons) { + _showingIcons = !_showingIcons; + _showingStyles = !_showingIcons; + Drawings = null; + } + + GUILayout.EndHorizontal(); + + string newSearch = GUILayout.TextField(_search); + if (newSearch != _search) { + _search = newSearch; + Drawings = null; + } + + float top = 36; + + if (Drawings == null) { + string lowerSearch = _search.ToLower(); + + Drawings = new List(); + + GUIContent inactiveText = new GUIContent("inactive"); + GUIContent activeText = new GUIContent("active"); + + float x = 5.0f; + float y = 5.0f; + + if (_showingStyles) { + foreach (GUIStyle ss in GUI.skin.customStyles) { + if (lowerSearch != "" && !ss.name.ToLower().Contains(lowerSearch)) + continue; + + GUIStyle thisStyle = ss; + + Drawing draw = new Drawing(); + + float width = Mathf.Max( + 100.0f, + GUI.skin.button.CalcSize(new GUIContent(ss.name)).x, + ss.CalcSize(inactiveText).x + ss.CalcSize(activeText).x + ) + 16.0f; + + float height = 60.0f; + + if (x + width > position.width - 32 && x > 5.0f) { + x = 5.0f; + y += height + 10.0f; + } + + draw.Rect = new Rect(x, y, width, height); + + width -= 8.0f; + + draw.Draw = () => { + if (GUILayout.Button(thisStyle.name, GUILayout.Width(width))) + CopyText("(GUIStyle)\"" + thisStyle.name + "\""); + + GUILayout.BeginHorizontal(); + GUILayout.Toggle(false, inactiveText, thisStyle, GUILayout.Width(width / 2)); + GUILayout.Toggle(false, activeText, thisStyle, GUILayout.Width(width / 2)); + GUILayout.EndHorizontal(); + }; + + x += width + 18.0f; + + Drawings.Add(draw); + } + } + else if (_showingIcons) { + if (_objects == null) { + _objects = new List(Resources.FindObjectsOfTypeAll(typeof(Texture))); + _objects.Sort((pA, pB) => System.String.Compare(pA.name, pB.name, System.StringComparison.OrdinalIgnoreCase)); + } + + float rowHeight = 0.0f; + + foreach (UnityEngine.Object oo in _objects) { + Texture texture = (Texture)oo; + + if (texture.name == "") + continue; + + if (lowerSearch != "" && !texture.name.ToLower().Contains(lowerSearch)) + continue; + + Drawing draw = new Drawing(); + + float width = Mathf.Max( + GUI.skin.button.CalcSize(new GUIContent(texture.name)).x, + texture.width + ) + 8.0f; + + float height = texture.height + GUI.skin.button.CalcSize(new GUIContent(texture.name)).y + 8.0f; + + if (x + width > position.width - 32.0f) { + x = 5.0f; + y += rowHeight + 8.0f; + rowHeight = 0.0f; + } + + draw.Rect = new Rect(x, y, width, height); + + rowHeight = Mathf.Max(rowHeight, height); + + width -= 8.0f; + + draw.Draw = () => { + if (GUILayout.Button(texture.name, GUILayout.Width(width))) + CopyText("EditorGUIUtility.FindTexture( \"" + texture.name + "\" )"); + + Rect textureRect = GUILayoutUtility.GetRect(texture.width, texture.width, texture.height, texture.height, GUILayout.ExpandHeight(false), GUILayout.ExpandWidth(false)); + EditorGUI.DrawTextureTransparent(textureRect, texture); + }; + + x += width + 8.0f; + + Drawings.Add(draw); + } + } + + _maxY = y; + } + + Rect r = position; + r.y = top; + r.height -= r.y; + r.x = r.width - 16; + r.width = 16; + + float areaHeight = position.height - top; + _scrollPos = GUI.VerticalScrollbar(r, _scrollPos, areaHeight, 0.0f, _maxY); + + Rect area = new Rect(0, top, position.width - 16.0f, areaHeight); + GUILayout.BeginArea(area); + + int count = 0; + foreach (Drawing draw in Drawings) { + Rect newRect = draw.Rect; + newRect.y -= _scrollPos; + + if (newRect.y + newRect.height > 0 && newRect.y < areaHeight) { + GUILayout.BeginArea(newRect, GUI.skin.textField); + draw.Draw(); + GUILayout.EndArea(); + + count++; + } + } + + GUILayout.EndArea(); + } + + void CopyText(string pText) { + TextEditor editor = new TextEditor(); + + //editor.content = new GUIContent(pText); // Unity 4.x code + editor.text = pText; // Unity 5.x code + + editor.SelectAll(); + editor.Copy(); + } +} \ No newline at end of file diff --git a/DevelopmentUtilities/Editor/BuiltInResourcesWindow.cs.meta b/DevelopmentUtilities/Editor/BuiltInResourcesWindow.cs.meta new file mode 100644 index 0000000..6f91ea0 --- /dev/null +++ b/DevelopmentUtilities/Editor/BuiltInResourcesWindow.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 597c4ff91568b244a849f38dc2ee3f4e +timeCreated: 1505418688 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Examples.meta b/Examples.meta new file mode 100644 index 0000000..a6b543b --- /dev/null +++ b/Examples.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 3cfe6eabeed0aa44e8d9d54b308a461f +folderAsset: yes +timeCreated: 1505418316 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/LICENSE.md.meta b/LICENSE.md.meta new file mode 100644 index 0000000..e7ad712 --- /dev/null +++ b/LICENSE.md.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4cf6e5838bfdc1e46866ef31ac6cd822 +timeCreated: 1505418267 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/README.md.meta b/README.md.meta new file mode 100644 index 0000000..f15072b --- /dev/null +++ b/README.md.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e239dd85f6aaf594989e993fcb7cba6c +timeCreated: 1505418267 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts.meta b/Scripts.meta new file mode 100644 index 0000000..ab712b6 --- /dev/null +++ b/Scripts.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 657b15cb3ec32a24ca80faebf094d0f4 +folderAsset: yes +timeCreated: 1505418321 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor.meta b/Scripts/Editor.meta new file mode 100644 index 0000000..b0ba142 --- /dev/null +++ b/Scripts/Editor.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 94d4fd78d9120634ebe0e8717610c412 +folderAsset: yes +timeCreated: 1505418345 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor/NodeEditorAction.cs b/Scripts/Editor/NodeEditorAction.cs new file mode 100644 index 0000000..3563594 --- /dev/null +++ b/Scripts/Editor/NodeEditorAction.cs @@ -0,0 +1,27 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; + +public static class NodeEditorAction { + + public static void Controls(NodeEditorWindow window) { + Event e = Event.current; + + switch (e.type) { + case EventType.ScrollWheel: + if (e.delta.y > 0) window.zoom += 0.1f * window.zoom; + else window.zoom -= 0.1f * window.zoom; + break; + case EventType.MouseDrag: + if (e.button == 1) window.panOffset += e.delta*window.zoom; + break; + case EventType.KeyDown: + if (e.keyCode == KeyCode.F) { + window.zoom = 2; + window.panOffset = Vector2.zero; + } + break; + } + } +} diff --git a/Scripts/Editor/NodeEditorAction.cs.meta b/Scripts/Editor/NodeEditorAction.cs.meta new file mode 100644 index 0000000..a081bf7 --- /dev/null +++ b/Scripts/Editor/NodeEditorAction.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: aa7d4286bf0ad2e4086252f2893d2cf5 +timeCreated: 1505426655 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor/NodeEditorGUI.cs b/Scripts/Editor/NodeEditorGUI.cs new file mode 100644 index 0000000..9b42037 --- /dev/null +++ b/Scripts/Editor/NodeEditorGUI.cs @@ -0,0 +1,34 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; + +namespace UNEC { + /// Contains GUI methods + public static class NodeEditorGUI { + + public static void DrawGrid(Rect rect, float zoom, Vector2 panOffset) { + rect.position = Vector2.zero; + + Vector2 center = rect.size / 2f; + Texture2D gridTex = NodeEditorResources.gridTexture; + Texture2D crossTex = NodeEditorResources.crossTexture; + + // Offset from origin in tile units + float xOffset = -(center.x * zoom + panOffset.x) / gridTex.width; + float yOffset = ((center.y - rect.size.y) * zoom + panOffset.y) / gridTex.height; + + Vector2 tileOffset = new Vector2(xOffset, yOffset); + + // Amount of tiles + float tileAmountX = Mathf.Round(rect.size.x * zoom) / gridTex.width; + float tileAmountY = Mathf.Round(rect.size.y * zoom) / gridTex.height; + + Vector2 tileAmount = new Vector2(tileAmountX, tileAmountY); + + // Draw tiled background + GUI.DrawTextureWithTexCoords(rect, gridTex, new Rect(tileOffset, tileAmount)); + GUI.DrawTextureWithTexCoords(rect, crossTex, new Rect(tileOffset + new Vector2(0.5f,0.5f), tileAmount)); + } + } +} \ No newline at end of file diff --git a/Scripts/Editor/NodeEditorGUI.cs.meta b/Scripts/Editor/NodeEditorGUI.cs.meta new file mode 100644 index 0000000..57b5555 --- /dev/null +++ b/Scripts/Editor/NodeEditorGUI.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 756276bfe9a0c2f4da3930ba1964f58d +timeCreated: 1505420917 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor/NodeEditorReflection.cs b/Scripts/Editor/NodeEditorReflection.cs new file mode 100644 index 0000000..c80a6af --- /dev/null +++ b/Scripts/Editor/NodeEditorReflection.cs @@ -0,0 +1,22 @@ +using System.Reflection; +using System.Linq; +using System; + +namespace UNEC { + /// Contains reflection-related info + public static class NodeEditorReflection { + + public static Type[] nodeTypes { get { return _nodeTypes != null ? _nodeTypes : _nodeTypes = GetNodeTypes(); } } + public static Type[] _nodeTypes; + + public static Type[] GetNodeTypes() { + //Get all classes deriving from Node via reflection + Type derivedType = typeof(Node); + Assembly assembly = Assembly.GetAssembly(derivedType); + return assembly.GetTypes().Where(t => + t != derivedType && + derivedType.IsAssignableFrom(t) + ).ToArray(); + } + } +} diff --git a/Scripts/Editor/NodeEditorReflection.cs.meta b/Scripts/Editor/NodeEditorReflection.cs.meta new file mode 100644 index 0000000..fe4ba9b --- /dev/null +++ b/Scripts/Editor/NodeEditorReflection.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: c78a0fa4a13abcd408ebe73006b7b1bb +timeCreated: 1505419458 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor/NodeEditorResources.cs b/Scripts/Editor/NodeEditorResources.cs new file mode 100644 index 0000000..1372471 --- /dev/null +++ b/Scripts/Editor/NodeEditorResources.cs @@ -0,0 +1,55 @@ +using UnityEngine; +using UnityEditor; + +namespace UNEC { + public static class NodeEditorResources { + + public static Texture2D gridTexture { get { return _gridTexture != null ? _gridTexture : _gridTexture = GenerateGridTexture(); } } + private static Texture2D _gridTexture; + public static Texture2D crossTexture { get { return _crossTexture != null ? _crossTexture : _crossTexture = GenerateCrossTexture(); } } + private static Texture2D _crossTexture; + + + private static Color backgroundColor = new Color(0.15f, 0.15f, 0.15f); + private static Color veinColor = new Color(0.2f, 0.2f, 0.2f); + private static Color arteryColor = new Color(0.28f, 0.28f, 0.28f); + private static Color crossColor = new Color(0.4f, 0.4f, 0.4f); + + public static Texture2D GenerateGridTexture() { + Texture2D tex = new Texture2D(64,64); + Color[] cols = new Color[64 * 64]; + for (int y = 0; y < 64; y++) { + for (int x = 0; x < 64; x++) { + Color col = backgroundColor; + if (y % 16 == 0 || x % 16 == 0) col = veinColor; + if (y == 63 || x == 63) col = arteryColor; + cols[(y * 64) + x] = col; + } + } + tex.SetPixels(cols); + tex.wrapMode = TextureWrapMode.Repeat; + tex.filterMode = FilterMode.Bilinear; + tex.name = "Grid"; + tex.Apply(); + return tex; + } + + public static Texture2D GenerateCrossTexture() { + Texture2D tex = new Texture2D(64, 64); + Color[] cols = new Color[64 * 64]; + for (int y = 0; y < 64; y++) { + for (int x = 0; x < 64; x++) { + Color col = crossColor; + if (y != 31 && x != 31) col.a = 0; + cols[(y * 64) + x] = col; + } + } + tex.SetPixels(cols); + tex.wrapMode = TextureWrapMode.Clamp; + tex.filterMode = FilterMode.Bilinear; + tex.name = "Grid"; + tex.Apply(); + return tex; + } + } +} \ No newline at end of file diff --git a/Scripts/Editor/NodeEditorResources.cs.meta b/Scripts/Editor/NodeEditorResources.cs.meta new file mode 100644 index 0000000..5e85895 --- /dev/null +++ b/Scripts/Editor/NodeEditorResources.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 69f55d341299026489b29443c3dd13d1 +timeCreated: 1505418919 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor/NodeEditorWindow.cs b/Scripts/Editor/NodeEditorWindow.cs new file mode 100644 index 0000000..dc8fae3 --- /dev/null +++ b/Scripts/Editor/NodeEditorWindow.cs @@ -0,0 +1,28 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; +using UNEC; + +public class NodeEditorWindow : EditorWindow { + + public Vector2 panOffset { get { return _panOffset; } set { _panOffset = value; Repaint(); } } + private Vector2 _panOffset; + public float zoom { get { return _zoom; } set { _zoom = Mathf.Clamp(value, 1f, 5f); Repaint(); } } + private float _zoom = 1; + + [MenuItem("Window/UNEC")] + static void Init() { + NodeEditorWindow w = CreateInstance(); + w.Show(); + } + + private void OnGUI() { + + NodeEditorAction.Controls(this); + + BeginWindows(); + NodeEditorGUI.DrawGrid(position, zoom, panOffset); + EndWindows(); + } +} diff --git a/Scripts/Editor/NodeEditorWindow.cs.meta b/Scripts/Editor/NodeEditorWindow.cs.meta new file mode 100644 index 0000000..541b5c7 --- /dev/null +++ b/Scripts/Editor/NodeEditorWindow.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 5ce2bf59ec7a25c4ba691cad7819bf38 +timeCreated: 1505418450 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Node.cs b/Scripts/Node.cs new file mode 100644 index 0000000..59e21d7 --- /dev/null +++ b/Scripts/Node.cs @@ -0,0 +1,19 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace UNEC { + /// Base class for all nodes + public abstract class Node : MonoBehaviour { + + // Use this for initialization + void Start() { + + } + + // Update is called once per frame + void Update() { + + } + } +} diff --git a/Scripts/Node.cs.meta b/Scripts/Node.cs.meta new file mode 100644 index 0000000..a267e40 --- /dev/null +++ b/Scripts/Node.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: f26231e5ab9368746948d0ea49e8178a +timeCreated: 1505419984 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Textures.meta b/Textures.meta new file mode 100644 index 0000000..891fa0a --- /dev/null +++ b/Textures.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 003638a12027abc46ba0fa1719d11246 +folderAsset: yes +timeCreated: 1505424851 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Textures/Grid.png b/Textures/Grid.png new file mode 100644 index 0000000..1c4457e Binary files /dev/null and b/Textures/Grid.png differ diff --git a/Textures/Grid.png.meta b/Textures/Grid.png.meta new file mode 100644 index 0000000..3c0be3f --- /dev/null +++ b/Textures/Grid.png.meta @@ -0,0 +1,82 @@ +fileFormatVersion: 2 +guid: 00e76aa739b5f474fabc717677698eef +timeCreated: 1505424840 +licenseType: Free +TextureImporter: + fileIDToRecycleName: {} + serializedVersion: 4 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 0 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: 1 + mipBias: -1 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spritePixelsToUnits: 100 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 2 + textureShape: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + - buildTarget: Standalone + maxTextureSize: 2048 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + spritePackingTag: + userData: + assetBundleName: + assetBundleVariant: