├── .gitignore ├── Build ├── Build.html └── Build.unity3d ├── Images ├── diagram.jpg ├── diagram.svg ├── logo.png ├── logo.svg └── webdemo.jpg ├── OpenGUI ├── Assets │ ├── Editor.meta │ ├── Editor │ │ ├── OpenGUI.meta │ │ └── OpenGUI │ │ │ ├── OGFontInspector.cs │ │ │ ├── OGFontInspector.cs.meta │ │ │ ├── OGMenuItems.cs │ │ │ ├── OGMenuItems.cs.meta │ │ │ ├── OGPageInspector.cs │ │ │ ├── OGPageInspector.cs.meta │ │ │ ├── OGRootInspector.cs │ │ │ ├── OGRootInspector.cs.meta │ │ │ ├── OGSkinInspector.cs │ │ │ ├── OGSkinInspector.cs.meta │ │ │ ├── OGWidgetInspector.cs │ │ │ └── OGWidgetInspector.cs.meta │ ├── Example.meta │ ├── Example │ │ ├── DropContainer.unity │ │ ├── DropContainer.unity.meta │ │ ├── Example.unity │ │ ├── Example.unity.meta │ │ ├── MultiPage.unity │ │ ├── MultiPage.unity.meta │ │ ├── TextEditor.unity │ │ └── TextEditor.unity.meta │ ├── Plugins.meta │ └── Plugins │ │ ├── OpenGUI.meta │ │ └── OpenGUI │ │ ├── Fonts.meta │ │ ├── Fonts │ │ ├── Ubuntu.meta │ │ └── Ubuntu │ │ │ ├── Ubuntu-R.prefab │ │ │ ├── Ubuntu-R.prefab.meta │ │ │ ├── Ubuntu-R_dynamic.ttf │ │ │ ├── Ubuntu-R_dynamic.ttf.meta │ │ │ ├── Ubuntu-R_unicode.ttf │ │ │ └── Ubuntu-R_unicode.ttf.meta │ │ ├── Scripts.meta │ │ ├── Scripts │ │ ├── OGButton.cs │ │ ├── OGButton.cs.meta │ │ ├── OGCameraWindow.cs │ │ ├── OGCameraWindow.cs.meta │ │ ├── OGDrawHelper.cs │ │ ├── OGDrawHelper.cs.meta │ │ ├── OGDropContainer.cs │ │ ├── OGDropContainer.cs.meta │ │ ├── OGDropDown.cs │ │ ├── OGDropDown.cs.meta │ │ ├── OGFont.cs │ │ ├── OGFont.cs.meta │ │ ├── OGLabel.cs │ │ ├── OGLabel.cs.meta │ │ ├── OGLineNode.cs │ │ ├── OGLineNode.cs.meta │ │ ├── OGListItem.cs │ │ ├── OGListItem.cs.meta │ │ ├── OGPage.cs │ │ ├── OGPage.cs.meta │ │ ├── OGPopUp.cs │ │ ├── OGPopUp.cs.meta │ │ ├── OGProgressBar.cs │ │ ├── OGProgressBar.cs.meta │ │ ├── OGRoot.cs │ │ ├── OGRoot.cs.meta │ │ ├── OGScrollView.cs │ │ ├── OGScrollView.cs.meta │ │ ├── OGSkin.cs │ │ ├── OGSkin.cs.meta │ │ ├── OGSlicedSprite.cs │ │ ├── OGSlicedSprite.cs.meta │ │ ├── OGSlider.cs │ │ ├── OGSlider.cs.meta │ │ ├── OGSprite.cs │ │ ├── OGSprite.cs.meta │ │ ├── OGTabs.cs │ │ ├── OGTabs.cs.meta │ │ ├── OGTestWidget.cs │ │ ├── OGTestWidget.cs.meta │ │ ├── OGTextEditor.cs │ │ ├── OGTextEditor.cs.meta │ │ ├── OGTextField.cs │ │ ├── OGTextField.cs.meta │ │ ├── OGTextInfo.cs │ │ ├── OGTextInfo.cs.meta │ │ ├── OGTexture.cs │ │ ├── OGTexture.cs.meta │ │ ├── OGTickBox.cs │ │ ├── OGTickBox.cs.meta │ │ ├── OGTween.cs │ │ ├── OGTween.cs.meta │ │ ├── OGWidget.cs │ │ └── OGWidget.cs.meta │ │ ├── Shaders.meta │ │ ├── Shaders │ │ ├── 3DText.shader │ │ ├── 3DText.shader.meta │ │ ├── UnlitAlphaColored.shader │ │ ├── UnlitAlphaColored.shader.meta │ │ ├── UnlitClipped.shader │ │ ├── UnlitClipped.shader.meta │ │ ├── UnlitVertexColored.shader │ │ └── UnlitVertexColored.shader.meta │ │ ├── Skins.meta │ │ └── Skins │ │ ├── OGDefault.meta │ │ └── OGDefault │ │ ├── OGDefault.mat │ │ ├── OGDefault.mat.meta │ │ ├── OGDefault.png │ │ ├── OGDefault.png.meta │ │ ├── OGDefault.prefab │ │ └── OGDefault.prefab.meta └── ProjectSettings │ ├── AudioManager.asset │ ├── DynamicsManager.asset │ ├── EditorBuildSettings.asset │ ├── EditorSettings.asset │ ├── GraphicsSettings.asset │ ├── InputManager.asset │ ├── NavMeshLayers.asset │ ├── NetworkManager.asset │ ├── Physics2DSettings.asset │ ├── ProjectSettings.asset │ ├── QualitySettings.asset │ ├── TagManager.asset │ └── TimeManager.asset └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.swp 3 | Library 4 | Temp 5 | -------------------------------------------------------------------------------- /Build/Build.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Unity Web Player | OpenGUI 6 | 7 | 15 | 63 | 117 | 118 | 119 |

Unity Web Player | OpenGUI

120 |
121 |
122 |
123 | 124 | Unity Web Player. Install now! 125 | 126 |
127 |
128 | 129 | Unity Web Player. Install now! Restart your browser after install. 130 | 131 |
132 |
133 |
134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /Build/Build.unity3d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/Build/Build.unity3d -------------------------------------------------------------------------------- /Images/diagram.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/Images/diagram.jpg -------------------------------------------------------------------------------- /Images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/Images/logo.png -------------------------------------------------------------------------------- /Images/webdemo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/Images/webdemo.jpg -------------------------------------------------------------------------------- /OpenGUI/Assets/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fa0bf0d823acfdd4380aebb98f70710f 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Editor/OpenGUI.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3392167d8166088479bb8990a854fa4b 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Editor/OpenGUI/OGFontInspector.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections; 4 | 5 | [CustomEditor (typeof(OGFont))] 6 | [InitializeOnLoad] 7 | public class OGFontInspector : Editor { 8 | private void SavePrefab () { 9 | GameObject selectedGameObject; 10 | PrefabType selectedPrefabType; 11 | GameObject parentGameObject; 12 | UnityEngine.Object prefabParent; 13 | 14 | // Get currently selected object in "Hierarchy" view and store 15 | // its type, parent, and the parent's prefab origin 16 | selectedGameObject = Selection.gameObjects[0]; 17 | selectedPrefabType = PrefabUtility.GetPrefabType(selectedGameObject); 18 | parentGameObject = selectedGameObject.transform.root.gameObject; 19 | prefabParent = PrefabUtility.GetPrefabParent(selectedGameObject); 20 | 21 | // Notify the script this is modifying that something changed 22 | EditorUtility.SetDirty(target); 23 | 24 | // If the selected object is an instance of a prefab 25 | if (selectedPrefabType == PrefabType.PrefabInstance) { 26 | // Replace parent's prefab origin with new parent as a prefab 27 | PrefabUtility.ReplacePrefab(parentGameObject, prefabParent, 28 | ReplacePrefabOptions.ConnectToPrefab); 29 | } 30 | } 31 | 32 | override public void OnInspectorGUI () { 33 | OGFont font = (OGFont) target; 34 | 35 | if ( !font ) { return; } 36 | 37 | font.dynamicFont = (Font) EditorGUILayout.ObjectField ( "Dynamic font", font.dynamicFont, typeof(Font), false ); 38 | font.bitmapFont = (Font) EditorGUILayout.ObjectField ( "Unicode font", font.bitmapFont, typeof(Font), false ); 39 | font.size = EditorGUILayout.IntField ( "Font size", font.size ); 40 | 41 | EditorGUILayout.Space (); 42 | 43 | /* DEBUG: Display available properties 44 | SerializedObject s = new SerializedObject ( font.bitmapFont ); 45 | SerializedProperty p = s.GetIterator(); 46 | 47 | for ( int i = 0; i < 40; i++ ) { 48 | p.Next(true); 49 | GUILayout.Label ( p.name + ", " + p.type ); 50 | } 51 | p.Reset();*/ 52 | 53 | 54 | GUI.backgroundColor = Color.green; 55 | if ( GUILayout.Button ( "Update", GUILayout.Height ( 30 ) ) ) { 56 | font.UpdateData (); 57 | } 58 | GUI.backgroundColor = Color.white; 59 | 60 | if ( GUI.changed ) { 61 | SavePrefab (); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Editor/OpenGUI/OGFontInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e7a328af151e8472fab580dbd49f17f8 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Editor/OpenGUI/OGMenuItems.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections; 4 | 5 | public class OGMenuItems : MonoBehaviour { 6 | // Helper voids 7 | private static void PlaceObject ( GameObject go, Vector3 scale ) { 8 | GameObject parent = UnityEditor.Selection.activeGameObject; 9 | OGRoot root = (OGRoot)GameObject.FindObjectOfType(typeof(OGRoot)); 10 | 11 | if ( !parent && root ) { 12 | parent = root.currentPage.gameObject; 13 | } 14 | 15 | go.transform.parent = parent.transform; 16 | 17 | go.transform.localPosition = Vector3.zero; 18 | go.transform.localScale = scale; 19 | go.transform.localEulerAngles = Vector3.zero; 20 | 21 | UnityEditor.Selection.activeGameObject = go; 22 | } 23 | 24 | // Menu voids 25 | [MenuItem ("OpenGUI/New Root")] 26 | static void NewRoot () { 27 | new GameObject ( "Root", typeof(Camera), typeof(OGRoot) ); 28 | } 29 | 30 | [MenuItem ("OpenGUI/New Page")] 31 | static void NewPage () { 32 | GameObject go = new GameObject ( "Page", typeof(OGPage) ); 33 | OGRoot root = (OGRoot)GameObject.FindObjectOfType(typeof(OGRoot)); 34 | 35 | if ( !root ) { 36 | Debug.LogWarning ( "No root in scene!" ); 37 | DestroyImmediate ( go ); 38 | } else { 39 | go.transform.parent = root.transform; 40 | go.transform.position = Vector3.one; 41 | go.transform.localScale = Vector3.one; 42 | go.transform.localEulerAngles = Vector3.zero; 43 | root.SetCurrentPage ( go.GetComponent() ); 44 | } 45 | 46 | Selection.activeGameObject = go; 47 | } 48 | 49 | [MenuItem ("OpenGUI/Widgets/Button")] 50 | static void NewButton () { 51 | OGButton w = new GameObject ( "btn_Button", typeof(OGButton) ).GetComponent(); 52 | 53 | PlaceObject ( w.gameObject, new Vector3 ( 100, 30, 1 ) ); 54 | 55 | w.text = "Button"; 56 | w.ApplyDefaultStyles (); 57 | } 58 | 59 | [MenuItem ("OpenGUI/Widgets/DropContainer")] 60 | static void NewDropContainer () { 61 | OGDropContainer w = new GameObject ( "drp_DropContainer", typeof(OGDropContainer) ).GetComponent(); 62 | 63 | PlaceObject ( w.gameObject, new Vector3 ( 100, 100, 1 ) ); 64 | 65 | w.ApplyDefaultStyles (); 66 | } 67 | 68 | [MenuItem ("OpenGUI/Widgets/DropDown")] 69 | static void NewDropDown () { 70 | OGDropDown w = new GameObject ( "ddn_DropDown", typeof(OGDropDown) ).GetComponent(); 71 | 72 | PlaceObject ( w.gameObject, new Vector3 ( 140, 20, 1 ) ); 73 | 74 | w.title = "Dropdown Menu"; 75 | w.ApplyDefaultStyles (); 76 | } 77 | 78 | [MenuItem ("OpenGUI/Widgets/Label")] 79 | static void NewLabel () { 80 | OGLabel w = new GameObject ( "lbl_Label", typeof(OGLabel) ).GetComponent(); 81 | 82 | PlaceObject ( w.gameObject, new Vector3 ( 140, 20, 1 ) ); 83 | 84 | w.text = "New Label"; 85 | w.ApplyDefaultStyles (); 86 | } 87 | 88 | [MenuItem ("OpenGUI/Widgets/PopUp")] 89 | static void NewPopUp () { 90 | OGPopUp w = new GameObject ( "pop_PopUp", typeof(OGPopUp) ).GetComponent(); 91 | 92 | PlaceObject ( w.gameObject, new Vector3 ( 100, 20, 1 ) ); 93 | 94 | w.title = "Popup Menu"; 95 | w.ApplyDefaultStyles (); 96 | } 97 | 98 | [MenuItem ("OpenGUI/Widgets/ProgressBar")] 99 | static void NewProgressBar () { 100 | OGProgressBar w = new GameObject ( "bar_ProgressBar", typeof(OGProgressBar) ).GetComponent(); 101 | 102 | PlaceObject ( w.gameObject, new Vector3 ( 200, 30, 1 ) ); 103 | 104 | w.padding = new Vector2 ( 8, 8 ); 105 | w.ApplyDefaultStyles (); 106 | } 107 | 108 | [MenuItem ("OpenGUI/Widgets/ScrollView")] 109 | static void NewScrollView () { 110 | OGScrollView w = new GameObject ( "ScrollView", typeof(OGScrollView) ).GetComponent(); 111 | 112 | PlaceObject ( w.gameObject, new Vector3 ( 1, 1, 1 ) ); 113 | 114 | w.size = new Vector2 ( 400, 300 ); 115 | w.ApplyDefaultStyles (); 116 | } 117 | 118 | [MenuItem ("OpenGUI/Widgets/SlicedSprite")] 119 | static void NewSlicedSprite () { 120 | OGSlicedSprite w = new GameObject ( "img_SlicedSprite", typeof(OGSlicedSprite) ).GetComponent(); 121 | 122 | PlaceObject ( w.gameObject, new Vector3 ( 200, 200, 1 ) ); 123 | 124 | w.ApplyDefaultStyles (); 125 | } 126 | 127 | [MenuItem ("OpenGUI/Widgets/Slider")] 128 | static void NewSlider () { 129 | OGSlider w = new GameObject ( "sld_Slider", typeof(OGSlider) ).GetComponent(); 130 | 131 | PlaceObject ( w.gameObject, new Vector3 ( 200, 20, 1 ) ); 132 | 133 | w.ApplyDefaultStyles (); 134 | } 135 | 136 | [MenuItem ("OpenGUI/Widgets/Sprite")] 137 | static void NewSprite () { 138 | OGSprite w = new GameObject ( "img_Sprite", typeof(OGSprite) ).GetComponent(); 139 | 140 | PlaceObject ( w.gameObject, new Vector3 ( 200, 20, 1 ) ); 141 | 142 | w.ApplyDefaultStyles (); 143 | } 144 | 145 | [MenuItem ("OpenGUI/Widgets/Tabs")] 146 | static void NewTabs () { 147 | OGTabs w = new GameObject ( "tab_Tabs", typeof(OGTabs) ).GetComponent(); 148 | 149 | PlaceObject ( w.gameObject, new Vector3 ( 200, 20, 1 ) ); 150 | 151 | w.ApplyDefaultStyles (); 152 | } 153 | 154 | [MenuItem ("OpenGUI/Widgets/TextField")] 155 | static void NewTextField () { 156 | OGTextField w = new GameObject ( "fld_TextField", typeof(OGTextField) ).GetComponent(); 157 | 158 | PlaceObject ( w.gameObject, new Vector3 ( 200, 20, 1 ) ); 159 | 160 | w.ApplyDefaultStyles (); 161 | } 162 | 163 | [MenuItem ("OpenGUI/Widgets/Texture")] 164 | static void NewTexture () { 165 | OGTexture w = new GameObject ( "img_Texture", typeof(OGTexture) ).GetComponent(); 166 | 167 | PlaceObject ( w.gameObject, new Vector3 ( 120, 120, 1 ) ); 168 | } 169 | 170 | [MenuItem ("OpenGUI/Widgets/TickBox")] 171 | static void NewTickBox () { 172 | OGTickBox w = new GameObject ( "tbx_TickBox", typeof(OGTickBox) ).GetComponent(); 173 | 174 | PlaceObject ( w.gameObject, new Vector3 ( 200, 20, 1 ) ); 175 | 176 | w.text = "Tickbox"; 177 | w.ApplyDefaultStyles (); 178 | } 179 | 180 | } 181 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Editor/OpenGUI/OGMenuItems.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 54a4ca3a12124ab40b3349541c25e5a4 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Editor/OpenGUI/OGPageInspector.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | using System.Collections; 4 | 5 | [CustomEditor (typeof(OGPage), true)] 6 | [System.Serializable] 7 | public class OGPageInspector : Editor { 8 | override public void OnInspectorGUI () { 9 | serializedObject.Update (); 10 | 11 | OGPage page = (OGPage) target; 12 | OGRoot root = OGRoot.GetInstance(); 13 | 14 | if ( !page || !root ) { return; } 15 | 16 | DrawDefaultInspector (); 17 | 18 | EditorGUILayout.Space (); 19 | 20 | GUI.backgroundColor = Color.red; 21 | 22 | if ( GUILayout.Button ( "Reset styles" ) ) { 23 | page.ResetStyles (); 24 | } 25 | 26 | GUI.backgroundColor = Color.green; 27 | 28 | 29 | foreach ( OGPage p in root.currentPages ) { 30 | if ( p == page ) { 31 | GUILayout.BeginHorizontal (); 32 | 33 | if ( GUILayout.Button ( "Update", GUILayout.Height(30) ) ) { 34 | page.UpdateStyles (); 35 | GUI.backgroundColor = Color.white; 36 | } 37 | 38 | if ( GUILayout.Button ( "-", GUILayout.Height ( 30 ), GUILayout.Width ( 40 ) ) ) { 39 | OGRoot.GetInstance().RemoveFromCurrentPages ( page ); 40 | page.gameObject.SetActive ( false ); 41 | } 42 | 43 | GUILayout.EndHorizontal (); 44 | 45 | return; 46 | } 47 | } 48 | 49 | GUILayout.BeginHorizontal (); 50 | 51 | if ( GUILayout.Button ( "Set current page", GUILayout.Height ( 30 ) ) ) { 52 | OGRoot.GetInstance().SetCurrentPage ( page ); 53 | page.gameObject.SetActive ( true ); 54 | } 55 | 56 | if ( GUILayout.Button ( "+", GUILayout.Height ( 30 ), GUILayout.Width ( 40 ) ) ) { 57 | OGRoot.GetInstance().AddToCurrentPages ( page ); 58 | page.gameObject.SetActive ( true ); 59 | } 60 | 61 | GUILayout.EndHorizontal (); 62 | 63 | GUI.backgroundColor = Color.white; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Editor/OpenGUI/OGPageInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fdd83d9322cc45a45b78390e9fbd3b4f 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Editor/OpenGUI/OGRootInspector.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEditor; 5 | 6 | [CustomEditor (typeof(OGRoot))] 7 | [InitializeOnLoad] 8 | public class OGRootInspector : Editor { 9 | static OGRootInspector () { 10 | OGRoot.EditorSelectWidget = (w, additive) => { 11 | if ( !w ) { 12 | Selection.activeObject = null; 13 | 14 | } else if ( additive ) { 15 | List< UnityEngine.Object > list = new List< UnityEngine.Object > ( Selection.objects ); 16 | bool remove = false; 17 | 18 | for ( int i = 0; i < list.Count; i++ ) { 19 | if ( list[i] as GameObject == w.gameObject ) { 20 | remove = true; 21 | break; 22 | } 23 | } 24 | 25 | if ( remove ) { 26 | list.Remove ( w.gameObject ); 27 | } else { 28 | list.Add ( w.gameObject ); 29 | } 30 | 31 | Selection.objects = list.ToArray (); 32 | 33 | } else { 34 | Selection.activeObject = w.gameObject; 35 | 36 | } 37 | }; 38 | } 39 | 40 | public static void SelectActiveObject ( OGWidget w, bool b = false ) 41 | { 42 | Selection.activeObject = w.gameObject; 43 | } 44 | 45 | override public void OnInspectorGUI () { 46 | OGRoot root = (OGRoot) target; 47 | 48 | if ( OGRoot.EditorSelectWidget == null ) { 49 | OGRoot.EditorSelectWidget = SelectActiveObject; 50 | } 51 | 52 | if ( !root ) { return; } 53 | 54 | DrawDefaultInspector (); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Editor/OpenGUI/OGRootInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 18f0d0609974bb544a3ec2a6a4c3946c 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Editor/OpenGUI/OGSkinInspector.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | 7 | [CustomEditor (typeof(OGSkin))] 8 | [System.Serializable] 9 | public class OGSkinInspector : Editor { 10 | private bool deleteMode = false; 11 | private bool addMode = false; 12 | private bool uvMode = false; 13 | private Vector2 uvScrollPosition; 14 | private float uvScale = 1; 15 | private string addStyleName = ""; 16 | private Color tintColor = Color.white; 17 | 18 | private static int currentStyle = 0; 19 | private static bool setDefaultsMode = false; 20 | private static bool showText = false; 21 | 22 | public static void SetCurrentStyle ( int i ) { 23 | currentStyle = i; 24 | setDefaultsMode = false; 25 | } 26 | 27 | public static void SetDefaultsMode () { 28 | setDefaultsMode = true; 29 | } 30 | 31 | private string[] GetStyles ( bool includeCancel ) { 32 | OGSkin skin = (OGSkin) target; 33 | List< string > tempList = new List< string >(); 34 | 35 | if ( includeCancel ) { 36 | tempList.Add ( "..." ); 37 | } 38 | 39 | foreach ( OGStyle style in skin.styles ) { 40 | tempList.Add ( style.name ); 41 | } 42 | 43 | return tempList.ToArray(); 44 | } 45 | 46 | private void AddStyle ( string n ) { 47 | OGSkin skin = (OGSkin) target; 48 | 49 | for ( int i = 0; i < skin.styles.Length; i++ ) { 50 | if ( n == skin.styles[i].name ) { 51 | Debug.LogWarning ( "OpenGUI: There is already a style by name '" + n + "'" ); 52 | return; 53 | } 54 | } 55 | 56 | List< OGStyle > tempList = new List< OGStyle > ( skin.styles ); 57 | OGStyle newStyle = new OGStyle (); 58 | newStyle.name = n; 59 | 60 | tempList.Add ( newStyle ); 61 | 62 | skin.styles = tempList.ToArray(); 63 | 64 | SortStyles ( skin, newStyle ); 65 | } 66 | 67 | private void RemoveStyle ( int i ) { 68 | OGSkin skin = (OGSkin) target; 69 | List< OGStyle > tempList = new List< OGStyle > ( skin.styles ); 70 | 71 | tempList.RemoveAt ( i ); 72 | 73 | skin.styles = tempList.ToArray(); 74 | } 75 | 76 | private int CompareNames ( OGStyle a, OGStyle b ) { 77 | return a.name.CompareTo ( b.name ); 78 | } 79 | 80 | private Vector3[] CalcBorderLines ( Rect controlRect, OGSkin skin ) { 81 | Vector3[] lines = new Vector3[8]; 82 | float width = skin.styles[currentStyle].coordinates.width * 2; 83 | float height = skin.styles[currentStyle].coordinates.height * 2; 84 | 85 | // Left 86 | lines[0] = new Vector3 ( controlRect.x + skin.styles[currentStyle].border.left * width / skin.styles[currentStyle].coordinates.width, controlRect.y, 0 ); 87 | lines[1] = lines[0] + new Vector3 ( 0, controlRect.height, 0 ); 88 | 89 | // Right 90 | lines[2] = new Vector3 ( controlRect.x + width - skin.styles[currentStyle].border.right * width / skin.styles[currentStyle].coordinates.width, controlRect.y, 0 ); 91 | lines[3] = lines[2] + new Vector3 ( 0, controlRect.height, 0 ); 92 | 93 | // Top 94 | lines[4] = new Vector3 ( controlRect.x, controlRect.y + skin.styles[currentStyle].border.top * height / skin.styles[currentStyle].coordinates.height, 0 ); 95 | lines[5] = lines[4] + new Vector3 ( controlRect.width, 0, 0 ); 96 | 97 | // Bottom 98 | lines[6] = new Vector3 ( controlRect.x, controlRect.y + height - skin.styles[currentStyle].border.bottom * height / skin.styles[currentStyle].coordinates.height, 0 ); 99 | lines[7] = lines[6] + new Vector3 ( controlRect.width, 0, 0 ); 100 | 101 | return lines; 102 | } 103 | 104 | private Vector3[] CalcUVBorderLines ( Rect controlRect, OGStyle style, Texture atlas ) { 105 | Vector3[] lines = new Vector3[8]; 106 | float width = style.coordinates.width * uvScale; 107 | float height = style.coordinates.height * uvScale; 108 | float x = controlRect.x + style.coordinates.x * uvScale; 109 | float y = controlRect.y + ( atlas.height - style.coordinates.y ) * uvScale; 110 | 111 | // Left 112 | lines[0] = new Vector3 ( x, y, 0 ); 113 | lines[1] = lines[0] - new Vector3 ( 0, height, 0 ); 114 | 115 | // Right 116 | lines[2] = new Vector3 ( x + width, y, 0 ); 117 | lines[3] = lines[2] - new Vector3 ( 0, height, 0 ); 118 | 119 | // Top 120 | lines[4] = new Vector3 ( x, y - height, 0 ); 121 | lines[5] = lines[4] + new Vector3 ( width, 0, 0 ); 122 | 123 | // Bottom 124 | lines[6] = new Vector3 ( x, y, 0 ); 125 | lines[7] = lines[6] + new Vector3 ( width, 0, 0 ); 126 | 127 | return lines; 128 | } 129 | 130 | private int GetStyleIndex ( OGSkin skin, OGStyle style ) { 131 | if ( skin != null && style != null ) { 132 | for ( int i = 0; i < skin.styles.Length; i++ ) { 133 | if ( skin.styles[i].name == style.name ) { 134 | return i; 135 | } 136 | } 137 | } 138 | 139 | return 0; 140 | } 141 | 142 | private int GuessStyleIndex ( OGSkin skin, OGWidgetType widgetType, OGStyleType styleType ) { 143 | int bestGuess = 0; 144 | 145 | if ( skin ) { 146 | for ( int i = 0; i < skin.styles.Length; i++ ) { 147 | if ( skin.styles[i].name == widgetType.ToString() && styleType == OGStyleType.Basic ) { 148 | bestGuess = i; 149 | break; 150 | 151 | } else if ( skin.styles[i].name.Contains ( widgetType.ToString() ) ) { 152 | bestGuess = i; 153 | 154 | if ( skin.styles[i].name.Contains ( styleType.ToString() ) ) { 155 | break; 156 | } 157 | } 158 | } 159 | } 160 | 161 | return bestGuess; 162 | } 163 | 164 | private string[] GetAnchors () { 165 | return System.Enum.GetNames(typeof(TextAnchor)); 166 | } 167 | 168 | private string[] GetStyles ( OGSkin skin ) { 169 | List< string > tempList = new List< string >(); 170 | 171 | if ( skin ) { 172 | foreach ( OGStyle style in skin.styles ) { 173 | tempList.Add ( style.name ); 174 | } 175 | } 176 | 177 | return tempList.ToArray(); 178 | } 179 | 180 | private string[] GetFonts ( OGSkin skin ) { 181 | List< string > tempList = new List< string >(); 182 | 183 | if ( skin != null ) { 184 | foreach ( OGFont font in skin.fonts ) { 185 | if ( font != null ) { 186 | tempList.Add ( font.name ); 187 | } 188 | } 189 | } 190 | 191 | return tempList.ToArray(); 192 | } 193 | 194 | private void SortStyles ( OGSkin skin ) { 195 | List< OGStyle > tempList = new List< OGStyle > ( skin.styles ); 196 | 197 | tempList.Sort ( CompareNames ); 198 | 199 | skin.styles = tempList.ToArray (); 200 | } 201 | 202 | private void SortStyles ( OGSkin skin, OGStyle focus ) { 203 | SortStyles ( skin ); 204 | 205 | for ( int i = 0; i < skin.styles.Length; i++ ) { 206 | if ( skin.styles[i] == focus ) { 207 | currentStyle = i; 208 | } 209 | } 210 | } 211 | 212 | private void SavePrefab () { 213 | GameObject selectedGameObject; 214 | PrefabType selectedPrefabType; 215 | GameObject parentGameObject; 216 | UnityEngine.Object prefabParent; 217 | 218 | // Get currently selected object in "Hierarchy" view and store 219 | // its type, parent, and the parent's prefab origin 220 | selectedGameObject = Selection.gameObjects[0]; 221 | selectedPrefabType = PrefabUtility.GetPrefabType(selectedGameObject); 222 | parentGameObject = selectedGameObject.transform.root.gameObject; 223 | prefabParent = PrefabUtility.GetPrefabParent(selectedGameObject); 224 | 225 | // Notify the script this is modifying that something changed 226 | EditorUtility.SetDirty(target); 227 | 228 | // If the selected object is an instance of a prefab 229 | if (selectedPrefabType == PrefabType.PrefabInstance) { 230 | // Replace parent's prefab origin with new parent as a prefab 231 | PrefabUtility.ReplacePrefab(parentGameObject, prefabParent, 232 | ReplacePrefabOptions.ConnectToPrefab); 233 | } 234 | } 235 | 236 | override public void OnInspectorGUI () { 237 | serializedObject.Update (); 238 | 239 | OGSkin skin = (OGSkin) target; 240 | 241 | if ( skin == null ) { 242 | EditorGUILayout.LabelField ( "Skin is null for some reason" ); 243 | return; 244 | } 245 | 246 | if ( skin.styles == null ) { 247 | EditorGUILayout.LabelField ( "Skin styles are null for some reason" ); 248 | return; 249 | } 250 | 251 | if ( currentStyle >= skin.styles.Length ) { 252 | currentStyle = skin.styles.Length - 1; 253 | } 254 | 255 | Object tempObj = null; 256 | OGStyle s = null; 257 | if ( skin.styles.Length > 0 ) { 258 | s = skin.styles[currentStyle]; 259 | } 260 | 261 | // Set defaults 262 | if ( setDefaultsMode ) { 263 | EditorGUILayout.BeginHorizontal (); 264 | 265 | EditorGUILayout.LabelField ( "Manage defaults", EditorStyles.boldLabel ); 266 | 267 | // Reset 268 | GUI.backgroundColor = Color.red; 269 | if ( GUILayout.Button ( "Reset", GUILayout.Width ( 50 ) ) ) { 270 | skin.ResetDefaults (); 271 | } 272 | 273 | EditorGUILayout.EndHorizontal (); 274 | 275 | EditorGUILayout.LabelField ( "Set the default widget styles" ); 276 | 277 | GUILayout.Space ( 10 ); 278 | 279 | // Back 280 | GUI.backgroundColor = Color.white; 281 | if ( GUILayout.Button ( "Back to inspector", GUILayout.Height ( 30 ) ) ) { 282 | setDefaultsMode = false; 283 | } 284 | 285 | // Auto detect 286 | bool autoDetect = false; 287 | if ( GUILayout.Button ( "Autodetect" ) ) { 288 | autoDetect = true; 289 | } 290 | 291 | GUILayout.Space ( 10 ); 292 | 293 | foreach ( OGDefault d in skin.GetAllDefaults() ) { 294 | EditorGUILayout.LabelField ( d.widgetType.ToString(), EditorStyles.boldLabel, GUILayout.Width ( 100 ) ); 295 | 296 | EditorGUILayout.BeginVertical (); 297 | 298 | foreach ( OGStyleType styleType in System.Enum.GetValues(typeof(OGStyleType)) as OGStyleType[] ) { 299 | if ( OGSkin.IsStyleUsed ( styleType, d.widgetType ) ) { 300 | string stateName = styleType.ToString(); 301 | OGStyle style = d.styleSet.GetStyle ( styleType ); 302 | int styleIndex; 303 | 304 | if ( autoDetect ) { 305 | styleIndex = GuessStyleIndex ( skin, d.widgetType, styleType ); 306 | } else { 307 | styleIndex = GetStyleIndex ( skin, style ); 308 | } 309 | 310 | EditorGUILayout.BeginHorizontal(); 311 | EditorGUILayout.LabelField ( stateName, GUILayout.Width ( 80 ) ); 312 | styleIndex = EditorGUILayout.Popup ( styleIndex, GetStyles ( skin ) ); 313 | EditorGUILayout.EndHorizontal (); 314 | d.styleSet.SetStyle ( styleType, skin.styles [ styleIndex ] ); 315 | } 316 | } 317 | 318 | EditorGUILayout.EndVertical (); 319 | 320 | GUILayout.Space ( 20 ); 321 | } 322 | 323 | // Back 324 | GUI.backgroundColor = Color.white; 325 | if ( GUILayout.Button ( "Back to inspector", GUILayout.Height ( 30 ) ) ) { 326 | setDefaultsMode = false; 327 | } 328 | 329 | // Adjust UV 330 | } else if ( uvMode ) { 331 | EditorGUILayout.BeginHorizontal (); 332 | EditorGUILayout.LabelField ( "Style", EditorStyles.boldLabel, GUILayout.Width ( 50 ) ); 333 | currentStyle = EditorGUILayout.Popup ( currentStyle, GetStyles ( false ), GUILayout.Width ( 100 )); 334 | EditorGUILayout.EndHorizontal (); 335 | 336 | EditorGUILayout.Space (); 337 | 338 | EditorGUILayout.LabelField ( "Edit widget UV coordinates" ); 339 | 340 | EditorGUILayout.Space (); 341 | 342 | // Atlas 343 | Texture uvAtlasTex = skin.atlas.mainTexture; 344 | 345 | s.coordinates.x = Mathf.Floor ( s.coordinates.x ); 346 | s.coordinates.y = Mathf.Floor ( s.coordinates.y ); 347 | s.coordinates.width = Mathf.Floor ( s.coordinates.width ); 348 | s.coordinates.height = Mathf.Floor ( s.coordinates.height ); 349 | 350 | s.coordinates.x = Mathf.Clamp ( s.coordinates.x, 0, uvAtlasTex.width - s.coordinates.width ); 351 | s.coordinates.y = Mathf.Clamp ( s.coordinates.y, 0, uvAtlasTex.height - s.coordinates.height ); 352 | 353 | s.coordinates = EditorGUILayout.RectField ( s.coordinates ); 354 | 355 | EditorGUILayout.Space (); 356 | 357 | uvScale = EditorGUILayout.Slider ( "Zoom", uvScale, 1, 10 ); 358 | 359 | EditorGUILayout.Space (); 360 | 361 | uvScrollPosition = GUILayout.BeginScrollView ( uvScrollPosition, GUILayout.Height ( Mathf.Clamp ( uvAtlasTex.height * uvScale, uvAtlasTex.height, 300 ) + 20 ) ); 362 | 363 | Rect uvControlRect = EditorGUILayout.GetControlRect ( false, uvAtlasTex.height * uvScale, GUILayout.Width ( uvAtlasTex.width * uvScale ) ); 364 | Vector3[] uvBorderLines = CalcUVBorderLines ( uvControlRect, s, uvAtlasTex ); 365 | 366 | GUI.DrawTexture ( uvControlRect, uvAtlasTex, ScaleMode.ScaleToFit, true ); 367 | 368 | Handles.color = Color.green; 369 | 370 | Handles.DrawLine ( uvBorderLines[0], uvBorderLines[1] ); 371 | Handles.DrawLine ( uvBorderLines[2], uvBorderLines[3] ); 372 | Handles.DrawLine ( uvBorderLines[4], uvBorderLines[5] ); 373 | Handles.DrawLine ( uvBorderLines[6], uvBorderLines[7] ); 374 | 375 | Handles.color = Color.white; 376 | 377 | GUILayout.EndScrollView (); 378 | 379 | EditorGUILayout.Space (); 380 | 381 | // Back 382 | GUI.backgroundColor = Color.white; 383 | if ( GUILayout.Button ( "Back to inspector", GUILayout.Height ( 30 ) ) ) { 384 | uvMode = false; 385 | } 386 | 387 | // Edit style 388 | } else { 389 | // Null check 390 | if ( skin.styles.Length > 0 ) { 391 | // Style 392 | EditorGUILayout.BeginHorizontal(); 393 | EditorGUILayout.LabelField ( "Style", EditorStyles.boldLabel, GUILayout.Width ( 50 ) ); 394 | currentStyle = EditorGUILayout.Popup ( currentStyle, GetStyles ( false ), GUILayout.Width ( 100 )); 395 | 396 | EditorGUILayout.Space (); 397 | 398 | // ^ Preview 399 | if ( skin.atlas != null && skin.atlas.mainTexture != null ) { 400 | GUI.color = tintColor; 401 | 402 | Rect newCoords = new Rect ( 403 | s.coordinates.x / skin.atlas.mainTexture.width, 404 | s.coordinates.y / skin.atlas.mainTexture.height, 405 | s.coordinates.width / skin.atlas.mainTexture.width, 406 | s.coordinates.height / skin.atlas.mainTexture.height 407 | ); 408 | 409 | Rect controlRect = EditorGUILayout.GetControlRect ( false, s.coordinates.height * 2, GUILayout.Width(s.coordinates.width * 2)); 410 | Vector3[] borderLines = CalcBorderLines ( controlRect, skin ); 411 | Texture previewTex = skin.atlas.mainTexture; 412 | 413 | GUI.DrawTextureWithTexCoords ( controlRect, previewTex, newCoords, true ); 414 | 415 | GUI.color = Color.white; 416 | 417 | Handles.DrawLine ( borderLines[0], borderLines[1] ); 418 | Handles.DrawLine ( borderLines[2], borderLines[3] ); 419 | Handles.DrawLine ( borderLines[4], borderLines[5] ); 420 | Handles.DrawLine ( borderLines[6], borderLines[7] ); 421 | } 422 | 423 | EditorGUILayout.EndHorizontal (); 424 | 425 | GUILayout.Space ( 20 ); 426 | 427 | // ^ Name 428 | EditorGUILayout.BeginHorizontal(); 429 | EditorGUILayout.LabelField ( "Name", GUILayout.Width ( 100 ) ); 430 | s.name = EditorGUILayout.TextField ( s.name ); 431 | EditorGUILayout.EndHorizontal(); 432 | 433 | // ^ Coordinates 434 | EditorGUILayout.BeginHorizontal(); 435 | EditorGUILayout.LabelField ( "Coordinates", GUILayout.Width ( 100 ) ); 436 | s.coordinates = EditorGUILayout.RectField ( s.coordinates ); 437 | if ( GUILayout.Button ( "Edit", GUILayout.Width ( 40 ), GUILayout.Height ( 30 ) ) ) { 438 | uvMode = true; 439 | } 440 | EditorGUILayout.EndHorizontal(); 441 | 442 | // ^ Border 443 | EditorGUILayout.BeginHorizontal(); 444 | EditorGUILayout.LabelField ( "Border", GUILayout.Width ( 100 ) ); 445 | 446 | EditorGUILayout.BeginVertical(); 447 | EditorGUILayout.BeginHorizontal(); 448 | EditorGUILayout.Space (); 449 | s.border.top = EditorGUILayout.FloatField ( s.border.top, GUILayout.Width ( 30 ) ); 450 | EditorGUILayout.Space (); 451 | EditorGUILayout.EndHorizontal(); 452 | EditorGUILayout.BeginHorizontal(); 453 | s.border.left = EditorGUILayout.FloatField ( s.border.left, GUILayout.Width ( 30 ) ); 454 | EditorGUILayout.Space (); 455 | s.border.right = EditorGUILayout.FloatField ( s.border.right, GUILayout.Width ( 30 ) ); 456 | EditorGUILayout.EndHorizontal(); 457 | EditorGUILayout.BeginHorizontal(); 458 | EditorGUILayout.Space (); 459 | s.border.bottom = EditorGUILayout.FloatField ( s.border.bottom, GUILayout.Width ( 30 ) ); 460 | EditorGUILayout.Space (); 461 | EditorGUILayout.EndHorizontal(); 462 | EditorGUILayout.EndVertical(); 463 | 464 | EditorGUILayout.EndHorizontal(); 465 | 466 | // ^ Color 467 | EditorGUILayout.BeginHorizontal(); 468 | EditorGUILayout.LabelField ( "Color", GUILayout.Width ( 100 ) ); 469 | s.color = EditorGUILayout.ColorField ( s.color ); 470 | 471 | tintColor = s.color; 472 | 473 | EditorGUILayout.EndHorizontal(); 474 | 475 | // ^ Text 476 | EditorGUILayout.Space (); 477 | 478 | showText = EditorGUILayout.Foldout ( showText, "Text" ); 479 | 480 | if ( s.text != null && showText ) { 481 | // ^^ Font 482 | EditorGUILayout.BeginHorizontal(); 483 | EditorGUILayout.LabelField ( "Font", GUILayout.Width ( 100 ) ); 484 | if ( s.text.fontIndex >= skin.fonts.Length ) { 485 | s.text.fontIndex = skin.fonts.Length - 1; 486 | 487 | } else if ( s.text.fontIndex < 0 ) { 488 | s.text.fontIndex = 0; 489 | 490 | } 491 | s.text.fontIndex = EditorGUILayout.Popup ( s.text.fontIndex, GetFonts ( skin )); 492 | s.text.font = skin.fonts[s.text.fontIndex]; 493 | EditorGUILayout.EndHorizontal(); 494 | 495 | // ^^ Size 496 | EditorGUILayout.BeginHorizontal(); 497 | EditorGUILayout.LabelField ( "Size", GUILayout.Width ( 100 ) ); 498 | s.text.fontSize = EditorGUILayout.IntField ( s.text.fontSize ); 499 | EditorGUILayout.EndHorizontal(); 500 | 501 | // ^^ Colour 502 | EditorGUILayout.BeginHorizontal(); 503 | EditorGUILayout.LabelField ( "Color", GUILayout.Width ( 100 ) ); 504 | s.text.fontColor = EditorGUILayout.ColorField ( s.text.fontColor ); 505 | EditorGUILayout.EndHorizontal(); 506 | 507 | // ^^ Alignment 508 | EditorGUILayout.BeginHorizontal(); 509 | EditorGUILayout.LabelField ( "Alignment", GUILayout.Width ( 100 ) ); 510 | s.text.alignment = (TextAnchor)EditorGUILayout.Popup ( (int)s.text.alignment, GetAnchors ()); 511 | EditorGUILayout.EndHorizontal(); 512 | 513 | // ^^ Word wrap 514 | EditorGUILayout.BeginHorizontal(); 515 | EditorGUILayout.LabelField ( "Word wrap", GUILayout.Width ( 100 ) ); 516 | s.text.wordWrap = EditorGUILayout.Toggle ( s.text.wordWrap ); 517 | EditorGUILayout.EndHorizontal(); 518 | 519 | // ^^ Padding 520 | EditorGUILayout.BeginHorizontal(); 521 | EditorGUILayout.LabelField ( "Padding", GUILayout.Width ( 100 ) ); 522 | 523 | EditorGUILayout.BeginVertical(); 524 | EditorGUILayout.BeginHorizontal(); 525 | EditorGUILayout.Space (); 526 | s.text.padding.top = (int)EditorGUILayout.FloatField ( s.text.padding.top, GUILayout.Width ( 30 ) ); 527 | EditorGUILayout.Space (); 528 | EditorGUILayout.EndHorizontal(); 529 | EditorGUILayout.BeginHorizontal(); 530 | s.text.padding.left = (int)EditorGUILayout.FloatField ( s.text.padding.left, GUILayout.Width ( 30 ) ); 531 | EditorGUILayout.Space (); 532 | s.text.padding.right = (int)EditorGUILayout.FloatField ( s.text.padding.right, GUILayout.Width ( 30 ) ); 533 | EditorGUILayout.EndHorizontal(); 534 | EditorGUILayout.BeginHorizontal(); 535 | EditorGUILayout.Space (); 536 | s.text.padding.bottom = (int)EditorGUILayout.FloatField ( s.text.padding.bottom, GUILayout.Width ( 30 ) ); 537 | EditorGUILayout.Space (); 538 | EditorGUILayout.EndHorizontal(); 539 | EditorGUILayout.EndVertical(); 540 | 541 | EditorGUILayout.EndHorizontal(); 542 | 543 | // ^^ Line height 544 | EditorGUILayout.BeginHorizontal(); 545 | EditorGUILayout.LabelField ( "Line height", GUILayout.Width ( 100 ) ); 546 | s.text.lineHeight = EditorGUILayout.FloatField ( s.text.lineHeight ); 547 | EditorGUILayout.EndHorizontal(); 548 | 549 | // ^^ Spacing 550 | EditorGUILayout.BeginHorizontal(); 551 | EditorGUILayout.LabelField ( "Spacing", GUILayout.Width ( 100 ) ); 552 | s.text.spacing = EditorGUILayout.FloatField ( s.text.spacing ); 553 | EditorGUILayout.EndHorizontal(); 554 | } 555 | 556 | GUILayout.Space ( 20 ); 557 | } 558 | 559 | // Fonts 560 | EditorGUILayout.LabelField ( "Fonts", EditorStyles.boldLabel ); 561 | List< OGFont > tmpList; 562 | 563 | if ( skin.fonts.Length < 1 ) { 564 | skin.fonts = new OGFont[1]; 565 | } 566 | 567 | for ( int i = 0; i < skin.fonts.Length; i++ ) { 568 | EditorGUILayout.BeginHorizontal(); 569 | 570 | EditorGUILayout.LabelField ( i.ToString(), GUILayout.Width ( 30 ) ); 571 | 572 | tempObj = (Object) skin.fonts[i]; 573 | tempObj = EditorGUILayout.ObjectField ( tempObj, typeof(OGFont), false ); 574 | skin.fonts[i] = (OGFont) tempObj; 575 | 576 | GUI.backgroundColor = Color.red; 577 | if ( GUILayout.Button ( "x", GUILayout.Width ( 30 ), GUILayout.Height ( 14 ) ) ) { 578 | tmpList = new List< OGFont > ( skin.fonts ); 579 | 580 | tmpList.RemoveAt ( i ); 581 | 582 | skin.fonts = tmpList.ToArray (); 583 | } 584 | GUI.backgroundColor = Color.white; 585 | 586 | EditorGUILayout.EndHorizontal(); 587 | } 588 | 589 | EditorGUILayout.BeginHorizontal(); 590 | 591 | GUI.backgroundColor = Color.green; 592 | if ( GUILayout.Button ( "+", GUILayout.Width ( 30 ), GUILayout.Height ( 14 ) ) ) { 593 | tmpList = new List< OGFont > ( skin.fonts ); 594 | 595 | tmpList.Add ( null ); 596 | 597 | skin.fonts = tmpList.ToArray (); 598 | } 599 | GUI.backgroundColor = Color.white; 600 | 601 | EditorGUILayout.EndHorizontal(); 602 | 603 | EditorGUILayout.Space(); 604 | 605 | // Font shader 606 | EditorGUILayout.LabelField ( "Font shader", EditorStyles.boldLabel ); 607 | tempObj = (Object) skin.fontShader; 608 | tempObj = EditorGUILayout.ObjectField ( tempObj, typeof(Shader), false ); 609 | skin.fontShader = (Shader) tempObj; 610 | 611 | EditorGUILayout.Space(); 612 | 613 | // Atlas 614 | EditorGUILayout.LabelField ( "Atlas", EditorStyles.boldLabel ); 615 | tempObj = (Object) skin.atlas; 616 | tempObj = EditorGUILayout.ObjectField ( tempObj, typeof(Material), false ); 617 | skin.atlas = (Material) tempObj; 618 | 619 | EditorGUILayout.Space(); 620 | 621 | // Delete mode 622 | if ( deleteMode ) { 623 | EditorGUILayout.LabelField ( "Delete style", EditorStyles.boldLabel ); 624 | 625 | EditorGUILayout.BeginHorizontal (); 626 | 627 | EditorGUILayout.LabelField ( "Are you sure?" ); 628 | 629 | // Cancel 630 | if ( GUILayout.Button ( "Cancel" ) ) { 631 | deleteMode = false; 632 | } 633 | 634 | GUI.backgroundColor = Color.red; 635 | if ( GUILayout.Button ( "Delete" ) ) { 636 | deleteMode = false; 637 | RemoveStyle ( currentStyle ); 638 | } 639 | GUI.backgroundColor = Color.white; 640 | 641 | EditorGUILayout.EndHorizontal (); 642 | 643 | // Add mode 644 | } else if ( addMode ) { 645 | EditorGUILayout.LabelField ( "Add style", EditorStyles.boldLabel ); 646 | 647 | EditorGUILayout.BeginHorizontal (); 648 | 649 | // Select 650 | addStyleName = EditorGUILayout.TextField ( addStyleName ); 651 | 652 | // Cancel 653 | if ( GUILayout.Button ( "Cancel" ) ) { 654 | addMode = false; 655 | } 656 | 657 | GUI.backgroundColor = Color.green; 658 | if ( GUILayout.Button ( "Create" ) ) { 659 | addMode = false; 660 | AddStyle ( addStyleName ); 661 | } 662 | GUI.backgroundColor = Color.white; 663 | 664 | EditorGUILayout.EndHorizontal (); 665 | 666 | // Else 667 | } else { 668 | EditorGUILayout.LabelField ( "Operations", EditorStyles.boldLabel ); 669 | 670 | EditorGUILayout.BeginHorizontal (); 671 | 672 | // Add Style 673 | GUI.backgroundColor = Color.green; 674 | if ( GUILayout.Button ( "Add style" ) ) { 675 | addStyleName = ""; 676 | addMode = true; 677 | } 678 | 679 | // Delete style 680 | GUI.backgroundColor = Color.red; 681 | if ( GUILayout.Button ( "Delete style" ) ) { 682 | deleteMode = true; 683 | } 684 | 685 | EditorGUILayout.EndHorizontal (); 686 | 687 | // Manage defaults 688 | GUI.backgroundColor = Color.white; 689 | if ( GUILayout.Button ( "Sort styles" ) ) { 690 | SortStyles ( skin ); 691 | } else if ( GUILayout.Button ( "Manage defaults", GUILayout.Height ( 30 ) ) ) { 692 | setDefaultsMode = true; 693 | } 694 | 695 | } 696 | 697 | EditorGUILayout.Space(); 698 | 699 | if ( GUI.changed ) { 700 | SavePrefab (); 701 | } 702 | } 703 | } 704 | } 705 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Editor/OpenGUI/OGSkinInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1aab05d021ddf9346bd64330800e1b36 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Editor/OpenGUI/OGWidgetInspector.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | 6 | [CustomEditor (typeof(OGWidget), true)] 7 | [System.Serializable] 8 | public class OGWidgetInspector : Editor { 9 | private string[] GetStyles ( OGWidget widget ) { 10 | List< string > tempList = new List< string >(); 11 | 12 | if ( widget && widget.root ) { 13 | foreach ( OGStyle style in widget.root.skin.styles ) { 14 | tempList.Add ( style.name ); 15 | } 16 | } 17 | 18 | return tempList.ToArray(); 19 | } 20 | 21 | private int GetStyleIndex ( OGWidget widget, OGStyle style ) { 22 | if ( widget.root && widget.root.skin ) { 23 | for ( int i = 0; i < widget.root.skin.styles.Length; i++ ) { 24 | if ( widget.root.skin.styles[i].name == style.name ) { 25 | return i; 26 | } 27 | } 28 | } 29 | 30 | return 0; 31 | } 32 | 33 | override public void OnInspectorGUI () { 34 | OGWidget widget = (OGWidget) target; 35 | 36 | if ( !widget || !widget.root ) { return; } 37 | 38 | // Check for hidden widgets 39 | if ( widget.hidden ) { 40 | EditorGUILayout.LabelField ( "This widget is rubbish that somehow didn't get deleted." ); 41 | 42 | // Kill! 43 | if ( GUILayout.Button ( "Fix" ) ) { 44 | DestroyImmediate ( target as GameObject ); 45 | } 46 | 47 | } else { 48 | // Default inspector 49 | DrawDefaultInspector (); 50 | 51 | // OGCameraWindow, OGLineNode and OGTexture don't need styles 52 | if ( target.GetType() != typeof(OGLineNode) && target.GetType() != typeof(OGTexture) && target.GetType() != typeof(OGCameraWindow) ) { 53 | EditorGUILayout.Space(); 54 | 55 | EditorGUILayout.LabelField ( "Style", EditorStyles.boldLabel ); 56 | 57 | foreach ( OGStyleType styleType in System.Enum.GetValues ( typeof(OGStyleType) ) as OGStyleType[] ) { 58 | if ( OGSkin.IsStyleUsed ( styleType, widget.ToEnum() ) ) { 59 | // Styles 60 | OGStyle wdStyle = widget.styles.GetStyle ( styleType ); 61 | int wdStyleIndex = GetStyleIndex ( widget, wdStyle ); 62 | EditorGUILayout.BeginHorizontal(); 63 | 64 | EditorGUILayout.LabelField ( styleType.ToString() ); 65 | 66 | wdStyleIndex = EditorGUILayout.Popup ( wdStyleIndex, GetStyles ( widget ) ); 67 | widget.styles.SetStyle ( styleType, widget.root.skin.styles [ wdStyleIndex ] ); 68 | 69 | // ^ Edit 70 | if ( GUILayout.Button ( "Edit", GUILayout.Width ( 40 ) ) ) { 71 | Selection.activeObject = widget.root.skin; 72 | OGSkinInspector.SetCurrentStyle ( wdStyleIndex ); 73 | } 74 | 75 | EditorGUILayout.EndHorizontal (); 76 | } 77 | } 78 | 79 | EditorGUILayout.BeginHorizontal(); 80 | 81 | // Get defaults 82 | if ( GUILayout.Button ( "Apply default styles" ) ) { 83 | ( target as OGWidget ).ApplyDefaultStyles(); 84 | } 85 | 86 | // ^ Edit 87 | if ( GUILayout.Button ( "Edit", GUILayout.Width ( 40 ) ) ) { 88 | Selection.activeObject = widget.root.skin; 89 | OGSkinInspector.SetDefaultsMode(); 90 | } 91 | 92 | EditorGUILayout.EndHorizontal (); 93 | } 94 | 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Editor/OpenGUI/OGWidgetInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 89c9f832a9b2a4a48b2090c98d5301db 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Example.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 036e8d16ee54643cfb6b370485f4ea0e 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Example/DropContainer.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/OpenGUI/Assets/Example/DropContainer.unity -------------------------------------------------------------------------------- /OpenGUI/Assets/Example/DropContainer.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3c43787fa704343eda7a9f1e06d9a14c 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Example/Example.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/OpenGUI/Assets/Example/Example.unity -------------------------------------------------------------------------------- /OpenGUI/Assets/Example/Example.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c32c7dfef887f00498524dc7aa942643 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Example/MultiPage.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/OpenGUI/Assets/Example/MultiPage.unity -------------------------------------------------------------------------------- /OpenGUI/Assets/Example/MultiPage.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f815b4e46a2e649b9bf76b10b7c81a0f 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Example/TextEditor.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/OpenGUI/Assets/Example/TextEditor.unity -------------------------------------------------------------------------------- /OpenGUI/Assets/Example/TextEditor.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4db83ea3ecec8484e996f340ce227d8d 3 | DefaultImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fbeca3213aab54b47a0502605f7a1ce0 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f987df3d5f6657f47baa9670b5466dd8 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Fonts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cb1565a319e1a96499c147082e33b81e 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Fonts/Ubuntu.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b91b6b2580f624c9f9cbcb6e0f38483a 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Fonts/Ubuntu/Ubuntu-R.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/OpenGUI/Assets/Plugins/OpenGUI/Fonts/Ubuntu/Ubuntu-R.prefab -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Fonts/Ubuntu/Ubuntu-R.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 71c50facf23474bf39105e5c98995d4b 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Fonts/Ubuntu/Ubuntu-R_dynamic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/OpenGUI/Assets/Plugins/OpenGUI/Fonts/Ubuntu/Ubuntu-R_dynamic.ttf -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Fonts/Ubuntu/Ubuntu-R_dynamic.ttf.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 35410564cecbc49e89c2567f01d103bd 3 | TrueTypeFontImporter: 4 | serializedVersion: 2 5 | fontSize: 48 6 | forceTextureCase: -2 7 | characterSpacing: 1 8 | characterPadding: 0 9 | includeFontData: 1 10 | use2xBehaviour: 0 11 | fontNames: [] 12 | customCharacters: 13 | fontRenderingMode: 0 14 | userData: 15 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Fonts/Ubuntu/Ubuntu-R_unicode.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/OpenGUI/Assets/Plugins/OpenGUI/Fonts/Ubuntu/Ubuntu-R_unicode.ttf -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Fonts/Ubuntu/Ubuntu-R_unicode.ttf.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 131adbf4c5e0eaf4eab283cb2d5fa72c 3 | TrueTypeFontImporter: 4 | serializedVersion: 2 5 | fontSize: 48 6 | forceTextureCase: -1 7 | characterSpacing: 1 8 | characterPadding: 0 9 | includeFontData: 1 10 | use2xBehaviour: 0 11 | fontNames: [] 12 | customCharacters: 13 | fontRenderingMode: 0 14 | userData: 15 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0f06fa7e4f96e0446990afa7199706e1 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGButton.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class OGButton : OGWidget { 5 | public string hiddenString = ""; 6 | public string text = ""; 7 | public GameObject target = null; 8 | public string message = ""; 9 | public string argument = ""; 10 | public OGDelegate func = null; 11 | public System.Action action = null; 12 | public System.Action< string > actionWithArgument = null; 13 | public MonoBehaviour argumentSource = null; 14 | public string argumentSourceField = ""; 15 | public bool enableImage = false; 16 | public Vector2 imageScale = Vector2.one; 17 | public Vector2 imageOffset = Vector2.zero; 18 | 19 | private bool isDown = false; 20 | 21 | 22 | //////////////////// 23 | // Rects 24 | //////////////////// 25 | private Rect GetImageRect () { 26 | return new Rect ( drawRct.x + ( drawRct.width / 2 ) - ( ( drawRct.width * imageScale.x ) / 2 ) + imageOffset.x, drawRct.y + ( drawRct.height / 2 ) - ( ( drawRct.height * imageScale.y ) / 2 ) - imageOffset.y, drawRct.width * imageScale.x, drawRct.height * imageScale.y ); 27 | } 28 | 29 | 30 | //////////////////// 31 | // Interact 32 | //////////////////// 33 | override public void OnMouseUp () { 34 | if ( func != null ) { 35 | if ( !string.IsNullOrEmpty ( argument ) ) { 36 | func ( argument ); 37 | 38 | } else { 39 | func (); 40 | 41 | } 42 | 43 | } else if ( action != null ) { 44 | action (); 45 | 46 | } else if ( actionWithArgument != null && !string.IsNullOrEmpty ( argument ) ) { 47 | actionWithArgument ( argument ); 48 | 49 | } else if ( target != null && !string.IsNullOrEmpty ( message ) ) { 50 | // if the source widget and source field are set then we 51 | // get the argument from this 52 | if ( argumentSource != null && !string.IsNullOrEmpty( argumentSourceField ) ) { 53 | target.SendMessage( message, argumentSource.GetType().GetField( argumentSourceField ).GetValue( argumentSource ) ); 54 | } else if ( !string.IsNullOrEmpty ( argument ) ) { 55 | target.SendMessage ( message, argument ); 56 | } else { 57 | target.SendMessage ( message, this ); 58 | } 59 | 60 | } else { 61 | Debug.LogWarning ( "OGButton '" + this.gameObject.name + "' | Target/message missing!" ); 62 | 63 | } 64 | 65 | OnMouseCancel (); 66 | } 67 | 68 | override public void OnMouseCancel () { 69 | isDown = false; 70 | root.ReleaseWidget (); 71 | } 72 | 73 | override public void OnMouseDown () { 74 | isDown = true; 75 | } 76 | 77 | 78 | //////////////////// 79 | // Update 80 | //////////////////// 81 | override public void UpdateWidget () { 82 | // Persistent vars 83 | isSelectable = true; 84 | 85 | // Styles 86 | if ( isDown ) { 87 | currentStyle = styles.active; 88 | } else if ( CheckMouseOver() ) { 89 | currentStyle = styles.hover; 90 | } else { 91 | currentStyle = styles.basic; 92 | } 93 | 94 | // Mouse 95 | mouseRct = drawRct; 96 | } 97 | 98 | 99 | //////////////////// 100 | // Draw 101 | //////////////////// 102 | override public void DrawSkin () { 103 | if ( currentStyle == null ) { return; } 104 | 105 | OGDrawHelper.DrawSlicedSprite ( drawRct, currentStyle, drawDepth, tint, clipTo ); 106 | 107 | if ( enableImage ) { 108 | OGDrawHelper.DrawSprite ( GetImageRect(), styles.thumb, drawDepth, tint, clipTo ); 109 | } 110 | } 111 | 112 | override public void DrawText () { 113 | OGDrawHelper.DrawLabel ( drawRct, text, currentStyle.text, drawDepth, tint, clipTo ); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGButton.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b939f26117da42740bc71b621d68273d 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGCameraWindow.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class OGCameraWindow : OGWidget { 5 | public Camera targetCamera; 6 | 7 | private Camera rootCamera; 8 | 9 | override public void UpdateWidget () { 10 | if ( targetCamera ) { 11 | if ( !rootCamera ) { 12 | rootCamera = root.GetComponent(); 13 | } 14 | 15 | targetCamera.rect = new Rect ( drawRct.x / Screen.width, drawRct.y / Screen.height, drawRct.width / Screen.width, drawRct.height / Screen.height ); 16 | 17 | // The target camera needs to render after the root camera 18 | if ( targetCamera.depth <= rootCamera.depth ) { 19 | targetCamera.depth = rootCamera.depth + 1; 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGCameraWindow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2086d12c5bcca9840805dda943e78504 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGDrawHelper.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | using System.Collections.Generic; 5 | 6 | [System.Serializable] 7 | public class OGDrawHelper { 8 | private static Vector2 texSize; 9 | private static OGRoot root; 10 | 11 | 12 | ////////////////// 13 | // Core 14 | ////////////////// 15 | // Pass 16 | public static void SetPass ( Material mat ) { 17 | mat.SetPass ( 0 ); 18 | texSize.x = mat.mainTexture.width; 19 | texSize.y = mat.mainTexture.height; 20 | } 21 | 22 | 23 | ////////////////// 24 | // Curve 25 | ////////////////// 26 | // Bezier 27 | public static Vector3 CalculateBezierPoint ( float t, Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3 ) { 28 | float u = 1 - t; 29 | float tt = t*t; 30 | float uu = u*u; 31 | float uuu = uu * u; 32 | float ttt = tt * t; 33 | 34 | Vector3 p = uuu * p0; 35 | p += 3 * uu * t * p1; 36 | p += 3 * u * tt * p2; 37 | p += ttt * p3; 38 | 39 | return p; 40 | } 41 | 42 | // Draw 43 | public static void DrawLine ( Vector3 start, Vector3 end, float depth ) { 44 | GL.Vertex ( start + new Vector3 ( 0, 0, depth ) ); 45 | GL.Vertex ( end + new Vector3 ( 0, 0, depth ) ); 46 | } 47 | 48 | public static void DrawCurve ( Vector3 start, Vector3 startDir, Vector3 endDir, Vector3 end, int segments ) { 49 | Vector3 lastPoint = Vector3.zero; 50 | 51 | for ( int i = 0; i < segments; i++ ) { 52 | float time = ( i * 1.0f ) * ( 1.0f / segments ); 53 | Vector3 p = CalculateBezierPoint ( time, start, startDir, endDir, end ); 54 | 55 | if ( i > 0f ) { 56 | GL.Vertex ( lastPoint ); 57 | GL.Vertex ( p ); 58 | } 59 | 60 | lastPoint = p; 61 | } 62 | } 63 | 64 | 65 | ////////////////// 66 | // Label 67 | ////////////////// 68 | // Get width 69 | public static float GetLabelWidth ( string str, OGTextStyle style ) { 70 | float width = style.padding.left + style.padding.right; 71 | 72 | float size = ( style.fontSize * 1.0f ) / style.font.size; 73 | float space = ( style.font.GetCharacterInfo ( " "[0] ).width * size ); 74 | 75 | for ( int c = 0; c < str.Length; c++ ) { 76 | if ( str[c] == " "[0] ) { 77 | width += space; 78 | 79 | } else { 80 | OGCharacterInfo info = style.font.GetCharacterInfo ( str[c] ); 81 | 82 | if ( info != null ) { 83 | width += info.width * size; 84 | } 85 | } 86 | } 87 | 88 | return width; 89 | } 90 | 91 | // Draw 92 | public static void DrawLabel ( Rect rect, string str, OGTextStyle style, float depth, Color tint ) { 93 | DrawLabel ( rect, str, style, style.fontSize, style.alignment, depth, tint, null, null ); 94 | } 95 | 96 | public static void DrawLabel ( Rect rect, string str, OGTextStyle style, float depth, Color tint, OGWidget clipping, OGTextEditor editor ) { 97 | DrawLabel ( rect, str, style, style.fontSize, style.alignment, depth, tint, clipping, editor ); 98 | } 99 | 100 | public static void DrawLabel ( Rect rect, string str, OGTextStyle style, float depth, Color tint, OGWidget clipping ) { 101 | DrawLabel ( rect, str, style, style.fontSize, style.alignment, depth, tint, clipping, null ); 102 | } 103 | 104 | public static void DrawLabel ( Rect rect, string str, OGTextStyle style, int intSize, TextAnchor alignment, float depth, Color tint ) { 105 | DrawLabel ( rect, str, style, intSize, alignment, depth, tint, null, null ); 106 | } 107 | 108 | public static void DrawLabel ( Rect rect, string str, OGTextStyle style, int intSize, TextAnchor alignment, float depth, Color tint, OGWidget clipping, OGTextEditor editor ) { 109 | // Check root 110 | if ( root == null ) { 111 | root = OGRoot.GetInstance (); 112 | return; 113 | } 114 | 115 | // Check font 116 | if ( style.font == null ) { 117 | style.font = OGRoot.GetInstance().skin.fonts [ style.fontIndex ]; 118 | return; 119 | } 120 | 121 | // Check string 122 | if ( string.IsNullOrEmpty ( str ) ) { 123 | if ( editor != null ) { 124 | editor.cursorIndex = 0; 125 | editor.cursorSelectIndex = 0; 126 | editor.cursorPos.x = rect.xMin; 127 | editor.cursorPos.y = rect.yMin - style.fontSize; 128 | } 129 | 130 | return; 131 | } 132 | 133 | // Check screen 134 | if ( rect.xMin > root.screenWidth || rect.xMax < 0 || rect.yMax < 0 || rect.yMin > root.screenHeight ) { 135 | return; 136 | } 137 | 138 | // Check clipping 139 | if ( clipping != null ) { 140 | if ( rect.xMin > clipping.drawRct.xMax || rect.xMax < clipping.drawRct.xMin || rect.yMax < clipping.drawRct.yMin || rect.yMin > clipping.drawRct.yMax ) { 141 | return; 142 | } 143 | } 144 | 145 | // Scale 146 | float size = ( intSize * 1.0f ) / style.font.size; 147 | Vector2 atlasSize = style.font.atlasSize; 148 | 149 | // Bounds 150 | float left = style.padding.left; 151 | float right = rect.width - style.padding.right - style.padding.left; 152 | float top = rect.height - style.padding.top; 153 | float bottom = style.padding.bottom; 154 | float middle = ( rect.height / 2 ) + ( ( style.font.info.lineSpacing * size ) / 2 ); 155 | float center = left + right / 2; 156 | 157 | // Positioning 158 | Vector2 anchor = Vector2.zero; 159 | float space = ( style.font.GetCharacterInfo ( " "[0] ).width * size ); 160 | 161 | // Line and progression management 162 | Vector2 advance = Vector2.zero; 163 | int nextLineStart = 0; 164 | int thisLineStart = 0; 165 | int lastSpace = 0; 166 | float lineWidth = 0; 167 | float lineWidthAtLastSpace = 0; 168 | float lineHeight = style.font.info.lineSpacing * size; 169 | int emergencyBrake = 0; 170 | 171 | // Temp vars 172 | OGCharacterInfo info; 173 | 174 | // Set anchor 175 | switch ( alignment ) { 176 | case TextAnchor.UpperLeft: 177 | anchor.x = left; 178 | anchor.y = top; 179 | break; 180 | 181 | case TextAnchor.MiddleLeft: 182 | anchor.x = left; 183 | anchor.y = middle; 184 | break; 185 | 186 | case TextAnchor.LowerLeft: 187 | anchor.x = left; 188 | anchor.y = bottom; 189 | break; 190 | 191 | case TextAnchor.UpperCenter: 192 | anchor.x = center; 193 | anchor.y = top; 194 | break; 195 | 196 | case TextAnchor.MiddleCenter: 197 | anchor.x = center; 198 | anchor.y = middle; 199 | break; 200 | 201 | case TextAnchor.LowerCenter: 202 | anchor.x = center; 203 | anchor.y = bottom; 204 | break; 205 | 206 | case TextAnchor.UpperRight: 207 | anchor.x = right; 208 | anchor.y = top; 209 | break; 210 | 211 | case TextAnchor.MiddleRight: 212 | anchor.x = right; 213 | anchor.y = middle; 214 | break; 215 | 216 | case TextAnchor.LowerRight: 217 | anchor.x = right; 218 | anchor.y = bottom; 219 | break; 220 | } 221 | 222 | // Color 223 | Color color = style.fontColor; 224 | color.r *= tint.r; 225 | color.g *= tint.g; 226 | color.b *= tint.b; 227 | color.a *= tint.a; 228 | GL.Color ( color ); 229 | 230 | // Draw loop 231 | while ( nextLineStart < str.Length && advance.y - style.padding.top > - ( rect.height - style.padding.top - style.padding.bottom ) ) { 232 | int c = 0; 233 | 234 | // Get next line 235 | lastSpace = 0; 236 | lineWidth = 0; 237 | thisLineStart = nextLineStart; 238 | 239 | // ^ Parse remaining string, set start and end integers 240 | for ( c = thisLineStart; c < str.Length; c++ ) { 241 | info = style.font.GetCharacterInfo ( str[c] ); 242 | 243 | // This character is a carriage return 244 | if ( str[c] == "\n"[0] ) { 245 | nextLineStart = c + 1; 246 | break; 247 | 248 | // This character is a space 249 | } else if ( str[c] == " "[0] ) { 250 | lineWidthAtLastSpace = lineWidth; 251 | lineWidth += space; 252 | lastSpace = c; 253 | 254 | // This character is a regular glyph 255 | } else if ( info != null ) { 256 | lineWidth += info.width * size; 257 | 258 | } 259 | 260 | // The line width has exceeded the border 261 | if ( lineWidth >= right ) { 262 | nextLineStart = lastSpace == 0 ? lastSpace : c + 1; 263 | lineWidth = lineWidthAtLastSpace; 264 | break; 265 | } 266 | } 267 | 268 | // The string has ended 269 | if ( c >= str.Length - 1 ) { 270 | nextLineStart = str.Length; 271 | } 272 | 273 | // Alignment advance adjustments 274 | if ( anchor.x == center ) { 275 | advance.x -= lineWidth / 2; 276 | } else if ( anchor.x == right ) { 277 | advance.x -= lineWidth; 278 | } 279 | 280 | // Draw glyphs 281 | for ( int g = thisLineStart; g < nextLineStart; g++ ) { 282 | info = style.font.GetCharacterInfo ( str[g] ); 283 | 284 | if ( info == null ) { 285 | continue; 286 | } 287 | 288 | Rect vert = new Rect ( info.vert.x * size, info.vert.y * size, info.vert.width * size, info.vert.height * size ); 289 | Vector2[] uv = new Vector2[4]; 290 | 291 | if ( info.flipped ) { 292 | uv[3] = new Vector2 ( info.uv.x, info.uv.y + info.uv.height ); 293 | uv[2] = new Vector2 ( info.uv.x + info.uv.width, info.uv.y + info.uv.height ); 294 | uv[1] = new Vector2 ( info.uv.x + info.uv.width, info.uv.y ); 295 | uv[0] = new Vector2 ( info.uv.x, info.uv.y ); 296 | } else { 297 | uv[0] = new Vector2 ( info.uv.x, info.uv.y ); 298 | uv[1] = new Vector2 ( info.uv.x, info.uv.y + info.uv.height ); 299 | uv[2] = new Vector2 ( info.uv.x + info.uv.width, info.uv.y + info.uv.height ); 300 | uv[3] = new Vector2 ( info.uv.x + info.uv.width, info.uv.y ); 301 | } 302 | 303 | // Quad corners 304 | float gLeft = anchor.x + vert.x + rect.x + advance.x; 305 | float gRight = anchor.x + vert.x + rect.x + advance.x + vert.width; 306 | float gBottom = anchor.y + vert.height + vert.y + rect.y + advance.y; 307 | float gTop = anchor.y + vert.height + vert.y + rect.y + advance.y - vert.height; 308 | 309 | // If it's a space, set appropriate corners 310 | if ( str[g] == " "[0] ) { 311 | gRight += space; 312 | } 313 | 314 | // Set cursor position 315 | if ( editor != null ) { 316 | if ( editor.cursorIndex == g ) { 317 | editor.cursorPos.x = gLeft; 318 | editor.cursorPos.y = gBottom; 319 | 320 | } else if ( editor.cursorIndex >= editor.str.Length && g == editor.str.Length - 1 ) { 321 | editor.cursorPos.x = gRight; 322 | editor.cursorPos.y = gBottom; 323 | 324 | } 325 | 326 | 327 | if ( editor.cursorSelectIndex == g ) { 328 | editor.cursorSelectPos.x = gLeft; 329 | editor.cursorSelectPos.y = gBottom; 330 | 331 | } else if ( editor.cursorSelectIndex >= editor.str.Length && g == editor.str.Length - 1 ) { 332 | editor.cursorSelectPos.x = gRight; 333 | editor.cursorSelectPos.y = gBottom; 334 | 335 | } 336 | 337 | editor.cursorSize.x = 1; 338 | editor.cursorSize.y = style.fontSize; 339 | } 340 | 341 | // If it's a space, continue the loop 342 | if ( str[g] == " "[0] ) { 343 | advance.x += space; 344 | continue; 345 | } 346 | 347 | // Advance regardless if the glyph is drawn or not 348 | advance.x += info.width * size; 349 | 350 | // Clipping 351 | if ( clipping != null ) { 352 | if ( gLeft < clipping.drawRct.xMin ) { 353 | uv[0].x += ( clipping.drawRct.xMin - gLeft ) / atlasSize.x; 354 | uv[1].x += ( clipping.drawRct.xMin - gLeft ) / atlasSize.x; 355 | gLeft = clipping.drawRct.xMin; 356 | } 357 | 358 | if ( gRight > clipping.drawRct.xMax ) { 359 | uv[2].x -= ( gRight - clipping.drawRct.xMax ) / atlasSize.x; 360 | uv[3].x -= ( gRight - clipping.drawRct.xMax ) / atlasSize.x; 361 | gRight = clipping.drawRct.xMax; 362 | } 363 | 364 | if ( gBottom < clipping.drawRct.yMin ) { 365 | uv[0].y += ( clipping.drawRct.yMin - gBottom ) / atlasSize.y; 366 | uv[3].y += ( clipping.drawRct.yMin - gBottom ) / atlasSize.y; 367 | gBottom = clipping.drawRct.yMin; 368 | } 369 | 370 | if ( gTop > clipping.drawRct.yMax ) { 371 | uv[1].y += ( gTop - clipping.drawRct.yMax ) / atlasSize.y; 372 | uv[2].y += ( gTop - clipping.drawRct.yMax ) / atlasSize.y; 373 | gTop = clipping.drawRct.yMax; 374 | } 375 | 376 | // If the sides overlap, the glyph shouldn't be drawn 377 | if ( gLeft >= gRight || gBottom >= gTop ) { 378 | continue; 379 | } 380 | } 381 | 382 | // Bottom Left 383 | GL.TexCoord2 ( uv[0].x, uv[0].y ); 384 | GL.Vertex3 ( gLeft, gBottom, depth ); 385 | 386 | // Top left 387 | GL.TexCoord2 ( uv[1].x, uv[1].y ); 388 | GL.Vertex3 ( gLeft, gTop, depth ); 389 | 390 | // Top right 391 | GL.TexCoord2 ( uv[2].x, uv[2].y ); 392 | GL.Vertex3 ( gRight, gTop, depth ); 393 | 394 | // Bottom right 395 | GL.TexCoord2 ( uv[3].x, uv[3].y ); 396 | GL.Vertex3 ( gRight, gBottom, depth ); 397 | 398 | } 399 | 400 | // Next line 401 | advance.y -= lineHeight; 402 | advance.x = 0; 403 | 404 | // Emergency 405 | if ( emergencyBrake > 1000 ) { 406 | Debug.Log ( "OGDrawHelper | Label exceeded 1000 lines!" ); 407 | return; 408 | } else { 409 | emergencyBrake++; 410 | } 411 | } 412 | 413 | GL.Color ( Color.white ); 414 | } 415 | 416 | 417 | ////////////////// 418 | // Sprites 419 | ////////////////// 420 | // Regular 421 | public static void DrawSprite ( Rect rect, OGStyle style, float depth, Color tint ) { 422 | if ( style == null ) { return; } 423 | 424 | DrawSprite ( rect, style, depth, tint, null ); 425 | } 426 | 427 | public static void DrawSprite ( Rect rect, OGStyle style, float depth, Color tint, OGWidget clipping ) { 428 | if ( style == null ) { return; } 429 | 430 | DrawSprite ( rect, style.coordinates, depth, style.color, tint, clipping ); 431 | } 432 | 433 | public static void DrawSprite ( Rect rect, Rect uvRect, float depth, Color color, Color tint, OGWidget clipping ) { 434 | if ( !root ) { 435 | root = OGRoot.GetInstance(); 436 | return; 437 | } 438 | 439 | // Check screen 440 | if ( rect.xMin > root.screenWidth || rect.xMax < 0 || rect.yMax < 0 || rect.yMin > root.screenHeight ) { 441 | return; 442 | } 443 | 444 | // Color 445 | color.r *= tint.r; 446 | color.g *= tint.g; 447 | color.b *= tint.b; 448 | color.a *= tint.a; 449 | GL.Color ( color ); 450 | 451 | // Quad corners 452 | float left = rect.x; 453 | float right = rect.x + rect.width; 454 | float bottom = rect.y; 455 | float top = rect.y + rect.height; 456 | 457 | // Check clipping 458 | if ( clipping != null ) { 459 | if ( rect.xMin > clipping.drawRct.xMax || rect.xMax < clipping.drawRct.xMin || rect.yMax < clipping.drawRct.yMin || rect.yMin > clipping.drawRct.yMax ) { 460 | return; 461 | } else { 462 | if ( left < clipping.drawRct.xMin ) { left = clipping.drawRct.xMin; } 463 | if ( right > clipping.drawRct.xMax ) { right = clipping.drawRct.xMax; } 464 | if ( bottom < clipping.drawRct.yMin ) { bottom = clipping.drawRct.yMin; } 465 | if ( top > clipping.drawRct.yMax ) { top = clipping.drawRct.yMax; } 466 | } 467 | } 468 | 469 | uvRect.x /= texSize.x; 470 | uvRect.y /= texSize.y; 471 | uvRect.width /= texSize.x; 472 | uvRect.height /= texSize.y; 473 | 474 | // Bottom Left 475 | GL.TexCoord2 ( uvRect.x, uvRect.y ); 476 | GL.Vertex3 ( left, bottom, depth ); 477 | 478 | // Top left 479 | GL.TexCoord2 ( uvRect.x, uvRect.y + uvRect.height ); 480 | GL.Vertex3 ( left, top, depth ); 481 | 482 | // Top right 483 | GL.TexCoord2 ( uvRect.x + uvRect.width, uvRect.y + uvRect.height ); 484 | GL.Vertex3 ( right, top, depth ); 485 | 486 | // Bottom right 487 | GL.TexCoord2 ( uvRect.x + uvRect.width, uvRect.y ); 488 | GL.Vertex3 ( right, bottom, depth ); 489 | 490 | // Reset color 491 | GL.Color ( Color.white ); 492 | } 493 | 494 | // Tiled 495 | public static void DrawTiledSprite ( Rect rect, OGStyle style, float depth, Color tint, float tileX, float tileY ) { 496 | DrawTiledSprite ( rect, style, depth, tint, tileX, tileY, null ); 497 | } 498 | 499 | public static void DrawTiledSprite ( Rect rect, OGStyle style, float depth, Color tint, float tileX, float tileY, OGWidget clipping ) { 500 | for ( int x = 0; x < tileX; x++ ) { 501 | for ( int y = 0; y < tileY; y++ ) { 502 | Vector2 newScale = new Vector2 ( rect.width / tileX, rect.height / tileY ); 503 | Vector2 newPosition = new Vector2 ( rect.x + x * newScale.x, rect.y + y * newScale.y ); 504 | 505 | DrawSprite ( new Rect ( newPosition.x, newPosition.y, newScale.x, newScale.y ), style, depth, tint, clipping ); 506 | } 507 | } 508 | } 509 | 510 | public static void DrawTiledSprite ( Rect rect, Rect uvRect, float depth, Color color, Color tint, float tileX, float tileY, OGWidget clipping ) { 511 | for ( int x = 0; x < tileX; x++ ) { 512 | for ( int y = 0; y < tileY; y++ ) { 513 | Vector2 newScale = new Vector2 ( rect.width / tileX, rect.height / tileY ); 514 | Vector2 newPosition = new Vector2 ( rect.x + x * newScale.x, rect.y + y * newScale.y ); 515 | 516 | DrawSprite ( new Rect ( newPosition.x, newPosition.y, newScale.x, newScale.y ), uvRect, depth, color, tint, clipping ); 517 | } 518 | } 519 | } 520 | 521 | // Sliced 522 | public static void DrawSlicedSprite ( Rect rect, OGStyle style, float depth, Color tint ) { 523 | DrawSlicedSprite ( rect, style, depth, tint, null ); 524 | } 525 | 526 | public static void DrawSlicedSprite ( Rect rect, OGStyle style, float depth, Color tint, OGWidget clipping ) { 527 | if ( style == null ) { return; } 528 | 529 | Rect uvRect = style.coordinates; 530 | OGSlicedSpriteOffset border = style.border; 531 | Color color = style.color; 532 | 533 | // If no border is defined, draw a regular sprite 534 | if ( border.left == 0 && border.right == 0 && border.top == 0 && border.bottom == 0 ) { 535 | DrawSprite ( rect, style, depth, tint, clipping ); 536 | 537 | // Draw all corners, panels and the center 538 | } else { 539 | // Bottom left corner 540 | DrawSprite ( 541 | new Rect ( rect.x, rect.y, border.left, border.bottom ), 542 | new Rect ( uvRect.x, uvRect.y, border.left, border.bottom ), 543 | depth, 544 | color, 545 | tint, 546 | clipping 547 | ); 548 | 549 | // Left panel 550 | DrawSprite ( 551 | new Rect ( rect.x, rect.y + border.bottom, border.left, rect.height - border.bottom - border.top ), 552 | new Rect ( uvRect.x, uvRect.y + border.bottom, border.left, uvRect.height - border.top - border.bottom ), 553 | depth, 554 | color, 555 | tint, 556 | clipping 557 | ); 558 | 559 | // Top left corner 560 | DrawSprite ( 561 | new Rect ( rect.x, rect.y + rect.height - border.top, border.left, border.top ), 562 | new Rect ( uvRect.x, uvRect.y + uvRect.height - border.top, border.left, border.top ), 563 | depth, 564 | color, 565 | tint, 566 | clipping 567 | ); 568 | 569 | // Top panel 570 | DrawSprite ( 571 | new Rect ( rect.x + border.left, rect.y + rect.height - border.top, rect.width - border.horizontal, border.top ), 572 | new Rect ( uvRect.x + border.left, uvRect.y + uvRect.height - border.top, uvRect.width - border.horizontal, border.top ), 573 | depth, 574 | color, 575 | tint, 576 | clipping 577 | ); 578 | 579 | // Top right corner 580 | DrawSprite ( 581 | new Rect ( rect.x + rect.width - border.right, rect.y + rect.height - border.top, border.right, border.top ), 582 | new Rect ( uvRect.x + uvRect.width - border.right, uvRect.y + uvRect.height - border.top, border.right, border.top ), 583 | depth, 584 | color, 585 | tint, 586 | clipping 587 | ); 588 | 589 | // Right panel 590 | DrawSprite ( 591 | new Rect ( rect.x + rect.width - border.right, rect.y + border.bottom, border.right, rect.height - border.vertical ), 592 | new Rect ( uvRect.x + uvRect.width - border.right, uvRect.y + border.bottom, border.right, uvRect.height - border.vertical ), 593 | depth, 594 | color, 595 | tint, 596 | clipping 597 | ); 598 | 599 | // Bottom left corner 600 | DrawSprite ( 601 | new Rect ( rect.x + rect.width - border.right, rect.y, border.right, border.bottom ), 602 | new Rect ( uvRect.x + uvRect.width - border.right, uvRect.y, border.right, border.bottom ), 603 | depth, 604 | color, 605 | tint, 606 | clipping 607 | ); 608 | 609 | // Top panel 610 | DrawSprite ( 611 | new Rect ( rect.x + border.left, rect.y, rect.width - border.horizontal, border.bottom ), 612 | new Rect ( uvRect.x + border.left, uvRect.y, uvRect.width - border.horizontal, border.bottom ), 613 | depth, 614 | color, 615 | tint, 616 | clipping 617 | ); 618 | 619 | // Center 620 | DrawSprite ( 621 | new Rect ( rect.x + border.left, rect.y + border.bottom, rect.width - border.right - border.left, rect.height - border.bottom - border.top ), 622 | new Rect ( uvRect.x + border.left, uvRect.y + border.bottom, uvRect.width - border.right - border.left, uvRect.height - border.bottom - border.top ), 623 | depth, 624 | color, 625 | tint, 626 | clipping 627 | ); 628 | } 629 | } 630 | 631 | // Tiled sliced 632 | public static void DrawTiledSlicedSprite ( Rect rect, OGStyle style, float depth, Color tint, float tileX, float tileY ) { 633 | DrawSlicedSprite ( rect, style, depth, tint, null ); 634 | } 635 | 636 | public static void DrawTiledSlicedSprite ( Rect rect, OGStyle style, float depth, Color tint, float tileX, float tileY, OGWidget clipping ) { 637 | Rect uvRect = style.coordinates; 638 | OGSlicedSpriteOffset border = style.border; 639 | Color color = style.color; 640 | 641 | // If no border is defined, draw a regular sprite 642 | if ( border.left == 0 && border.right == 0 && border.top == 0 && border.bottom == 0 ) { 643 | DrawSprite ( rect, style, depth, tint, clipping ); 644 | 645 | // Draw all corners, panels and the center 646 | } else { 647 | // Bottom left corner 648 | DrawSprite ( 649 | new Rect ( rect.x, rect.y, border.left, border.bottom ), 650 | new Rect ( uvRect.x, uvRect.y, border.left, border.bottom ), 651 | depth, 652 | color, 653 | tint, 654 | clipping 655 | ); 656 | 657 | // Left panel 658 | DrawTiledSprite ( 659 | new Rect ( rect.x, rect.y + border.bottom, border.left, rect.height - border.bottom - border.top ), 660 | new Rect ( uvRect.x, uvRect.y + border.bottom, border.left, uvRect.height - border.top - border.bottom ), 661 | depth, 662 | color, 663 | tint, 664 | 1.0f, 665 | tileY, 666 | clipping 667 | ); 668 | 669 | // Top left corner 670 | DrawSprite ( 671 | new Rect ( rect.x, rect.y + rect.height - border.top, border.left, border.top ), 672 | new Rect ( uvRect.x, uvRect.y + uvRect.height - border.top, border.left, border.top ), 673 | depth, 674 | color, 675 | tint, 676 | clipping 677 | ); 678 | 679 | // Top panel 680 | DrawTiledSprite ( 681 | new Rect ( rect.x + border.left, rect.y + rect.height - border.top, rect.width - border.horizontal, border.top ), 682 | new Rect ( uvRect.x + border.left, uvRect.y + uvRect.height - border.top, uvRect.width - border.horizontal, border.top ), 683 | depth, 684 | color, 685 | tint, 686 | tileX, 687 | 1.0f, 688 | clipping 689 | ); 690 | 691 | // Top right corner 692 | DrawSprite ( 693 | new Rect ( rect.x + rect.width - border.right, rect.y + rect.height - border.top, border.right, border.top ), 694 | new Rect ( uvRect.x + uvRect.width - border.right, uvRect.y + uvRect.height - border.top, border.right, border.top ), 695 | depth, 696 | color, 697 | tint, 698 | clipping 699 | ); 700 | 701 | // Right panel 702 | DrawTiledSprite ( 703 | new Rect ( rect.x + rect.width - border.right, rect.y + border.bottom, border.right, rect.height - border.vertical ), 704 | new Rect ( uvRect.x + uvRect.width - border.right, uvRect.y + border.bottom, border.right, uvRect.height - border.vertical ), 705 | depth, 706 | color, 707 | tint, 708 | 1.0f, 709 | tileY, 710 | clipping 711 | ); 712 | 713 | // Bottom left corner 714 | DrawSprite ( 715 | new Rect ( rect.x + rect.width - border.right, rect.y, border.right, border.bottom ), 716 | new Rect ( uvRect.x + uvRect.width - border.right, uvRect.y, border.right, border.bottom ), 717 | depth, 718 | color, 719 | tint, 720 | clipping 721 | ); 722 | 723 | // Top panel 724 | DrawTiledSprite ( 725 | new Rect ( rect.x + border.left, rect.y, rect.width - border.horizontal, border.bottom ), 726 | new Rect ( uvRect.x + border.left, uvRect.y, uvRect.width - border.horizontal, border.bottom ), 727 | depth, 728 | color, 729 | tint, 730 | tileX, 731 | 1.0f, 732 | clipping 733 | ); 734 | 735 | // Center 736 | DrawTiledSprite ( 737 | new Rect ( rect.x + border.left, rect.y + border.bottom, rect.width - border.right - border.left, rect.height - border.bottom - border.top ), 738 | new Rect ( uvRect.x + border.left, uvRect.y + border.bottom, uvRect.width - border.right - border.left, uvRect.height - border.bottom - border.top ), 739 | depth, 740 | color, 741 | tint, 742 | tileX, 743 | tileY, 744 | clipping 745 | ); 746 | } 747 | } 748 | } 749 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGDrawHelper.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 90d8581177f457846b325c9bfa777860 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGDropContainer.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class OGDropContainer : OGWidget { 5 | public bool displayName = true; 6 | public OGWidget containedObject = null; 7 | public float containedScale = 1; 8 | public GameObject target = null; 9 | public string droppedMessage = ""; 10 | public string clearedMessage = ""; 11 | 12 | 13 | //////////////////// 14 | // Interact 15 | //////////////////// 16 | private TouchPhase GetTouch () { 17 | if ( Input.touchCount < 1 ) { 18 | return (TouchPhase)(-1); 19 | 20 | } else { 21 | Touch touch = Input.GetTouch ( 0 ); 22 | 23 | return touch.phase; 24 | } 25 | } 26 | 27 | public void Clear () { 28 | if ( containedObject ) { 29 | Destroy ( containedObject.gameObject ); 30 | 31 | if ( target && !string.IsNullOrEmpty ( clearedMessage ) ) { 32 | target.SendMessage ( clearedMessage ); 33 | } 34 | } 35 | } 36 | 37 | 38 | //////////////////// 39 | // Update 40 | //////////////////// 41 | override public void UpdateWidget () { 42 | // Persistent vars 43 | isSelectable = true; 44 | 45 | if ( CheckMouseOver () ) { 46 | currentStyle = styles.hover; 47 | } else { 48 | currentStyle = styles.basic; 49 | } 50 | 51 | // Mouse 52 | if ( Input.GetMouseButtonUp ( 0 ) || GetTouch () == TouchPhase.Ended ) { 53 | if ( OGRoot.GetInstance().downWidget && OGRoot.GetInstance().downWidget.isDraggable && CheckMouseOver() ) { 54 | if ( containedObject ) { 55 | Destroy ( containedObject.gameObject ); 56 | } 57 | 58 | containedObject = (OGWidget)Instantiate ( OGRoot.GetInstance().downWidget ); 59 | containedObject.gameObject.name = containedObject.gameObject.name.Replace ( "(Clone)", "" ); 60 | containedObject.transform.parent = this.transform; 61 | containedObject.transform.localScale = new Vector3 ( containedScale, containedScale, 1 ); 62 | containedObject.transform.localPosition = new Vector3 ( 1 - containedScale, 1 - containedScale, -1 ); 63 | containedObject.isSelectable = false; 64 | containedObject.isDraggable = false; 65 | 66 | if ( target && !string.IsNullOrEmpty ( droppedMessage ) ) { 67 | target.SendMessage ( droppedMessage, this ); 68 | } 69 | } 70 | } 71 | 72 | mouseRct = drawRct; 73 | } 74 | 75 | 76 | //////////////////// 77 | // Draw 78 | //////////////////// 79 | override public void DrawSkin () { 80 | if ( currentStyle == null ) { return; } 81 | 82 | OGDrawHelper.DrawSlicedSprite ( drawRct, currentStyle, drawDepth, tint, clipTo ); 83 | } 84 | 85 | override public void DrawText () { 86 | if ( currentStyle == null ) { return; } 87 | 88 | if ( containedObject != null && displayName ) { 89 | OGDrawHelper.DrawLabel ( drawRct, containedObject.gameObject.name, currentStyle.text, drawDepth, tint, clipTo ); 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGDropContainer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 70165d08a367e4aac9a0b98eb911f890 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGDropDown.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | using System.Collections.Generic; 5 | 6 | public class OGDropDown : OGWidget { 7 | // Classes 8 | [System.Serializable] 9 | public class DropDownItem { 10 | public string name; 11 | public string message; 12 | public string argument; 13 | public bool tickable = false; 14 | public bool isTicked = false; 15 | } 16 | 17 | [System.Serializable] 18 | public class DropDownItemNested : DropDownItem { 19 | public bool tickoverrides = false; 20 | } 21 | 22 | [System.Serializable] 23 | public class DropDownItemRoot : DropDownItem { 24 | public DropDownItemNested[] nestedMenu; 25 | } 26 | 27 | // Vars 28 | public string title = ""; 29 | public GameObject target = null; 30 | public float nestedOffset = -10; 31 | public DropDownItemRoot[] submenu = null; 32 | public bool isDown = false; 33 | 34 | private int activeNestedMenu = -1; 35 | private float timeStamp; 36 | 37 | 38 | //////////////////// 39 | // Interaction 40 | //////////////////// 41 | override public void OnMouseUp () { 42 | if ( isDown ) { 43 | // Is the mouse over any nested menu items? 44 | if ( activeNestedMenu != -1 ) { 45 | for ( int n = 0; n < submenu[activeNestedMenu].nestedMenu.Length; n++ ) { 46 | if ( CheckMouseOver ( GetNestedItemRect ( n ) ) ) { 47 | SelectNestedItem ( n ); 48 | return; 49 | } 50 | } 51 | } 52 | 53 | // Is the mouse over any root menu items? 54 | for ( int s = 0; s < submenu.Length; s++ ) { 55 | if ( CheckMouseOver ( GetRootItemRect ( s ) ) ) { 56 | SelectRootItem ( s ); 57 | return; 58 | } 59 | } 60 | 61 | // Nope, exit 62 | Exit (); 63 | 64 | } else { 65 | isDown = true; 66 | 67 | } 68 | } 69 | 70 | override public void OnMouseCancel () { 71 | Exit (); 72 | } 73 | 74 | // Exit 75 | private void Exit () { 76 | isDown = false; 77 | activeNestedMenu = -1; 78 | 79 | root.ReleaseWidget (); 80 | } 81 | 82 | // Menu item 83 | public void SelectRootItem ( int i ) { 84 | DropDownItemRoot item = submenu[i]; 85 | 86 | if ( !string.IsNullOrEmpty ( item.message ) ) { 87 | if ( !string.IsNullOrEmpty ( item.argument ) ) { 88 | target.SendMessage ( item.message, item.argument ); 89 | } else { 90 | target.SendMessage ( item.message ); 91 | } 92 | } 93 | 94 | if ( item.tickable ) { 95 | item.isTicked = !item.isTicked; 96 | activeNestedMenu = -1; 97 | Exit (); 98 | 99 | } else if ( item.nestedMenu.Length > 0 ) { 100 | if ( activeNestedMenu == i ) { 101 | activeNestedMenu = -1; 102 | } else { 103 | activeNestedMenu = i; 104 | } 105 | 106 | } else { 107 | Exit (); 108 | 109 | } 110 | 111 | } 112 | 113 | // Nested item 114 | public void SelectNestedItem ( int i ) { 115 | if ( activeNestedMenu < 0 ) { 116 | Debug.LogWarning ( "OGDropDown | Nested menu out of bounds!" ); 117 | return; 118 | } 119 | 120 | DropDownItemNested item = submenu[activeNestedMenu].nestedMenu[i]; 121 | 122 | if ( item.tickable ) { 123 | if ( item.tickoverrides ) { 124 | for ( int o = 0; o < submenu[activeNestedMenu].nestedMenu.Length; o++ ) { 125 | submenu[activeNestedMenu].nestedMenu[o].isTicked = o == i; 126 | } 127 | } else { 128 | item.isTicked = !item.isTicked; 129 | } 130 | } 131 | 132 | Exit (); 133 | 134 | if ( !string.IsNullOrEmpty ( item.message ) ) { 135 | if ( !string.IsNullOrEmpty ( item.argument ) ) { 136 | target.SendMessage ( item.message, item.argument ); 137 | } else { 138 | target.SendMessage ( item.message ); 139 | } 140 | } 141 | } 142 | 143 | 144 | //////////////////// 145 | // Rects 146 | //////////////////// 147 | private Rect GetMouseRect () { 148 | return new Rect ( drawRct.x, drawRct.y, drawRct.width / 2, drawRct.height ); 149 | } 150 | 151 | private Rect GetRootBackgroundRect () { 152 | return new Rect ( drawRct.x, drawRct.y - submenu.Length * drawRct.height - styles.active.text.padding.top - styles.active.text.padding.bottom, drawRct.width, drawRct.height * submenu.Length + styles.active.text.padding.top + styles.active.text.padding.bottom ); 153 | } 154 | 155 | private Rect GetNestedBackgroundRect () { 156 | return new Rect ( drawRct.x + drawRct.width + nestedOffset, drawRct.y - ( activeNestedMenu + submenu[activeNestedMenu].nestedMenu.Length ) * drawRct.height - styles.active.text.padding.top - styles.active.text.padding.bottom, drawRct.width, drawRct.height * submenu[activeNestedMenu].nestedMenu.Length + styles.active.text.padding.bottom + styles.active.text.padding.top ); 157 | } 158 | 159 | private Rect GetRootItemRect ( int i ) { 160 | return new Rect ( drawRct.x, drawRct.y - ( ( 1 + i ) * drawRct.height ) - styles.active.text.padding.top, drawRct.width, drawRct.height ); 161 | } 162 | 163 | private Rect GetNestedItemRect ( int i ) { 164 | return new Rect ( drawRct.x + drawRct.width + nestedOffset, drawRct.y - ( 1 + activeNestedMenu + i ) * drawRct.height - styles.active.text.padding.top, drawRct.width, drawRct.height ); 165 | } 166 | 167 | private Rect GetTickRect ( int i, bool isRoot ) { 168 | if ( isRoot ) { 169 | return new Rect ( drawRct.x + drawRct.width - drawRct.height - styles.ticked.text.padding.right, drawRct.y - ( ( 1 + i ) * drawRct.height + styles.ticked.text.padding.top ), drawRct.height, drawRct.height ); 170 | } else { 171 | return new Rect ( drawRct.x + ( drawRct.width * 2 ) - drawRct.height - styles.ticked.text.padding.right + nestedOffset, drawRct.y - ( ( 1 + activeNestedMenu + i ) * drawRct.height + styles.ticked.text.padding.top ), drawRct.height, drawRct.height ); 172 | } 173 | } 174 | 175 | 176 | //////////////////// 177 | // Style 178 | //////////////////// 179 | private OGStyle GetRootItemStyle ( int i ) { 180 | if ( CheckMouseOver ( GetRootItemRect ( i ) ) ) { 181 | return styles.hover; 182 | } else { 183 | return styles.active; 184 | } 185 | } 186 | 187 | private OGStyle GetNestedItemStyle ( int i ) { 188 | if ( CheckMouseOver ( GetNestedItemRect ( i ) ) ) { 189 | return styles.hover; 190 | } else { 191 | return styles.active; 192 | } 193 | } 194 | 195 | 196 | //////////////////// 197 | // Update 198 | //////////////////// 199 | override public void UpdateWidget () { 200 | // Persistent vars 201 | isSelectable = true; 202 | 203 | // Mouse 204 | if ( isDown ) { 205 | if ( activeNestedMenu != -1 ) { 206 | mouseRct = CombineRects ( GetRootBackgroundRect(), GetNestedBackgroundRect() ); 207 | } else { 208 | mouseRct = GetRootBackgroundRect (); 209 | } 210 | } else { 211 | mouseRct = GetMouseRect(); 212 | } 213 | 214 | } 215 | 216 | 217 | //////////////////// 218 | // Draw 219 | //////////////////// 220 | override public void DrawSkin () { 221 | if ( isDown ) { 222 | OGDrawHelper.DrawSlicedSprite ( GetRootBackgroundRect (), styles.active, drawDepth, tint, clipTo ); 223 | 224 | // Draw item graphics 225 | for ( int s = 0; s < submenu.Length; s++ ) { 226 | if ( submenu[s].isTicked ) { 227 | OGDrawHelper.DrawSprite ( GetTickRect ( s, true ), styles.ticked, drawDepth, tint, clipTo ); 228 | 229 | } else if ( submenu[s].nestedMenu.Length > 0 ) { 230 | OGDrawHelper.DrawSprite ( GetTickRect ( s, true ), styles.thumb, drawDepth, tint, clipTo ); 231 | 232 | } 233 | 234 | if ( GetRootItemStyle ( s ) == styles.hover ) { 235 | OGDrawHelper.DrawSprite ( GetRootItemRect ( s ), styles.hover, drawDepth, tint, clipTo ); 236 | } 237 | } 238 | 239 | if ( activeNestedMenu != -1 ) { 240 | OGDrawHelper.DrawSlicedSprite ( GetNestedBackgroundRect (), styles.active, drawDepth, tint, clipTo ); 241 | 242 | for ( int n = 0; n < submenu[activeNestedMenu].nestedMenu.Length; n++ ) { 243 | if ( submenu[activeNestedMenu].nestedMenu[n].isTicked ) { 244 | OGDrawHelper.DrawSprite ( GetTickRect ( n, false ), styles.ticked, drawDepth, tint, clipTo ); 245 | } 246 | 247 | if ( GetNestedItemStyle ( n ) == styles.hover ) { 248 | OGDrawHelper.DrawSprite ( GetNestedItemRect ( n ), styles.hover, drawDepth, tint, clipTo ); 249 | } 250 | } 251 | } 252 | 253 | } 254 | } 255 | 256 | override public void DrawText () { 257 | OGDrawHelper.DrawLabel ( drawRct, title, styles.basic.text, drawDepth, tint ); 258 | 259 | if ( isDown ) { 260 | for ( int s = 0; s < submenu.Length; s++ ) { 261 | OGDrawHelper.DrawLabel ( GetRootItemRect ( s ), submenu[s].name, GetRootItemStyle ( s ).text, drawDepth, tint, clipTo ); 262 | } 263 | 264 | if ( activeNestedMenu != -1 ) { 265 | for ( int n = 0; n < submenu[activeNestedMenu].nestedMenu.Length; n++ ) { 266 | OGDrawHelper.DrawLabel ( GetNestedItemRect ( n ), submenu[activeNestedMenu].nestedMenu[n].name, GetNestedItemStyle ( n ).text, drawDepth, tint, clipTo ); 267 | } 268 | } 269 | } 270 | } 271 | } 272 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGDropDown.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2a395b1f620fb364f87750580b8f0672 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGFont.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | [System.Serializable] 5 | public class OGCharacterInfo { 6 | public int index; 7 | public float width; 8 | public Rect uv; 9 | public Rect vert; 10 | public bool flipped; 11 | 12 | public bool carriageReturn { 13 | get { 14 | return index == '\n'; 15 | } 16 | } 17 | 18 | public bool space { 19 | get { 20 | return index == ' '; 21 | } 22 | } 23 | } 24 | 25 | [System.Serializable] 26 | public class OGFontInfo { 27 | public string name; 28 | public float kerning; 29 | public float lineSpacing; 30 | public float ascent; 31 | public int convertCase; 32 | public int characterPadding; 33 | public int characterSpacing; 34 | public OGCharacterInfo[] characterRects; 35 | } 36 | 37 | public class OGFont : MonoBehaviour { 38 | public Font bitmapFont; 39 | public Font dynamicFont; 40 | public int size = 72; 41 | public OGFontInfo info; 42 | public Vector2 atlasSize; 43 | 44 | public void UpdateData () { 45 | #if UNITY_EDITOR 46 | UnityEditor.SerializedObject s = new UnityEditor.SerializedObject ( bitmapFont ); 47 | 48 | info.name = s.FindProperty ( "m_Name" ).stringValue; 49 | info.kerning = s.FindProperty ( "m_Kerning" ).floatValue; 50 | info.lineSpacing = s.FindProperty ( "m_LineSpacing" ).floatValue; 51 | info.ascent = s.FindProperty ( "m_Ascent" ).floatValue; 52 | info.characterPadding = s.FindProperty ( "m_CharacterPadding" ).intValue; 53 | info.characterSpacing = s.FindProperty ( "m_CharacterSpacing" ).intValue; 54 | info.convertCase = s.FindProperty ( "m_ConvertCase" ).intValue; 55 | 56 | int size = s.FindProperty ( "m_CharacterRects.Array.size" ).intValue; 57 | info.characterRects = new OGCharacterInfo[size]; 58 | 59 | for ( int i = 0; i < size; i++ ) { 60 | OGCharacterInfo ci = new OGCharacterInfo (); 61 | 62 | ci.index = s.FindProperty ( "m_CharacterRects.Array.data[" + i + "].index" ).intValue; 63 | ci.uv = s.FindProperty ( "m_CharacterRects.Array.data[" + i + "].uv" ).rectValue; 64 | ci.vert = s.FindProperty ( "m_CharacterRects.Array.data[" + i + "].vert" ).rectValue; 65 | ci.width = s.FindProperty ( "m_CharacterRects.Array.data[" + i + "].width" ).floatValue; 66 | ci.flipped = s.FindProperty ( "m_CharacterRects.Array.data[" + i + "].flipped" ).boolValue; 67 | 68 | info.characterRects[i] = ci; 69 | } 70 | 71 | atlasSize = new Vector2 ( bitmapFont.material.mainTexture.width, bitmapFont.material.mainTexture.height ); 72 | #endif 73 | } 74 | 75 | public OGCharacterInfo GetCharacterInfo ( int index ) { 76 | for ( int i = 0; i < info.characterRects.Length; i++ ) { 77 | if ( info.characterRects[i].index == index ) { 78 | return info.characterRects[i]; 79 | } 80 | } 81 | 82 | return null; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGFont.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a3eca26852d36416c92c338709395154 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGLabel.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class OGLabel : OGWidget { 5 | public string text = ""; 6 | public bool overrideFontSize = false; 7 | public int fontSize; 8 | public bool overrideAlignment = false; 9 | public TextAnchor alignment; 10 | 11 | [HideInInspector] public float lineWidth = 0; 12 | 13 | 14 | ///////////////// 15 | // Update 16 | ///////////////// 17 | override public void UpdateWidget () { 18 | // Update data 19 | if ( !overrideFontSize ) { 20 | fontSize = styles.basic.text.fontSize; 21 | } 22 | 23 | if ( !overrideAlignment ) { 24 | alignment = styles.basic.text.alignment; 25 | } 26 | 27 | // Mouse 28 | mouseRct = drawRct; 29 | } 30 | 31 | 32 | ////////////////// 33 | // Draw 34 | ////////////////// 35 | override public void DrawText () { 36 | OGDrawHelper.DrawLabel ( drawRct, text, styles.basic.text, fontSize, alignment, drawDepth, tint, clipTo, null ); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGLabel.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6cf85498c81483e49b991b79d244577a 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGLineNode.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | public class OGLineNode : OGWidget { 6 | public enum LineType { 7 | Straight, 8 | Bezier 9 | } 10 | 11 | [System.Serializable] 12 | public class Connection { 13 | public OGLineNode node; 14 | public Vector3[] segments = new Vector3 [0]; 15 | 16 | public Connection ( OGLineNode node ) { 17 | this.node = node; 18 | } 19 | 20 | public Connection ( OGLineNode node, Vector3[] segments ) { 21 | this.node = node; 22 | this.segments = segments; 23 | } 24 | 25 | public void SetSegment ( int i, Vector3 segment ) { 26 | List< Vector3 > tmp = new List< Vector3 > ( segments ); 27 | 28 | tmp.Insert ( i, segment ); 29 | 30 | segments = tmp.ToArray (); 31 | } 32 | } 33 | 34 | public LineType lineType; 35 | public Connection[] connections = new Connection [ 0 ]; 36 | 37 | public void AddConnection ( OGLineNode node ) { 38 | AddConnection ( node, new Vector3 [0] ); 39 | } 40 | 41 | public void AddConnection ( OGLineNode node, Vector3[] segments ) { 42 | List< Connection > tmp = new List< Connection > ( connections ); 43 | 44 | tmp.Add ( new Connection ( node, segments ) ); 45 | 46 | connections = tmp.ToArray (); 47 | } 48 | 49 | public void SetConnection ( int i, OGLineNode node ) { 50 | SetConnection ( i, node, new Vector3 [0] ); 51 | } 52 | 53 | public void SetConnection ( int i, OGLineNode node, Vector3[] segments ) { 54 | List< Connection > tmp = new List< Connection > ( connections ); 55 | 56 | if ( i >= tmp.Count ) { 57 | for ( int n = tmp.Count; n <= i; n++ ) { 58 | tmp.Add ( null ); 59 | } 60 | } 61 | 62 | tmp[i] = new Connection ( node, segments ); 63 | 64 | connections = tmp.ToArray (); 65 | } 66 | 67 | private static Vector2 ToVector2 (Vector3 v) { 68 | return new Vector2 (v.x, v.y); 69 | } 70 | 71 | override public void DrawLine () { 72 | for ( int i = 0; i < connections.Length; i++ ) { 73 | if ( connections[i] != null && connections[i].node != null ) { 74 | if ( lineType == LineType.Straight ) { 75 | if ( connections[i].segments.Length == 0 ) { 76 | OGDrawHelper.DrawLine ( drawRct.center, connections[i].node.drawRct.center, drawDepth ); 77 | 78 | } else { 79 | for ( int s = 0; s < connections[i].segments.Length; s++ ) { 80 | if ( s == 0 ) { 81 | OGDrawHelper.DrawLine ( drawRct.center, drawRct.center + ToVector2(connections[i].segments[s]), drawDepth ); 82 | 83 | } else if ( s == connections[i].segments.Length - 1 ) { 84 | OGDrawHelper.DrawLine ( drawRct.center + ToVector2(connections[i].segments[s-1]), drawRct.center + ToVector2(connections[i].segments[s]), drawDepth ); 85 | OGDrawHelper.DrawLine ( drawRct.center + ToVector2(connections[i].segments[s]), connections[i].node.drawRct.center, drawDepth ); 86 | 87 | } else { 88 | OGDrawHelper.DrawLine ( drawRct.center + ToVector2(connections[i].segments[s-1]), drawRct.center + ToVector2(connections[i].segments[s]), drawDepth ); 89 | 90 | } 91 | } 92 | } 93 | 94 | } else { 95 | Vector3 startDir = Vector3.zero; 96 | Vector3 endDir = Vector3.zero; 97 | 98 | if ( connections[i].segments.Length > 0 ) { 99 | startDir = connections[i].segments[0]; 100 | } 101 | 102 | if ( connections[i].segments.Length > 1 ) { 103 | endDir = connections[i].segments[1]; 104 | } 105 | 106 | OGDrawHelper.DrawCurve ( drawRct.center, startDir, endDir, connections[i].node.drawRct.center, 10 ); 107 | 108 | } 109 | } 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGLineNode.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b796bbaab3612be4bac5e5d21487ca77 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGListItem.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class OGListItem : OGWidget { 5 | public string text = ""; 6 | public bool isSelected = false; 7 | public bool isTicked = false; 8 | public Object obj; 9 | public GameObject target; 10 | public string message; 11 | public string hoverMessage; 12 | public string argument; 13 | public OGDelegate func; 14 | public OGDelegate hoverFunc; 15 | 16 | 17 | ////////////////// 18 | // Interaction 19 | ////////////////// 20 | private void Select () { 21 | isSelected = true; 22 | 23 | foreach ( OGListItem li in this.transform.parent.GetComponentsInChildren() ) { 24 | if ( li != this ) { 25 | li.isSelected = false; 26 | } 27 | } 28 | 29 | if ( hoverFunc != null ) { 30 | hoverFunc (); 31 | } 32 | 33 | if ( target != null ) { 34 | if ( !string.IsNullOrEmpty ( hoverMessage ) ) { 35 | if ( !string.IsNullOrEmpty ( argument ) ) { 36 | target.SendMessage ( hoverMessage, argument ); 37 | 38 | } else if ( obj != null ) { 39 | target.SendMessage ( hoverMessage, obj ); 40 | 41 | } else { 42 | target.SendMessage ( hoverMessage, this ); 43 | 44 | } 45 | } 46 | } 47 | } 48 | 49 | private void Action () { 50 | if ( func != null ) { 51 | func (); 52 | } 53 | 54 | if ( target != null ) { 55 | if ( !string.IsNullOrEmpty ( message ) ) { 56 | if ( !string.IsNullOrEmpty ( argument ) ) { 57 | target.SendMessage ( message, argument ); 58 | 59 | } else if ( obj != null ) { 60 | target.SendMessage ( message, obj ); 61 | 62 | } else { 63 | target.SendMessage ( message, this ); 64 | 65 | } 66 | } 67 | } 68 | } 69 | 70 | private void Tick () { 71 | isTicked = true; 72 | 73 | foreach ( OGListItem li in this.transform.parent.GetComponentsInChildren() ) { 74 | if ( li != this ) { 75 | li.isTicked = false; 76 | } 77 | } 78 | } 79 | 80 | override public void OnMouseCancel () { 81 | isSelected = false; 82 | } 83 | 84 | override public void OnMouseDown () { 85 | if ( !isDisabled ) { 86 | Action (); 87 | Tick (); 88 | } 89 | } 90 | 91 | override public void OnMouseOver () { 92 | if ( !isSelected && !isDisabled ) { 93 | Select (); 94 | } 95 | } 96 | 97 | 98 | ////////////////// 99 | // Update 100 | ////////////////// 101 | override public void UpdateWidget () { 102 | // Persistent vars 103 | isSelectable = true; 104 | 105 | // Mouse 106 | mouseRct = drawRct; 107 | 108 | // ^ Cancel check 109 | if ( !CheckMouseOver ( mouseRct ) ) { OnMouseCancel(); } 110 | 111 | // Styles 112 | if ( isSelected ) { 113 | currentStyle = this.styles.hover; 114 | } else if ( isTicked ) { 115 | currentStyle = this.styles.ticked; 116 | } else { 117 | currentStyle = this.styles.basic; 118 | } 119 | } 120 | 121 | ////////////////// 122 | // Draw 123 | ////////////////// 124 | override public void DrawSkin () { 125 | OGDrawHelper.DrawSlicedSprite ( drawRct, currentStyle, drawDepth, tint, clipTo ); 126 | } 127 | 128 | override public void DrawText () { 129 | OGDrawHelper.DrawLabel ( drawRct, text, currentStyle.text, drawDepth, tint, clipTo ); 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGListItem.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3c0d12cf30edcc24f8ffff496b0cbbda 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGPage.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class OGPage : MonoBehaviour { 5 | public string pageName = "New Page"; 6 | 7 | public void StartPage () {} 8 | public void UpdatePage () {} 9 | public void ExitPage () {} 10 | public void DrawPage () {} 11 | 12 | public void UpdateStyles () { 13 | foreach ( OGWidget w in this.transform.GetComponentsInChildren(true) ) { 14 | if ( w.root == null ) { 15 | w.root = OGRoot.GetInstance(); 16 | } 17 | 18 | if ( w.styles == null ) { 19 | w.ApplyDefaultStyles (); 20 | } 21 | 22 | w.styles.Refresh ( w.root.skin ); 23 | } 24 | } 25 | 26 | public void ResetStyles () { 27 | foreach ( OGWidget w in this.transform.GetComponentsInChildren(true) ) { 28 | w.ApplyDefaultStyles (); 29 | } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGPage.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ece6f022ee9515a478aa268f54388303 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGPopUp.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class OGPopUp : OGWidget { 5 | public string title = ""; 6 | public string[] options; 7 | public string selectedOption; 8 | public GameObject target; 9 | public string message; 10 | public bool passSelectedOption = false; 11 | public bool isUp = false; 12 | 13 | private float timeStamp; 14 | 15 | 16 | //////////////////// 17 | // Data 18 | //////////////////// 19 | public int selectedIndex { 20 | get { 21 | for ( int i = 0; i < options.Length; i++ ) { 22 | if ( selectedOption == options[i] ) { 23 | return i; 24 | } 25 | } 26 | 27 | return 0; 28 | } 29 | } 30 | 31 | 32 | //////////////////// 33 | // Options 34 | //////////////////// 35 | private Rect GetOptionRect ( int i ) { 36 | float bottom = drawRct.y - options.Length * drawRct.height; 37 | float top = drawRct.y + options.Length * drawRct.height; 38 | 39 | if ( bottom < 0 || clipTo && bottom < clipTo.drawRct.y ) { 40 | return new Rect ( drawRct.x, top - ( i * ( drawRct.height + styles.active.text.padding.bottom ) ), drawRct.width, drawRct.height ); 41 | } else { 42 | return new Rect ( drawRct.x, drawRct.y - ( ( 1 + i ) * drawRct.height ), drawRct.width, drawRct.height ); 43 | } 44 | } 45 | 46 | private OGStyle GetOptionStyle ( int i ) { 47 | return ( CheckMouseOver ( GetOptionRect ( i ) ) ) ? styles.hover : styles.active; 48 | } 49 | 50 | private int GetMouseOverOption () { 51 | for ( int i = 0; i < options.Length; i++ ) { 52 | if ( CheckMouseOver ( GetOptionRect ( i ) ) ) { 53 | return i; 54 | } 55 | } 56 | 57 | return -1; 58 | } 59 | 60 | private Rect GetThumbRect () { 61 | return new Rect ( drawRct.x + drawRct.width - drawRct.height - styles.basic.text.padding.right, drawRct.y, drawRct.height, drawRct.height ); 62 | } 63 | 64 | private Rect GetExpandedRect () { 65 | float totalHeight = styles.active.text.padding.bottom + styles.active.text.padding.top + drawRct.height + options.Length * drawRct.height; 66 | float bottom = drawRct.y - totalHeight + drawRct.height; 67 | 68 | if ( bottom < 0 || clipTo && bottom < clipTo.drawRct.y ) { 69 | return new Rect ( drawRct.x, drawRct.y, drawRct.width, totalHeight ); 70 | } else { 71 | return new Rect ( drawRct.x, bottom, drawRct.width, totalHeight ); 72 | } 73 | } 74 | 75 | public void SetOptions ( string[] list ) { 76 | options = list; 77 | } 78 | 79 | 80 | //////////////////// 81 | // Interaction 82 | //////////////////// 83 | override public void OnMouseUp () { 84 | int mouseOverOption = GetMouseOverOption (); 85 | 86 | if ( Time.time - timeStamp > 0.5 || mouseOverOption != -1 ) { 87 | OnMouseCancel (); 88 | } 89 | 90 | if ( mouseOverOption != -1 ) { 91 | selectedOption = options[mouseOverOption]; 92 | 93 | if ( target != null && !string.IsNullOrEmpty ( message ) ) { 94 | if ( passSelectedOption ) { 95 | target.SendMessage ( message, selectedOption ); 96 | } else { 97 | target.SendMessage ( message ); 98 | } 99 | } 100 | 101 | isUp = false; 102 | } 103 | } 104 | 105 | override public void OnMouseDown () { 106 | if ( !isUp && GetMouseOverOption() == -1 ) { 107 | isUp = true; 108 | timeStamp = Time.time; 109 | } 110 | } 111 | 112 | override public void OnMouseCancel () { 113 | isUp = false; 114 | 115 | OGRoot.GetInstance().ReleaseWidget (); 116 | } 117 | 118 | 119 | //////////////////// 120 | // Update 121 | //////////////////// 122 | override public void UpdateWidget () { 123 | // Persistent vars 124 | isSelectable = true; 125 | 126 | // Update data 127 | isAlwaysOnTop = isUp; 128 | 129 | // Mouse 130 | if ( isUp ) { 131 | mouseRct = GetExpandedRect (); 132 | } else { 133 | mouseRct = drawRct; 134 | } 135 | 136 | // Styles 137 | if ( isUp ) { 138 | currentStyle = styles.active; 139 | } else { 140 | currentStyle = styles.basic; 141 | } 142 | } 143 | 144 | 145 | /////////////////// 146 | // Draw 147 | /////////////////// 148 | override public void DrawSkin () { 149 | if ( isUp ) { 150 | OGDrawHelper.DrawSlicedSprite ( GetExpandedRect(), currentStyle, drawDepth, tint, clipTo ); 151 | 152 | for ( int i = 0; i < options.Length; i++ ) { 153 | if ( GetOptionStyle ( i ) == styles.hover ) { 154 | OGDrawHelper.DrawSprite ( GetOptionRect ( i ), styles.hover, drawDepth, tint, clipTo ); 155 | } 156 | } 157 | 158 | } else { 159 | OGDrawHelper.DrawSlicedSprite ( drawRct, currentStyle, drawDepth, tint, clipTo ); 160 | OGDrawHelper.DrawSprite ( GetThumbRect (), styles.thumb, drawDepth, tint, clipTo ); 161 | } 162 | } 163 | 164 | override public void DrawText () { 165 | if ( isUp ) { 166 | OGDrawHelper.DrawLabel ( drawRct, title, styles.basic.text, drawDepth, tint, clipTo ); 167 | 168 | for ( int i = 0; i < options.Length; i++ ) { 169 | OGDrawHelper.DrawLabel ( GetOptionRect ( i ), options[i], GetOptionStyle ( i ).text, drawDepth, tint, clipTo ); 170 | } 171 | 172 | } else if ( !string.IsNullOrEmpty ( selectedOption ) ) { 173 | OGDrawHelper.DrawLabel ( drawRct, selectedOption, currentStyle.text, drawDepth, tint, clipTo ); 174 | 175 | } else { 176 | OGDrawHelper.DrawLabel ( drawRct, title, currentStyle.text, drawDepth, tint, clipTo ); 177 | 178 | } 179 | } 180 | } 181 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGPopUp.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 85036f9f458ddb440b8cf020cb2bed1a 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGProgressBar.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class OGProgressBar : OGWidget { 5 | public enum LayoutType { 6 | Horizontal, 7 | Vertical 8 | } 9 | 10 | public float value = 0.5f; 11 | public Vector2 padding; 12 | public LayoutType type; 13 | 14 | public void SetValue ( float value ) { 15 | if ( this.value == value ) { return; } 16 | 17 | this.value = value; 18 | value = Mathf.Clamp ( value, 0, 1 ); 19 | } 20 | 21 | private Rect GetThumbRect () { 22 | if ( type == LayoutType.Horizontal ) { 23 | return new Rect ( drawRct.x + padding.x, drawRct.y + padding.y, ( drawRct.width - ( padding.x * 2 ) ) * value, drawRct.height - ( padding.y * 2 ) ); 24 | } else { 25 | return new Rect ( drawRct.x + padding.x, drawRct.y + padding.y, ( drawRct.width - ( padding.x * 2 ) ), (drawRct.height - ( padding.y * 2 )) * value ); 26 | 27 | } 28 | } 29 | 30 | 31 | ///////////////// 32 | // Draw 33 | ///////////////// 34 | override public void DrawSkin () { 35 | // Background 36 | OGDrawHelper.DrawSlicedSprite ( drawRct, styles.basic, drawDepth, tint, clipTo ); 37 | 38 | // Thumb 39 | OGDrawHelper.DrawSprite ( GetThumbRect (), styles.thumb, drawDepth, tint, clipTo ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGProgressBar.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5991fcaaf1e036d4e95ed9634cca37b7 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGRoot.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | public delegate void OGDelegate ( params object[] parameters ); 7 | 8 | [System.Serializable] 9 | public class OGLine { 10 | public OGWidget start; 11 | public Vector3 startDir; 12 | public OGWidget end; 13 | public Vector3 endDir; 14 | public int segments; 15 | 16 | public OGLine ( OGWidget start, Vector3 startDir, OGWidget end, Vector3 endDir, int segments ) { 17 | this.start = start; 18 | this.startDir = startDir; 19 | this.end = end; 20 | this.endDir = endDir; 21 | this.segments = segments; 22 | } 23 | } 24 | 25 | [ExecuteInEditMode] 26 | public class OGRoot : MonoBehaviour { 27 | 28 | public static OGRoot instance; 29 | 30 | public Vector2 targetResolution; 31 | public OGSkin skin; 32 | public OGPage[] currentPages = new OGPage [ 0 ]; 33 | public Material lineMaterial; 34 | public OGWidget downWidget; 35 | public bool isMouseOver = false; 36 | 37 | private OGWidget[] widgets; 38 | private List< OGWidget > mouseOver = new List< OGWidget > (); 39 | private Texture2D guiTex; 40 | private Camera cam; 41 | 42 | 43 | ////////////////// 44 | // Instance 45 | ////////////////// 46 | public static OGRoot GetInstance () { 47 | return instance; 48 | } 49 | 50 | public OGPage currentPage { 51 | get { 52 | if ( currentPages.Length > 0 ) { 53 | return currentPages [ 0 ]; 54 | 55 | } else { 56 | return null; 57 | 58 | } 59 | } 60 | } 61 | 62 | public Vector2 ratio { 63 | get { 64 | Vector2 result = Vector2.one; 65 | 66 | result.x = Screen.width / screenWidth; 67 | result.y = Screen.height / screenHeight; 68 | 69 | return result; 70 | } 71 | } 72 | 73 | public Vector2 reverseRatio { 74 | get { 75 | Vector2 result = Vector2.one; 76 | 77 | result.x = screenWidth / Screen.width; 78 | result.y = screenHeight / Screen.height; 79 | 80 | return result; 81 | } 82 | } 83 | 84 | public float screenWidth { 85 | get { 86 | if ( targetResolution.x > 0 ) { 87 | return targetResolution.x; 88 | 89 | } else if ( targetResolution.y > 0 ) { 90 | float ratio = targetResolution.y / Screen.height; 91 | 92 | return Screen.width * ratio; 93 | 94 | } else { 95 | return Screen.width; 96 | 97 | } 98 | } 99 | } 100 | 101 | public float screenHeight { 102 | get { 103 | if ( targetResolution.y > 0 ) { 104 | return targetResolution.y; 105 | 106 | } else if ( targetResolution.x > 0 ) { 107 | float ratio = targetResolution.x / Screen.width; 108 | 109 | return Screen.height * ratio; 110 | 111 | } else { 112 | return Screen.height; 113 | 114 | } 115 | } 116 | } 117 | 118 | 119 | ////////////////// 120 | // Page management 121 | ////////////////// 122 | public void RemoveFromCurrentPages ( OGPage page ) { 123 | List< OGPage > pages = new List< OGPage > ( currentPages ); 124 | 125 | pages.Remove ( page ); 126 | 127 | currentPages = pages.ToArray (); 128 | } 129 | 130 | public void AddToCurrentPages ( OGPage page ) { 131 | List< OGPage > pages = new List< OGPage > ( currentPages ); 132 | 133 | pages.Add ( page ); 134 | 135 | currentPages = pages.ToArray (); 136 | } 137 | 138 | public void SetCurrentPages ( OGPage[] pages ) { 139 | currentPages = pages; 140 | 141 | foreach ( OGPage p in this.GetComponentsInChildren(true) ) { 142 | foreach ( OGPage cp in pages ) { 143 | if ( p == cp ) { 144 | p.gameObject.SetActive ( true ); 145 | p.UpdateStyles (); 146 | 147 | if ( Application.isPlaying ) { 148 | p.StartPage (); 149 | } 150 | 151 | } else if ( p.gameObject.activeSelf ) { 152 | if ( Application.isPlaying ) { 153 | p.ExitPage (); 154 | } 155 | 156 | p.gameObject.SetActive ( false ); 157 | } 158 | } 159 | } 160 | } 161 | 162 | public void SetCurrentPage ( OGPage page ) { 163 | currentPages = new OGPage [] { page }; 164 | 165 | foreach ( OGPage p in this.GetComponentsInChildren(true) ) { 166 | if ( p == page ) { 167 | p.gameObject.SetActive ( true ); 168 | p.UpdateStyles (); 169 | 170 | if ( Application.isPlaying ) { 171 | p.StartPage (); 172 | } 173 | 174 | } else if ( p.gameObject.activeSelf ) { 175 | if ( Application.isPlaying ) { 176 | p.ExitPage (); 177 | } 178 | 179 | p.gameObject.SetActive ( false ); 180 | 181 | } 182 | } 183 | } 184 | 185 | public void GoToPages ( params string[] pageNames ) { 186 | List< OGPage > pages = new List< OGPage > (); 187 | 188 | foreach ( OGPage p in currentPages ) { 189 | p.ExitPage (); 190 | 191 | p.gameObject.SetActive ( false ); 192 | } 193 | 194 | foreach ( OGPage p in this.GetComponentsInChildren(true) ) { 195 | foreach ( string n in pageNames ) { 196 | if ( p.pageName == n ) { 197 | pages.Add ( p ); 198 | } 199 | } 200 | } 201 | 202 | SetCurrentPages ( pages.ToArray () ); 203 | } 204 | 205 | public void GoToPage ( string pageName ) { 206 | foreach ( OGPage p in this.GetComponentsInChildren(true) ) { 207 | if ( p.pageName == pageName ) { 208 | SetCurrentPage ( p ); 209 | } 210 | } 211 | 212 | if ( currentPage != null ) { 213 | currentPage.gameObject.SetActive ( true ); 214 | 215 | } 216 | } 217 | 218 | 219 | ////////////////// 220 | // Draw loop 221 | ////////////////// 222 | public void OnPostRender () { 223 | if ( skin != null && widgets != null ) { 224 | int i = 0; 225 | int o = 0; 226 | OGWidget w; 227 | 228 | GL.PushMatrix(); 229 | GL.LoadPixelMatrix ( 0, screenWidth, 0, screenHeight ); 230 | 231 | // Draw skin 232 | GL.Begin(GL.QUADS); 233 | OGDrawHelper.SetPass(skin.atlas); 234 | 235 | for ( i = 0; i < widgets.Length; i++ ) { 236 | w = widgets[i]; 237 | 238 | if ( w == null ) { 239 | continue; 240 | 241 | } else if ( w.drawRct.x == 0 && w.drawRct.y == 0 && w.drawRct.height == 0 && w.drawRct.width == 0 ) { 242 | w.Recalculate (); 243 | continue; 244 | } 245 | 246 | if ( w.currentStyle == null ) { 247 | w.currentStyle = w.styles.basic; 248 | } 249 | 250 | if ( w.gameObject.activeSelf && w.isDrawn && w.drawRct.height > 0 && w.drawRct.width > 0 ) { 251 | w.DrawSkin (); 252 | } 253 | } 254 | 255 | GL.End (); 256 | 257 | // Draw text 258 | for ( i = 0; i < skin.fonts.Length; i++ ) { 259 | if ( skin.fonts[0] == null ) { continue; } 260 | 261 | GL.Begin(GL.QUADS); 262 | 263 | if ( skin.fontShader != null && skin.fonts[i].bitmapFont != null ) { 264 | skin.fonts[i].bitmapFont.material.shader = skin.fontShader; 265 | } 266 | 267 | if ( skin.fonts[i].bitmapFont != null ) { 268 | OGDrawHelper.SetPass ( skin.fonts[i].bitmapFont.material ); 269 | } 270 | 271 | for ( o = 0; o < widgets.Length; o++ ) { 272 | w = widgets[o]; 273 | 274 | if ( w == null ) { continue; } 275 | 276 | if ( w.styles == null ) { 277 | skin.ApplyDefaultStyles ( w ); 278 | 279 | } else if ( w.isDrawn && w.gameObject.activeSelf ) { 280 | if ( w.currentStyle != null && w.currentStyle.text.fontIndex == i ) { 281 | if ( w.currentStyle.text.font == null ) { 282 | w.currentStyle.text.font = skin.fonts[i]; 283 | } 284 | 285 | w.DrawText (); 286 | } 287 | } 288 | } 289 | 290 | GL.End (); 291 | } 292 | 293 | // Draw lines 294 | if ( lineMaterial != null ) { 295 | GL.Begin(GL.LINES); 296 | lineMaterial.SetPass(0); 297 | 298 | for ( i = 0; i < widgets.Length; i++ ) { 299 | w = widgets[i]; 300 | 301 | if ( w != null && w.gameObject.activeSelf && w.isDrawn ) { 302 | w.DrawLine(); 303 | } 304 | } 305 | 306 | GL.End(); 307 | } 308 | 309 | // Draw textures 310 | for ( i = 0; i < widgets.Length; i++ ) { 311 | w = widgets[i]; 312 | 313 | if ( w != null && w.gameObject.activeSelf && w.isDrawn ) { 314 | w.DrawGL(); 315 | } 316 | } 317 | 318 | 319 | GL.PopMatrix(); 320 | } 321 | } 322 | 323 | 324 | ////////////////// 325 | // Init 326 | ////////////////// 327 | public void Awake () { 328 | instance = this; 329 | } 330 | 331 | public void Start () { 332 | if ( currentPage != null && Application.isPlaying ) { 333 | currentPage.StartPage (); 334 | } 335 | } 336 | 337 | 338 | ////////////////// 339 | // Update 340 | ////////////////// 341 | public void ReleaseWidget () { 342 | downWidget = null; 343 | } 344 | 345 | private OGWidget [] GetCurrentWidgets () { 346 | List< OGWidget > list = new List< OGWidget > (); 347 | 348 | for ( int i = 0; i < currentPages.Length; i++ ) { 349 | OGPage page = currentPages [ i ]; 350 | OGWidget[] ws = page.gameObject.GetComponentsInChildren(); 351 | 352 | for ( int w = 0; w < ws.Length; w++ ) { 353 | list.Add ( ws [ w ] ); 354 | } 355 | } 356 | 357 | return list.OrderByDescending ( (w) => w.transform.position.z ).ToArray (); 358 | } 359 | 360 | public void Update () { 361 | if ( instance == null ) { 362 | instance = this; 363 | } 364 | 365 | if ( !cam ) { 366 | cam = this.gameObject.GetComponent< Camera > (); 367 | 368 | if ( !cam ) { 369 | cam = this.gameObject.AddComponent< Camera > (); 370 | } 371 | } 372 | 373 | cam.hideFlags = HideFlags.None; 374 | cam.cullingMask = 1 << this.gameObject.layer; 375 | cam.clearFlags = CameraClearFlags.Depth; 376 | 377 | if ( Camera.main ) { 378 | cam.depth = Camera.main.depth + 5; 379 | } 380 | 381 | this.transform.localScale = Vector3.one; 382 | this.transform.localPosition = Vector3.zero; 383 | this.transform.localEulerAngles = Vector3.zero; 384 | 385 | // Dirty 386 | UpdateWidgets (); 387 | 388 | // Only update these when playing 389 | if ( Application.isPlaying && currentPage != null ) { 390 | // Current page 391 | currentPage.UpdatePage (); 392 | 393 | // Update styles if in edit mode 394 | if ( !Application.isPlaying ) { 395 | currentPage.UpdateStyles (); 396 | } 397 | 398 | // Mouse interaction 399 | UpdateMouse (); 400 | } 401 | 402 | // Force OGPage transformation 403 | if ( currentPage ) { 404 | currentPage.gameObject.layer = this.gameObject.layer; 405 | 406 | currentPage.transform.localScale = Vector3.one; 407 | currentPage.transform.localPosition = Vector3.zero; 408 | currentPage.transform.localEulerAngles = Vector3.zero; 409 | } 410 | } 411 | 412 | 413 | ////////////////// 414 | // Mouse interaction 415 | ////////////////// 416 | private Vector2 GetDragging () { 417 | Vector2 dragging = Vector2.zero; 418 | 419 | if ( Input.GetMouseButton ( 0 ) || Input.GetMouseButton ( 2 ) ) { 420 | dragging.x = Input.GetAxis ( "Mouse X" ); 421 | dragging.y = Input.GetAxis ( "Mouse Y" ); 422 | 423 | } else if ( GetTouch () == TouchPhase.Moved ) { 424 | Touch t = Input.GetTouch ( 0 ); 425 | dragging = t.deltaPosition * ( Time.deltaTime / t.deltaTime ); 426 | } 427 | 428 | return dragging; 429 | } 430 | 431 | private TouchPhase GetTouch () { 432 | if ( Input.touchCount < 1 ) { 433 | return (TouchPhase)(-1); 434 | 435 | } else { 436 | Touch touch = Input.GetTouch ( 0 ); 437 | 438 | return touch.phase; 439 | } 440 | } 441 | 442 | public void UpdateMouse () { 443 | if ( widgets == null ) { return; } 444 | 445 | int i = 0; 446 | OGWidget w; 447 | 448 | // Click 449 | if ( Input.GetMouseButtonDown ( 0 ) || Input.GetMouseButtonDown ( 2 ) || GetTouch () == TouchPhase.Began ) { 450 | OGWidget topWidget = null; 451 | 452 | for ( i = 0; i < mouseOver.Count; i++ ) { 453 | w = mouseOver[i]; 454 | 455 | if ( ( w.GetType() != typeof ( OGScrollView ) || ( w as OGScrollView ).touchControl ) && ( topWidget == null || w.transform.position.z < topWidget.transform.position.z ) && w.isSelectable ) { 456 | topWidget = w; 457 | } 458 | } 459 | 460 | if ( downWidget && downWidget != topWidget ) { 461 | downWidget.OnMouseCancel (); 462 | } 463 | 464 | if ( topWidget != null && topWidget.CheckMouseOver() && !topWidget.isDisabled ) { 465 | topWidget.OnMouseDown (); 466 | downWidget = topWidget; 467 | } 468 | 469 | // Release 470 | } else if ( Input.GetMouseButtonUp ( 0 ) || Input.GetMouseButtonUp ( 2 ) || GetTouch () == TouchPhase.Ended || GetTouch () == TouchPhase.Canceled ) { 471 | if ( downWidget ) { 472 | // Draggable 473 | if ( downWidget.resetAfterDrag && downWidget.GetType() != typeof ( OGScrollView ) ) { 474 | downWidget.transform.position = downWidget.dragOrigPos; 475 | downWidget.dragOffset = Vector3.zero; 476 | downWidget.dragOrigPos = Vector3.zero; 477 | } 478 | 479 | // Mouse over 480 | if ( ( downWidget.CheckMouseOver() || GetTouch () == TouchPhase.Ended ) && !downWidget.isDisabled && downWidget.CheckMouseOver()) { 481 | downWidget.OnMouseUp (); 482 | 483 | // Mouse out 484 | } else { 485 | downWidget.OnMouseCancel (); 486 | 487 | } 488 | 489 | } 490 | 491 | // Dragging 492 | } else if ( GetDragging () != Vector2.zero ) { 493 | if ( downWidget != null && !downWidget.isDisabled ) { 494 | if ( downWidget.clipTo && downWidget.clipTo.GetType() == typeof ( OGScrollView ) && ( downWidget.clipTo as OGScrollView ).touchControl ) { 495 | OGWidget thisWidget = downWidget; 496 | thisWidget.OnMouseCancel (); 497 | downWidget = thisWidget.clipTo; 498 | } 499 | 500 | downWidget.OnMouseDrag (); 501 | 502 | if ( downWidget.isDraggable && downWidget.GetType() != typeof ( OGScrollView ) ) { 503 | Vector3 mousePos = Input.mousePosition; 504 | mousePos.y = screenHeight - mousePos.y; 505 | 506 | if ( downWidget.dragOffset == Vector3.zero ) { 507 | if ( downWidget.resetAfterDrag ) { 508 | downWidget.dragOrigPos = downWidget.transform.position; 509 | } 510 | 511 | downWidget.dragOffset = downWidget.transform.position - mousePos; 512 | } 513 | 514 | Vector3 newPos = downWidget.transform.position; 515 | newPos = mousePos + downWidget.dragOffset; 516 | downWidget.transform.position = newPos; 517 | } 518 | } 519 | } 520 | 521 | // Escape key 522 | if ( Input.GetKeyDown ( KeyCode.Escape ) ) { 523 | if ( downWidget != null ) { 524 | downWidget.OnMouseCancel (); 525 | ReleaseWidget (); 526 | } 527 | } 528 | } 529 | 530 | // OnGUI selection 531 | #if UNITY_EDITOR 532 | 533 | public static System.Action EditorSelectWidget = null; 534 | 535 | private OGWidget FindMouseOverWidget ( Event e ) { 536 | Vector2 pos = new Vector2 ( e.mousePosition.x * reverseRatio.x, screenHeight - e.mousePosition.y * reverseRatio.y ); 537 | 538 | for ( int i = widgets.Length - 1; i >= 0; i-- ) { 539 | if ( widgets[i].drawRct.Contains ( pos ) ) { 540 | return widgets[i]; 541 | } 542 | } 543 | 544 | return null; 545 | } 546 | 547 | private void MoveSelection ( float x, float y ) { 548 | for ( int i = 0; i < UnityEditor.Selection.gameObjects.Length; i++ ) { 549 | OGWidget w = UnityEditor.Selection.gameObjects[i].GetComponent(); 550 | 551 | if ( w ) { 552 | Vector3 newPos = new Vector3 ( x, y, 0 ); 553 | 554 | w.transform.localPosition = w.transform.localPosition + newPos; 555 | } 556 | } 557 | } 558 | 559 | public void OnGUI () { 560 | Event e = Event.current; 561 | 562 | if ( !Application.isPlaying ) { 563 | Color color = Color.white; 564 | 565 | if ( !guiTex ) { 566 | guiTex = new Texture2D ( 1, 1 ); 567 | guiTex.SetPixel ( 0, 0, color ); 568 | guiTex.Apply (); 569 | } 570 | 571 | GUIStyle style = new GUIStyle(); 572 | style.normal.background = guiTex; 573 | OGWidget w = null; 574 | 575 | for ( int i = 0; i < UnityEditor.Selection.gameObjects.Length; i++ ) { 576 | w = UnityEditor.Selection.gameObjects[i].GetComponent(); 577 | 578 | if ( w ) { 579 | Rect revRect = w.scaledRct; 580 | revRect.y = Screen.height - revRect.y - revRect.height; 581 | 582 | Rect pivotRect = new Rect ( w.transform.position.x - 2, w.transform.position.y - 2, 4, 4 ); 583 | 584 | pivotRect.x *= ratio.x; 585 | pivotRect.width *= ratio.x; 586 | pivotRect.y *= ratio.y; 587 | pivotRect.height *= ratio.y; 588 | 589 | UnityEditor.Handles.color = color; 590 | 591 | // Draw outline 592 | UnityEditor.Handles.DrawPolyLine ( 593 | new Vector3 ( revRect.xMin, revRect.yMin, 0 ), 594 | new Vector3 ( revRect.xMin, revRect.yMax, 0 ), 595 | new Vector3 ( revRect.xMax, revRect.yMax, 0 ), 596 | new Vector3 ( revRect.xMax, revRect.yMin, 0 ), 597 | new Vector3 ( revRect.xMin, revRect.yMin, 0 ) 598 | ); 599 | 600 | // Draw pivot 601 | GUI.Box ( pivotRect, "", style ); 602 | 603 | } 604 | } 605 | 606 | switch ( e.type ) { 607 | case EventType.MouseDown: 608 | w = FindMouseOverWidget ( e ); 609 | 610 | EditorSelectWidget ( w, e.shift ); 611 | 612 | break; 613 | 614 | case EventType.KeyDown: 615 | int modifier = 1; 616 | 617 | if ( e.shift ) { 618 | modifier = 10; 619 | } 620 | 621 | switch ( e.keyCode ) { 622 | case KeyCode.UpArrow: 623 | MoveSelection ( 0, -modifier ); 624 | break; 625 | 626 | case KeyCode.DownArrow: 627 | MoveSelection ( 0, modifier ); 628 | break; 629 | 630 | case KeyCode.LeftArrow: 631 | MoveSelection ( -modifier, 0 ); 632 | break; 633 | 634 | case KeyCode.RightArrow: 635 | MoveSelection ( modifier, 0 ); 636 | break; 637 | } 638 | 639 | break; 640 | } 641 | } 642 | } 643 | #endif 644 | 645 | 646 | ////////////////// 647 | // Widget management 648 | ////////////////// 649 | public void UpdateWidgets () { 650 | if ( currentPage == null ) { return; } 651 | 652 | mouseOver.Clear (); 653 | 654 | // Update widget lists 655 | widgets = GetCurrentWidgets (); 656 | 657 | for ( int i = 0; i < widgets.Length; i++ ) { 658 | OGWidget w = widgets[i]; 659 | 660 | if ( w == null || !w.isDrawn || w.isDisabled ) { continue; } 661 | 662 | // Check mouse 663 | if ( w.CheckMouseOver() ) 664 | { 665 | w.OnMouseOver (); 666 | mouseOver.Add ( w ); 667 | } 668 | 669 | // Check scroll offset 670 | if ( !w.clipTo ) { 671 | w.scrollOffset.x = 0; 672 | w.scrollOffset.y = 0; 673 | } 674 | 675 | w.root = this; 676 | w.gameObject.layer = this.gameObject.layer; 677 | w.UpdateWidget (); 678 | w.Recalculate (); 679 | 680 | // Cleanup from previous OpenGUI versions 681 | if ( w.hidden ) { 682 | DestroyImmediate ( w.gameObject ); 683 | } 684 | } 685 | 686 | // Is mouse over anything? 687 | isMouseOver = mouseOver.Count > 0; 688 | } 689 | } 690 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGRoot.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8e5734da34424da42a06790d50338a49 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGScrollView.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class OGScrollView : OGWidget { 5 | public enum ScrollDirection { 6 | None, 7 | X, 8 | Y 9 | } 10 | 11 | public enum ScrollbarVisibility { 12 | Hidden, 13 | Auto 14 | } 15 | 16 | public bool touchControl = false; 17 | public bool infiniteScrolling = false; 18 | public ScrollDirection lockAxis; 19 | public ScrollbarVisibility scrollbarVisibility = ScrollbarVisibility.Auto; 20 | public Vector2 size; 21 | public Vector2 position; 22 | public Vector2 padding = new Vector2 ( 10, 10 ); 23 | public float elasticity = 2; 24 | public Vector2 thumbScale = new Vector2 ( 16, 1 ); 25 | 26 | private OGWidget[] widgets; 27 | private Vector2 bounds; 28 | private bool inPlace = true; 29 | 30 | 31 | //////////////// 32 | // Rects 33 | //////////////// 34 | private Rect GetScrollbarYRect () { 35 | Vector2 size = new Vector2 ( thumbScale.x, ( drawRct.height + bounds.y ) * thumbScale.y ); 36 | Vector2 pos = new Vector2 ( drawRct.xMax - thumbScale.x, drawRct.yMax - size.y ); 37 | float percentage = Mathf.Clamp ( position.y, bounds.y, 0 ) / bounds.y; 38 | 39 | pos.y -= percentage * ( drawRct.height - size.y ); 40 | 41 | return new Rect ( pos.x, pos.y, size.x, size.y ); 42 | } 43 | 44 | private Rect GetScrollbarXRect () { 45 | Vector2 size = new Vector2 ( ( drawRct.width + bounds.x ) * thumbScale.y, thumbScale.x ); 46 | Vector2 pos = new Vector2 ( drawRct.xMin, drawRct.yMin ); 47 | float percentage = Mathf.Clamp ( position.x, bounds.x, 0 ) / bounds.x; 48 | 49 | pos.x += percentage * ( drawRct.width - size.x ); 50 | 51 | return new Rect ( pos.x, pos.y, size.x, size.y ); 52 | } 53 | 54 | 55 | //////////////// 56 | // Update 57 | //////////////// 58 | private void UpdateChildren () { 59 | widgets = this.gameObject.GetComponentsInChildren(); 60 | 61 | bounds = Vector2.zero; 62 | 63 | for ( int i = 0; i < widgets.Length; i++ ) { 64 | OGWidget w = widgets[i]; 65 | 66 | if ( w != null && w != this ) { 67 | w.scrollOffset = new Vector3 ( padding.x + position.x, padding.y + position.y, 0 ); 68 | 69 | // Reposition for infinite scrolling 70 | CheckWidgetOffset ( w ); 71 | 72 | w.anchor.x = RelativeX.None; 73 | w.anchor.y = RelativeY.None; 74 | w.clipTo = this; 75 | 76 | float bottom = w.transform.position.y - this.transform.position.y + w.transform.localScale.y - size.y + padding.y * 2; 77 | float right = w.transform.position.x - this.transform.position.x + w.transform.localScale.x - size.x + padding.x * 2; 78 | 79 | if ( -bottom < bounds.y ) { 80 | bounds.y = -bottom; 81 | } 82 | 83 | if ( -right < bounds.x ) { 84 | bounds.x = -right; 85 | } 86 | } 87 | } 88 | } 89 | 90 | private IEnumerator SnapBack () { 91 | inPlace = false; 92 | 93 | bool xInPlace = false; 94 | bool yInPlace = false; 95 | 96 | // If the scoll position is not in place, keep going 97 | while ( !inPlace ) { 98 | // Out of bounds top 99 | if ( !IsInfiniteY() && position.y > 0 ) { 100 | position.y = Mathf.Lerp ( position.y, 0, Time.deltaTime * padding.y ); 101 | yInPlace = false; 102 | 103 | if ( position.y < 1 ) { 104 | position.y = 0; 105 | } 106 | 107 | // Out of bounds bottom 108 | } else if ( !IsInfiniteY() && position.y < bounds.y ) { 109 | position.y = Mathf.Lerp ( position.y, bounds.y, Time.deltaTime * padding.y ); 110 | yInPlace = false; 111 | 112 | if ( position.y > bounds.y - 1 ) { 113 | position.y = bounds.y; 114 | } 115 | 116 | } else { 117 | yInPlace = true; 118 | } 119 | 120 | // Out of bounds left 121 | if ( !IsInfiniteX() && position.x > 0 ) { 122 | position.x = Mathf.Lerp ( position.x, 0, Time.deltaTime * padding.x ); 123 | xInPlace = false; 124 | 125 | if ( position.x < 1 ) { 126 | position.x = 0; 127 | } 128 | 129 | // Out of bounds right 130 | } else if ( !IsInfiniteX() && position.x < bounds.x ) { 131 | position.x = Mathf.Lerp ( position.x, bounds.x, Time.deltaTime * padding.x ); 132 | xInPlace = false; 133 | 134 | if ( position.x > bounds.x - 1 ) { 135 | position.x = bounds.x; 136 | } 137 | 138 | } else { 139 | xInPlace = true; 140 | } 141 | 142 | if ( yInPlace && xInPlace ) { 143 | inPlace = true; 144 | } 145 | 146 | UpdateChildren(); 147 | 148 | yield return null; 149 | } 150 | } 151 | 152 | private bool IsInfiniteX () { 153 | return infiniteScrolling && lockAxis == ScrollDirection.X; 154 | } 155 | 156 | private bool IsInfiniteY () { 157 | return infiniteScrolling && lockAxis == ScrollDirection.Y; 158 | } 159 | 160 | private void CheckPositionReset () { 161 | if ( IsInfiniteY() ) { 162 | // Top 163 | if ( position.y <= - ( drawRct.height + padding.y * 4 ) ) { 164 | position.y = 0; 165 | 166 | // Bottom 167 | } else if ( position.y >= drawRct.height + padding.y * 4 ) { 168 | position.y = 0; 169 | 170 | } 171 | } 172 | 173 | if ( IsInfiniteX() ) { 174 | // Left 175 | if ( position.x <= - ( drawRct.width + padding.x * 4 ) ) { 176 | position.x = 0; 177 | 178 | // Right 179 | } else if ( position.x >= drawRct.width + padding.x * 4 ) { 180 | position.x = 0; 181 | 182 | } 183 | } 184 | } 185 | 186 | private void CheckWidgetOffset ( OGWidget w ) { 187 | if ( IsInfiniteY() ) { 188 | // Top 189 | if ( position.y < bounds.y && w.transform.position.y + w.transform.localScale.y + w.scrollOffset.y <= this.transform.position.y ) { 190 | w.scrollOffset.y += drawRct.height + padding.y * 4; 191 | 192 | // Bottom 193 | } else if ( position.y > 0 && w.transform.position.y + w.scrollOffset.y >= this.transform.position.y + size.y ) { 194 | w.scrollOffset.y -= drawRct.height + padding.y * 4; 195 | 196 | } 197 | } 198 | 199 | if ( IsInfiniteX() ) { 200 | // Right 201 | if ( position.x < bounds.x && w.transform.position.x + w.transform.localScale.x + w.scrollOffset.x <= this.transform.position.x ) { 202 | w.scrollOffset.x += drawRct.width + padding.x * 4; 203 | 204 | // Left 205 | } else if ( position.x > 0 && w.transform.position.x + w.scrollOffset.x >= this.transform.position.x + size.x ) { 206 | w.scrollOffset.x -= drawRct.width + padding.x * 4; 207 | 208 | } 209 | } 210 | } 211 | 212 | 213 | ////////////////// 214 | // Mouse 215 | ////////////////// 216 | override public void OnMouseDrag () { 217 | Vector2 drag; 218 | Vector2 amount; 219 | 220 | drag.x = Input.GetAxis ( "Mouse X" ); 221 | drag.y = Input.GetAxis ( "Mouse Y" ); 222 | 223 | amount.x = Mathf.Floor ( drag.x * 12 ); 224 | amount.y = -Mathf.Floor ( drag.y * 12 ); 225 | 226 | // Elasticity 227 | if ( !IsInfiniteX() && lockAxis != ScrollDirection.Y ) { 228 | if ( position.x + amount.x > 0 ) { 229 | amount.x *= elasticity / ( elasticity * ( position.x + amount.x ) ); 230 | } else if ( position.x + amount.x < bounds.x ) { 231 | amount.x *= elasticity / ( elasticity * ( bounds.x - ( position.x + amount.x ) ) ); 232 | } 233 | } 234 | 235 | if ( !IsInfiniteY() && lockAxis != ScrollDirection.X ) { 236 | if ( position.y + amount.y > 0 ) { 237 | amount.y *= elasticity / ( elasticity * ( position.y + amount.y ) ); 238 | } else if ( position.y + amount.y < bounds.y ) { 239 | amount.y *= elasticity / ( elasticity * ( bounds.y - ( position.y + amount.y ) ) ); 240 | } 241 | } 242 | 243 | if ( lockAxis == ScrollDirection.X || lockAxis == ScrollDirection.None ) { 244 | position.x += amount.x; 245 | } 246 | 247 | if ( lockAxis == ScrollDirection.Y || lockAxis == ScrollDirection.None ) { 248 | position.y += amount.y; 249 | } 250 | 251 | CheckPositionReset(); 252 | } 253 | 254 | override public void OnMouseCancel () { 255 | StartCoroutine ( SnapBack () ); 256 | 257 | root.ReleaseWidget (); 258 | } 259 | 260 | override public void OnMouseUp () { 261 | StartCoroutine ( SnapBack () ); 262 | 263 | root.ReleaseWidget (); 264 | } 265 | 266 | override public void OnMouseOver () { 267 | Vector2 amount = Vector2.zero; 268 | float scroll = Input.GetAxis ( "Mouse ScrollWheel" ); 269 | 270 | if ( scroll > 0 && inPlace ) { 271 | if ( Input.GetKey ( KeyCode.LeftShift ) ) { 272 | if ( IsInfiniteX() || position.x > bounds.x ) { 273 | amount.x = -20; 274 | } 275 | } else { 276 | if ( IsInfiniteY() || position.y < 0 ) { 277 | amount.y = 20; 278 | } 279 | } 280 | 281 | } else if ( scroll < 0 && inPlace ) { 282 | if ( Input.GetKey ( KeyCode.LeftShift ) ) { 283 | if ( IsInfiniteX() || position.x < 0 ) { 284 | amount.x = 20; 285 | } 286 | } else { 287 | if ( IsInfiniteY() || position.y > bounds.y ) { 288 | amount.y = -20; 289 | } 290 | } 291 | } 292 | 293 | if ( lockAxis == ScrollDirection.X || lockAxis == ScrollDirection.None ) { 294 | position.x += amount.x; 295 | } 296 | 297 | if ( lockAxis == ScrollDirection.Y || lockAxis == ScrollDirection.None ) { 298 | position.y += amount.y; 299 | } 300 | 301 | CheckPositionReset (); 302 | UpdateChildren (); 303 | } 304 | 305 | override public void UpdateWidget () { 306 | // Persistent vars 307 | if ( lockAxis == ScrollDirection.None ) { 308 | infiniteScrolling = false; 309 | } 310 | 311 | if ( thumbScale.y > 1 ) { 312 | thumbScale.y = 1; 313 | } 314 | 315 | isSelectable = true; 316 | 317 | // Mouse 318 | mouseRct = drawRct; 319 | 320 | // Reset scale 321 | this.transform.localScale = Vector3.one; 322 | 323 | // Update all widgets in scroll view 324 | UpdateChildren (); 325 | } 326 | 327 | override public void DrawSkin () { 328 | OGDrawHelper.DrawSlicedSprite ( drawRct, styles.basic, drawDepth - 10, tint ); 329 | 330 | if ( scrollbarVisibility == ScrollbarVisibility.Auto ) { 331 | if ( bounds.x < 0 && !IsInfiniteX() && lockAxis != ScrollDirection.Y ) { 332 | OGDrawHelper.DrawSlicedSprite ( GetScrollbarXRect(), styles.thumb, drawDepth - 9, tint ); 333 | } 334 | 335 | if ( bounds.y < 0 && !IsInfiniteY() && lockAxis != ScrollDirection.X ) { 336 | OGDrawHelper.DrawSlicedSprite ( GetScrollbarYRect(), styles.thumb, drawDepth - 9, tint ); 337 | } 338 | } 339 | } 340 | } 341 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGScrollView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 668593e9100cece4e85d4003565bc41f 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGSkin.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | public enum OGStyleType { 6 | Basic, 7 | Hover, 8 | Active, 9 | Ticked, 10 | Thumb, 11 | } 12 | 13 | public enum OGWidgetType { 14 | NONE, 15 | Button, 16 | DropContainer, 17 | DropDown, 18 | Label, 19 | ListItem, 20 | PopUp, 21 | ProgressBar, 22 | ScrollView, 23 | Slider, 24 | SlicedSprite, 25 | Sprite, 26 | Tabs, 27 | TextField, 28 | TickBox 29 | } 30 | 31 | [System.Serializable] 32 | public class OGSlicedSpriteOffset { 33 | public float top; 34 | public float bottom; 35 | public float left; 36 | public float right; 37 | 38 | public OGSlicedSpriteOffset ( float l, float r, float t, float b ) { 39 | left = l; 40 | right = r; 41 | top = t; 42 | bottom = b; 43 | } 44 | 45 | public float horizontal { 46 | get { 47 | return left + right; 48 | } 49 | } 50 | 51 | public float vertical { 52 | get { 53 | return top + bottom; 54 | } 55 | } 56 | } 57 | 58 | [System.Serializable] 59 | public class OGTextStyle { 60 | public int fontIndex = 0; 61 | public OGFont font; 62 | public int fontSize = 12; 63 | public Color fontColor = Color.white; 64 | public int shadowSize = 0; 65 | public Color shadowColor = Color.black; 66 | public TextAnchor alignment; 67 | public bool wordWrap = true; 68 | public RectOffset padding; 69 | public float lineHeight = 1.25f; 70 | public float spacing = 1f; 71 | } 72 | 73 | [System.Serializable] 74 | public class OGStyle { 75 | public string name = "New Style"; 76 | public Rect coordinates = new Rect ( 0, 0, 32, 32 ); 77 | public OGSlicedSpriteOffset border = new OGSlicedSpriteOffset ( 0, 0, 0, 0 ); 78 | public Color color = Color.white; 79 | public OGTextStyle text; 80 | } 81 | 82 | [System.Serializable] 83 | public class OGStyleSet { 84 | public OGStyle basic; 85 | public OGStyle hover; 86 | public OGStyle active; 87 | public OGStyle ticked; 88 | public OGStyle thumb; 89 | 90 | public void Refresh ( OGSkin skin ) { 91 | if ( !skin ) { return; } 92 | 93 | OGStyle newStyle; 94 | 95 | if ( basic != null ) { 96 | newStyle = skin.GetStyle ( basic.name ); 97 | if ( newStyle != null ) { basic = newStyle; } 98 | } 99 | 100 | if ( hover != null ) { 101 | newStyle = skin.GetStyle ( hover.name ); 102 | if ( newStyle != null ) { hover = newStyle; } 103 | } 104 | 105 | if ( active != null ) { 106 | newStyle = skin.GetStyle ( active.name ); 107 | if ( newStyle != null ) { active = newStyle; } 108 | } 109 | 110 | if ( ticked != null ) { 111 | newStyle = skin.GetStyle ( ticked.name ); 112 | if ( newStyle != null ) { ticked = newStyle; } 113 | } 114 | 115 | if ( thumb != null ) { 116 | newStyle = skin.GetStyle ( thumb.name ); 117 | if ( newStyle != null ) { thumb = newStyle; } 118 | } 119 | } 120 | 121 | public OGStyle GetStyle ( OGStyleType typ ) { 122 | OGStyle result = null; 123 | 124 | switch ( typ ) { 125 | case OGStyleType.Basic: 126 | result = basic; 127 | break; 128 | 129 | case OGStyleType.Hover: 130 | result = hover; 131 | break; 132 | 133 | case OGStyleType.Active: 134 | result = active; 135 | break; 136 | 137 | case OGStyleType.Ticked: 138 | result = ticked; 139 | break; 140 | 141 | case OGStyleType.Thumb: 142 | result = thumb; 143 | break; 144 | } 145 | 146 | return result; 147 | } 148 | 149 | public void SetStyle ( OGStyleType typ, OGStyle stl ) { 150 | switch ( typ ) { 151 | case OGStyleType.Basic: 152 | basic = stl; 153 | break; 154 | 155 | case OGStyleType.Hover: 156 | hover = stl; 157 | break; 158 | 159 | case OGStyleType.Active: 160 | active = stl; 161 | break; 162 | 163 | case OGStyleType.Ticked: 164 | ticked = stl; 165 | break; 166 | 167 | case OGStyleType.Thumb: 168 | thumb = stl; 169 | break; 170 | } 171 | } 172 | } 173 | 174 | [System.Serializable] 175 | public class OGDefault { 176 | public OGWidgetType widgetType; 177 | public OGStyleSet styleSet; 178 | 179 | public OGDefault ( OGWidgetType t, OGStyleSet s ) { 180 | widgetType = t; 181 | styleSet = s; 182 | } 183 | } 184 | 185 | public class OGSkin : MonoBehaviour { 186 | public Material atlas; 187 | public OGFont[] fonts = new OGFont[0]; 188 | public Shader fontShader; 189 | public OGStyle[] styles = new OGStyle[0]; 190 | public OGDefault[] defaults = new OGDefault[0]; 191 | 192 | private static Dictionary< System.Type, OGWidgetType > widgetEnums = new Dictionary< System.Type, OGWidgetType > (); 193 | 194 | public static OGWidgetType GetWidgetEnum ( OGWidget w ) { 195 | if ( widgetEnums.Count < 1 ) { 196 | widgetEnums.Add ( typeof(OGButton), OGWidgetType.Button ); 197 | widgetEnums.Add ( typeof(OGDropDown), OGWidgetType.DropDown ); 198 | widgetEnums.Add ( typeof(OGDropContainer), OGWidgetType.DropContainer ); 199 | widgetEnums.Add ( typeof(OGLabel), OGWidgetType.Label ); 200 | widgetEnums.Add ( typeof(OGListItem), OGWidgetType.ListItem ); 201 | widgetEnums.Add ( typeof(OGPopUp), OGWidgetType.PopUp ); 202 | widgetEnums.Add ( typeof(OGProgressBar), OGWidgetType.ProgressBar ); 203 | widgetEnums.Add ( typeof(OGScrollView), OGWidgetType.ScrollView ); 204 | widgetEnums.Add ( typeof(OGSlider), OGWidgetType.Slider ); 205 | widgetEnums.Add ( typeof(OGSlicedSprite), OGWidgetType.SlicedSprite ); 206 | widgetEnums.Add ( typeof(OGSprite), OGWidgetType.Sprite ); 207 | widgetEnums.Add ( typeof(OGTabs), OGWidgetType.Tabs ); 208 | widgetEnums.Add ( typeof(OGTextField), OGWidgetType.TextField ); 209 | widgetEnums.Add ( typeof(OGTickBox), OGWidgetType.TickBox ); 210 | } 211 | 212 | if ( widgetEnums.ContainsKey ( w.GetType() ) ) { 213 | return widgetEnums [ w.GetType() ]; 214 | } else { 215 | return OGWidgetType.NONE; 216 | } 217 | } 218 | 219 | public static bool IsStyleUsed ( OGStyleType styleType, OGWidgetType widgetType ) { 220 | if ( widgetType == OGWidgetType.NONE ) { 221 | return false; 222 | 223 | // All widgets use basic style 224 | } else if ( styleType == OGStyleType.Basic ) { 225 | return true; 226 | 227 | } else { 228 | OGStyleType[] s = null; 229 | 230 | switch ( widgetType ) { 231 | case OGWidgetType.Button: s = new OGStyleType[] { OGStyleType.Active, OGStyleType.Hover, OGStyleType.Thumb }; break; 232 | case OGWidgetType.DropContainer: s = new OGStyleType[] { OGStyleType.Hover }; break; 233 | case OGWidgetType.DropDown: s = new OGStyleType[] { OGStyleType.Active, OGStyleType.Hover, OGStyleType.Thumb, OGStyleType.Ticked }; break; 234 | case OGWidgetType.ListItem: s = new OGStyleType[] { OGStyleType.Hover, OGStyleType.Ticked }; break; 235 | case OGWidgetType.PopUp: s = new OGStyleType[] { OGStyleType.Active, OGStyleType.Hover, OGStyleType.Thumb }; break; 236 | case OGWidgetType.ProgressBar: s = new OGStyleType[] { OGStyleType.Thumb }; break; 237 | case OGWidgetType.Slider: s = new OGStyleType[] { OGStyleType.Thumb }; break; 238 | case OGWidgetType.ScrollView: s = new OGStyleType[] { OGStyleType.Thumb }; break; 239 | case OGWidgetType.Tabs: s = new OGStyleType[] { OGStyleType.Active, OGStyleType.Thumb }; break; 240 | case OGWidgetType.TextField: s = new OGStyleType[] { OGStyleType.Active, OGStyleType.Thumb }; break; 241 | case OGWidgetType.TickBox: s = new OGStyleType[] { OGStyleType.Active, OGStyleType.Ticked }; break; 242 | default: return false; 243 | } 244 | 245 | for ( int i = 0; i < s.Length ; i++ ) { 246 | if ( styleType == s[i] ) { 247 | return true; 248 | } 249 | } 250 | } 251 | 252 | return false; 253 | } 254 | 255 | public OGDefault[] GetAllDefaults () { 256 | if ( defaults == null || defaults.Length < 1 ) { 257 | ResetDefaults (); 258 | } 259 | 260 | return defaults; 261 | } 262 | 263 | public void ResetDefaults () { 264 | defaults = new OGDefault[] { 265 | new OGDefault ( OGWidgetType.Button, new OGStyleSet() ), 266 | new OGDefault ( OGWidgetType.DropDown, new OGStyleSet() ), 267 | new OGDefault ( OGWidgetType.DropContainer, new OGStyleSet() ), 268 | new OGDefault ( OGWidgetType.Label, new OGStyleSet() ), 269 | new OGDefault ( OGWidgetType.ListItem, new OGStyleSet() ), 270 | new OGDefault ( OGWidgetType.PopUp, new OGStyleSet() ), 271 | new OGDefault ( OGWidgetType.ProgressBar, new OGStyleSet() ), 272 | new OGDefault ( OGWidgetType.ScrollView, new OGStyleSet() ), 273 | new OGDefault ( OGWidgetType.Slider, new OGStyleSet() ), 274 | new OGDefault ( OGWidgetType.Tabs, new OGStyleSet() ), 275 | new OGDefault ( OGWidgetType.TextField, new OGStyleSet() ), 276 | new OGDefault ( OGWidgetType.TickBox, new OGStyleSet() ) 277 | }; 278 | } 279 | 280 | public void ApplyDefaultStyles ( OGWidget w ) { 281 | foreach ( OGDefault d in GetAllDefaults() ) { 282 | if ( d.widgetType == w.ToEnum () ) { 283 | if ( w.styles == null ) { 284 | w.styles = new OGStyleSet (); 285 | } 286 | 287 | w.styles.basic = d.styleSet.basic; 288 | w.styles.active = d.styleSet.active; 289 | w.styles.hover = d.styleSet.hover; 290 | w.styles.thumb = d.styleSet.thumb; 291 | w.styles.ticked = d.styleSet.ticked; 292 | 293 | w.styles.Refresh ( this ); 294 | 295 | return; 296 | } 297 | } 298 | } 299 | 300 | public OGStyle GetStyle ( string n ) { 301 | foreach ( OGStyle s in styles ) { 302 | if ( s.name == n ) { 303 | return s; 304 | } 305 | } 306 | 307 | return null; 308 | } 309 | 310 | public Material GetAtlas () { 311 | return (Material) Instantiate ( atlas ); 312 | } 313 | } 314 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGSkin.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f50b42847b9f211448b0f91d4f629a64 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGSlicedSprite.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class OGSlicedSprite : OGWidget { 5 | public Vector2 tile = Vector2.one; 6 | 7 | ////////////////// 8 | // Update 9 | ////////////////// 10 | override public void UpdateWidget () { 11 | mouseRct = drawRct; 12 | } 13 | 14 | 15 | ////////////////// 16 | // Draw 17 | ////////////////// 18 | override public void DrawSkin () { 19 | if ( drawRct == new Rect() ) { return; } 20 | 21 | if ( tile.x == 1 && tile.y == 1 ) { 22 | OGDrawHelper.DrawSlicedSprite ( drawRct, styles.basic, drawDepth, tint, clipTo ); 23 | 24 | } else { 25 | OGDrawHelper.DrawTiledSlicedSprite ( drawRct, styles.basic, drawDepth, tint, tile.x, tile.y, clipTo ); 26 | 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGSlicedSprite.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cf7ad9f3468794f4ea38d72dd7e11647 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGSlider.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class OGSlider : OGWidget { 5 | public enum Orientation { 6 | Horizontal, 7 | Vertical 8 | } 9 | 10 | public Orientation orientation; 11 | public float sliderValue = 0; 12 | public OGLabel sliderLabel; 13 | public float backgroundHeight = 0.25f; 14 | public bool toPercent = true; 15 | public string suffix = ""; 16 | 17 | 18 | //////////////// 19 | // Rects 20 | //////////////// 21 | private Rect GetThumbRect () { 22 | if ( orientation == Orientation.Horizontal ) { 23 | return new Rect ( drawRct.x + ( sliderValue * drawRct.width ) - ( drawRct.height / 2 ), drawRct.y, drawRct.height, drawRct.height ); 24 | } else { 25 | return new Rect ( drawRct.x, drawRct.y + ( sliderValue * drawRct.height ) - ( drawRct.width / 2 ), drawRct.width, drawRct.width ); 26 | } 27 | } 28 | 29 | private Rect GetBackgroundRect () { 30 | if ( orientation == Orientation.Horizontal ) { 31 | return new Rect ( drawRct.x, drawRct.y + ( drawRct.height / 2 ) - ( ( drawRct.height * backgroundHeight ) / 2 ), drawRct.width, drawRct.height * backgroundHeight ); 32 | } else { 33 | return new Rect ( drawRct.x + ( drawRct.width / 2 ) - ( ( drawRct.width * backgroundHeight ) / 2 ), drawRct.y, drawRct.width * backgroundHeight, drawRct.height ); 34 | } 35 | } 36 | 37 | 38 | //////////////// 39 | // Mouse 40 | //////////////// 41 | override public void OnMouseDrag () { 42 | if ( sliderValue >= 0 && sliderValue <= 1 ) { 43 | if ( orientation == Orientation.Horizontal ) { 44 | sliderValue = ( Input.mousePosition.x - drawRct.x ) / drawRct.width; 45 | } else { 46 | sliderValue = ( Input.mousePosition.y - drawRct.y ) / drawRct.height; 47 | } 48 | } 49 | 50 | 51 | sliderValue = Mathf.Clamp ( Mathf.Round ( sliderValue * 100 ) / 100, 0, 1 ); 52 | } 53 | 54 | override public void OnMouseCancel () { 55 | root.ReleaseWidget(); 56 | } 57 | 58 | override public void OnMouseUp () { 59 | root.ReleaseWidget(); 60 | } 61 | 62 | 63 | //////////////// 64 | // Update 65 | //////////////// 66 | override public void UpdateWidget () { 67 | // Persistent vars 68 | isSelectable = true; 69 | 70 | // Mouse 71 | mouseRct = CombineRects ( GetThumbRect(), GetBackgroundRect() ); 72 | 73 | // Update data 74 | if ( sliderLabel ) { 75 | if ( toPercent ) { 76 | sliderLabel.text = ( sliderValue * 100 ).ToString() + suffix; 77 | } else { 78 | sliderLabel.text = sliderValue.ToString() + suffix; 79 | } 80 | } 81 | } 82 | 83 | 84 | //////////////// 85 | // Draw 86 | //////////////// 87 | override public void DrawSkin () { 88 | // Background 89 | OGDrawHelper.DrawSprite ( GetBackgroundRect(), styles.basic, drawDepth, tint, clipTo ); 90 | 91 | // Thumb 92 | OGDrawHelper.DrawSlicedSprite ( GetThumbRect(), styles.thumb, drawDepth, tint, clipTo ); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGSlider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4eff7eb68f1d5be46a37c57738e8485b 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGSprite.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class OGSprite : OGWidget { 5 | public Vector2 tile = Vector2.one; 6 | 7 | ////////////////// 8 | // Draw 9 | ////////////////// 10 | override public void DrawSkin () { 11 | if ( drawCrd == new Rect() || drawRct == new Rect() ) { return; } 12 | 13 | if ( tile.x != 1 || tile.y != 1 ) { 14 | OGDrawHelper.DrawTiledSprite ( drawRct, styles.basic, drawDepth, tint, tile.x, tile.y, clipTo ); 15 | } else { 16 | OGDrawHelper.DrawSprite ( drawRct, styles.basic, drawDepth, tint, clipTo ); 17 | } 18 | } 19 | 20 | //////////////// 21 | // Update 22 | //////////////// 23 | override public void UpdateWidget () { 24 | tile.x = Mathf.Floor ( tile.x ); 25 | tile.y = Mathf.Floor ( tile.y ); 26 | 27 | mouseRct = drawRct; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGSprite.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b0d0bc449a04bfd4495496d7876b9dba 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGTabs.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | public class OGTabs : OGWidget { 6 | [System.Serializable] 7 | public class Tab { 8 | public string title = "Tab"; 9 | public GameObject content; 10 | 11 | public Tab ( string title, GameObject content ) { 12 | this.title = title; 13 | this.content = content; 14 | } 15 | } 16 | 17 | public int activeTab; 18 | public string leftArrow = "«"; 19 | public string rightArrow = "»"; 20 | public List tabs = new List(); 21 | public GameObject target; 22 | public string message; 23 | public string argument; 24 | public bool passSelectedTab = false; 25 | 26 | private bool overflow = false; 27 | private int maxTabs = 0; 28 | private int focusTab = 0; 29 | private bool leftNavDown = false; 30 | private bool rightNavDown = false; 31 | 32 | 33 | ////////////////// 34 | // Rects 35 | ////////////////// 36 | private float GetTotalWidth () { 37 | float width = 0f; 38 | float widestTab = 0f; 39 | 40 | for ( int i = 0; i < tabs.Count; i++ ) { 41 | float newWidth = OGDrawHelper.GetLabelWidth ( tabs[i].title, GetTabStyle ( i ).text ); 42 | width += newWidth; 43 | 44 | if ( newWidth > widestTab ) { 45 | widestTab = newWidth; 46 | } 47 | } 48 | 49 | if ( width > drawRct.width ) { 50 | maxTabs = (int) Mathf.Clamp ( Mathf.Floor ( drawRct.width / widestTab ), 1f, tabs.Count ); 51 | 52 | } else { 53 | maxTabs = tabs.Count; 54 | 55 | } 56 | 57 | return width; 58 | } 59 | 60 | private Rect GetTabRect ( int i ) { 61 | float tabWidth; 62 | 63 | if ( !overflow ) { 64 | tabWidth = drawRct.width / tabs.Count; 65 | 66 | } else { 67 | float width = drawRct.width; 68 | 69 | if ( activeTab > 0 ) { 70 | width -= drawRct.height; 71 | } 72 | 73 | if ( activeTab < tabs.Count - 1 ) { 74 | width -= drawRct.height; 75 | } 76 | 77 | tabWidth = width / maxTabs; 78 | 79 | } 80 | 81 | Rect rect = new Rect ( drawRct.x + tabWidth * ( i - focusTab ), drawRct.y, tabWidth, drawRct.height ); 82 | 83 | if ( activeTab > 0 && overflow ) { 84 | rect.x += drawRct.height; 85 | } 86 | 87 | return rect; 88 | } 89 | 90 | private Rect GetLeftRect () { 91 | return new Rect ( drawRct.x, drawRct.y, drawRct.height, drawRct.height ); 92 | } 93 | 94 | private Rect GetRightRect () { 95 | return new Rect ( drawRct.xMax - drawRct.height, drawRct.y, drawRct.height, drawRct.height ); 96 | } 97 | 98 | 99 | ////////////////// 100 | // Styles 101 | ////////////////// 102 | private OGStyle GetTabStyle ( int i ) { 103 | if ( i == activeTab ) { 104 | return styles.active; 105 | } else { 106 | return styles.basic; 107 | } 108 | } 109 | 110 | 111 | ////////////////// 112 | // Management 113 | ////////////////// 114 | public void AddTab ( string tabName, GameObject tabObject, bool switchTo ) { 115 | Tab newTab = new Tab ( tabName, tabObject ); 116 | 117 | tabs.Add ( newTab ); 118 | 119 | if ( switchTo ) { 120 | SetActiveTab ( tabs.Count - 1 ); 121 | } else if ( tabs.Count < 2 ) { 122 | SetActiveTab ( 0 ); 123 | } 124 | } 125 | 126 | public void ClearTabs () { 127 | tabs.Clear (); 128 | activeTab = -1; 129 | } 130 | 131 | public void SetActiveTab ( string n ) { 132 | SetActiveTab ( int.Parse ( n ) ); 133 | } 134 | 135 | public void SetActiveTab ( int tab ) { 136 | activeTab = tab; 137 | 138 | for ( int i = 0; i < tabs.Count; i++ ) { 139 | if ( tabs[i].content ) { 140 | tabs[i].content.SetActive ( i == activeTab ); 141 | } 142 | } 143 | } 144 | 145 | 146 | ////////////////// 147 | // Mouse 148 | ////////////////// 149 | override public void OnMouseDown () { 150 | if ( CheckMouseOver ( GetLeftRect () ) && activeTab > 0 ) { 151 | leftNavDown = true; 152 | 153 | } else if ( CheckMouseOver ( GetRightRect () ) && activeTab < tabs.Count - 1 ) { 154 | rightNavDown = true; 155 | 156 | } else { 157 | for ( int i = 0; i < tabs.Count; i++ ) { 158 | if ( CheckMouseOver ( GetTabRect ( i ) ) ) { 159 | SetActiveTab ( i ); 160 | 161 | if ( target && !string.IsNullOrEmpty ( message ) ) { 162 | if ( passSelectedTab ) { 163 | target.SendMessage ( message, i ); 164 | 165 | } else if ( !string.IsNullOrEmpty ( argument ) ) { 166 | target.SendMessage ( message, argument ); 167 | 168 | } else { 169 | target.SendMessage ( message ); 170 | 171 | } 172 | } 173 | } 174 | } 175 | } 176 | } 177 | 178 | override public void OnMouseUp () { 179 | if ( leftNavDown ) { 180 | SetActiveTab ( activeTab - 1 ); 181 | 182 | } else if ( rightNavDown ) { 183 | SetActiveTab ( activeTab + 1 ); 184 | 185 | } 186 | 187 | OnMouseCancel (); 188 | } 189 | 190 | override public void OnMouseCancel () { 191 | leftNavDown = false; 192 | rightNavDown = false; 193 | 194 | root.ReleaseWidget(); 195 | } 196 | 197 | 198 | ////////////////// 199 | // Update 200 | ////////////////// 201 | override public void UpdateWidget () { 202 | isSelectable = true; 203 | 204 | // Mouse 205 | mouseRct = drawRct; 206 | 207 | // Update data 208 | overflow = GetTotalWidth () > drawRct.width; 209 | 210 | if ( activeTab >= tabs.Count && tabs.Count > 0 ) { 211 | SetActiveTab ( tabs.Count - 1 ); 212 | } 213 | 214 | if ( !overflow ) { 215 | focusTab = 0; 216 | 217 | } else if ( activeTab < focusTab ) { 218 | focusTab--; 219 | 220 | } else if ( activeTab >= focusTab + maxTabs ) { 221 | focusTab++; 222 | 223 | } 224 | } 225 | 226 | 227 | ////////////////// 228 | // Draw 229 | ////////////////// 230 | override public void DrawSkin () { 231 | for ( int i = focusTab; i < focusTab + maxTabs; i++ ) { 232 | OGDrawHelper.DrawSlicedSprite ( GetTabRect(i), GetTabStyle(i), drawDepth, tint, clipTo ); 233 | } 234 | 235 | if ( overflow ) { 236 | if ( activeTab > 0 ) { 237 | OGDrawHelper.DrawSlicedSprite ( GetLeftRect (), styles.thumb, drawDepth, tint, clipTo ); 238 | } 239 | 240 | if ( activeTab < tabs.Count - 1 ) { 241 | OGDrawHelper.DrawSlicedSprite ( GetRightRect (), styles.thumb, drawDepth, tint, clipTo ); 242 | } 243 | } 244 | } 245 | 246 | override public void DrawText () { 247 | for ( int i = focusTab; i < focusTab + maxTabs; i++ ) { 248 | OGDrawHelper.DrawLabel ( GetTabRect ( i ), tabs[i].title, GetTabStyle(i).text, drawDepth, tint, clipTo ); 249 | } 250 | 251 | if ( overflow ) { 252 | if ( activeTab > 0 ) { 253 | OGDrawHelper.DrawLabel ( GetLeftRect (), leftArrow, styles.thumb.text, drawDepth, tint, clipTo ); 254 | } 255 | 256 | if ( activeTab < tabs.Count - 1 ) { 257 | OGDrawHelper.DrawLabel ( GetRightRect (), rightArrow, styles.thumb.text, drawDepth, tint, clipTo ); 258 | } 259 | } 260 | 261 | } 262 | } 263 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGTabs.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 710228318d2b91649934e6695474f3d9 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGTestWidget.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class OGTestWidget : OGWidget { 5 | public Texture2D mainTexture; 6 | 7 | private Material material; 8 | 9 | private Matrix4x4 matrix; 10 | 11 | private Vector3 GetVector ( float x, float y ) { 12 | float height = this.transform.localScale.y; 13 | float width = this.transform.localScale.x; 14 | float depth = this.transform.position.z; 15 | 16 | float left = 0; 17 | float top = -height; 18 | 19 | switch ( pivot.x ) { 20 | case RelativeX.Center: 21 | left = -width / 2; 22 | break; 23 | 24 | case RelativeX.Right: 25 | left = -width; 26 | break; 27 | } 28 | 29 | switch ( pivot.y ) { 30 | case RelativeY.Center: 31 | top = -height / 2; 32 | break; 33 | 34 | case RelativeY.Bottom: 35 | top = 0; 36 | break; 37 | } 38 | 39 | return matrix.MultiplyPoint3x4 ( new Vector3 ( x * width + left, y * height + top, depth ) ); 40 | } 41 | 42 | override public void UpdateWidget () { 43 | mouseRct = drawRct; 44 | } 45 | 46 | override public void DrawGL () { 47 | if ( drawRct == new Rect() || mainTexture == null ) { 48 | return; 49 | } 50 | 51 | if ( material == null ) { 52 | material = new Material ( root.skin.atlas.shader ); 53 | return; 54 | } 55 | 56 | if ( material.mainTexture != mainTexture ) { 57 | material.mainTexture = mainTexture; 58 | return; 59 | } 60 | 61 | matrix.SetTRS ( new Vector3 ( this.transform.position.x, root.screenHeight - this.transform.position.y, drawDepth ), Quaternion.Euler ( 0, 0, -this.transform.eulerAngles.z ), Vector3.one ); 62 | 63 | Rect uvRct = new Rect ( 0, 0, 1, 1 ); 64 | 65 | GL.Begin(GL.QUADS); 66 | 67 | GL.Color ( tint ); 68 | 69 | material.SetPass ( 0 ); 70 | 71 | // Bottom Left 72 | GL.TexCoord2 ( uvRct.x, uvRct.y ); 73 | GL.Vertex ( GetVector ( 0, 0 ) ); 74 | 75 | // Top left 76 | GL.TexCoord2 ( uvRct.x, uvRct.y + uvRct.height ); 77 | GL.Vertex ( GetVector ( 0, 1 ) ); 78 | 79 | // Top right 80 | GL.TexCoord2 ( uvRct.x + uvRct.width, uvRct.y + uvRct.height ); 81 | GL.Vertex ( GetVector ( 1, 1 ) ); 82 | 83 | // Bottom right 84 | GL.TexCoord2 ( uvRct.x + uvRct.width, uvRct.y ); 85 | GL.Vertex ( GetVector ( 1, 0 ) ); 86 | 87 | GL.Color ( Color.white ); 88 | 89 | GL.End(); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGTestWidget.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 64dbebc7bdb0c5846b28e07c953265cc 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGTextEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Reflection; 4 | 5 | public class OGTextEditor { 6 | public class ClipboardHelper { 7 | private static PropertyInfo m_systemCopyBufferProperty = null; 8 | 9 | private static PropertyInfo GetSystemCopyBufferProperty () { 10 | if ( m_systemCopyBufferProperty == null ) { 11 | System.Type T = typeof ( GUIUtility ); 12 | m_systemCopyBufferProperty = T.GetProperty ( "systemCopyBuffer", BindingFlags.Static | BindingFlags.NonPublic ); 13 | 14 | if ( m_systemCopyBufferProperty == null ) { 15 | Debug.LogError ( "Can't access internal member 'GUIUtility.systemCopyBuffer' it may have been removed / renamed" ); 16 | } 17 | } 18 | 19 | return m_systemCopyBufferProperty; 20 | } 21 | 22 | public static string GetClipboard () { 23 | PropertyInfo P = GetSystemCopyBufferProperty (); 24 | return P.GetValue ( null, null ).ToString (); 25 | } 26 | 27 | public static void SetClipboard ( string val ) { 28 | PropertyInfo P = GetSystemCopyBufferProperty (); 29 | P.SetValue ( null, val, null ); 30 | } 31 | } 32 | 33 | public bool enabled = false; 34 | public string str = ""; 35 | public Vector2 cursorPos; 36 | public Vector2 cursorSelectPos; 37 | public Vector2 cursorSize = new Vector2 ( 2, 12 ); 38 | public Rect cursorRect; 39 | public Rect[] selectionRects = new Rect[0]; 40 | public int cursorIndex; 41 | public int cursorSelectIndex; 42 | public int delayUntilRepeat = 20; 43 | public int repeat = 10; 44 | public KeyCode exitKey = KeyCode.Escape; 45 | public System.Action exitAction; 46 | 47 | private ClipboardHelper clipboardHelper; 48 | 49 | private bool shiftPressed { 50 | get { 51 | return Input.GetKey ( KeyCode.LeftShift ) || Input.GetKey ( KeyCode.RightShift ); 52 | } 53 | } 54 | 55 | private bool arrowPressed { 56 | get { 57 | return Input.GetKey ( KeyCode.LeftArrow ) || Input.GetKey ( KeyCode.DownArrow ) || Input.GetKey ( KeyCode.UpArrow ) || Input.GetKey ( KeyCode.RightArrow ); 58 | } 59 | } 60 | 61 | private bool ctrlOrCmdPressed { 62 | get { 63 | return Input.GetKey ( KeyCode.LeftControl ) || Input.GetKey ( KeyCode.LeftCommand ) || Input.GetKey ( KeyCode.RightControl ) || Input.GetKey ( KeyCode.RightCommand ); 64 | } 65 | } 66 | 67 | private bool exitKeyPressed { 68 | get { 69 | return Input.GetKey ( exitKey ); 70 | } 71 | } 72 | 73 | public void Backspace () { 74 | if ( cursorIndex >= 0 && str.Length > 0 ) { 75 | if ( cursorSelectIndex == cursorIndex ) { 76 | cursorIndex--; 77 | } 78 | 79 | str = str.Remove ( cursorIndex, cursorSelectIndex - cursorIndex ); 80 | 81 | cursorSelectIndex = cursorIndex; 82 | } 83 | } 84 | 85 | public void Delete () { 86 | if ( cursorIndex < str.Length ) { 87 | if ( cursorSelectIndex == cursorIndex ) { 88 | cursorSelectIndex++; 89 | } 90 | 91 | str = str.Remove ( cursorIndex, cursorSelectIndex - cursorIndex ); 92 | 93 | cursorSelectIndex = cursorIndex; 94 | } 95 | } 96 | 97 | public void InsertText ( string newText ) { 98 | if ( string.IsNullOrEmpty ( newText ) ) { 99 | return; 100 | } 101 | 102 | if ( cursorIndex != cursorSelectIndex ) { 103 | Backspace (); 104 | } 105 | 106 | if ( cursorIndex < str.Length ) { 107 | string before = str.Substring ( 0, cursorIndex ); 108 | string after = str.Substring ( cursorIndex, str.Length - cursorIndex ); 109 | str = before + newText + after; 110 | 111 | } else { 112 | str += newText; 113 | 114 | } 115 | 116 | cursorIndex += newText.Length; 117 | cursorSelectIndex = cursorIndex; 118 | } 119 | 120 | public void MoveUp () { 121 | MoveLeft (); 122 | } 123 | 124 | public void MoveDown () { 125 | MoveRight (); 126 | } 127 | 128 | public void MoveLeft () { 129 | if ( cursorIndex > 0 ) { 130 | if ( !shiftPressed ) { 131 | if ( cursorIndex != cursorSelectIndex ) { 132 | cursorSelectIndex = cursorIndex; 133 | 134 | } else { 135 | cursorIndex--; 136 | cursorSelectIndex = cursorIndex; 137 | } 138 | 139 | } else { 140 | cursorIndex--; 141 | 142 | } 143 | } 144 | } 145 | 146 | public void MoveRight () { 147 | if ( cursorIndex < str.Length ) { 148 | if ( !shiftPressed ) { 149 | if ( cursorIndex != cursorSelectIndex ) { 150 | cursorIndex = cursorSelectIndex; 151 | 152 | } else { 153 | cursorIndex++; 154 | cursorSelectIndex = cursorIndex; 155 | } 156 | 157 | } else { 158 | cursorSelectIndex++; 159 | 160 | } 161 | } 162 | } 163 | 164 | public string Update ( string text, Rect rect ) { 165 | str = text; 166 | string copyString = ""; 167 | 168 | if ( Input.GetKeyDown ( KeyCode.Backspace ) ) { 169 | Backspace (); 170 | 171 | } else if ( Input.GetKeyDown ( KeyCode.Delete ) ) { 172 | Delete (); 173 | 174 | // Select all 175 | } else if ( ctrlOrCmdPressed && Input.GetKeyDown ( KeyCode.A ) ) { 176 | cursorIndex = 0; 177 | cursorSelectIndex = str.Length; 178 | 179 | // Paste 180 | } else if ( ctrlOrCmdPressed && Input.GetKeyDown ( KeyCode.V ) ) { 181 | InsertText ( ClipboardHelper.GetClipboard () ); 182 | 183 | // Copy 184 | } else if ( ctrlOrCmdPressed && Input.GetKeyDown ( KeyCode.C ) ) { 185 | copyString = str.Substring ( cursorIndex, cursorSelectIndex - cursorIndex ); 186 | 187 | if ( !string.IsNullOrEmpty ( copyString ) ) { 188 | ClipboardHelper.SetClipboard ( copyString ); 189 | } 190 | 191 | // Cut 192 | } else if ( ctrlOrCmdPressed && Input.GetKeyDown ( KeyCode.X ) ) { 193 | copyString = str.Substring ( cursorIndex, cursorSelectIndex - cursorIndex ); 194 | 195 | if ( !string.IsNullOrEmpty ( copyString ) ) { 196 | ClipboardHelper.SetClipboard ( copyString ); 197 | Backspace (); 198 | } 199 | 200 | } else if ( Input.GetKeyDown ( KeyCode.LeftArrow ) ) { 201 | MoveLeft (); 202 | 203 | } else if ( Input.GetKeyDown ( KeyCode.UpArrow ) ) { 204 | MoveUp (); 205 | 206 | } else if ( Input.GetKeyDown ( KeyCode.DownArrow ) ) { 207 | MoveDown (); 208 | 209 | } else if ( Input.GetKeyDown ( KeyCode.RightArrow ) ) { 210 | MoveRight (); 211 | 212 | } else if ( !ctrlOrCmdPressed ) { 213 | InsertText ( Input.inputString ); 214 | 215 | } 216 | 217 | if ( cursorIndex != cursorSelectIndex ) { 218 | cursorRect = new Rect ( 0, 0, 0, 0 ); 219 | 220 | int lines = (int)(( cursorSelectPos.y - cursorPos.y ) / cursorSize.y); 221 | 222 | lines++; 223 | 224 | selectionRects = new Rect[lines]; 225 | 226 | for ( int i = 0; i < lines; i++ ) { 227 | if ( i < 1 ) { 228 | if ( lines > 1 ) { 229 | selectionRects[i] = new Rect ( cursorPos.x, cursorPos.y, rect.xMax - cursorPos.x, cursorSize.y ); 230 | 231 | } else { 232 | selectionRects[i] = new Rect ( cursorPos.x, cursorPos.y, cursorSelectPos.x - cursorPos.x, cursorSize.y ); 233 | 234 | } 235 | 236 | } else if ( i == lines ) { 237 | selectionRects[i] = new Rect ( rect.x, cursorPos.y + ( i * cursorSize.y ), cursorSelectPos.x - rect.x, cursorSize.y ); 238 | 239 | } else { 240 | selectionRects[i] = new Rect ( rect.x, cursorPos.y + ( i * cursorSize.y ), rect.width, cursorSize.y ); 241 | 242 | } 243 | } 244 | 245 | } else { 246 | cursorRect = new Rect ( cursorPos.x, cursorPos.y, cursorSize.x, cursorSize.y ); 247 | selectionRects = new Rect[0]; 248 | 249 | } 250 | 251 | 252 | return str; 253 | } 254 | } 255 | 256 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGTextEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6bdcca9d801301b41b356346c167f43d 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGTextField.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Text.RegularExpressions; 4 | 5 | public class OGTextField : OGWidget { 6 | public enum RegExPreset { 7 | None, 8 | OnlyNumbers, 9 | OnlyNumbersAndPeriod, 10 | OnlyASCII, 11 | NoSpaces 12 | } 13 | 14 | public string text = ""; 15 | public int maxLength = 200; 16 | public string regex; 17 | public RegExPreset regexPreset; 18 | public bool locked = false; 19 | public bool singleLine = false; 20 | public bool fitToText = false; 21 | public bool hideText = false; 22 | public OGTextEditor betaEditor = new OGTextEditor (); 23 | 24 | [HideInInspector] public bool listening = false; 25 | 26 | private RegExPreset currentPreset = RegExPreset.None; 27 | 28 | 29 | ////////////////// 30 | // Interaction 31 | ////////////////// 32 | override public void OnMouseDown () { 33 | listening = true; 34 | 35 | betaEditor.cursorPos = Input.mousePosition; 36 | } 37 | 38 | override public void OnMouseDrag () { 39 | listening = true; 40 | 41 | betaEditor.cursorSelectPos = Input.mousePosition; 42 | } 43 | 44 | override public void OnMouseCancel () { 45 | listening = false; 46 | } 47 | 48 | public void OnGUI () { 49 | if ( listening ) { 50 | if ( !betaEditor.enabled ) { 51 | GUI.SetNextControlName ( "ActiveTextField" ); 52 | 53 | GUIStyle style = new GUIStyle(); 54 | style.normal.textColor = currentStyle.text.fontColor; 55 | style.font = currentStyle.text.font.dynamicFont; 56 | style.fontSize = currentStyle.text.fontSize; 57 | style.alignment = currentStyle.text.alignment; 58 | style.wordWrap = currentStyle.text.wordWrap; 59 | style.padding = currentStyle.text.padding; 60 | style.clipping = TextClipping.Clip; 61 | 62 | Color c = currentStyle.text.fontColor; 63 | GUI.skin.settings.selectionColor = new Color ( 1.0f - c.r, 1.0f - c.g, 1.0f - c.b, c.a ); 64 | 65 | Rect invertedRct = drawRct; 66 | 67 | invertedRct.y = Screen.height - invertedRct.y - invertedRct.height; 68 | 69 | if ( string.IsNullOrEmpty ( text ) ) { 70 | text = ""; 71 | } 72 | 73 | text = GUI.TextArea ( invertedRct, text, style ); 74 | 75 | if ( singleLine ) { 76 | text = text.Replace("\n", "").Replace("\r", ""); 77 | } 78 | 79 | GUIUtility.GetControlID(drawRct.GetHashCode(), FocusType.Keyboard); 80 | 81 | GUI.FocusControl ( "ActiveTextField" ); 82 | } 83 | } 84 | } 85 | 86 | //////////////////// 87 | // Update 88 | //////////////////// 89 | override public void UpdateWidget () { 90 | // Persistent vars 91 | isSelectable = true; 92 | 93 | if ( fitToText ) { 94 | singleLine = true; 95 | } 96 | 97 | // Update data 98 | mouseRct = drawRct; 99 | isAlwaysOnTop = listening; 100 | 101 | if ( fitToText ) { 102 | this.transform.localScale = new Vector3 ( OGDrawHelper.GetLabelWidth ( text, currentStyle.text ), this.transform.localScale.y, this.transform.localScale.z ); 103 | } 104 | 105 | if ( string.IsNullOrEmpty ( text ) ) { 106 | text = ""; 107 | } 108 | 109 | if ( singleLine ) { 110 | text = text.Replace("\n", "").Replace("\r", ""); 111 | } 112 | 113 | if ( !string.IsNullOrEmpty ( regex ) && regex != "\\" && regexPreset != RegExPreset.None ) { 114 | text = Regex.Replace ( text, "[" + regex + "]", "" ); 115 | } 116 | 117 | // Styles 118 | if ( listening ) { 119 | currentStyle = styles.active; 120 | } else { 121 | currentStyle = styles.basic; 122 | } 123 | 124 | if ( betaEditor.enabled ) { 125 | text = betaEditor.Update ( text, drawRct ); 126 | } 127 | 128 | // ^ Regex presets 129 | if ( regexPreset != currentPreset ) { 130 | currentPreset = regexPreset; 131 | 132 | if ( currentPreset == RegExPreset.None ) { 133 | regex = ""; 134 | 135 | } else if ( currentPreset == RegExPreset.OnlyNumbers ) { 136 | regex = "^0-9"; 137 | 138 | } else if ( currentPreset == RegExPreset.OnlyASCII ) { 139 | regex = "^a-zA-Z0-9"; 140 | 141 | } else if ( currentPreset == RegExPreset.NoSpaces ) { 142 | regex = " "; 143 | 144 | } else if ( currentPreset == RegExPreset.OnlyNumbersAndPeriod) { 145 | regex = "^0-9."; 146 | 147 | } 148 | } 149 | } 150 | 151 | 152 | ///////////////// 153 | // Draw 154 | ///////////////// 155 | override public void DrawSkin () { 156 | OGDrawHelper.DrawSlicedSprite ( drawRct, currentStyle, drawDepth, tint, clipTo ); 157 | 158 | if ( listening && betaEditor.enabled ) { 159 | Color color = tint; 160 | 161 | if ( betaEditor.cursorIndex != betaEditor.cursorSelectIndex ) { 162 | color = new Color ( 1 - color.r, 1 - color.g, 1 - color.b, color.a ); 163 | 164 | for ( int i = 0; i < betaEditor.selectionRects.Length; i++ ) { 165 | OGDrawHelper.DrawSprite ( betaEditor.selectionRects[i], styles.thumb, drawDepth, color, this ); 166 | } 167 | 168 | } else { 169 | OGDrawHelper.DrawSprite ( betaEditor.cursorRect, styles.thumb, drawDepth, color, this ); 170 | 171 | } 172 | } 173 | } 174 | 175 | override public void DrawText () { 176 | if ( !listening || betaEditor.enabled ) { 177 | if ( hideText ) { 178 | string secure = ""; 179 | 180 | for ( int i = 0; i < text.Length; i++ ) { 181 | secure += "*"; 182 | } 183 | 184 | OGDrawHelper.DrawLabel ( drawRct, secure, currentStyle.text, drawDepth, tint, this, betaEditor ); 185 | 186 | } else { 187 | OGDrawHelper.DrawLabel ( drawRct, text, currentStyle.text, drawDepth, tint, this, betaEditor ); 188 | 189 | } 190 | } 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGTextField.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 22155d8efc0c0714a89f2f43a34fd92c 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGTextInfo.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | // Label info 5 | public class OGTextInfo { 6 | public class LineInfo { 7 | public int start; 8 | public int end; 9 | public float width; 10 | public float height; 11 | public OGCharacterInfo[] chars = new OGCharacterInfo [ 999 ]; 12 | 13 | private int cIndex = 0; 14 | 15 | public int length { 16 | get { 17 | return end - start; 18 | } 19 | } 20 | 21 | public LineInfo ( int s, float h ) { 22 | start = s; 23 | height = h; 24 | cIndex = 0; 25 | } 26 | 27 | public void End ( int e ) { 28 | end = e; 29 | cIndex = 0; 30 | } 31 | 32 | public void AddChar ( OGCharacterInfo info ) { 33 | chars[cIndex] = info; 34 | cIndex++; 35 | } 36 | } 37 | 38 | public LineInfo[] lines = new LineInfo [ 999 ]; 39 | public float height; 40 | public float width; 41 | public float lineHeight; 42 | public int length = 0; 43 | 44 | private int lIndex = 0; 45 | 46 | private LineInfo NewLine ( int i ) { 47 | if ( lIndex >= 999 ) { 48 | lIndex = 0; 49 | } 50 | 51 | LineInfo newLine = new LineInfo ( i, lineHeight ); 52 | lines[lIndex] = ( newLine ); 53 | height += lineHeight; 54 | lIndex++; 55 | return newLine; 56 | } 57 | 58 | public void Calculate ( string str, OGTextStyle style, float size, Rect rect ) { 59 | lineHeight = style.font.info.lineSpacing * size; 60 | 61 | LineInfo line = NewLine ( 0 ); 62 | int lastSpace = 0; 63 | float lineWidthAtLastSpace = 0; 64 | float space = ( style.font.GetCharacterInfo ( " "[0] ).width * size ); 65 | 66 | float right = rect.width - style.padding.right - style.padding.left; 67 | 68 | int c = 0; 69 | 70 | for ( c = 0; c < str.Length; c++ ) { 71 | OGCharacterInfo info = style.font.GetCharacterInfo ( str[c] ); 72 | 73 | // This character is a carriage return 74 | if ( str[c] == "\n"[0] ) { 75 | line.End ( c ); 76 | line = NewLine ( line.end ); 77 | 78 | // This character is a space 79 | } else if ( info.space ) { 80 | line.width += space; 81 | lastSpace = c; 82 | 83 | // The line width has exceeded the border 84 | if ( line.width >= right ) { 85 | line.width = lineWidthAtLastSpace; 86 | c = lastSpace == 0 ? lastSpace : c; 87 | line.End ( c - 1 ); 88 | line = NewLine ( c + 1 ); 89 | 90 | } else { 91 | lineWidthAtLastSpace = line.width - space; 92 | line.AddChar ( info ); 93 | 94 | } 95 | 96 | // This character is a regular glyph 97 | } else { 98 | line.width += info.width * size; 99 | 100 | // The line width has exceeded the border 101 | if ( line.width >= right ) { 102 | line.width = lineWidthAtLastSpace; 103 | c = lastSpace == 0 ? lastSpace : c; 104 | line.End ( c - 1 ); 105 | line = NewLine ( c + 1 ); 106 | 107 | } else { 108 | line.AddChar ( info ); 109 | 110 | } 111 | } 112 | } 113 | 114 | line.End ( c ); 115 | 116 | length = lIndex; 117 | 118 | lIndex = 0; 119 | } 120 | } 121 | 122 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGTextInfo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5376a32076ae149558d1962c6ab9f8fb 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGTexture.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class OGTexture : OGWidget { 5 | public Texture2D mainTexture; 6 | 7 | private Material material; 8 | 9 | override public void UpdateWidget () { 10 | 11 | mouseRct = drawRct; 12 | } 13 | 14 | override public void DrawGL () { 15 | if ( drawRct == new Rect() || mainTexture == null ) { 16 | return; 17 | } 18 | 19 | if ( material == null ) { 20 | material = new Material ( root.skin.atlas.shader ); 21 | return; 22 | } 23 | 24 | if ( material.mainTexture != mainTexture ) { 25 | material.mainTexture = mainTexture; 26 | return; 27 | } 28 | 29 | Rect displayRct = drawRct; 30 | Rect uvRct = drawCrd; 31 | 32 | if ( clipTo ) { 33 | if ( displayRct.xMin > clipTo.drawRct.xMax || displayRct.xMax < clipTo.drawRct.xMin || displayRct.yMax < clipTo.drawRct.yMin || displayRct.yMin > clipTo.drawRct.yMax ) { 34 | return; 35 | } 36 | 37 | if ( clipTo.drawRct.xMin > displayRct.xMin ) { 38 | uvRct.xMin = ( clipTo.drawRct.xMin - displayRct.xMin ) / this.transform.lossyScale.x; 39 | displayRct.xMin = clipTo.drawRct.xMin; 40 | } 41 | 42 | if ( clipTo.drawRct.xMax < displayRct.xMax ) { 43 | uvRct.xMax = ( displayRct.xMax - clipTo.drawRct.xMax ) / this.transform.lossyScale.x; 44 | displayRct.xMax = clipTo.drawRct.xMax; 45 | } 46 | 47 | if ( clipTo.drawRct.yMin > displayRct.yMin ) { 48 | uvRct.yMin = ( clipTo.drawRct.yMin - displayRct.yMin ) / this.transform.lossyScale.y; 49 | displayRct.yMin = clipTo.drawRct.yMin; 50 | } 51 | 52 | if ( clipTo.drawRct.yMax < displayRct.yMax ) { 53 | uvRct.yMax = ( displayRct.yMax - clipTo.drawRct.yMax ) / this.transform.lossyScale.y; 54 | displayRct.yMax = clipTo.drawRct.yMax; 55 | } 56 | } 57 | 58 | GL.Begin(GL.QUADS); 59 | 60 | GL.Color ( tint ); 61 | 62 | material.SetPass ( 0 ); 63 | 64 | // Bottom Left 65 | GL.TexCoord2 ( uvRct.x, uvRct.y ); 66 | GL.Vertex3 ( displayRct.x, displayRct.y, drawDepth ); 67 | 68 | // Top left 69 | GL.TexCoord2 ( uvRct.x, uvRct.y + uvRct.height ); 70 | GL.Vertex3 ( displayRct.x, displayRct.y + displayRct.height, drawDepth ); 71 | 72 | // Top right 73 | GL.TexCoord2 ( uvRct.x + uvRct.width, uvRct.y + uvRct.height ); 74 | GL.Vertex3 ( displayRct.x + displayRct.width, displayRct.y + displayRct.height, drawDepth ); 75 | 76 | // Bottom right 77 | GL.TexCoord2 ( uvRct.x + uvRct.width, uvRct.y ); 78 | GL.Vertex3 ( displayRct.x + displayRct.width, displayRct.y, drawDepth ); 79 | 80 | GL.Color ( Color.white ); 81 | 82 | GL.End(); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGTexture.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2e56e459b97d51c4b9567269592cb638 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGTickBox.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class OGTickBox : OGWidget { 5 | public string text; 6 | public bool isTicked; 7 | 8 | private bool isDown = false; 9 | 10 | 11 | //////////////// 12 | // Interaction 13 | //////////////// 14 | override public void OnMouseCancel () { 15 | isDown = false; 16 | root.ReleaseWidget (); 17 | } 18 | 19 | override public void OnMouseDown () { 20 | isDown = true; 21 | } 22 | 23 | override public void OnMouseUp () { 24 | isTicked = !isTicked; 25 | 26 | OnMouseCancel (); 27 | } 28 | 29 | 30 | //////////////// 31 | // Rects 32 | //////////////// 33 | private Rect GetTickRect () { 34 | return new Rect ( drawRct.x + drawRct.width - drawRct.height, drawRct.y, drawRct.height, drawRct.height ); 35 | } 36 | 37 | 38 | //////////////// 39 | // Update 40 | //////////////// 41 | override public void UpdateWidget () { 42 | // Persistent vars 43 | isSelectable = true; 44 | 45 | // Mouse 46 | mouseRct = drawRct; 47 | } 48 | 49 | 50 | //////////////// 51 | // Draw 52 | //////////////// 53 | override public void DrawSkin () { 54 | OGDrawHelper.DrawSlicedSprite ( GetTickRect(), isDown ? styles.active : styles.basic, drawDepth, tint, clipTo ); 55 | 56 | if ( isTicked ) { 57 | OGDrawHelper.DrawSprite ( GetTickRect(), styles.ticked, drawDepth, tint, clipTo ); 58 | } 59 | } 60 | 61 | override public void DrawText () { 62 | OGDrawHelper.DrawLabel ( drawRct, text, styles.basic.text, drawDepth, tint, clipTo ); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGTickBox.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e9ba25bd75abba342b707f4313372411 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGTween.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class OGTween : MonoBehaviour { 5 | /* enum TweenMessageSend { 6 | Begin, 7 | Complete 8 | } 9 | 10 | private class TweenType { 11 | bool enabled = false; 12 | Vector3 destination; 13 | float time = 1.0; 14 | iTween easing.EaseType; 15 | } 16 | 17 | TweenType move; 18 | TweenType rotate; 19 | TweenType scale; 20 | 21 | bool ignoreTimeScale = true; 22 | bool autoPlay = false; 23 | 24 | GameObject messageTarget; 25 | String message; 26 | String argument; 27 | Function func; 28 | TweenMessageSend sendMessageOn = TweenMessageSend.Complete; 29 | 30 | [HideInInspector] float timer = 0.0; 31 | [HideInInspector] bool timerStarted = false; 32 | 33 | [HideInInspector] Vector3 startPos; 34 | [HideInInspector] Vector3 startRot; 35 | [HideInInspector] Vector3 startScl; 36 | 37 | void OGCallBack () { 38 | if ( func ) { 39 | func (); 40 | return; 41 | } 42 | 43 | if ( !messageTarget ) { return; } 44 | if ( !message ) { return; } 45 | 46 | if ( argument ) { 47 | messageTarget.SendMessage ( message, argument ); 48 | } else { 49 | messageTarget.SendMessage ( message ); 50 | } 51 | } 52 | 53 | float FindGreatest () { 54 | float a = 0.0; 55 | float b = 0.0; 56 | float c = 0.0; 57 | 58 | if ( move.enabled ) { a = move.time; } 59 | if ( rotate.enabled ) { b = rotate.time; } 60 | if ( scale.enabled ) { c = scale.time; } 61 | 62 | return Mathf.Max ( a, b, c ); 63 | } 64 | 65 | void Play ( bool forward ) { 66 | if ( move.enabled ) { 67 | Vector3 moveDest; 68 | 69 | if ( forward ) { moveDest = move.destination; } 70 | else { moveDest = startPos; } 71 | 72 | iTween.MoveTo ( gameObject, iTween.Hash ( 73 | "position", moveDest, 74 | "time", move.time, 75 | "easetype", move.easing, 76 | "islocal", true, 77 | "ignoretimescale", ignoreTimeScale, 78 | "onupdatetarget", this.gameObject, 79 | "onupdate", "SetDirty" 80 | ) ); 81 | } 82 | 83 | if ( rotate.enabled ) { 84 | Vector3 rotDest; 85 | 86 | if ( forward ) { rotDest = rotate.destination; } 87 | else { rotDest = startRot; } 88 | 89 | iTween.RotateTo ( gameObject, iTween.Hash ( 90 | "rotation", rotDest, 91 | "time", rotate.time, 92 | "easetype", rotate.easing, 93 | "islocal", true, 94 | "ignoretimescale", ignoreTimeScale, 95 | "onupdatetarget", this.gameObject, 96 | "onupdate", "SetDirty" 97 | ) ); 98 | } 99 | 100 | if ( scale.enabled ) { 101 | Vector3 sclDest; 102 | 103 | if ( forward ) { sclDest = scale.destination; } 104 | else { sclDest = startScl; } 105 | 106 | iTween.ScaleTo ( gameObject, iTween.Hash ( 107 | "scale", sclDest, 108 | "time", scale.time, 109 | "easetype", scale.easing, 110 | "islocal", true, 111 | "ignoretimescale", ignoreTimeScale, 112 | "onupdatetarget", this.gameObject, 113 | "onupdate", "SetDirty" 114 | ) ); 115 | } 116 | 117 | if ( sendMessageOn == TweenMessageSend.Begin ) { 118 | OGCallBack (); 119 | } else { 120 | timerStarted = true; 121 | timer = FindGreatest(); 122 | } 123 | } 124 | 125 | void Update () { 126 | if ( timerStarted && timer > 0.0 ) { 127 | timer -= Time.deltaTime; 128 | } else if ( timerStarted ) { 129 | OGCallBack(); 130 | } 131 | } 132 | 133 | void Start () { 134 | Time.timeScale = 1.0; 135 | 136 | startPos = transform.localPosition; 137 | startRot = transform.localEulerAngles; 138 | startScl = transform.localScale; 139 | 140 | if ( autoPlay ) { 141 | Play ( true ); 142 | } 143 | } 144 | */} 145 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGTween.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 373a618f2f94bcd488b189824865f849 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGWidget.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public enum RelativeX { 5 | None, 6 | Left, 7 | Center, 8 | Right, 9 | Factor 10 | } 11 | 12 | public enum RelativeY { 13 | None, 14 | Top, 15 | Center, 16 | Bottom, 17 | Factor 18 | } 19 | 20 | public enum ScreenSize { 21 | None, 22 | ScreenWidth, 23 | ScreenHeight 24 | } 25 | 26 | public enum ButtonAction { 27 | OnRelease, 28 | OnPress, 29 | OnHover 30 | } 31 | 32 | public class OGWidget : MonoBehaviour { 33 | [System.Serializable] 34 | public class Stretch { 35 | public ScreenSize width = ScreenSize.None; 36 | public float widthFactor = 1.0f; 37 | public float widthOffset = 0.0f; 38 | 39 | public ScreenSize height = ScreenSize.None; 40 | public float heightFactor = 1.0f; 41 | public float heightOffset = 0.0f; 42 | } 43 | 44 | [System.Serializable] 45 | public class Pivot { 46 | public RelativeX x; 47 | public RelativeY y; 48 | } 49 | 50 | [System.Serializable] 51 | public class Anchor { 52 | public RelativeX x = RelativeX.None; 53 | public float xOffset = 0.0f; 54 | public float xFactor = 0.0f; 55 | 56 | public RelativeY y = RelativeY.None; 57 | public float yOffset = 0.0f; 58 | public float yFactor = 0.0f; 59 | } 60 | 61 | public OGRoot root; 62 | public bool isDrawn = true; 63 | public bool isDisabled = false; 64 | public bool isSelectable = false; 65 | public bool isDraggable = false; 66 | public bool resetAfterDrag = false; 67 | public Color tint = Color.white; 68 | public Pivot pivot = new Pivot(); 69 | public Anchor anchor = new Anchor(); 70 | public Stretch stretch = new Stretch(); 71 | public OGWidget clipTo; 72 | 73 | [HideInInspector] public OGStyleSet styles = new OGStyleSet(); 74 | [HideInInspector] public OGStyle currentStyle; 75 | [HideInInspector] public Rect drawCrd; 76 | [HideInInspector] public Rect drawRct; 77 | [HideInInspector] public Rect mouseRct; 78 | [HideInInspector] public float drawDepth; 79 | [HideInInspector] public Vector3 scrollOffset; 80 | [HideInInspector] public Vector3 dragOffset; 81 | [HideInInspector] public Vector3 dragOrigPos; 82 | [HideInInspector] public Vector3 offset; 83 | [HideInInspector] public bool hidden = false; 84 | [HideInInspector] public bool outOfBounds = false; 85 | [HideInInspector] public bool isDirty = false; 86 | [HideInInspector] public bool isAlwaysOnTop = false; 87 | 88 | ////////////////// 89 | // Calculations 90 | ////////////////// 91 | // Convert to enum 92 | public OGWidgetType ToEnum () { 93 | return OGSkin.GetWidgetEnum ( this ); 94 | } 95 | 96 | // Get scaled rect 97 | public Rect scaledRct { 98 | get { 99 | Rect result = drawRct; 100 | 101 | OGRoot root = OGRoot.GetInstance (); 102 | 103 | if ( root ) { 104 | result.x *= root.ratio.x; 105 | result.width *= root.ratio.x; 106 | result.y *= root.ratio.y; 107 | result.height *= root.ratio.y; 108 | } 109 | 110 | return result; 111 | } 112 | } 113 | 114 | // Find child 115 | public GameObject FindChild ( string n ) { 116 | for ( int i = 0; i < this.transform.childCount; i++ ) { 117 | if ( this.transform.GetChild ( i ).gameObject.name == n ) { 118 | return this.transform.GetChild ( i ).gameObject; 119 | } 120 | } 121 | 122 | return null; 123 | } 124 | 125 | // Combine rects 126 | public Rect CombineRects ( Rect a, Rect b ) { 127 | Rect result = new Rect ( 0, 0, 0, 0 ); 128 | 129 | result.x = ( a.x < b.x ) ? a.x : b.x; 130 | result.y = ( a.y < b.y ) ? a.y : b.y; 131 | result.xMax = ( a.xMax > b.xMax ) ? a.xMax : b.xMax; 132 | result.yMax = ( a.yMax > b.yMax ) ? a.yMax : b.yMax; 133 | 134 | return result; 135 | } 136 | 137 | // Check mouseover 138 | public bool CheckMouseOver () { 139 | if ( mouseRct != new Rect (0,0,0,0) ) { 140 | return CheckMouseOver ( mouseRct ); 141 | } else { 142 | return false; 143 | } 144 | } 145 | 146 | public bool CheckMouseOver ( Rect rect ) { 147 | if ( !root ) { 148 | root = OGRoot.GetInstance(); 149 | } 150 | 151 | Vector2 pos = new Vector2 ( Input.mousePosition.x * root.reverseRatio.x, Input.mousePosition.y * root.reverseRatio.y ); 152 | 153 | if ( SystemInfo.deviceType == DeviceType.Handheld && Input.touchCount == 0 ) { 154 | return false; 155 | } 156 | 157 | return rect.Contains ( pos ); 158 | } 159 | 160 | public bool CheckMouseOver ( Rect rect1, Rect rect2 ) { 161 | return CheckMouseOver ( rect1 ) || CheckMouseOver ( rect2 ); 162 | } 163 | 164 | // Scale (based on screen size) 165 | public Vector3 RecalcScale () { 166 | CalcStretch (); 167 | 168 | OGScrollView scrollView = this as OGScrollView; 169 | 170 | if ( scrollView ) { 171 | return new Vector3 ( scrollView.size.x, scrollView.size.y, 1 ); 172 | } else { 173 | return this.transform.lossyScale; 174 | } 175 | } 176 | 177 | // Position (based on screen size and flipped vertically because of OpenGL) 178 | public Vector3 RecalcPosition () { 179 | CalcAnchor (); 180 | CalcPivot (); 181 | 182 | Vector3 newPos = this.transform.position; 183 | OGScrollView scrollView = this as OGScrollView; 184 | 185 | newPos += offset; 186 | newPos += scrollOffset; 187 | 188 | if ( scrollView ) { 189 | newPos.y += scrollView.size.y; 190 | } else { 191 | newPos.y += this.transform.lossyScale.y; 192 | } 193 | 194 | newPos.y = root.screenHeight - newPos.y; 195 | 196 | return newPos; 197 | } 198 | 199 | // Stretch (based on screen size) 200 | private void CalcStretch () { 201 | if ( stretch == null ) { return; } 202 | 203 | Vector3 newScale = this.transform.localScale; 204 | OGScrollView scrollView = this as OGScrollView; 205 | 206 | if ( scrollView ) { 207 | newScale.x = scrollView.size.x; 208 | newScale.y = scrollView.size.y; 209 | } 210 | 211 | if ( stretch.width == ScreenSize.ScreenWidth ) { 212 | newScale.x = ( root.screenWidth * stretch.widthFactor ) + stretch.widthOffset; 213 | } else if ( stretch.width == ScreenSize.ScreenHeight ) { 214 | newScale.x = ( root.screenHeight * stretch.widthFactor ) + stretch.widthOffset; 215 | } 216 | 217 | if ( stretch.height == ScreenSize.ScreenWidth ) { 218 | newScale.y = ( root.screenWidth * stretch.heightFactor ) + stretch.heightOffset; 219 | } else if ( stretch.height == ScreenSize.ScreenHeight ) { 220 | newScale.y = ( root.screenHeight * stretch.heightFactor ) + stretch.heightOffset; 221 | } 222 | 223 | if ( !scrollView ) { 224 | this.transform.localScale = newScale; 225 | 226 | } else { 227 | scrollView.size.x = newScale.x; 228 | scrollView.size.y = newScale.y; 229 | } 230 | 231 | } 232 | 233 | // Anchor (based on screen size) 234 | private void CalcAnchor () { 235 | if ( anchor == null ) { return; } 236 | 237 | Vector3 newPos = this.transform.position; 238 | 239 | if ( anchor.x != RelativeX.None ) { 240 | if ( anchor.x == RelativeX.Left ) { 241 | anchor.xFactor = 0f; 242 | } else if ( anchor.x == RelativeX.Center ) { 243 | anchor.xFactor = 0.5f; 244 | } else if ( anchor.x == RelativeX.Right ) { 245 | anchor.xFactor = 1f; 246 | } 247 | 248 | newPos.x = (root.screenWidth * anchor.xFactor) + anchor.xOffset; 249 | } 250 | 251 | if ( anchor.y != RelativeY.None ) { 252 | if ( anchor.y == RelativeY.Top ) { 253 | anchor.yFactor = 0f; 254 | } else if ( anchor.y == RelativeY.Center ) { 255 | anchor.yFactor = 0.5f; 256 | } else if ( anchor.y == RelativeY.Bottom ) { 257 | anchor.yFactor = 1f; 258 | } 259 | 260 | newPos.y = (root.screenHeight * anchor.yFactor) + anchor.yOffset; 261 | } 262 | 263 | this.transform.position = newPos; 264 | } 265 | 266 | // Pivot (based on object size) 267 | private void CalcPivot () { 268 | Vector2 scale; 269 | OGScrollView scrollview = this as OGScrollView; 270 | 271 | if ( scrollview ) { 272 | scale = scrollview.size; 273 | } else { 274 | scale.x = this.transform.lossyScale.x; 275 | scale.y = this.transform.lossyScale.y; 276 | } 277 | 278 | switch ( pivot.y ) { 279 | case RelativeY.Top: case RelativeY.None: 280 | offset.y = 0; 281 | break; 282 | 283 | case RelativeY.Center: 284 | offset.y = -scale.y/2; 285 | break; 286 | 287 | case RelativeY.Bottom: 288 | offset.y = -scale.y; 289 | break; 290 | } 291 | 292 | switch ( pivot.x ) { 293 | case RelativeX.Right: 294 | offset.x = -scale.x; 295 | break; 296 | 297 | case RelativeX.Center: 298 | offset.x = -scale.x/2; 299 | break; 300 | 301 | case RelativeX.Left: case RelativeX.None: 302 | offset.x = 0; 303 | break; 304 | } 305 | } 306 | 307 | // Apply all calculations 308 | public void Recalculate () { 309 | if ( !root ) { return; } 310 | 311 | OGTexture texture = this as OGTexture; 312 | Vector3 drawScl = RecalcScale (); 313 | Vector3 drawPos = RecalcPosition (); 314 | 315 | if ( texture != null ) { 316 | drawCrd.x = 0; 317 | drawCrd.y = 0; 318 | drawCrd.width = 1; 319 | drawCrd.height = 1; 320 | 321 | } else if ( currentStyle != null ) { 322 | drawCrd = currentStyle.coordinates; 323 | 324 | } else if ( styles.basic != null ) { 325 | drawCrd = styles.basic.coordinates; 326 | } 327 | 328 | if ( isAlwaysOnTop ) { 329 | drawDepth = 0; 330 | } else { 331 | drawDepth = -this.transform.position.z; 332 | } 333 | 334 | drawRct = new Rect ( drawPos.x, drawPos.y, drawScl.x, drawScl.y ); 335 | } 336 | 337 | 338 | ////////////////// 339 | // Init 340 | ////////////////// 341 | public void Awake () { 342 | root = OGRoot.GetInstance (); 343 | } 344 | 345 | public void Start () { 346 | Recalculate (); 347 | } 348 | 349 | 350 | ////////////////// 351 | // Mouse 352 | ////////////////// 353 | public virtual void OnMouseDown () {} 354 | public virtual void OnMouseUp () {} 355 | public virtual void OnMouseOver () {} 356 | public virtual void OnMouseDrag () {} 357 | public virtual void OnMouseCancel () {} 358 | 359 | 360 | ////////////////// 361 | // Update 362 | ////////////////// 363 | public virtual void UpdateWidget () {} 364 | public void ApplyDefaultStyles () { 365 | if ( !root ) { 366 | root = OGRoot.GetInstance(); 367 | } 368 | 369 | OGSkin skin = root.skin; 370 | 371 | if ( !skin ) { 372 | Debug.LogWarning ( "OpenGUI | No OGSkin attached to OGRoot" ); 373 | } else { 374 | skin.ApplyDefaultStyles ( this ); 375 | } 376 | } 377 | 378 | 379 | ////////////////// 380 | // Draw 381 | ////////////////// 382 | public virtual void DrawGL () {} 383 | public virtual void DrawLine () {} 384 | public virtual void DrawSkin () {} 385 | public virtual void DrawText () {} 386 | } 387 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Scripts/OGWidget.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b57158aa55ffb564697aae03f4a069d8 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Shaders.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0d6919fbf5560d64a92bf997e00394ff 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Shaders/3DText.shader: -------------------------------------------------------------------------------- 1 | Shader "GUI/3D Text Shader" { 2 | Properties { 3 | _MainTex ("Font Texture", 2D) = "white" {} 4 | _Color ("Text Color", Color) = (1,1,1,1) 5 | } 6 | 7 | SubShader { 8 | 9 | Tags { 10 | "Queue"="Transparent" 11 | "IgnoreProjector"="True" 12 | "RenderType"="Transparent" 13 | "PreviewType"="Plane" 14 | } 15 | Lighting Off Cull Off ZWrite Off Fog { Mode Off } 16 | Blend SrcAlpha OneMinusSrcAlpha 17 | 18 | Pass { 19 | CGPROGRAM 20 | #pragma vertex vert 21 | #pragma fragment frag 22 | 23 | #include "UnityCG.cginc" 24 | 25 | struct appdata_t { 26 | float4 vertex : POSITION; 27 | fixed4 color : COLOR; 28 | float2 texcoord : TEXCOORD0; 29 | }; 30 | 31 | struct v2f { 32 | float4 vertex : POSITION; 33 | fixed4 color : COLOR; 34 | float2 texcoord : TEXCOORD0; 35 | }; 36 | 37 | sampler2D _MainTex; 38 | uniform float4 _MainTex_ST; 39 | uniform fixed4 _Color; 40 | 41 | v2f vert (appdata_t v) 42 | { 43 | v2f o; 44 | o.vertex = mul(UNITY_MATRIX_MVP, v.vertex); 45 | o.color = v.color * _Color; 46 | o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); 47 | return o; 48 | } 49 | 50 | fixed4 frag (v2f i) : COLOR 51 | { 52 | fixed4 col = i.color; 53 | 54 | col.a *= tex2D(_MainTex, i.texcoord).a; 55 | 56 | return col; 57 | } 58 | ENDCG 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Shaders/3DText.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a449386ab48a3f4428e96cd322b89e84 3 | ShaderImporter: 4 | defaultTextures: [] 5 | userData: 6 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Shaders/UnlitAlphaColored.shader: -------------------------------------------------------------------------------- 1 | Shader "Unlit/Alpha Colored" { 2 | Properties { 3 | _Color ("Color Tint", Color) = (1,1,1,1) 4 | _MainTex ("Base (RGB) Alpha (A)", 2D) = "white" 5 | } 6 | 7 | Category { 8 | Lighting Off 9 | Blend SrcAlpha OneMinusSrcAlpha 10 | Tags {Queue=Transparent} 11 | 12 | SubShader { 13 | Pass { 14 | SetTexture [_MainTex] { 15 | ConstantColor [_Color] 16 | Combine Texture * constant 17 | } 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Shaders/UnlitAlphaColored.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8749b9e042c9f47eabbd07f2c4078a78 3 | ShaderImporter: 4 | defaultTextures: [] 5 | userData: 6 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Shaders/UnlitClipped.shader: -------------------------------------------------------------------------------- 1 | Shader "GUI/Alpha Sliced" { 2 | Properties { 3 | _MainTex ("Texture", 2D) = "white" {} 4 | _ClipRect ( "Clipping", Vector ) = ( 0, 0, 0, 0 ) 5 | _Color ("Color", Color ) = (1,1,1,1) 6 | } 7 | 8 | SubShader { 9 | Tags { 10 | "RenderType"="Transparent" 11 | "Queue"="Transparent" 12 | "IgnoreProjector"="True" 13 | } 14 | 15 | LOD 200 16 | Lighting Off 17 | Blend SrcAlpha OneMinusSrcAlpha 18 | 19 | Pass { 20 | CGPROGRAM 21 | #pragma exclude_renderers d3d11 xbox360 22 | #pragma vertex vert 23 | #pragma fragment frag 24 | #include "UnityCG.cginc" 25 | 26 | struct v2f { 27 | float4 pos : SV_POSITION; 28 | float2 uv_MainTex : TEXCOORD0; 29 | float3 wpos; 30 | }; 31 | 32 | float4 _MainTex_ST; 33 | float4 _ClipRect; 34 | float4 _Color; 35 | 36 | v2f vert(appdata_base v) { 37 | v2f o; 38 | o.pos = mul(UNITY_MATRIX_MVP, v.vertex); 39 | o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex); 40 | o.wpos = mul(_Object2World, v.vertex); 41 | return o; 42 | } 43 | 44 | sampler2D _MainTex; 45 | 46 | float4 frag(v2f IN) : COLOR { 47 | if ( (IN.wpos.x<_ClipRect.x) || (IN.wpos.x>_ClipRect.y) || (IN.wpos.y<_ClipRect.z) || (IN.wpos.y>_ClipRect.w) ) { 48 | half4 colorTransparent = half4(0,0,0,0); 49 | return colorTransparent; 50 | } else { 51 | half4 c = tex2D (_MainTex, IN.uv_MainTex); 52 | return c; 53 | } 54 | } 55 | ENDCG 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Shaders/UnlitClipped.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2263483c679e54c5db24e83c9f7f0de8 3 | ShaderImporter: 4 | defaultTextures: [] 5 | userData: 6 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Shaders/UnlitVertexColored.shader: -------------------------------------------------------------------------------- 1 | Shader "Unlit/Vertex Colored" { 2 | Properties { 3 | _MainTex ("Texture", 2D) = "white" {} 4 | } 5 | 6 | Category { 7 | Cull Off Lighting Off 8 | Blend SrcAlpha OneMinusSrcAlpha 9 | Tags { "Queue"="Geometry" } 10 | 11 | BindChannels { 12 | Bind "Color", color 13 | Bind "Vertex", vertex 14 | Bind "TexCoord", texcoord 15 | } 16 | 17 | SubShader { 18 | Pass { 19 | SetTexture [_MainTex] { 20 | Combine Texture * primary 21 | } 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Shaders/UnlitVertexColored.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1abe4c68534b4ac40bd2a8b100d67909 3 | ShaderImporter: 4 | defaultTextures: [] 5 | userData: 6 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Skins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 283728514dec2dd44af69c2d75d03c81 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Skins/OGDefault.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 58fd61f2959049e4fb5b991de23555c8 3 | folderAsset: yes 4 | DefaultImporter: 5 | userData: 6 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Skins/OGDefault/OGDefault.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/OpenGUI/Assets/Plugins/OpenGUI/Skins/OGDefault/OGDefault.mat -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Skins/OGDefault/OGDefault.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ad0e916e2459a294ea18c648c5e1a7e9 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Skins/OGDefault/OGDefault.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/OpenGUI/Assets/Plugins/OpenGUI/Skins/OGDefault/OGDefault.png -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Skins/OGDefault/OGDefault.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 28a6a0a4fc851464ba5a5b73e5c610c9 3 | TextureImporter: 4 | serializedVersion: 2 5 | mipmaps: 6 | mipMapMode: 0 7 | enableMipMap: 0 8 | linearTexture: 1 9 | correctGamma: 0 10 | fadeOut: 0 11 | borderMipMap: 0 12 | mipMapFadeDistanceStart: 1 13 | mipMapFadeDistanceEnd: 3 14 | bumpmap: 15 | convertToNormalMap: 0 16 | externalNormalMap: 0 17 | heightScale: .25 18 | normalMapFilter: 0 19 | isReadable: 0 20 | grayScaleToAlpha: 0 21 | generateCubemap: 0 22 | seamlessCubemap: 0 23 | textureFormat: -3 24 | maxTextureSize: 1024 25 | textureSettings: 26 | filterMode: 0 27 | aniso: 1 28 | mipBias: -1 29 | wrapMode: 1 30 | nPOTScale: 0 31 | lightmap: 0 32 | compressionQuality: 50 33 | spriteMode: 0 34 | spriteExtrude: 1 35 | spriteMeshType: 1 36 | alignment: 0 37 | spritePivot: {x: .5, y: .5} 38 | spritePixelsToUnits: 100 39 | alphaIsTransparency: 1 40 | textureType: 2 41 | buildTargetSettings: [] 42 | spriteSheet: 43 | sprites: [] 44 | spritePackingTag: 45 | userData: 46 | -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Skins/OGDefault/OGDefault.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/OpenGUI/Assets/Plugins/OpenGUI/Skins/OGDefault/OGDefault.prefab -------------------------------------------------------------------------------- /OpenGUI/Assets/Plugins/OpenGUI/Skins/OGDefault/OGDefault.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8db56b7a0d73e774ca26d2e2c923e673 3 | NativeFormatImporter: 4 | userData: 5 | -------------------------------------------------------------------------------- /OpenGUI/ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/OpenGUI/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /OpenGUI/ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/OpenGUI/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /OpenGUI/ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/OpenGUI/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /OpenGUI/ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/OpenGUI/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /OpenGUI/ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/OpenGUI/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /OpenGUI/ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/OpenGUI/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /OpenGUI/ProjectSettings/NavMeshLayers.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/OpenGUI/ProjectSettings/NavMeshLayers.asset -------------------------------------------------------------------------------- /OpenGUI/ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/OpenGUI/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /OpenGUI/ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/OpenGUI/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /OpenGUI/ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/OpenGUI/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /OpenGUI/ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/OpenGUI/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /OpenGUI/ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/OpenGUI/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /OpenGUI/ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/unity3d-open-tools/opengui/684f4c5b911c98d9cc4ca08f7ff555e0d1fa714e/OpenGUI/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Notice 2 | This project is unmaintained, but feel free to fork it. 3 | 4 | ![](https://raw.githubusercontent.com/mrzapp/opengui/master/Images/logo.png) 5 | 6 | ### What? 7 | It's a GUI framework for Unity that aims to keep things as simple as possible while keeping draw calls to an absolute minimum. I am developing this in tandem with my Deus Ex-based game project [The Vongott Chronicles](http://jeppezapp.com/vongott/) 8 | 9 | ### Why? 10 | GI frameworks for Unity are overpriced, and the built-in API is a ridiculous resource hog with every widget requiring one or more draw calls each. And we can't expect Unity to provide a decent UI system "sometime in the future", when we are ready to develop games now :) So this framework is using the OpenGL API to render widgets, and trying its best to be simple and easy to use at the same time. 11 | 12 | ### Demo 13 | [![demo](https://raw.githubusercontent.com/mrzapp/opengui/master/Images/webdemo.jpg)](http://htmlpreview.github.io/?http://github.com/mrzapp/opengui/blob/master/Build/Build.html) 14 | 15 | ### Documentation and tutorials 16 | In the [wiki](https://github.com/mrzapp/opengui/wiki) 17 | 18 | ### FAQ 19 | #### I have created widgets, but nothing is displaying. What might be wrong? 20 | Make sure your [`OGPage`](https://github.com/mrzapp/opengui/wiki/OGPage) object is the current one, and make sure your [`OGRoot`](https://github.com/mrzapp/opengui/wiki/OGRoot) object has a [`Camera`](http://docs.unity3d.com/Documentation/ScriptReference/Camera.html) component 21 | 22 | #### Where are the tutorials and documentation? 23 | In the [wiki](https://github.com/mrzapp/opengui/wiki) 24 | 25 | #### What about examples? 26 | This repository serves as one. Just download/clone the whole thing. 27 | 28 | #### How can I align objects relatively to the screen? 29 | The "anchor" and "pivot" properties of the [`OGWidget`](https://github.com/mrzapp/opengui/wiki/OGWidget) and subclasses take care of that. 30 | 31 | #### How do I deal with different aspect ratios? 32 | Make sure to use "anchor" and "stretch" to position your content, if you want it to be flexible. 33 | 34 | ### License 35 | MIT 36 | --------------------------------------------------------------------------------