├── Editor.meta ├── Editor ├── ArrayTest.cs ├── ArrayTest.cs.meta ├── ModelDrivenGUI.Editor.asmdef ├── ModelDrivenGUI.Editor.asmdef.meta ├── ReflectionTest.cs └── ReflectionTest.cs.meta ├── README.md ├── README.md.meta ├── Scripts.meta └── Scripts ├── Accessor.meta ├── Accessor ├── IValueAccessor.cs ├── IValueAccessor.cs.meta ├── IVectorAccessor.cs ├── IVectorAccessor.cs.meta ├── ValueAccessor.cs ├── ValueAccessor.cs.meta ├── VectorAccessor.cs └── VectorAccessor.cs.meta ├── Attributes.meta ├── Attributes ├── ClassTooltipAttribute.cs ├── ClassTooltipAttribute.cs.meta ├── CommentAttribute.cs ├── CommentAttribute.cs.meta ├── TitleAttribute.cs └── TitleAttribute.cs.meta ├── ClassConfigurator.cs ├── ClassConfigurator.cs.meta ├── Enums.meta ├── Enums ├── DataDivisionEnum.cs ├── DataDivisionEnum.cs.meta ├── DataSectionEnum.cs ├── DataSectionEnum.cs.meta ├── VectorTypeEnum.cs └── VectorTypeEnum.cs.meta ├── Examples.meta ├── Examples ├── MainUI.cs ├── MainUI.cs.meta ├── TestViewModel.cs ├── TestViewModel.cs.meta ├── TestViewModel.unity └── TestViewModel.unity.meta ├── Exhibitors.meta ├── Exhibitors ├── ListExhibitor.cs ├── ListExhibitor.cs.meta ├── SelfTransform2DExhibitor.cs ├── SelfTransform2DExhibitor.cs.meta ├── Transform2DExhibitor.cs ├── Transform2DExhibitor.cs.meta ├── TransformExhibitor.cs └── TransformExhibitor.cs.meta ├── Extensions.meta ├── Extensions ├── ConstructorExtension.cs ├── ConstructorExtension.cs.meta ├── FieldInfoExtension.cs ├── FieldInfoExtension.cs.meta ├── GUIExtension.cs ├── GUIExtension.cs.meta ├── MethodInfoExtension.cs ├── MethodInfoExtension.cs.meta ├── VectorExtension.cs └── VectorExtension.cs.meta ├── Factory.meta ├── Factory ├── ArrayElementModelFactory.cs ├── ArrayElementModelFactory.cs.meta ├── FieldModelFactory.cs ├── FieldModelFactory.cs.meta ├── IModelFactory.cs ├── IModelFactory.cs.meta ├── IViewFactory.cs ├── IViewFactory.cs.meta ├── ListElementModelFactory.cs ├── ListElementModelFactory.cs.meta ├── SimpleViewFactory.cs └── SimpleViewFactory.cs.meta ├── ModelDrivenGUI.asmdef ├── ModelDrivenGUI.asmdef.meta ├── ValueWrapper.meta ├── ValueWrapper ├── ArrayElementValue.cs ├── ArrayElementValue.cs.meta ├── BaseValue.cs ├── BaseValue.cs.meta ├── FieldIndexedValue.cs ├── FieldIndexedValue.cs.meta ├── FieldValue.cs ├── FieldValue.cs.meta ├── IFieldValue.cs ├── IFieldValue.cs.meta ├── IIndexedValue.cs ├── IIndexedValue.cs.meta ├── IValue.cs ├── IValue.cs.meta ├── ListElementValue.cs └── ListElementValue.cs.meta ├── View.meta ├── View ├── ArrayView.cs ├── ArrayView.cs.meta ├── BaseView.cs ├── BaseView.cs.meta ├── BoolView.cs ├── BoolView.cs.meta ├── ClassView.cs ├── ClassView.cs.meta ├── EnumView.cs ├── EnumView.cs.meta ├── LabelView.cs ├── LabelView.cs.meta ├── ListView.cs ├── ListView.cs.meta ├── TextFieldView.cs ├── TextFieldView.cs.meta ├── VectorView.cs └── VectorView.cs.meta ├── ViewModel.meta └── ViewModel ├── ArrayViewModel.cs ├── ArrayViewModel.cs.meta ├── BaseViewModel.cs ├── BaseViewModel.cs.meta ├── BypassViewModel.cs ├── BypassViewModel.cs.meta ├── ListViewModel.cs ├── ListViewModel.cs.meta ├── NumberViewModel.cs ├── NumberViewModel.cs.meta ├── VectorViewModel.cs └── VectorViewModel.cs.meta /Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 958020f493630034899015223213c03e 3 | folderAsset: yes 4 | timeCreated: 1519797715 5 | licenseType: Pro 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Editor/ArrayTest.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | 6 | namespace ModelDrivenGUISystem.Editor { 7 | 8 | public class ArrayTest { 9 | 10 | [Test] 11 | public void TestArrayType() { 12 | var array0 = new int[32]; 13 | var array1 = (System.Array)array0; 14 | 15 | var array0elementType = array0.GetType().GetElementType(); 16 | var array1elementType = array1.GetType().GetElementType(); 17 | 18 | var element0 = System.Activator.CreateInstance(array0elementType); 19 | var element1 = System.Activator.CreateInstance(array1elementType); 20 | 21 | Debug.LogFormat("int[] is array ? {0}", array0.GetType().IsArray); 22 | Debug.LogFormat("Array is array ? {0}", array1.GetType().IsArray); 23 | 24 | Debug.LogFormat("Element type of int[] ? {0}", array0elementType.Name); 25 | Debug.LogFormat("Element type of Array ? {0}", array1elementType.Name); 26 | 27 | Debug.LogFormat("Create element of int[0] : {0}", element0.GetType().Name); 28 | Debug.LogFormat("Create element of Array : {0}", element1.GetType().Name); 29 | } 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /Editor/ArrayTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e10571ebe65c53f419635588536042bc 3 | timeCreated: 1520621141 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Editor/ModelDrivenGUI.Editor.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ModelDrivenGUI.Editor", 3 | "references": [ 4 | "ModelDrivenGUI" 5 | ], 6 | "optionalUnityReferences": [ 7 | "TestAssemblies" 8 | ], 9 | "includePlatforms": [], 10 | "excludePlatforms": [], 11 | "allowUnsafeCode": false, 12 | "overrideReferences": false, 13 | "precompiledReferences": [], 14 | "autoReferenced": true, 15 | "defineConstraints": [] 16 | } -------------------------------------------------------------------------------- /Editor/ModelDrivenGUI.Editor.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0e8672924beb20b4e88a4cabce5d6fd2 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Editor/ReflectionTest.cs: -------------------------------------------------------------------------------- 1 | using ModelDrivenGUISystem.Extensions.FieldInfoExt; 2 | using NUnit.Framework; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using UnityEngine; 7 | 8 | namespace ModelDrivenGUISystem.Editor { 9 | 10 | public class ReflectionTest { 11 | [Test] 12 | public void GenericInterfaceTest() { 13 | var genericInterface = typeof(IList<>); 14 | var list = new List(); 15 | var interfaces = list.GetType() 16 | .GetInterfaces() 17 | .ToArray(); 18 | 19 | Assert.AreEqual( 20 | genericInterface, 21 | typeof(IList).GetGenericTypeDefinition()); 22 | 23 | Assert.True(interfaces.Any(v => 24 | v.IsGenericType && (v.GetGenericTypeDefinition() == genericInterface) 25 | )); 26 | } 27 | [Test] 28 | public void ReflectionTestSimplePasses() { 29 | var data = new Data(); 30 | Assert.AreEqual( 31 | DataSectionEnum.ValueType_Vector, 32 | data.vector3float.Section()); 33 | Assert.AreEqual( 34 | DataSectionEnum.Primitive_Int, 35 | data.serializeFieldInt.Section()); 36 | Assert.AreEqual( 37 | DataSectionEnum.Class_Array, 38 | data.floatArray.Section()); 39 | Assert.AreEqual( 40 | DataSectionEnum.Class_ListGeneric, 41 | data.floatList.Section()); 42 | 43 | Debug.Log(data.stringField.Dump()); 44 | } 45 | 46 | public struct SomeStruct { 47 | public int intData; 48 | } 49 | 50 | [System.Serializable] 51 | public class Data { 52 | public List floatList; 53 | public float[] floatArray; 54 | public Vector3 vector3float; 55 | public SomeStruct someStruct; 56 | 57 | public int serializeFieldInt; 58 | public string stringField; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Editor/ReflectionTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 64db7724a9cf778439c74668f1f193f5 3 | timeCreated: 1519797723 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Model Driven GUI Generator for Unity 2 | ![Screenshot](screenshot01.png) 3 | 4 | ### Video preview 5 | [![Capture](http://img.youtube.com/vi/pofYBfI8eyM/0.jpg)](https://youtu.be/pofYBfI8eyM) 6 | 7 | Features: 8 | - MVVM architecture 9 | - Factory-based GUI (View) 10 | 11 | Supported types: 12 | - Primitives (int, float, etc.) 13 | - Vector2, Vector3, etc. 14 | - User defined classes 15 | - Arrays 16 | 17 | ## Usage 18 | Define data class (Model) 19 | ```csharp 20 | [System.Serializable] 21 | public class InnerModel { 22 | public bool bool01; 23 | public string string01; 24 | public int int01; 25 | public float float01; 26 | } 27 | [System.Serializable] 28 | public class Model { 29 | public enum SimpleEnum { One, Two } 30 | 31 | public Vector2 vec2_01; 32 | public Vector3 vec3_01; 33 | public Vector4 vec4_01; 34 | public Vector2Int vec2int01; 35 | 36 | public InnerModel innerClass01; 37 | } 38 | ``` 39 | Create view from the data 40 | ```csharp 41 | public class TestViewModel : MonoBehaviour { 42 | public Model data; 43 | protected BaseView view; 44 | 45 | void OnEnable() { 46 | var viewFactory = new SimpleViewFactory(); 47 | view = ClassConfigurator.GenerateClassView(new BaseValue(data), viewFactory); 48 | } 49 | void OnDisable() { 50 | view.Dispose(); 51 | } 52 | ``` 53 | Call Draw() method in MonoBehaviour.OnGUI() 54 | ```csharp 55 | void OnGUI() { 56 | window = GUILayout.Window(GetInstanceID(), window, Window, name); 57 | } 58 | void Window(int id) { 59 | view.Draw(); 60 | GUI.DragWindow(); 61 | } 62 | ``` 63 | 64 | [Sample](Examples/TestViewModel.cs) 65 | 66 | ## Installation 67 | Import [UniRx](https://www.assetstore.unity3d.com/#!/content/17276) plugin from Unity Asset Store. 68 | 69 | Add this repository in your project. 70 | ``` 71 | git submodule add https://github.com/nobnak/ModelDrivenGUI.git Assets/Packages/ModelDrivenGUI 72 | ``` 73 | -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 012b1cafd0a1de94b91d590990f0e801 3 | timeCreated: 1519895489 4 | licenseType: Pro 5 | TextScriptImporter: 6 | externalObjects: {} 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4a48295d04d733d41b7dbba1b7e731c9 3 | folderAsset: yes 4 | timeCreated: 1520010755 5 | licenseType: Pro 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Scripts/Accessor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3de1e3a3ed94a714e9f2dc01ec41832d 3 | folderAsset: yes 4 | timeCreated: 1520494068 5 | licenseType: Pro 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Scripts/Accessor/IValueAccessor.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace ModelDrivenGUISystem.Accessor { 6 | 7 | public interface IValueAccessor { 8 | 9 | bool TryParse(string s, out ValueType result); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Scripts/Accessor/IValueAccessor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 076551f25efdd2343a29dcbececb1d9e 3 | timeCreated: 1520494078 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Accessor/IVectorAccessor.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace ModelDrivenGUISystem.Accessor { 6 | 7 | public interface IVectorAccessor { 8 | int Count { get; } 9 | 10 | IEnumerable Split(VectorType vector); 11 | VectorType Join(IEnumerable elements); 12 | 13 | ElementType GetElement(ref VectorType vector, int index); 14 | void SetElement(ref VectorType vector, int index, ElementType element); 15 | 16 | bool TryParse(string s, out ElementType result); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Scripts/Accessor/IVectorAccessor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a65c06885adf4d947b4a8537bce82b76 3 | timeCreated: 1520494078 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Accessor/ValueAccessor.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace ModelDrivenGUISystem.Accessor { 6 | 7 | public class IntAccessor : IValueAccessor { 8 | 9 | public bool TryParse(string s, out int result) { 10 | return int.TryParse(s, out result); 11 | } 12 | } 13 | 14 | public class FloatAccessor : IValueAccessor { 15 | 16 | public bool TryParse(string s, out float result) { 17 | return float.TryParse(s, out result); 18 | } 19 | } 20 | 21 | public class EnumAccessor : IValueAccessor { 22 | public System.Type EnumType { get; set; } 23 | 24 | public EnumAccessor(System.Type enumType) { 25 | this.EnumType = enumType; 26 | } 27 | 28 | public bool TryParse(string s, out object result) { 29 | try { 30 | result = System.Enum.Parse(EnumType, s); 31 | return true; 32 | } catch (System.Exception e) { 33 | Debug.LogWarning(e); 34 | } 35 | 36 | result = default(object); 37 | return false; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Scripts/Accessor/ValueAccessor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3adb2da57c9c6d44b8849e924875c5d1 3 | timeCreated: 1520494078 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Accessor/VectorAccessor.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using Unity.Mathematics; 4 | using UnityEngine; 5 | 6 | namespace ModelDrivenGUISystem.Accessor { 7 | 8 | 9 | public class Vector2Accessor : IVectorAccessor { 10 | public int Count { get; protected set; } 11 | 12 | public Vector2Accessor() { 13 | this.Count = 2; 14 | } 15 | 16 | public Vector2 Join(IEnumerable elements) { 17 | var vec = new Vector2(); 18 | var stream = elements.GetEnumerator(); 19 | for (var i = 0; i < Count && stream.MoveNext(); i++) 20 | vec[i] = stream.Current; 21 | return vec; 22 | } 23 | public float GetElement(ref Vector2 vector, int index) { 24 | return vector[index]; 25 | } 26 | public void SetElement(ref Vector2 vector, int index, float element) { 27 | vector[index] = element; 28 | } 29 | public IEnumerable Split(Vector2 vector) { 30 | for (var i = 0; i < Count; i++) 31 | yield return vector[i]; 32 | } 33 | 34 | public bool TryParse(string s, out float result) { 35 | return float.TryParse(s, out result); 36 | } 37 | } 38 | public class Vector3Accessor : IVectorAccessor { 39 | public int Count { get; protected set; } 40 | 41 | public Vector3Accessor() { 42 | this.Count = 3; 43 | } 44 | 45 | public Vector3 Join(IEnumerable elements) { 46 | var vec = new Vector3(); 47 | var stream = elements.GetEnumerator(); 48 | for (var i = 0; i < Count && stream.MoveNext(); i++) 49 | vec[i] = stream.Current; 50 | return vec; 51 | } 52 | public float GetElement(ref Vector3 vector, int index) { 53 | return vector[index]; 54 | } 55 | public void SetElement(ref Vector3 vector, int index, float element) { 56 | vector[index] = element; 57 | } 58 | public IEnumerable Split(Vector3 vector) { 59 | for (var i = 0; i < Count; i++) 60 | yield return vector[i]; 61 | } 62 | 63 | public bool TryParse(string s, out float result) { 64 | return float.TryParse(s, out result); 65 | } 66 | } 67 | public class Vector4Accessor : IVectorAccessor { 68 | public int Count { get; protected set; } 69 | 70 | public Vector4Accessor() { 71 | this.Count = 4; 72 | } 73 | 74 | public Vector4 Join(IEnumerable elements) { 75 | var vec = new Vector4(); 76 | var stream = elements.GetEnumerator(); 77 | for (var i = 0; i < Count && stream.MoveNext(); i++) 78 | vec[i] = stream.Current; 79 | return vec; 80 | } 81 | public float GetElement(ref Vector4 vector, int index) { 82 | return vector[index]; 83 | } 84 | public void SetElement(ref Vector4 vector, int index, float element) { 85 | vector[index] = element; 86 | } 87 | public IEnumerable Split(Vector4 vector) { 88 | for (var i = 0; i < Count; i++) 89 | yield return vector[i]; 90 | } 91 | 92 | public bool TryParse(string s, out float result) { 93 | return float.TryParse(s, out result); 94 | } 95 | } 96 | public class Float2Accessor : IVectorAccessor { 97 | public int Count { get; protected set; } 98 | 99 | public Float2Accessor() { 100 | this.Count = 2; 101 | } 102 | 103 | public float2 Join(IEnumerable elements) { 104 | var vec = new float2(); 105 | var stream = elements.GetEnumerator(); 106 | for (var i = 0; i < Count && stream.MoveNext(); i++) 107 | vec[i] = stream.Current; 108 | return vec; 109 | } 110 | public float GetElement(ref float2 vector, int index) { 111 | return vector[index]; 112 | } 113 | public void SetElement(ref float2 vector, int index, float element) { 114 | vector[index] = element; 115 | } 116 | public IEnumerable Split(float2 vector) { 117 | for (var i = 0; i < Count; i++) 118 | yield return vector[i]; 119 | } 120 | 121 | public bool TryParse(string s, out float result) { 122 | return float.TryParse(s, out result); 123 | } 124 | } 125 | public class Float3Accessor : IVectorAccessor { 126 | public int Count { get; protected set; } 127 | 128 | public Float3Accessor() { 129 | this.Count = 3; 130 | } 131 | 132 | public float3 Join(IEnumerable elements) { 133 | var vec = new Vector3(); 134 | var stream = elements.GetEnumerator(); 135 | for (var i = 0; i < Count && stream.MoveNext(); i++) 136 | vec[i] = stream.Current; 137 | return vec; 138 | } 139 | public float GetElement(ref float3 vector, int index) { 140 | return vector[index]; 141 | } 142 | public void SetElement(ref float3 vector, int index, float element) { 143 | vector[index] = element; 144 | } 145 | public IEnumerable Split(float3 vector) { 146 | for (var i = 0; i < Count; i++) 147 | yield return vector[i]; 148 | } 149 | 150 | public bool TryParse(string s, out float result) { 151 | return float.TryParse(s, out result); 152 | } 153 | } 154 | public class Float4Accessor : IVectorAccessor { 155 | public int Count { get; protected set; } 156 | 157 | public Float4Accessor() { 158 | this.Count = 4; 159 | } 160 | 161 | public float4 Join(IEnumerable elements) { 162 | var vec = new Vector4(); 163 | var stream = elements.GetEnumerator(); 164 | for (var i = 0; i < Count && stream.MoveNext(); i++) 165 | vec[i] = stream.Current; 166 | return vec; 167 | } 168 | public float GetElement(ref float4 vector, int index) { 169 | return vector[index]; 170 | } 171 | public void SetElement(ref float4 vector, int index, float element) { 172 | vector[index] = element; 173 | } 174 | public IEnumerable Split(float4 vector) { 175 | for (var i = 0; i < Count; i++) 176 | yield return vector[i]; 177 | } 178 | 179 | public bool TryParse(string s, out float result) { 180 | return float.TryParse(s, out result); 181 | } 182 | } 183 | public class ColorAccessor : IVectorAccessor { 184 | public int Count { get; protected set; } 185 | 186 | public ColorAccessor() { 187 | this.Count = 4; 188 | } 189 | 190 | public Color Join(IEnumerable elements) { 191 | var vec = new Color(); 192 | var stream = elements.GetEnumerator(); 193 | for (var i = 0; i < Count && stream.MoveNext(); i++) 194 | vec[i] = stream.Current; 195 | return vec; 196 | } 197 | public float GetElement(ref Color vector, int index) { 198 | return vector[index]; 199 | } 200 | public void SetElement(ref Color vector, int index, float element) { 201 | vector[index] = element; 202 | } 203 | public IEnumerable Split(Color vector) { 204 | for (var i = 0; i < Count; i++) 205 | yield return vector[i]; 206 | } 207 | 208 | public bool TryParse(string s, out float result) { 209 | return float.TryParse(s, out result); 210 | } 211 | } 212 | 213 | public class Vector2IntAccessor : IVectorAccessor { 214 | public int Count { get; protected set; } 215 | 216 | public Vector2IntAccessor() { 217 | this.Count = 2; 218 | } 219 | 220 | public Vector2Int Join(IEnumerable elements) { 221 | var vec = new Vector2Int(); 222 | var stream = elements.GetEnumerator(); 223 | for (var i = 0; i < Count && stream.MoveNext(); i++) 224 | vec[i] = stream.Current; 225 | return vec; 226 | } 227 | public int GetElement(ref Vector2Int vector, int index) { 228 | return vector[index]; 229 | } 230 | public void SetElement(ref Vector2Int vector, int index, int element) { 231 | vector[index] = element; 232 | } 233 | public IEnumerable Split(Vector2Int vector) { 234 | for (var i = 0; i < Count; i++) 235 | yield return vector[i]; 236 | } 237 | 238 | public bool TryParse(string s, out int result) { 239 | return int.TryParse(s, out result); 240 | } 241 | } 242 | public class Vector3IntAccessor : IVectorAccessor { 243 | public int Count { get; protected set; } 244 | 245 | public Vector3IntAccessor() { 246 | this.Count = 3; 247 | } 248 | 249 | public Vector3Int Join(IEnumerable elements) { 250 | var vec = new Vector3Int(); 251 | var stream = elements.GetEnumerator(); 252 | for (var i = 0; i < Count && stream.MoveNext(); i++) 253 | vec[i] = stream.Current; 254 | return vec; 255 | } 256 | public int GetElement(ref Vector3Int vector, int index) { 257 | return vector[index]; 258 | } 259 | public void SetElement(ref Vector3Int vector, int index, int element) { 260 | vector[index] = element; 261 | } 262 | public IEnumerable Split(Vector3Int vector) { 263 | for (var i = 0; i < Count; i++) 264 | yield return vector[i]; 265 | } 266 | 267 | public bool TryParse(string s, out int result) { 268 | return int.TryParse(s, out result); 269 | } 270 | } 271 | } 272 | -------------------------------------------------------------------------------- /Scripts/Accessor/VectorAccessor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 93d462179a4f82648b99ec4cea8071f2 3 | timeCreated: 1520494078 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Attributes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 75334e02c71a9a74a9d28a33f2cf820b 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Scripts/Attributes/ClassTooltipAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace ModelDrivenGUISystem.Attributes { 6 | 7 | [System.AttributeUsage(System.AttributeTargets.Class)] 8 | public class ClassTooltipAttribute : TooltipAttribute { 9 | 10 | public ClassTooltipAttribute(string tooltip) : base(tooltip) { 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Scripts/Attributes/ClassTooltipAttribute.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8c04072cb940ac640b2f9ab50089716b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Attributes/CommentAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace ModelDrivenGUISystem.Attributes { 6 | 7 | public class CommentAttribute : System.Attribute { 8 | public readonly string text; 9 | 10 | public CommentAttribute(string text) { 11 | this.text = text; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Scripts/Attributes/CommentAttribute.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 07c6ff15096131f458760b4579f11ffc 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Attributes/TitleAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace ModelDrivenGUISystem.Attributes { 6 | 7 | public class TitleAttribute : System.Attribute { 8 | public readonly string title; 9 | 10 | public TitleAttribute(string title) { 11 | this.title = title; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Scripts/Attributes/TitleAttribute.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 82e90a820da931d4896f8b6c8bbc4899 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/ClassConfigurator.cs: -------------------------------------------------------------------------------- 1 | using ModelDrivenGUISystem.Attributes; 2 | using ModelDrivenGUISystem.Extensions.FieldInfoExt; 3 | using ModelDrivenGUISystem.Factory; 4 | using ModelDrivenGUISystem.ValueWrapper; 5 | using ModelDrivenGUISystem.View; 6 | using nobnak.Gist.DocSys; 7 | using nobnak.Gist.Extensions.CustomAttrExt; 8 | using System.Collections.Generic; 9 | using System.Reflection; 10 | using Unity.Mathematics; 11 | using UnityEngine; 12 | using CustomData = System.Collections.Generic.Dictionary; 13 | 14 | namespace ModelDrivenGUISystem { 15 | 16 | public static class ClassConfigurator { 17 | public const string CD_MODEL = "Model"; 18 | public const string CD_ATTRIBUTES = "Attributes"; 19 | 20 | public static BaseView GenerateClassView(IValue parentModel, IViewFactory viewFactory, bool isRoot = true) { 21 | var classType = parentModel.Value.GetType(); 22 | var customData = classType.GenerateCustomData(); 23 | var views = new List(); 24 | 25 | views.AddRange(classType.GenerateMemberComment(viewFactory, customData)); 26 | 27 | foreach (var f in parentModel.Value.Fields()) { 28 | var modelFactory = new FieldModelFactory(parentModel, f); 29 | var fieldCustomData = f.GenerateCustomData(); 30 | views.AddRange( 31 | GenerateFieldView(modelFactory, viewFactory, f)); 32 | views.AddRange(f.GenerateMemberComment(viewFactory, fieldCustomData)); 33 | } 34 | 35 | var parentTitle = classType.GetTitle(); 36 | var parentTooltip = classType.GetTooltip(); 37 | if (isRoot) 38 | customData[ClassView.KEY_EXTRUDE_CHILDREN] = true; 39 | var parentView = viewFactory.CreateClassView(parentModel, customData); 40 | parentView.Title = parentTitle; 41 | parentView.Tooltip = parentTooltip; 42 | parentView.Children = views; 43 | return parentView; 44 | } 45 | 46 | public static IEnumerable GenerateFieldView( 47 | IModelFactory modelFactory, IViewFactory viewFactory, 48 | FieldInfo f) { 49 | 50 | var title = f.GetTitle(); 51 | var tooltip = f.GetTooltip(); 52 | var fieldType = f.FieldType; 53 | 54 | return GenerateFieldView( 55 | modelFactory, viewFactory, 56 | fieldType, title, tooltip); 57 | } 58 | public static IEnumerable GenerateFieldView( 59 | IModelFactory modelFactory, IViewFactory viewFactory, 60 | System.Type fieldType, string title = "", string tooltip = "") { 61 | 62 | var customData = fieldType.GenerateCustomData(); 63 | 64 | switch (fieldType.Section()) { 65 | case DataSectionEnum.Primitive_Bool: { 66 | var model = modelFactory.CreateValue(); 67 | var view = viewFactory.CreateBoolView(model, customData); 68 | view.Title = title; 69 | view.Tooltip = tooltip; 70 | yield return view; 71 | break; 72 | } 73 | 74 | case DataSectionEnum.Primitive_Int: { 75 | var model = modelFactory.CreateValue(); 76 | var view = viewFactory.CreateIntView(model, customData); 77 | view.Title = title; 78 | view.Tooltip = tooltip; 79 | yield return view; 80 | break; 81 | } 82 | 83 | case DataSectionEnum.Primitive_Float: { 84 | var model = modelFactory.CreateValue(); 85 | var view = viewFactory.CreateFloatView(model, customData); 86 | view.Title = title; 87 | view.Tooltip = tooltip; 88 | yield return view; 89 | break; 90 | } 91 | 92 | case DataSectionEnum.Class_String: { 93 | var model = modelFactory.CreateValue(); 94 | var view = viewFactory.CreateStringView(model, customData); 95 | view.Title = title; 96 | view.Tooltip = tooltip; 97 | yield return view; 98 | break; 99 | } 100 | 101 | case DataSectionEnum.ValueType_Enum: { 102 | var model = modelFactory.CreateValue(); 103 | var view = viewFactory.CreateEnumView(model, customData); 104 | view.Title = title; 105 | view.Tooltip = tooltip; 106 | yield return view; 107 | break; 108 | } 109 | 110 | 111 | case DataSectionEnum.ValueType_Vector: 112 | switch (fieldType.VectorType()) { 113 | case VectorTypeEnum.Vector2: { 114 | var model = modelFactory.CreateValue(); 115 | var view = viewFactory.CreateVector2View(model, customData); 116 | view.Title = title; 117 | view.Tooltip = tooltip; 118 | yield return view; 119 | break; 120 | } 121 | case VectorTypeEnum.Vector3: { 122 | var model = modelFactory.CreateValue(); 123 | var view = viewFactory.CreateVector3View(model, customData); 124 | view.Title = title; 125 | view.Tooltip = tooltip; 126 | yield return view; 127 | break; 128 | } 129 | case VectorTypeEnum.Vector4: { 130 | var model = modelFactory.CreateValue(); 131 | var view = viewFactory.CreateVector4View(model, customData); 132 | view.Title = title; 133 | view.Tooltip = tooltip; 134 | yield return view; 135 | break; 136 | } 137 | case VectorTypeEnum.Color: { 138 | var model = modelFactory.CreateValue(); 139 | var view = viewFactory.CreateColorView(model, customData); 140 | view.Title = title; 141 | view.Tooltip = tooltip; 142 | yield return view; 143 | break; 144 | } 145 | 146 | case VectorTypeEnum.Float2: { 147 | var model = modelFactory.CreateValue(); 148 | var view = viewFactory.CreateVector2View(model, customData); 149 | view.Title = title; 150 | view.Tooltip = tooltip; 151 | yield return view; 152 | break; 153 | } 154 | case VectorTypeEnum.Float3: { 155 | var model = modelFactory.CreateValue(); 156 | var view = viewFactory.CreateVector3View(model, customData); 157 | view.Title = title; 158 | view.Tooltip = tooltip; 159 | yield return view; 160 | break; 161 | } 162 | case VectorTypeEnum.Float4: { 163 | var model = modelFactory.CreateValue(); 164 | var view = viewFactory.CreateVector4View(model, customData); 165 | view.Title = title; 166 | view.Tooltip = tooltip; 167 | yield return view; 168 | break; 169 | } 170 | } 171 | break; 172 | case DataSectionEnum.ValueType_VectorInt: 173 | switch (fieldType.VectorType()) { 174 | case VectorTypeEnum.Vector2Int: { 175 | var model = modelFactory.CreateValue(); 176 | var view = viewFactory.CreateVector2IntView(model, customData); 177 | view.Title = title; 178 | view.Tooltip = tooltip; 179 | yield return view; 180 | break; 181 | } 182 | case VectorTypeEnum.Vector3Int: { 183 | var model = modelFactory.CreateValue(); 184 | var view = viewFactory.CreateVector3IntView(model, customData); 185 | view.Title = title; 186 | view.Tooltip = tooltip; 187 | yield return view; 188 | break; 189 | } 190 | } 191 | break; 192 | 193 | case DataSectionEnum.Class_UserDefined: { 194 | var model = modelFactory.CreateValue(); 195 | if (model.Value != null) { 196 | var view = GenerateClassView(model, viewFactory, false); 197 | view.Title = title; 198 | view.Tooltip = tooltip; 199 | yield return view; 200 | } 201 | break; 202 | } 203 | 204 | case DataSectionEnum.Class_Array: { 205 | var model = modelFactory.CreateValue(fieldType); 206 | var methodCreateView = viewFactory.GetType().GetMethod("CreateArrayView") 207 | .MakeGenericMethod(fieldType.GetElementType()); 208 | var view = (BaseView)methodCreateView.Invoke( 209 | viewFactory, new object[] { model, customData }); 210 | view.Title = title; 211 | view.Tooltip = tooltip; 212 | yield return view; 213 | break; 214 | } 215 | case DataSectionEnum.Class_ListGeneric: { 216 | var model = modelFactory.CreateValue(fieldType); 217 | var elementType = fieldType.GetGenericArguments()[0]; 218 | var methodCreateView = viewFactory.GetType().GetMethod("CreateListView"); 219 | methodCreateView = methodCreateView.MakeGenericMethod(elementType); 220 | var view = (BaseView)methodCreateView.Invoke( 221 | viewFactory, new object[] { model, customData }); 222 | view.Title = title; 223 | view.Tooltip = tooltip; 224 | yield return view; 225 | break; 226 | } 227 | } 228 | } 229 | public static CustomData GenerateCustomData(this MemberInfo info) { 230 | var attributes = info.GetCustomAttributes(); 231 | var result = new CustomData(); 232 | result[CD_ATTRIBUTES] = attributes; 233 | return result; 234 | } 235 | public static string GetTitle(this MemberInfo info) { 236 | var titleAttr = info.GetCustomAttribute(); 237 | var title = (titleAttr == null) ? info.Name : titleAttr.title; 238 | return title; 239 | } 240 | public static IEnumerable GenerateMemberComment( 241 | this MemberInfo info, IViewFactory viewFactory, CustomData customData) { 242 | 243 | var attr = default(CommentAttribute); 244 | if (info.TryGetAttribute(out attr)) { 245 | customData[LabelView.CD_USAGE] = LabelView.UsageEnum.Comment; 246 | var comment = viewFactory.CreateLabelView(customData); 247 | comment.Title = attr.text; 248 | yield return comment; 249 | } 250 | } 251 | } 252 | } 253 | -------------------------------------------------------------------------------- /Scripts/ClassConfigurator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 15fd3585583da7c46835e4e1f4a89bfa 3 | timeCreated: 1520275716 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Enums.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a17fda0d45a51b345b462dc44a5beb4d 3 | folderAsset: yes 4 | timeCreated: 1519890212 5 | licenseType: Pro 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Scripts/Enums/DataDivisionEnum.cs: -------------------------------------------------------------------------------- 1 | namespace ModelDrivenGUISystem { 2 | 3 | public enum DataDivisionEnum { 4 | Primitive, 5 | ValueType, 6 | Class 7 | } 8 | } -------------------------------------------------------------------------------- /Scripts/Enums/DataDivisionEnum.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 317f9b5821193af418d1b51e61597354 3 | timeCreated: 1519890138 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Enums/DataSectionEnum.cs: -------------------------------------------------------------------------------- 1 | namespace ModelDrivenGUISystem { 2 | 3 | public enum DataSectionEnum { 4 | Primitive_Bool, 5 | Primitive_Int, 6 | Primitive_Float, 7 | Primitive_Other, 8 | ValueType_Struct, 9 | ValueType_Enum, 10 | ValueType_Vector, 11 | ValueType_VectorInt, 12 | Class_UserDefined, 13 | Class_ListGeneric, 14 | Class_String, 15 | Class_Array 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Scripts/Enums/DataSectionEnum.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e63bd138e57d11f4ea235ed004cafe5e 3 | timeCreated: 1519890108 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Enums/VectorTypeEnum.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace ModelDrivenGUISystem { 4 | 5 | public enum VectorTypeEnum { 6 | Unsupported, 7 | Vector2, 8 | Vector3, 9 | Vector4, 10 | Float2, 11 | Float3, 12 | Float4, 13 | Vector2Int, 14 | Vector3Int, 15 | Color, 16 | Color32 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Scripts/Enums/VectorTypeEnum.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f14f6363e26add24fb54179f3b77a90b 3 | timeCreated: 1520305890 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Examples.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3e5f4fbfbdd904b4d9df197d0519553b 3 | folderAsset: yes 4 | timeCreated: 1520010749 5 | licenseType: Pro 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Scripts/Examples/MainUI.cs: -------------------------------------------------------------------------------- 1 | using nobnak.Gist; 2 | using nobnak.Gist.DocSys; 3 | using nobnak.Gist.Events; 4 | using nobnak.Gist.Exhibitor; 5 | using nobnak.Gist.Extensions.FileExt; 6 | using nobnak.Gist.Extensions.ReflectionExt; 7 | using nobnak.Gist.IMGUI.Scope; 8 | using nobnak.Gist.InputDevice; 9 | using nobnak.Gist.Loader; 10 | using nobnak.Gist.MathAlgorithms.Extensions.MathExt; 11 | using System.Collections.Generic; 12 | using System.Linq; 13 | using System.Reflection; 14 | using System.Text; 15 | using UniRx; 16 | using UniRx.Diagnostics; 17 | using UnityEngine; 18 | using UnityEngine.SceneManagement; 19 | using nobnak.Gist.Extensions.ScreenExt; 20 | using ModelDrivenGUISystem.Extensions.GUIExt; 21 | using UnityEngine.Events; 22 | 23 | 24 | #if UNITY_EDITOR 25 | using UnityEditor; 26 | #endif 27 | 28 | namespace ModelDrivenGUISystem.Examples { 29 | 30 | [ExecuteAlways] 31 | public class MainUI : MonoBehaviour { 32 | public const string SERIALIZED_EXT = "txt"; 33 | 34 | [SerializeField] 35 | protected ExhibitorFolder exhitFolder = new ExhibitorFolder(); 36 | [SerializeField] 37 | protected FolderPath folderPath = new FolderPath(); 38 | [SerializeField] 39 | protected Tuner tuner = new Tuner(); 40 | [SerializeField] 41 | protected Events events = new Events(); 42 | 43 | [SerializeField] 44 | protected KeycodeToggle uiVisibility = new KeycodeToggle(KeyCode.C); 45 | protected bool currUIVisibility; 46 | 47 | protected Validator validator = new Validator(); 48 | protected Rect windowRect = new Rect(10, 10, 300f, 500f); 49 | protected Vector2 scrollPos; 50 | protected Vector2 scrollSizeDiff; 51 | 52 | protected int selectedTab = 0; 53 | protected string[] tabNames = new string[0]; 54 | protected GUIContent[] tabContens = new GUIContent[0]; 55 | protected string[] serializedNames = new string[0]; 56 | 57 | protected System.IDisposable unirxLogger; 58 | 59 | #region unity 60 | private void OnEnable() { 61 | unirxLogger = ObservableLogger.Listener.Where(v => v.LogType == LogType.Exception).LogToUnityDebug(); 62 | 63 | uiVisibility.Reset(); 64 | uiVisibility.Toggle += v => NotifyVisibility(); 65 | 66 | validator.Reset(); 67 | validator.Validation += () => { 68 | var exhibitors = exhitFolder.exhibitors; 69 | tabNames = exhibitors.Select(v => v.Name).ToArray(); 70 | tabContens = exhibitors.Select(v => new GUIContent(v.Name, v.RawData().GetType().GetTooltip())).ToArray(); 71 | var appName = Application.productName.SanitizeFilename(); 72 | var scene = SceneManager.GetActiveScene(); 73 | var sceneName = scene.name; 74 | serializedNames = exhibitors 75 | .Select(v => $"{appName}-{sceneName}-{v.gameObject.name.SanitizeFilename()}-{v.GetType().Name.SanitizeFilename()}.{SERIALIZED_EXT}") 76 | .ToArray(); 77 | }; 78 | 79 | NotifyVisibility(); 80 | 81 | Load(); 82 | } 83 | private void OnDisable() { 84 | if (unirxLogger != null) { 85 | unirxLogger.Dispose(); 86 | unirxLogger = null; 87 | } 88 | NotifyVisibility(); 89 | } 90 | private void OnValidate() { 91 | validator.Invalidate(); 92 | } 93 | private void Update() { 94 | validator.Validate(); 95 | uiVisibility.Update(); 96 | } 97 | private void OnGUI() { 98 | if (!uiVisibility.Visible) 99 | return; 100 | 101 | if (tuner.enableDpiScale) { 102 | ScreenExtension.ScaleGUIBasedOnDpi(); 103 | } 104 | 105 | windowRect = GUILayout.Window(GetInstanceID(), windowRect, Window, name); 106 | 107 | var currSize = windowRect.size; 108 | currSize.x += Mathf.Max(0f, scrollSizeDiff.x); 109 | windowRect.size = currSize; 110 | } 111 | #endregion 112 | 113 | #region member 114 | protected void Window(int id) { 115 | var exhibitors = exhitFolder.exhibitors; 116 | GUILayout.BeginVertical(); 117 | 118 | GUILayout.BeginHorizontal(); 119 | if (GUILayout.Button("Save")) { 120 | Save(); 121 | } 122 | if (GUILayout.Button("Load")) { 123 | Load(); 124 | } 125 | GUILayout.EndHorizontal(); 126 | GUILayout.Label("", GUI.skin.horizontalSlider); 127 | 128 | selectedTab = GUILayout.Toolbar(selectedTab, tabContens); 129 | var currExhibit = (0 <= selectedTab && selectedTab < exhibitors.Length) 130 | ? exhibitors[selectedTab] : null; 131 | if (currExhibit != null) { 132 | using (new GUIChangedScope(() => currExhibit.ReflectChangeOf(MVVMComponent.View))) 133 | currExhibit.Draw(); 134 | } 135 | 136 | GUILayout.EndVertical(); 137 | 138 | GUIExtension.DrawTooltips(); 139 | 140 | GUI.DragWindow(); 141 | } 142 | 143 | private void Save() { 144 | Debug.Log($"Save : {GetType().Name}"); 145 | validator.Validate(); 146 | var exhibitors = exhitFolder.exhibitors; 147 | for (var i = 0; i < exhibitors.Length; i++) { 148 | var ex = exhibitors[i]; 149 | var filename = serializedNames[i]; 150 | var json = ex.SerializeToJson(); 151 | folderPath.TrySave(filename, json); 152 | } 153 | } 154 | private void Load() { 155 | Debug.Log($"Load : {GetType().Name}"); 156 | validator.Validate(); 157 | var exhibitors = exhitFolder.exhibitors; 158 | for (var i = 0; i < exhibitors.Length; i++) { 159 | var ex = exhibitors[i]; 160 | var filename = serializedNames[i]; 161 | string json; 162 | if (folderPath.TryLoad(filename, out json)) { 163 | ex.DeserializeFromJson(json); 164 | } 165 | } 166 | } 167 | 168 | private void NotifyVisibility(bool v) { 169 | if (currUIVisibility != v) { 170 | currUIVisibility = v; 171 | events.onVisibilityChanged?.Invoke(GetInstanceID(), v); 172 | } 173 | } 174 | private void NotifyVisibility() { 175 | NotifyVisibility(isActiveAndEnabled && uiVisibility.Visible); 176 | } 177 | #endregion 178 | 179 | #region interfaces 180 | public IEnumerable GenerateDoc(AbstractExhibitor e) { 181 | var root = e.RawData().GetType(); 182 | foreach (var fi in root.GetInstancePublicFields()) { 183 | foreach (var line in fi.GenerateDoc(0)) { 184 | yield return line; 185 | } 186 | } 187 | } 188 | public IEnumerable GenerateDoc(IEnumerable list, int i = 0) { 189 | foreach (var e in list) { 190 | if (e is ExhibitorGroup) { 191 | foreach (var line in GenerateDoc(((ExhibitorGroup)e).Exhibitors, i + 1)) 192 | yield return line; 193 | continue; 194 | } 195 | 196 | yield return $"{new string('#', i + 1)} {e.Name} : {e.RawData().GetType().GetTooltip()}"; 197 | foreach (var line in GenerateDoc(e)) { 198 | yield return line; 199 | } 200 | } 201 | } 202 | public IEnumerable GenerateDoc() { 203 | foreach (var line in GenerateDoc(exhitFolder.exhibitors)) { 204 | yield return line; 205 | } 206 | } 207 | #endregion 208 | 209 | #region classes 210 | [System.Serializable] 211 | public class ExhibitorFolder { 212 | public AbstractExhibitor[] exhibitors = new AbstractExhibitor[0]; 213 | } 214 | [System.Serializable] 215 | public class Tuner { 216 | public bool enableDpiScale = true; 217 | } 218 | 219 | [System.Serializable] 220 | public class Events { 221 | public UnityEvent onVisibilityChanged = new(); 222 | } 223 | #endregion 224 | } 225 | } 226 | -------------------------------------------------------------------------------- /Scripts/Examples/MainUI.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 06cd84eed88bb554b84f2b7858284c09 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Examples/TestViewModel.cs: -------------------------------------------------------------------------------- 1 | using ModelDrivenGUISystem.Attributes; 2 | using ModelDrivenGUISystem.Extensions.FieldInfoExt; 3 | using ModelDrivenGUISystem.Factory; 4 | using ModelDrivenGUISystem.ValueWrapper; 5 | using ModelDrivenGUISystem.View; 6 | using System.Collections.Generic; 7 | using UnityEngine; 8 | 9 | namespace ModelDrivenGUISystem.Examples { 10 | 11 | public class TestViewModel : MonoBehaviour { 12 | public Model data; 13 | 14 | protected Rect window; 15 | protected BaseView view; 16 | 17 | private void OnEnable() { 18 | window = new Rect(10f, 10f, 300f, 300f); 19 | var viewFactory = new SimpleViewFactory(); 20 | view = ClassConfigurator.GenerateClassView(new BaseValue(data), viewFactory); 21 | } 22 | private void OnDisable() { 23 | if (view != null) { 24 | view.Dispose(); 25 | view = null; 26 | } 27 | } 28 | private void OnGUI() { 29 | window = GUILayout.Window(GetInstanceID(), window, Window, name); 30 | } 31 | private void Window(int id) { 32 | view.Draw(); 33 | GUI.DragWindow(); 34 | } 35 | 36 | [System.Serializable] 37 | public class InnerInnerModel { 38 | public bool bool0; 39 | public int[] intArray0; 40 | } 41 | [System.Serializable] 42 | public class InnerModel { 43 | public int[] int0; 44 | public InnerInnerModel innerInnerModel0; 45 | } 46 | [System.Serializable] 47 | [Title("Model by Title")] 48 | [Comment("あれをこれする設定")] 49 | public class Model { 50 | public enum SimpleEnum { One, Two } 51 | [Title("int0 by Title")] 52 | public int int0; 53 | [Comment("あっちをこっちにする")] 54 | public SimpleEnum simpleEnum0; 55 | [Comment("これをどれする")] 56 | public string string0; 57 | 58 | public int[] intArray0 = new int[0]; 59 | [Comment("あまり使わない設定")] 60 | public InnerModel[] innterModelArray0 = new InnerModel[0]; 61 | [Comment("マニアックな設定")] 62 | public InnerInnerModel[] innerInnerModelArray0 = new InnerInnerModel[0]; 63 | 64 | public List intList0 = new List(); 65 | public List innerInnerModel0 = new List(); 66 | public StepAndCurveData stepData0 = new StepAndCurveData(); 67 | } 68 | 69 | 70 | [System.Serializable] 71 | public class RouteInfo { 72 | public List points = new List(); 73 | public List indices = new List(); 74 | public string connections; 75 | } 76 | [System.Serializable] 77 | public class RouteMap { 78 | public List routes = new List(); 79 | } 80 | [System.Serializable] 81 | public class StepAndCurveData { 82 | public RouteMap routes = new RouteMap(); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Scripts/Examples/TestViewModel.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e3b7ea85389ad4e4b80050a79a06bff9 3 | timeCreated: 1520282314 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Examples/TestViewModel.unity: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!29 &1 4 | OcclusionCullingSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_OcclusionBakeSettings: 8 | smallestOccluder: 5 9 | smallestHole: 0.25 10 | backfaceThreshold: 100 11 | m_SceneGUID: 00000000000000000000000000000000 12 | m_OcclusionCullingData: {fileID: 0} 13 | --- !u!104 &2 14 | RenderSettings: 15 | m_ObjectHideFlags: 0 16 | serializedVersion: 9 17 | m_Fog: 0 18 | m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} 19 | m_FogMode: 3 20 | m_FogDensity: 0.01 21 | m_LinearFogStart: 0 22 | m_LinearFogEnd: 300 23 | m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} 24 | m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} 25 | m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} 26 | m_AmbientIntensity: 1 27 | m_AmbientMode: 0 28 | m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} 29 | m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} 30 | m_HaloStrength: 0.5 31 | m_FlareStrength: 1 32 | m_FlareFadeSpeed: 3 33 | m_HaloTexture: {fileID: 0} 34 | m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} 35 | m_DefaultReflectionMode: 0 36 | m_DefaultReflectionResolution: 128 37 | m_ReflectionBounces: 1 38 | m_ReflectionIntensity: 1 39 | m_CustomReflection: {fileID: 0} 40 | m_Sun: {fileID: 0} 41 | m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1} 42 | m_UseRadianceAmbientProbe: 0 43 | --- !u!157 &3 44 | LightmapSettings: 45 | m_ObjectHideFlags: 0 46 | serializedVersion: 11 47 | m_GIWorkflowMode: 1 48 | m_GISettings: 49 | serializedVersion: 2 50 | m_BounceScale: 1 51 | m_IndirectOutputScale: 1 52 | m_AlbedoBoost: 1 53 | m_EnvironmentLightingMode: 0 54 | m_EnableBakedLightmaps: 1 55 | m_EnableRealtimeLightmaps: 1 56 | m_LightmapEditorSettings: 57 | serializedVersion: 12 58 | m_Resolution: 2 59 | m_BakeResolution: 40 60 | m_AtlasSize: 1024 61 | m_AO: 0 62 | m_AOMaxDistance: 1 63 | m_CompAOExponent: 1 64 | m_CompAOExponentDirect: 0 65 | m_ExtractAmbientOcclusion: 0 66 | m_Padding: 2 67 | m_LightmapParameters: {fileID: 0} 68 | m_LightmapsBakeMode: 1 69 | m_TextureCompression: 1 70 | m_FinalGather: 0 71 | m_FinalGatherFiltering: 1 72 | m_FinalGatherRayCount: 256 73 | m_ReflectionCompression: 2 74 | m_MixedBakeMode: 2 75 | m_BakeBackend: 0 76 | m_PVRSampling: 1 77 | m_PVRDirectSampleCount: 32 78 | m_PVRSampleCount: 500 79 | m_PVRBounces: 2 80 | m_PVREnvironmentSampleCount: 500 81 | m_PVREnvironmentReferencePointCount: 2048 82 | m_PVRFilteringMode: 2 83 | m_PVRDenoiserTypeDirect: 0 84 | m_PVRDenoiserTypeIndirect: 0 85 | m_PVRDenoiserTypeAO: 0 86 | m_PVRFilterTypeDirect: 0 87 | m_PVRFilterTypeIndirect: 0 88 | m_PVRFilterTypeAO: 0 89 | m_PVREnvironmentMIS: 0 90 | m_PVRCulling: 1 91 | m_PVRFilteringGaussRadiusDirect: 1 92 | m_PVRFilteringGaussRadiusIndirect: 5 93 | m_PVRFilteringGaussRadiusAO: 2 94 | m_PVRFilteringAtrousPositionSigmaDirect: 0.5 95 | m_PVRFilteringAtrousPositionSigmaIndirect: 2 96 | m_PVRFilteringAtrousPositionSigmaAO: 1 97 | m_ShowResolutionOverlay: 1 98 | m_ExportTrainingData: 0 99 | m_LightingDataAsset: {fileID: 0} 100 | m_UseShadowmask: 1 101 | --- !u!196 &4 102 | NavMeshSettings: 103 | serializedVersion: 2 104 | m_ObjectHideFlags: 0 105 | m_BuildSettings: 106 | serializedVersion: 2 107 | agentTypeID: 0 108 | agentRadius: 0.5 109 | agentHeight: 2 110 | agentSlope: 45 111 | agentClimb: 0.4 112 | ledgeDropHeight: 0 113 | maxJumpAcrossDistance: 0 114 | minRegionArea: 2 115 | manualCellSize: 0 116 | cellSize: 0.16666667 117 | manualTileSize: 0 118 | tileSize: 256 119 | accuratePlacement: 0 120 | debug: 121 | m_Flags: 0 122 | m_NavMeshData: {fileID: 0} 123 | --- !u!1 &1217427258 124 | GameObject: 125 | m_ObjectHideFlags: 0 126 | m_CorrespondingSourceObject: {fileID: 0} 127 | m_PrefabInstance: {fileID: 0} 128 | m_PrefabAsset: {fileID: 0} 129 | serializedVersion: 6 130 | m_Component: 131 | - component: {fileID: 1217427262} 132 | - component: {fileID: 1217427261} 133 | - component: {fileID: 1217427260} 134 | - component: {fileID: 1217427259} 135 | m_Layer: 0 136 | m_Name: Main Camera 137 | m_TagString: MainCamera 138 | m_Icon: {fileID: 0} 139 | m_NavMeshLayer: 0 140 | m_StaticEditorFlags: 0 141 | m_IsActive: 1 142 | --- !u!81 &1217427259 143 | AudioListener: 144 | m_ObjectHideFlags: 0 145 | m_CorrespondingSourceObject: {fileID: 0} 146 | m_PrefabInstance: {fileID: 0} 147 | m_PrefabAsset: {fileID: 0} 148 | m_GameObject: {fileID: 1217427258} 149 | m_Enabled: 1 150 | --- !u!124 &1217427260 151 | Behaviour: 152 | m_ObjectHideFlags: 0 153 | m_CorrespondingSourceObject: {fileID: 0} 154 | m_PrefabInstance: {fileID: 0} 155 | m_PrefabAsset: {fileID: 0} 156 | m_GameObject: {fileID: 1217427258} 157 | m_Enabled: 1 158 | --- !u!20 &1217427261 159 | Camera: 160 | m_ObjectHideFlags: 0 161 | m_CorrespondingSourceObject: {fileID: 0} 162 | m_PrefabInstance: {fileID: 0} 163 | m_PrefabAsset: {fileID: 0} 164 | m_GameObject: {fileID: 1217427258} 165 | m_Enabled: 1 166 | serializedVersion: 2 167 | m_ClearFlags: 2 168 | m_BackGroundColor: {r: 1, g: 1, b: 1, a: 0} 169 | m_projectionMatrixMode: 1 170 | m_GateFitMode: 2 171 | m_FOVAxisMode: 0 172 | m_SensorSize: {x: 36, y: 24} 173 | m_LensShift: {x: 0, y: 0} 174 | m_FocalLength: 50 175 | m_NormalizedViewPortRect: 176 | serializedVersion: 2 177 | x: 0 178 | y: 0 179 | width: 1 180 | height: 1 181 | near clip plane: 0.3 182 | far clip plane: 1000 183 | field of view: 60 184 | orthographic: 0 185 | orthographic size: 5 186 | m_Depth: -1 187 | m_CullingMask: 188 | serializedVersion: 2 189 | m_Bits: 4294967295 190 | m_RenderingPath: -1 191 | m_TargetTexture: {fileID: 0} 192 | m_TargetDisplay: 0 193 | m_TargetEye: 3 194 | m_HDR: 1 195 | m_AllowMSAA: 1 196 | m_AllowDynamicResolution: 0 197 | m_ForceIntoRT: 0 198 | m_OcclusionCulling: 1 199 | m_StereoConvergence: 10 200 | m_StereoSeparation: 0.022 201 | --- !u!4 &1217427262 202 | Transform: 203 | m_ObjectHideFlags: 0 204 | m_CorrespondingSourceObject: {fileID: 0} 205 | m_PrefabInstance: {fileID: 0} 206 | m_PrefabAsset: {fileID: 0} 207 | m_GameObject: {fileID: 1217427258} 208 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 209 | m_LocalPosition: {x: 0, y: 1, z: -10} 210 | m_LocalScale: {x: 1, y: 1, z: 1} 211 | m_Children: [] 212 | m_Father: {fileID: 0} 213 | m_RootOrder: 0 214 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 215 | --- !u!1 &1259776484 216 | GameObject: 217 | m_ObjectHideFlags: 0 218 | m_CorrespondingSourceObject: {fileID: 0} 219 | m_PrefabInstance: {fileID: 0} 220 | m_PrefabAsset: {fileID: 0} 221 | serializedVersion: 6 222 | m_Component: 223 | - component: {fileID: 1259776486} 224 | - component: {fileID: 1259776485} 225 | m_Layer: 0 226 | m_Name: Directional Light 227 | m_TagString: Untagged 228 | m_Icon: {fileID: 0} 229 | m_NavMeshLayer: 0 230 | m_StaticEditorFlags: 0 231 | m_IsActive: 1 232 | --- !u!108 &1259776485 233 | Light: 234 | m_ObjectHideFlags: 0 235 | m_CorrespondingSourceObject: {fileID: 0} 236 | m_PrefabInstance: {fileID: 0} 237 | m_PrefabAsset: {fileID: 0} 238 | m_GameObject: {fileID: 1259776484} 239 | m_Enabled: 1 240 | serializedVersion: 9 241 | m_Type: 1 242 | m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} 243 | m_Intensity: 1 244 | m_Range: 10 245 | m_SpotAngle: 30 246 | m_InnerSpotAngle: 21.80208 247 | m_CookieSize: 10 248 | m_Shadows: 249 | m_Type: 2 250 | m_Resolution: -1 251 | m_CustomResolution: -1 252 | m_Strength: 1 253 | m_Bias: 0.05 254 | m_NormalBias: 0.4 255 | m_NearPlane: 0.2 256 | m_CullingMatrixOverride: 257 | e00: 1 258 | e01: 0 259 | e02: 0 260 | e03: 0 261 | e10: 0 262 | e11: 1 263 | e12: 0 264 | e13: 0 265 | e20: 0 266 | e21: 0 267 | e22: 1 268 | e23: 0 269 | e30: 0 270 | e31: 0 271 | e32: 0 272 | e33: 1 273 | m_UseCullingMatrixOverride: 0 274 | m_Cookie: {fileID: 0} 275 | m_DrawHalo: 0 276 | m_Flare: {fileID: 0} 277 | m_RenderMode: 0 278 | m_CullingMask: 279 | serializedVersion: 2 280 | m_Bits: 4294967295 281 | m_RenderingLayerMask: 1 282 | m_Lightmapping: 4 283 | m_LightShadowCasterMode: 0 284 | m_AreaSize: {x: 1, y: 1} 285 | m_BounceIntensity: 1 286 | m_ColorTemperature: 6570 287 | m_UseColorTemperature: 0 288 | m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0} 289 | m_UseBoundingSphereOverride: 0 290 | m_ShadowRadius: 0 291 | m_ShadowAngle: 0 292 | --- !u!4 &1259776486 293 | Transform: 294 | m_ObjectHideFlags: 0 295 | m_CorrespondingSourceObject: {fileID: 0} 296 | m_PrefabInstance: {fileID: 0} 297 | m_PrefabAsset: {fileID: 0} 298 | m_GameObject: {fileID: 1259776484} 299 | m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} 300 | m_LocalPosition: {x: 0, y: 3, z: 0} 301 | m_LocalScale: {x: 1, y: 1, z: 1} 302 | m_Children: [] 303 | m_Father: {fileID: 0} 304 | m_RootOrder: 1 305 | m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} 306 | --- !u!1 &1757799410 307 | GameObject: 308 | m_ObjectHideFlags: 0 309 | m_CorrespondingSourceObject: {fileID: 0} 310 | m_PrefabInstance: {fileID: 0} 311 | m_PrefabAsset: {fileID: 0} 312 | serializedVersion: 6 313 | m_Component: 314 | - component: {fileID: 1757799412} 315 | - component: {fileID: 1757799411} 316 | m_Layer: 0 317 | m_Name: Model 318 | m_TagString: Untagged 319 | m_Icon: {fileID: 0} 320 | m_NavMeshLayer: 0 321 | m_StaticEditorFlags: 0 322 | m_IsActive: 1 323 | --- !u!114 &1757799411 324 | MonoBehaviour: 325 | m_ObjectHideFlags: 0 326 | m_CorrespondingSourceObject: {fileID: 0} 327 | m_PrefabInstance: {fileID: 0} 328 | m_PrefabAsset: {fileID: 0} 329 | m_GameObject: {fileID: 1757799410} 330 | m_Enabled: 1 331 | m_EditorHideFlags: 0 332 | m_Script: {fileID: 11500000, guid: e3b7ea85389ad4e4b80050a79a06bff9, type: 3} 333 | m_Name: 334 | m_EditorClassIdentifier: 335 | data: 336 | int0: 0 337 | simpleEnum0: 0 338 | string0: 339 | intArray0: 340 | innterModelArray0: [] 341 | innerInnerModelArray0: [] 342 | intList0: 0400000003000000 343 | innerInnerModel0: [] 344 | stepData0: 345 | routes: 346 | routes: [] 347 | --- !u!4 &1757799412 348 | Transform: 349 | m_ObjectHideFlags: 0 350 | m_CorrespondingSourceObject: {fileID: 0} 351 | m_PrefabInstance: {fileID: 0} 352 | m_PrefabAsset: {fileID: 0} 353 | m_GameObject: {fileID: 1757799410} 354 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 355 | m_LocalPosition: {x: 0, y: 0, z: 0} 356 | m_LocalScale: {x: 1, y: 1, z: 1} 357 | m_Children: [] 358 | m_Father: {fileID: 0} 359 | m_RootOrder: 2 360 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 361 | -------------------------------------------------------------------------------- /Scripts/Examples/TestViewModel.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a2eb67c65306f3b4e9184dc9f90f8b74 3 | timeCreated: 1520282328 4 | licenseType: Pro 5 | DefaultImporter: 6 | externalObjects: {} 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Scripts/Exhibitors.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ce22636712f77e34eac3ac655e6febbe 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Scripts/Exhibitors/ListExhibitor.cs: -------------------------------------------------------------------------------- 1 | using ModelDrivenGUISystem.Factory; 2 | using ModelDrivenGUISystem.ValueWrapper; 3 | using ModelDrivenGUISystem.View; 4 | using nobnak.Gist; 5 | using nobnak.Gist.Exhibitor; 6 | using nobnak.Gist.Extensions.ComponentExt; 7 | using nobnak.Gist.Layer2; 8 | using nobnak.Gist.ObjectExt; 9 | using System.Collections.Generic; 10 | using UnityEngine; 11 | 12 | namespace ModelDrivenGUISystem.Exhibitors { 13 | 14 | public abstract class ListExhibitor 15 | : AbstractExhibitor where ArtWorkType : Component { 16 | 17 | public Layer layer; 18 | public Transform parent; 19 | public ArtWorkType nodefab; 20 | 21 | protected List nodes = new List(); 22 | protected Validator validator = new Validator(); 23 | 24 | protected BaseView view; 25 | 26 | #region Unity 27 | protected virtual void OnEnable() { 28 | validator.Validation += () => { 29 | ReflectChangeOf(MVVMComponent.Model); 30 | }; 31 | validator.Validate(); 32 | } 33 | protected virtual void Update() { 34 | validator.Validate(); 35 | } 36 | protected virtual void OnValidate() { 37 | validator.Invalidate(); 38 | } 39 | protected virtual void OnDisable() { 40 | validator.Reset(); 41 | Clear(); 42 | } 43 | #endregion 44 | 45 | #region interfaces 46 | 47 | #region List 48 | protected virtual void Add(ArtWorkType n) { 49 | n.gameObject.hideFlags = HideFlags.DontSave; 50 | n.transform.SetParent(parent, false); 51 | nodes.Add(n); 52 | n.CallbackSelf(l => l.ExhibitorOnParent(parent)); 53 | } 54 | protected virtual void AddRange(IEnumerable niter) { 55 | foreach (var n in niter) 56 | Add(n); 57 | } 58 | protected virtual void Remove(ArtWorkType n) { 59 | nodes.Remove(n); 60 | if (n != null) n.CallbackSelf(l => l.ExhibitorOnUnparent(parent)); 61 | } 62 | protected virtual void Removerange(IEnumerable niter) { 63 | foreach (var n in niter) 64 | Remove(n); 65 | } 66 | protected virtual void Clear() { 67 | var removelist = new List(nodes); 68 | #if false //UNITY_EDITOR 69 | if (parent != null) { 70 | foreach (var n in parent.GetComponentsInChildren()) 71 | if (n != parent && !removelist.Contains(n)) removelist.Add(n); 72 | } 73 | #endif 74 | foreach (var n in removelist) { 75 | Remove(n); 76 | n.DestroyGo(); 77 | } 78 | nodes.Clear(); 79 | } 80 | #endregion 81 | 82 | #region IExhibitor 83 | public override string SerializeToJson() { 84 | validator.Validate(); 85 | return JsonUtility.ToJson(CurrentData); 86 | } 87 | public override void DeserializeFromJson(string json) { 88 | CurrentData = JsonUtility.FromJson(json); 89 | validator.Invalidate(); 90 | } 91 | public override object RawData() { return CurrentData; } 92 | public override void Draw() { 93 | validator.Validate(); 94 | GetView().Draw(); 95 | } 96 | 97 | public override void ResetViewModelFromModel() { 98 | ResetNodesFromData(); 99 | } 100 | public override void ApplyViewModelToModel() { 101 | ResetNodesFromData(); 102 | } 103 | public override void ResetView() { 104 | if (view != null) { 105 | view.Dispose(); 106 | view = null; 107 | } 108 | } 109 | #endregion 110 | 111 | public abstract DataTransformType CurrentData { get; set; } 112 | public abstract void ResetNodesFromData(); 113 | 114 | public virtual Validator Validator { get { return validator; } } 115 | #endregion 116 | 117 | #region member 118 | protected virtual BaseView GetView() { 119 | validator.Validate(); 120 | if (view == null) { 121 | var f = new SimpleViewFactory(); 122 | view = ClassConfigurator.GenerateClassView(new BaseValue(CurrentData), f); 123 | } 124 | return view; 125 | } 126 | #endregion 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /Scripts/Exhibitors/ListExhibitor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e828496064bc5e94f831e3496dc36df6 3 | timeCreated: 1518685518 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Exhibitors/SelfTransform2DExhibitor.cs: -------------------------------------------------------------------------------- 1 | using ModelDrivenGUISystem.Factory; 2 | using ModelDrivenGUISystem.ValueWrapper; 3 | using ModelDrivenGUISystem.View; 4 | using nobnak.Gist; 5 | using nobnak.Gist.Exhibitor; 6 | using UnityEngine; 7 | 8 | namespace ModelDrivenGUISystem.Exhibitors { 9 | 10 | [ExecuteAlways] 11 | public class SelfTransform2DExhibitor : AbstractExhibitor { 12 | 13 | [SerializeField] 14 | protected Converter converter = new Converter(); 15 | [SerializeField] 16 | protected Data data = new Data(); 17 | 18 | protected Validator validator = new Validator(); 19 | protected BaseView view; 20 | 21 | #region unity 22 | private void OnEnable() { 23 | validator.Reset(); 24 | validator.Validation += () => { 25 | ReflectChangeOf(MVVMComponent.Model); 26 | }; 27 | } 28 | private void OnValidate() { 29 | ReflectChangeOf(MVVMComponent.ViewModel); 30 | } 31 | private void Update() { 32 | validator.Validate(); 33 | } 34 | #endregion 35 | 36 | #region interface 37 | #region Exhibitor 38 | public override void DeserializeFromJson(string json) { 39 | JsonUtility.FromJsonOverwrite(json, data); 40 | ReflectChangeOf(MVVMComponent.ViewModel); 41 | } 42 | public override object RawData() { 43 | validator.Validate(); 44 | return data; 45 | } 46 | public override string SerializeToJson() { 47 | validator.Validate(); 48 | return JsonUtility.ToJson(data); 49 | } 50 | public override void ResetViewModelFromModel() { 51 | data.name = gameObject.name; 52 | var n = data.node; 53 | n.position = converter.EncodePosition(transform.localPosition); 54 | n.rotation = converter.EncodeRotation(transform.localRotation); 55 | n.scale = converter.EncodePosition(transform.localScale); 56 | data.node = n; 57 | } 58 | public override void ApplyViewModelToModel() { 59 | gameObject.name = data.name; 60 | var n = data.node; 61 | transform.localPosition = converter.DecodePosition(n.position, 0f); 62 | transform.localRotation = converter.DecodeRotation(n.rotation); 63 | transform.localScale = converter.DecodePosition(n.scale, 1f); 64 | } 65 | public override void ResetView() { 66 | if (view != null) { 67 | view.Dispose(); 68 | view = null; 69 | } 70 | } 71 | public override void Draw() { 72 | GetView().Draw(); 73 | } 74 | #endregion 75 | 76 | #endregion 77 | 78 | #region member 79 | protected BaseView GetView() { 80 | validator.Validate(); 81 | if (view == null) { 82 | var factory = new SimpleViewFactory(); 83 | view = ClassConfigurator.GenerateClassView(new BaseValue(data), factory); 84 | } 85 | return view; 86 | } 87 | #endregion 88 | 89 | #region Classes 90 | [System.Serializable] 91 | public class Data { 92 | public string name = "No name"; 93 | public TransformData node = new TransformData(); 94 | } 95 | [System.Serializable] 96 | public class TransformData { 97 | public Vector2 position; 98 | public float rotation; 99 | public Vector2 scale; 100 | } 101 | 102 | [System.Serializable] 103 | public class Converter { 104 | public Vector2Int indices = new Vector2Int(0, 1); 105 | 106 | public Vector2 EncodePosition(Vector3 v3, out float z) { 107 | z = v3[IndexOfZ]; 108 | return new Vector2(v3[indices.x], v3[indices.y]); 109 | } 110 | public Vector2 EncodePosition(Vector3 v3) { 111 | float z; 112 | return EncodePosition(v3, out z); 113 | } 114 | public float EncodeRotation(Quaternion q) { 115 | return q.eulerAngles[IndexOfZ]; 116 | } 117 | 118 | public Vector3 DecodePosition(Vector2 v2, float z = 0f) { 119 | var v3 = Vector3.zero; 120 | v3[indices.x] = v2.x; 121 | v3[indices.y] = v2.y; 122 | v3[IndexOfZ] = z; 123 | return v3; 124 | } 125 | public Quaternion DecodeRotation(float r) { 126 | var v3 = Vector3.zero; 127 | v3[IndexOfZ] = r; 128 | return Quaternion.Euler(v3); 129 | } 130 | 131 | public int IndexOfZ { 132 | get { return 3 - (indices.x + indices.y); } 133 | } 134 | } 135 | #endregion 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /Scripts/Exhibitors/SelfTransform2DExhibitor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8a36050a9b1adeb4e9ca990593db8e29 3 | timeCreated: 1518685518 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Exhibitors/Transform2DExhibitor.cs: -------------------------------------------------------------------------------- 1 | using nobnak.Gist.Exhibitor; 2 | using System.Linq; 3 | using UnityEngine; 4 | 5 | namespace ModelDrivenGUISystem.Exhibitors { 6 | 7 | [ExecuteInEditMode] 8 | public class Transform2DExhibitor 9 | : ListExhibitor { 10 | [SerializeField] 11 | protected Data data; 12 | [SerializeField] 13 | protected Settings settings; 14 | 15 | #region interfaces 16 | 17 | #region ListExhibitor 18 | public override Data CurrentData { 19 | get { return data; } 20 | set { 21 | data = value; 22 | ReflectChangeOf(MVVMComponent.Model); 23 | } 24 | } 25 | public override void ResetNodesFromData() { 26 | Clear(); 27 | if (data != null && data.exhibits != null) 28 | AddRange(data.exhibits.Select(i => { 29 | var n = Instantiate(nodefab); 30 | return Decode(n, i); 31 | })); 32 | } 33 | #endregion 34 | 35 | public virtual Transform Decode(Transform node, Exhibit info) { 36 | var go = node.gameObject; 37 | go.name = info.name; 38 | return Decode(node, info.node); 39 | } 40 | public virtual Transform Decode(Transform tr, Transform2DExhibitor.TransformData ndata) { 41 | tr.localPosition = settings.ConvertPosition(ndata.position, 0f); 42 | tr.localRotation = Quaternion.Euler(settings.ConvertRotation(ndata.rotation)); 43 | tr.localScale = settings.ConvertPosition(ndata.scale, 1f); 44 | return tr; 45 | } 46 | #endregion 47 | 48 | #region Classes 49 | [System.Serializable] 50 | public class Data { 51 | public Exhibit[] exhibits; 52 | } 53 | [System.Serializable] 54 | public class Exhibit { 55 | public string name; 56 | public TransformData node; 57 | } 58 | [System.Serializable] 59 | public class TransformData { 60 | public Vector2 position; 61 | public float rotation; 62 | public Vector2 scale; 63 | } 64 | 65 | [System.Serializable] 66 | public class Settings { 67 | public Vector2Int indices = new Vector2Int(0, 1); 68 | 69 | public Vector3 ConvertPosition(Vector2 v2, float z = 0f) { 70 | var v3 = Vector3.zero; 71 | v3[indices.x] = v2.x; 72 | v3[indices.y] = v2.y; 73 | v3[IndexOfZ] = z; 74 | return v3; 75 | } 76 | public Vector2 ConvertPosition(Vector3 v3, out float z) { 77 | z = v3[IndexOfZ]; 78 | return new Vector2(v3[indices.x], v3[indices.y]); 79 | } 80 | public Vector2 ConvertPosition(Vector3 v3) { 81 | float z; 82 | return ConvertPosition(v3, out z); 83 | } 84 | public Vector3 ConvertRotation(float r) { 85 | var v3 = Vector3.zero; 86 | v3[IndexOfZ] = r; 87 | return v3; 88 | } 89 | 90 | public int IndexOfZ { 91 | get { return 3 - (indices.x + indices.y); } 92 | } 93 | } 94 | #endregion 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /Scripts/Exhibitors/Transform2DExhibitor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1c56b5871be6bf54a8eb890159da93ff 3 | timeCreated: 1518685518 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Exhibitors/TransformExhibitor.cs: -------------------------------------------------------------------------------- 1 | using nobnak.Gist.Exhibitor; 2 | using System.Linq; 3 | using UnityEngine; 4 | 5 | namespace ModelDrivenGUISystem.Exhibitors { 6 | 7 | [ExecuteInEditMode] 8 | public class TransformExhibitor : ListExhibitor { 9 | [SerializeField] 10 | protected Data data; 11 | 12 | #region interface 13 | 14 | #region ListExhibitor 15 | public override Data CurrentData { 16 | get { return data; } 17 | set { 18 | data = value; 19 | ReflectChangeOf(MVVMComponent.Model); 20 | } 21 | } 22 | public override void ResetNodesFromData() { 23 | Clear(); 24 | if (data != null && data.exhibits != null) 25 | AddRange(data.exhibits.Select(i => { 26 | var n = Instantiate(nodefab); 27 | return Decode(n, i); 28 | })); 29 | } 30 | #endregion 31 | 32 | public virtual Transform Decode(Transform node, Exhibit info) { 33 | node.gameObject.name = info.name; 34 | return Decode(node, info.node); 35 | } 36 | public static Transform Decode(Transform tr, TransformExhibitor.TransformData ndata) { 37 | tr.localPosition = ndata.position; 38 | tr.localRotation = Quaternion.Euler(ndata.rotation); 39 | tr.localScale = ndata.scale; 40 | return tr; 41 | } 42 | #endregion 43 | 44 | #region classes 45 | [System.Serializable] 46 | public class Data { 47 | public Exhibit[] exhibits; 48 | } 49 | [System.Serializable] 50 | public class Exhibit { 51 | public string name; 52 | public TransformData node; 53 | } 54 | [System.Serializable] 55 | public class TransformData { 56 | public Vector3 position; 57 | public Vector3 rotation; 58 | public Vector3 scale; 59 | } 60 | #endregion 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /Scripts/Exhibitors/TransformExhibitor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 10d4ec41d156d4f429b942285cf1e70b 3 | timeCreated: 1518685518 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Extensions.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e521f11702be4194faa3669c43f4cf51 3 | folderAsset: yes 4 | timeCreated: 1519890208 5 | licenseType: Pro 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Scripts/Extensions/ConstructorExtension.cs: -------------------------------------------------------------------------------- 1 | using ModelDrivenGUISystem.Extensions.FieldInfoExt; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | 6 | namespace ModelDrivenGUISystem.Extensions.ConstructorExt { 7 | 8 | public static class ConstructorExtension { 9 | 10 | public static object CreateInstance(this System.Type t) { 11 | object instance; 12 | if (t.IsArray) 13 | instance = System.Array.CreateInstance(t.GetElementType(), 0); 14 | else if (t == typeof(string)) 15 | instance = ""; 16 | else 17 | instance = System.Activator.CreateInstance(t); 18 | return instance; 19 | } 20 | 21 | public static object CreateInstanceHierarchy(this System.Type t) { 22 | var instance = CreateInstance(t); 23 | 24 | foreach (var f in instance.Fields()) { 25 | var typeOfField = f.FieldType; 26 | if (typeOfField.IsClass) { 27 | f.SetValue(instance, CreateInstanceHierarchy(typeOfField)); 28 | } 29 | } 30 | 31 | return instance; 32 | } 33 | 34 | public static T CreateInstanceHierarchy() { 35 | return (T)CreateInstanceHierarchy(typeof(T)); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Scripts/Extensions/ConstructorExtension.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b1fd08ad258c7a845b18374694a98c97 3 | timeCreated: 1520838372 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Extensions/FieldInfoExtension.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Linq.Expressions; 5 | using System.Reflection; 6 | using Unity.Mathematics; 7 | using UnityEngine; 8 | 9 | namespace ModelDrivenGUISystem.Extensions.FieldInfoExt { 10 | 11 | public static class FieldInfoExtension { 12 | 13 | public static IEnumerable Fields(this S s) { 14 | return s.GetType().GetFields(BindingFlags.Instance 15 | | BindingFlags.Public 16 | | BindingFlags.FlattenHierarchy); 17 | } 18 | 19 | public static DataDivisionEnum Division(this System.Type t) { 20 | return t.IsPrimitive ? DataDivisionEnum.Primitive 21 | : (t.IsValueType ? DataDivisionEnum.ValueType : DataDivisionEnum.Class); 22 | } 23 | public static DataDivisionEnum Division(this S obj) { 24 | return Division(typeof(S)); 25 | } 26 | 27 | public static DataSectionEnum Section(this System.Type t) { 28 | var div = Division(t); 29 | 30 | switch (div) { 31 | case DataDivisionEnum.Class: 32 | if (t.IsArray) 33 | return DataSectionEnum.Class_Array; 34 | else if (t.GetInterfaces() 35 | .Any(v => v.IsGenericType 36 | && (v.GetGenericTypeDefinition() == typeof(IList<>)) 37 | )) 38 | return DataSectionEnum.Class_ListGeneric; 39 | else if (t == typeof(string)) 40 | return DataSectionEnum.Class_String; 41 | return DataSectionEnum.Class_UserDefined; 42 | 43 | case DataDivisionEnum.ValueType: 44 | if (t.IsEnum) 45 | return DataSectionEnum.ValueType_Enum; 46 | else if (t == typeof(Vector2) 47 | || t == typeof(Vector3) 48 | || t == typeof(Vector4) 49 | || t == typeof(Color) 50 | || t == typeof(float2) 51 | || t == typeof(float3) 52 | || t == typeof(float4) 53 | ) 54 | return DataSectionEnum.ValueType_Vector; 55 | else if (t == typeof(Vector2Int) 56 | || t == typeof(Vector3Int) 57 | || t == typeof(Color32)) 58 | return DataSectionEnum.ValueType_VectorInt; 59 | return DataSectionEnum.ValueType_Struct; 60 | 61 | default: 62 | if (t == typeof(int)) 63 | return DataSectionEnum.Primitive_Int; 64 | else if (t == typeof(float)) 65 | return DataSectionEnum.Primitive_Float; 66 | else if (t == typeof(bool)) 67 | return DataSectionEnum.Primitive_Bool; 68 | 69 | Debug.Log($"Primitive type not found : {t}"); 70 | return DataSectionEnum.Primitive_Other; 71 | } 72 | } 73 | public static DataSectionEnum Section(this S obj) { 74 | return Section(typeof(S)); 75 | } 76 | public static DataSectionEnum Section(this FieldInfo f) { 77 | return Section(f.FieldType); 78 | } 79 | public static string Dump(this S obj) { 80 | var t = typeof(S); 81 | return string.Format("array={0} class={1} enum={2} primitive={3} valuetype={4}", 82 | t.IsArray, t.IsClass, t.IsEnum, t.IsPrimitive, t.IsValueType); 83 | } 84 | public static VectorTypeEnum VectorType(this System.Type t) { 85 | if (t == typeof(Vector2)) 86 | return VectorTypeEnum.Vector2; 87 | else if (t == typeof(Vector3)) 88 | return VectorTypeEnum.Vector3; 89 | else if (t == typeof(Vector4)) 90 | return VectorTypeEnum.Vector4; 91 | 92 | if (t == typeof(float2)) 93 | return VectorTypeEnum.Float2; 94 | else if (t == typeof(float3)) 95 | return VectorTypeEnum.Float3; 96 | else if (t == typeof(float4)) 97 | return VectorTypeEnum.Float4; 98 | 99 | else if (t == typeof(Color)) 100 | return VectorTypeEnum.Color; 101 | else if (t == typeof(Vector2Int)) 102 | return VectorTypeEnum.Vector2Int; 103 | else if (t == typeof(Vector3Int)) 104 | return VectorTypeEnum.Vector3Int; 105 | else if (t == typeof(Color32)) 106 | return VectorTypeEnum.Color32; 107 | return VectorTypeEnum.Unsupported; 108 | 109 | } 110 | public static VectorTypeEnum VectorType(this FieldInfo f) { 111 | return VectorType(f.FieldType); 112 | } 113 | 114 | public static string GetMemberName(Expression> memberAccess) { 115 | return ((MemberExpression)memberAccess.Body).Member.Name; 116 | } 117 | public static string GetMemberName(this T t, Expression> memberAccess) { 118 | return ((MemberExpression)memberAccess.Body).Member.Name; 119 | } 120 | public static FieldInfo GetField(this T t, Expression> memberAccess) { 121 | return typeof(T).GetField(t.GetMemberName(memberAccess)); 122 | } 123 | 124 | public static IEnumerable DumpGenericMethodInfo(this MethodInfo mi) { 125 | yield return string.Format("Method : {0}\n", mi); 126 | yield return string.Format("\tGeneric method definition? {0}\n", mi.IsGenericMethodDefinition); 127 | yield return string.Format("\tGeneric method? {0}\n", mi.IsGenericMethod); 128 | if (mi.IsGenericMethod) { 129 | var typeArguments = mi.GetGenericArguments(); 130 | yield return string.Format("\nList type arguments ({0}):\n", typeArguments.Length); 131 | 132 | foreach (var tparam in typeArguments) { 133 | if (tparam.IsGenericParameter) 134 | yield return string.Format("\t\tParameter:{0} at {1}, declaring method:{2}\n", 135 | tparam, tparam.GenericParameterPosition, tparam.DeclaringMethod); 136 | else 137 | yield return string.Format("\t\t{0}\n", tparam); 138 | } 139 | } 140 | } 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /Scripts/Extensions/FieldInfoExtension.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 503c8bae358e6ff48a2037d404d65205 3 | timeCreated: 1519890229 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Extensions/GUIExtension.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace ModelDrivenGUISystem.Extensions.GUIExt { 6 | 7 | public static class GUIExtension { 8 | 9 | public static void AddTooltipForLastGUIELement(this string tooltip) { 10 | var rectTextField = GUILayoutUtility.GetLastRect(); 11 | GUI.Label(rectTextField, new GUIContent("", tooltip)); 12 | } 13 | 14 | public static void DrawTooltips() { 15 | if (!string.IsNullOrWhiteSpace(GUI.tooltip)) { 16 | var cont = new GUIContent(GUI.tooltip); 17 | var size = GUI.skin.label.CalcSize(cont); 18 | var pos = Event.current.mousePosition; 19 | pos.y -= size.y; 20 | var rectTooltip = new Rect(pos, size); 21 | 22 | var bgcolor = GUI.backgroundColor; 23 | GUI.backgroundColor = new Color(0f, 0f, 0f, 0.5f); 24 | var style = new GUIStyle(GUI.skin.label); 25 | style.normal.background = Texture2D.whiteTexture; 26 | GUI.Label(rectTooltip, cont, style); 27 | GUI.backgroundColor = bgcolor; 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Scripts/Extensions/GUIExtension.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: da51805fcda8cdb4db1f0f516597b0c2 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Scripts/Extensions/MethodInfoExtension.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Linq.Expressions; 4 | using System.Reflection; 5 | using UnityEngine; 6 | 7 | namespace ModelDrivenGUISystem.Extensions.MethodInfoExt { 8 | 9 | public static class MethodInfoExtension { 10 | 11 | public static MethodInfo GetMethodInfo(LambdaExpression expression) { 12 | var body = expression.Body as MethodCallExpression; 13 | if (body == null) 14 | throw new System.ArgumentException("Not method call expression"); 15 | return body.Method; 16 | } 17 | 18 | public static MethodInfo GetMethodInfo( 19 | Expression> expression) { 20 | return GetMethodInfo((LambdaExpression)expression); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Scripts/Extensions/MethodInfoExtension.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b9625c69164ea2b41b943e922fc7e3f3 3 | timeCreated: 1520692445 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Extensions/VectorExtension.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace ModelDrivenGUISystem.Extensions.VectorExt { 6 | 7 | public static class VectorExtension { 8 | 9 | public static IEnumerable Split(this Vector4 v) { 10 | for (var i = 0; i < 4; i++) 11 | yield return v[i]; 12 | } 13 | public static IEnumerable Split(this Vector3 v) { 14 | for (var i = 0; i < 3; i++) 15 | yield return v[i]; 16 | } 17 | public static IEnumerable Split(this Vector2 v) { 18 | for (var i = 0; i < 2; i++) 19 | yield return v[i]; 20 | } 21 | 22 | public static Vector4 ToVector4(this IEnumerable buffer) { 23 | var stream = buffer.GetEnumerator(); 24 | var v = new Vector4(); 25 | for (var i = 0; i < 4 && stream.MoveNext(); i++) 26 | v[i] = stream.Current; 27 | return v; 28 | } 29 | public static Vector3 ToVector3(this IEnumerable buffer) { 30 | var stream = buffer.GetEnumerator(); 31 | var v = new Vector3(); 32 | for (var i = 0; i < 3 && stream.MoveNext(); i++) 33 | v[i] = stream.Current; 34 | return v; 35 | } 36 | public static Vector2 ToVector2(this IEnumerable buffer) { 37 | var stream = buffer.GetEnumerator(); 38 | var v = new Vector2(); 39 | for (var i = 0; i < 4 && stream.MoveNext(); i++) 40 | v[i] = stream.Current; 41 | return v; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Scripts/Extensions/VectorExtension.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 615aea6bd4b35d041be4106400911291 3 | timeCreated: 1520318631 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Factory.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: eb3a7f0cacdf5fa48a5a813f28dbc77a 3 | folderAsset: yes 4 | timeCreated: 1520492803 5 | licenseType: Pro 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Scripts/Factory/ArrayElementModelFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using ModelDrivenGUISystem.ValueWrapper; 5 | using UnityEngine; 6 | 7 | namespace ModelDrivenGUISystem.Factory { 8 | 9 | public class ArrayElementModelFactory : IModelFactory { 10 | public System.Array Array { get; set; } 11 | public int Index { get; set; } 12 | 13 | public ArrayElementModelFactory(System.Array array, int index) { 14 | this.Array = array; 15 | this.Index = index; 16 | } 17 | 18 | public IValue CreateValue() { 19 | return new ArrayElementValue(Array, Index); 20 | } 21 | 22 | public object CreateValue(Type typeOfValue) { 23 | var typeOfModel = typeof(ArrayElementValue<>).MakeGenericType(typeOfValue); 24 | return Activator.CreateInstance(typeOfModel, new object[] { Array, Index }); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Scripts/Factory/ArrayElementModelFactory.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c20b803cce8413b438bba60cd114d495 3 | timeCreated: 1520777304 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Factory/FieldModelFactory.cs: -------------------------------------------------------------------------------- 1 | using ModelDrivenGUISystem.ValueWrapper; 2 | using System.Reflection; 3 | 4 | namespace ModelDrivenGUISystem.Factory { 5 | 6 | public class FieldModelFactory : IModelFactory { 7 | public IValue Parent { get; protected set; } 8 | public FieldInfo Field { get; protected set; } 9 | 10 | public FieldModelFactory(IValue parent, FieldInfo field) { 11 | this.Parent = parent; 12 | this.Field = field; 13 | } 14 | 15 | public IValue CreateValue() { 16 | return new FieldValue(Parent, Field); 17 | } 18 | 19 | public object CreateValue(System.Type typeOfValue) { 20 | var modelType = typeof(FieldValue<>).MakeGenericType(Field.FieldType); 21 | return System.Activator.CreateInstance(modelType, new object[] { Parent, Field }); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Scripts/Factory/FieldModelFactory.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: baaf397627cbcef418bc11e48f2366b0 3 | timeCreated: 1520770753 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Factory/IModelFactory.cs: -------------------------------------------------------------------------------- 1 | using ModelDrivenGUISystem.ValueWrapper; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | 6 | namespace ModelDrivenGUISystem.Factory { 7 | 8 | public interface IModelFactory { 9 | 10 | IValue CreateValue(); 11 | object CreateValue(System.Type typeOfValue); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Scripts/Factory/IModelFactory.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 69fe470ef3d8c0948bcd2c01ee7709f0 3 | timeCreated: 1520769859 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Factory/IViewFactory.cs: -------------------------------------------------------------------------------- 1 | using ModelDrivenGUISystem.ValueWrapper; 2 | using ModelDrivenGUISystem.View; 3 | using System.Collections.Generic; 4 | using Unity.Mathematics; 5 | using UnityEngine; 6 | 7 | using CustomData = System.Collections.Generic.Dictionary; 8 | 9 | namespace ModelDrivenGUISystem.Factory { 10 | 11 | public interface IViewFactory { 12 | 13 | BaseView CreateClassView(IValue model, CustomData customData = null); 14 | 15 | BaseView CreateStringView(IValue model, CustomData customData = null); 16 | BaseView CreateEnumView(IValue modelm, CustomData customData = null); 17 | 18 | BaseView CreateBoolView(IValue model, CustomData customData = null); 19 | BaseView CreateIntView(IValue model, CustomData customData = null); 20 | BaseView CreateFloatView(IValue model, CustomData customData = null); 21 | 22 | BaseView CreateVector2View(IValue model, CustomData customData = null); 23 | BaseView CreateVector3View(IValue model, CustomData customData = null); 24 | BaseView CreateVector4View(IValue model, CustomData customData = null); 25 | BaseView CreateVector2View(IValue model, CustomData customData = null); 26 | BaseView CreateVector3View(IValue model, CustomData customData = null); 27 | BaseView CreateVector4View(IValue model, CustomData customData = null); 28 | BaseView CreateColorView(IValue model, CustomData customData = null); 29 | BaseView CreateVector2IntView(IValue model, CustomData customData = null); 30 | BaseView CreateVector3IntView(IValue model, CustomData customData = null); 31 | 32 | BaseView CreateArrayView(IValue model, CustomData customData = null) where T : new(); 33 | BaseView CreateListView(IValue> model, CustomData customData = null) where T : new(); 34 | 35 | BaseView CreateLabelView(CustomData customData = null); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Scripts/Factory/IViewFactory.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3d7201d02ea8a174480671cc0b9d6ad3 3 | timeCreated: 1520492796 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Factory/ListElementModelFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using ModelDrivenGUISystem.ValueWrapper; 5 | using UnityEngine; 6 | 7 | namespace ModelDrivenGUISystem.Factory { 8 | 9 | public class ListElementModelFactory : IModelFactory { 10 | public IList list { get; set; } 11 | public int Index { get; set; } 12 | 13 | public ListElementModelFactory(IList list, int index) { 14 | this.list = list; 15 | this.Index = index; 16 | } 17 | 18 | public IValue CreateValue() { 19 | return new ListElementValue(list, Index); 20 | } 21 | 22 | public object CreateValue(Type typeOfValue) { 23 | var typeOfModel = typeof(ListElementValue<>).MakeGenericType(typeOfValue); 24 | return Activator.CreateInstance(typeOfModel, new object[] { list, Index }); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Scripts/Factory/ListElementModelFactory.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 71394d5f1936e834c9e94e96b28db734 3 | timeCreated: 1520777304 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/Factory/SimpleViewFactory.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using ModelDrivenGUISystem.Accessor; 4 | using ModelDrivenGUISystem.ValueWrapper; 5 | using ModelDrivenGUISystem.View; 6 | using ModelDrivenGUISystem.ViewModel; 7 | using Unity.Mathematics; 8 | using UnityEngine; 9 | 10 | using CustomData = System.Collections.Generic.Dictionary; 11 | 12 | namespace ModelDrivenGUISystem.Factory { 13 | 14 | public class SimpleViewFactory : IViewFactory { 15 | public virtual BaseView CreateClassView(IValue model, CustomData customData = null) { 16 | return new ClassView() { 17 | CustomData = customData, 18 | }; 19 | } 20 | 21 | public virtual BaseView CreateStringView(IValue model, CustomData customData = null) { 22 | var vm = new BypassViewModel(model); 23 | return new TextFieldView() { 24 | Input = vm.Output, 25 | CustomData = customData 26 | }; 27 | } 28 | public virtual BaseView CreateEnumView(IValue model, CustomData customData = null) { 29 | var accessor = new EnumAccessor(model.Value.GetType()); 30 | var vm = new NumberViewModel(model, accessor); 31 | return new EnumView() { 32 | Input = vm.Output, 33 | EnumType = model.Value.GetType(), 34 | CustomData = customData 35 | }; 36 | } 37 | 38 | public virtual BaseView CreateBoolView(IValue model, CustomData customData = null) { 39 | var vm = new BypassViewModel(model); 40 | return new BoolView() { 41 | Input = vm.Output, 42 | CustomData = customData 43 | }; 44 | } 45 | public virtual BaseView CreateIntView(IValue model, CustomData customData = null) { 46 | var accessor = new IntAccessor(); 47 | var vm = new NumberViewModel(model, accessor); 48 | return new TextFieldView() { 49 | Input = vm.Output, 50 | CustomData = customData 51 | }; 52 | } 53 | public virtual BaseView CreateFloatView(IValue model, CustomData customData = null) { 54 | var accessor = new FloatAccessor(); 55 | var vm = new NumberViewModel(model, accessor); 56 | return new TextFieldView() { 57 | Input = vm.Output, 58 | CustomData = customData 59 | }; 60 | } 61 | 62 | public virtual BaseView CreateVector2View(IValue model, CustomData customData = null) { 63 | var vm = new VectorViewModel(model, new Vector2Accessor()); 64 | return new VectorView() { 65 | Input = vm.Output, 66 | CustomData = customData 67 | }; 68 | } 69 | public virtual BaseView CreateVector3View(IValue model, CustomData customData = null) { 70 | var vm = new VectorViewModel(model, new Vector3Accessor()); 71 | return new VectorView() { 72 | Input = vm.Output, 73 | CustomData = customData 74 | }; 75 | } 76 | public virtual BaseView CreateVector4View(IValue model, CustomData customData = null) { 77 | var vm = new VectorViewModel(model, new Vector4Accessor()); 78 | return new VectorView() { 79 | Input = vm.Output, 80 | CustomData = customData 81 | }; 82 | } 83 | public virtual BaseView CreateVector2View(IValue model, CustomData customData = null) { 84 | var vm = new VectorViewModel(model, new Float2Accessor()); 85 | return new VectorView() { 86 | Input = vm.Output, 87 | CustomData = customData 88 | }; 89 | } 90 | public virtual BaseView CreateVector3View(IValue model, CustomData customData = null) { 91 | var vm = new VectorViewModel(model, new Float3Accessor()); 92 | return new VectorView() { 93 | Input = vm.Output, 94 | CustomData = customData 95 | }; 96 | } 97 | public virtual BaseView CreateVector4View(IValue model, CustomData customData = null) { 98 | var vm = new VectorViewModel(model, new Float4Accessor()); 99 | return new VectorView() { 100 | Input = vm.Output, 101 | CustomData = customData 102 | }; 103 | } 104 | public virtual BaseView CreateColorView(IValue model, CustomData customData = null) { 105 | var vm = new VectorViewModel(model, new ColorAccessor()); 106 | return new VectorView() { 107 | Input = vm.Output, 108 | CustomData = customData 109 | }; 110 | } 111 | public virtual BaseView CreateVector2IntView(IValue model, CustomData customData = null) { 112 | var vm = new VectorViewModel(model, new Vector2IntAccessor()); 113 | return new VectorView() { 114 | Input = vm.Output, 115 | CustomData = customData 116 | }; 117 | } 118 | public virtual BaseView CreateVector3IntView(IValue model, CustomData customData = null) { 119 | var vm = new VectorViewModel(model, new Vector3IntAccessor()); 120 | return new VectorView() { 121 | Input = vm.Output, 122 | CustomData = customData 123 | }; 124 | } 125 | 126 | public virtual BaseView CreateArrayView(IValue model, CustomData customData = null) where T : new() { 127 | var vm = new ArrayViewModel(model, this); 128 | return new ArrayView() { 129 | Views = vm.OutputViews, 130 | Count = vm.OutputCount, 131 | CommandAdd = vm.CommandAdd, 132 | CommandRemove = vm.CommandRemove, 133 | CustomData = customData 134 | }; 135 | } 136 | public virtual BaseView CreateListView(IValue> model, CustomData customData = null) where T : new() { 137 | var vm = new ListViewModel(model, this); 138 | return new ListView() { 139 | Views = vm.OutputViews, 140 | Count = vm.OutputCount, 141 | CommandAdd = vm.CommandAdd, 142 | CommandRemove = vm.CommandRemove, 143 | CustomData = customData 144 | }; 145 | } 146 | public virtual BaseView CreateLabelView(CustomData customData = null) { 147 | return new LabelView() { 148 | CustomData = customData 149 | }; 150 | } 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /Scripts/Factory/SimpleViewFactory.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 889089a44da0701439a3dc276cce0fab 3 | timeCreated: 1520492796 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/ModelDrivenGUI.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ModelDrivenGUI", 3 | "rootNamespace": "", 4 | "references": [ 5 | "Unity.Mathematics", 6 | "nobnak.Gist", 7 | "UniRx" 8 | ], 9 | "includePlatforms": [], 10 | "excludePlatforms": [], 11 | "allowUnsafeCode": false, 12 | "overrideReferences": false, 13 | "precompiledReferences": [], 14 | "autoReferenced": true, 15 | "defineConstraints": [], 16 | "versionDefines": [], 17 | "noEngineReferences": false 18 | } -------------------------------------------------------------------------------- /Scripts/ModelDrivenGUI.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 04baea1731b1b374d91088266938baf1 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Scripts/ValueWrapper.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e7001c748ffd8d3439cd7c377ab108da 3 | folderAsset: yes 4 | timeCreated: 1520389750 5 | licenseType: Pro 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Scripts/ValueWrapper/ArrayElementValue.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using UnityEngine; 5 | 6 | namespace ModelDrivenGUISystem.ValueWrapper { 7 | 8 | public class ArrayElementValue : IValue { 9 | public System.Array Array { get; set; } 10 | public int Index { get; set; } 11 | 12 | public ArrayElementValue(System.Array array, int index) { 13 | this.Array = array; 14 | this.Index = index; 15 | } 16 | 17 | public ValueType Value { 18 | get { 19 | return (ValueType)Array.GetValue(Index); 20 | } 21 | set { 22 | Array.SetValue(value, Index); 23 | } 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Scripts/ValueWrapper/ArrayElementValue.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7575e14617e27e1419c4be3426c12b94 3 | timeCreated: 1520353231 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/ValueWrapper/BaseValue.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using UnityEngine; 5 | 6 | namespace ModelDrivenGUISystem.ValueWrapper { 7 | 8 | public class BaseValue : IValue { 9 | public ValueType Value { get; set; } 10 | 11 | public BaseValue(ValueType value) { 12 | this.Value = value; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Scripts/ValueWrapper/BaseValue.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 06233735416c4c148b90431deebfe422 3 | timeCreated: 1520353231 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/ValueWrapper/FieldIndexedValue.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using UnityEngine; 5 | 6 | namespace ModelDrivenGUISystem.ValueWrapper { 7 | 8 | public abstract class FieldIndexedValue 9 | : FieldValue, IIndexedValue { 10 | 11 | public FieldIndexedValue(object parent, FieldInfo field) : base(parent, field) { 12 | } 13 | 14 | public abstract ValueElementType this[int index] { get; set; } 15 | 16 | public abstract int CountElement { get; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Scripts/ValueWrapper/FieldIndexedValue.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b1173446e951908438ac4d95d4cbd430 3 | timeCreated: 1520355372 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/ValueWrapper/FieldValue.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using UnityEngine; 5 | 6 | namespace ModelDrivenGUISystem.ValueWrapper { 7 | 8 | public class FieldValue : IFieldValue { 9 | public virtual IValue Parent { get; protected set; } 10 | public virtual FieldInfo Field { get; protected set; } 11 | 12 | public FieldValue(IValue parent, FieldInfo field) { 13 | this.Parent = parent; 14 | this.Field = field; 15 | } 16 | public FieldValue(object parent, FieldInfo field) 17 | : this(new BaseValue(parent), field) { } 18 | 19 | public virtual ValueType Value { 20 | get { 21 | return (ValueType)Field.GetValue(Parent.Value); 22 | } 23 | set { 24 | Field.SetValue(Parent.Value, value); 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Scripts/ValueWrapper/FieldValue.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9e801e9fbad54844098a675b89187cbc 3 | timeCreated: 1520353231 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/ValueWrapper/IFieldValue.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using UnityEngine; 5 | 6 | namespace ModelDrivenGUISystem.ValueWrapper { 7 | 8 | public interface IFieldValue : IValue { 9 | IValue Parent { get; } 10 | FieldInfo Field { get; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Scripts/ValueWrapper/IFieldValue.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d8a776dcdd909aa4f95296c651070d8a 3 | timeCreated: 1520353231 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/ValueWrapper/IIndexedValue.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using UnityEngine; 5 | 6 | namespace ModelDrivenGUISystem.ValueWrapper { 7 | 8 | public interface IIndexedValue : IValue { 9 | int CountElement { get; } 10 | ValueElementType this[int index] {get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Scripts/ValueWrapper/IIndexedValue.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4806ffc38fe6c484aae82848b62e8054 3 | timeCreated: 1520355372 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/ValueWrapper/IValue.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using UnityEngine; 5 | 6 | namespace ModelDrivenGUISystem.ValueWrapper { 7 | 8 | public interface IValue { 9 | ValueType Value { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Scripts/ValueWrapper/IValue.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2de9f222899f100408a7f2c927417258 3 | timeCreated: 1520353231 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/ValueWrapper/ListElementValue.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using UnityEngine; 5 | 6 | namespace ModelDrivenGUISystem.ValueWrapper { 7 | 8 | public class ListElementValue : IValue { 9 | public IList List { get; set; } 10 | public int Index { get; set; } 11 | 12 | public ListElementValue(IList list, int index) { 13 | this.List = list; 14 | this.Index = index; 15 | } 16 | 17 | public ValueType Value { 18 | get { 19 | return (ValueType)List[Index]; 20 | } 21 | set { 22 | List[Index] = value; 23 | } 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Scripts/ValueWrapper/ListElementValue.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 06781b1b832e7614a8bf961db394d74a 3 | timeCreated: 1520353231 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/View.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1fce4a7c3baeb71468f42cd7350ac2da 3 | folderAsset: yes 4 | timeCreated: 1520324135 5 | licenseType: Pro 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Scripts/View/ArrayView.cs: -------------------------------------------------------------------------------- 1 | using nobnak.Gist.IMGUI.Scope; 2 | using UniRx; 3 | using UnityEngine; 4 | 5 | namespace ModelDrivenGUISystem.View { 6 | 7 | public class ArrayView : BaseView { 8 | public virtual IReadOnlyReactiveProperty Count { get; set; } 9 | public virtual IReadOnlyReactiveProperty Views { get; set; } 10 | 11 | public virtual ReactiveCommand CommandAdd { get; set; } 12 | public virtual ReactiveCommand CommandRemove { get; set; } 13 | 14 | protected bool visible = true; 15 | 16 | public override void Initialize() { 17 | if (initialized) 18 | return; 19 | base.Initialize(); 20 | 21 | foreach (var v in Views.Value) 22 | v.Initialize(); 23 | } 24 | public override void Draw() { 25 | using (new GUILayout.VerticalScope(new GUIContent(Title, Tooltip), GUIStyle.none)) 26 | using (new FoldoutScope(ref visible, Title, Tooltip)) 27 | using (new IndentScope(20f)) { 28 | if (visible) { 29 | GUILayout.Label(string.Format("Size : {0}", Count.Value)); 30 | using (new GUILayout.HorizontalScope()) { 31 | if (GUILayout.Button("Add")) 32 | CommandAdd.Execute(); 33 | if (GUILayout.Button("Remove")) 34 | CommandRemove.Execute(); 35 | } 36 | if (Views.Value != null) 37 | foreach (var v in Views.Value) 38 | v.Draw(); 39 | } 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Scripts/View/ArrayView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9a2ac13b5c1ac414fbf87daa69a4c515 3 | timeCreated: 1520695380 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/View/BaseView.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | using CustomData = System.Collections.Generic.Dictionary; 6 | 7 | namespace ModelDrivenGUISystem.View { 8 | 9 | public class BaseView : System.IDisposable { 10 | public virtual string Title { get; set; } 11 | public virtual string Tooltip { get; set; } 12 | public virtual IList Children { get; set; } 13 | public virtual CustomData CustomData { get; set; } 14 | 15 | protected bool initialized; 16 | 17 | public virtual void Initialize() { 18 | initialized = true; 19 | } 20 | public virtual void Draw() { } 21 | 22 | public virtual void Dispose() { 23 | if (Children != null) 24 | foreach (var v in Children) 25 | v.Dispose(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Scripts/View/BaseView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 39429236bf37ddd4fa6ba3ab2cba1c56 3 | timeCreated: 1520324164 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/View/BoolView.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UniRx; 4 | using UnityEngine; 5 | 6 | namespace ModelDrivenGUISystem.View { 7 | 8 | public class BoolView : BaseView { 9 | public ReactiveProperty Input { get; set; } 10 | 11 | public override void Draw() { 12 | Input.Value = GUILayout.Toggle(Input.Value, new GUIContent(Title, Tooltip), GUILayout.ExpandWidth(false)); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Scripts/View/BoolView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 73def72877345144e8556d2f3719ebd2 3 | timeCreated: 1520281134 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/View/ClassView.cs: -------------------------------------------------------------------------------- 1 | using nobnak.Gist.IMGUI.Scope; 2 | using UnityEngine; 3 | 4 | namespace ModelDrivenGUISystem.View { 5 | 6 | public class ClassView : BaseView { 7 | 8 | public const string KEY_EXTRUDE_CHILDREN = "_EXTRUDE_CHILDREN"; 9 | 10 | protected bool visible = false; 11 | protected bool expand = false; 12 | 13 | public ClassView(bool visible = false) { 14 | this.visible = visible; 15 | } 16 | 17 | public override void Initialize() { 18 | if (initialized) 19 | return; 20 | base.Initialize(); 21 | 22 | foreach (var c in Children) 23 | c.Initialize(); 24 | 25 | expand = CustomData.TryGetValue(KEY_EXTRUDE_CHILDREN, out object v) 26 | && v is bool 27 | && (bool)v; 28 | visible = visible || expand; 29 | } 30 | public override void Draw() { 31 | Initialize(); 32 | 33 | using (new GUILayout.VerticalScope()) { 34 | if (expand) 35 | DrawChildren(); 36 | else { 37 | using (new FoldoutScope(ref visible, Title, Tooltip)) 38 | using (new IndentScope()) { 39 | DrawChildren(); 40 | } 41 | } 42 | } 43 | } 44 | 45 | #region member 46 | protected void DrawChildren() { 47 | if (visible && Children != null) 48 | foreach (var v in Children) 49 | v.Draw(); 50 | } 51 | #endregion 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Scripts/View/ClassView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0d5c214c8972f3e48b75aaaefc996642 3 | timeCreated: 1520426020 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/View/EnumView.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using UniRx; 5 | using UnityEngine; 6 | 7 | namespace ModelDrivenGUISystem.View { 8 | 9 | public class EnumView : BaseView { 10 | public ReactiveProperty Input { get; set; } 11 | 12 | public int NumberOfColums { get; set; } 13 | 14 | protected System.Type enumType; 15 | protected string[] names; 16 | 17 | public EnumView() { 18 | this.NumberOfColums = 10; 19 | } 20 | 21 | public System.Type EnumType { 22 | get { return enumType; } 23 | set { 24 | enumType = value; 25 | names = System.Enum.GetNames(value); 26 | } 27 | } 28 | 29 | public override void Draw() { 30 | using (new GUILayout.VerticalScope(new GUIContent(Title, Tooltip), GUIStyle.none)) { 31 | GUILayout.Label($"{Title}:"); 32 | var index = System.Array.FindIndex(names, v => v == Input.Value); 33 | index = GUILayout.SelectionGrid(index, names, Mathf.Min(names.Length, NumberOfColums)); 34 | if (0 <= index && index < names.Length) { 35 | Input.Value = names[index]; 36 | } 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Scripts/View/EnumView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f5b7f74a15100494bb60bac79e171a7f 3 | timeCreated: 1520281134 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/View/LabelView.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UniRx; 4 | using UnityEngine; 5 | 6 | namespace ModelDrivenGUISystem.View { 7 | 8 | public class LabelView : BaseView { 9 | public enum UsageEnum { Normal = 0, Comment } 10 | public const string CD_USAGE = "LabelUsage"; 11 | public const string CD_STYLE = "Style"; 12 | 13 | public GUIStyle Style { get; set; } 14 | public UsageEnum Usage { get; set; } 15 | 16 | public override void Initialize() { 17 | if (initialized) 18 | return; 19 | base.Initialize(); 20 | 21 | var usageObj = default(object); 22 | if (CustomData != null 23 | && CustomData.TryGetValue(CD_USAGE, out usageObj) 24 | && usageObj != null 25 | && usageObj is UsageEnum) { 26 | 27 | Usage = (UsageEnum)usageObj; 28 | } 29 | 30 | switch (Usage) { 31 | case UsageEnum.Comment: 32 | Style = new GUIStyle(GUI.skin.label); 33 | Style.normal.textColor = Color.gray; 34 | Style.fontStyle = FontStyle.Italic; 35 | break; 36 | } 37 | } 38 | public override void Draw() { 39 | if (Style != null) 40 | GUILayout.Label(new GUIContent(Title, Tooltip), Style); 41 | else 42 | GUILayout.Label(new GUIContent(Title, Tooltip)); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Scripts/View/LabelView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 555f63a42ac8ee841a8fad56dca56b66 3 | timeCreated: 1520281134 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/View/ListView.cs: -------------------------------------------------------------------------------- 1 | using nobnak.Gist.IMGUI.Scope; 2 | using UniRx; 3 | using UnityEngine; 4 | 5 | namespace ModelDrivenGUISystem.View { 6 | 7 | public class ListView : BaseView { 8 | public virtual IReadOnlyReactiveProperty Count { get; set; } 9 | public virtual IReadOnlyReactiveProperty Views { get; set; } 10 | 11 | public virtual ReactiveCommand CommandAdd { get; set; } 12 | public virtual ReactiveCommand CommandRemove { get; set; } 13 | 14 | protected bool visible = true; 15 | 16 | public override void Initialize() { 17 | if (initialized) 18 | return; 19 | base.Initialize(); 20 | 21 | foreach (var v in Views.Value) 22 | v.Initialize(); 23 | } 24 | public override void Draw() { 25 | using (new GUILayout.VerticalScope(new GUIContent(Title, Tooltip), GUIStyle.none)) 26 | using (new FoldoutScope(ref visible, Title, Tooltip)) 27 | using (new IndentScope(20f)) { 28 | if (visible) { 29 | GUILayout.Label(string.Format("Size : {0}", Count.Value)); 30 | using (new GUILayout.HorizontalScope()) { 31 | if (GUILayout.Button("Add")) 32 | CommandAdd.Execute(); 33 | if (GUILayout.Button("Remove")) 34 | CommandRemove.Execute(); 35 | } 36 | if (Views.Value != null) 37 | foreach (var v in Views.Value) 38 | v.Draw(); 39 | } 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Scripts/View/ListView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fafde0c0f548a5f448c58957c13793f4 3 | timeCreated: 1520695380 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/View/TextFieldView.cs: -------------------------------------------------------------------------------- 1 | using ModelDrivenGUISystem.Extensions.GUIExt; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UniRx; 5 | using UnityEngine; 6 | 7 | namespace ModelDrivenGUISystem.View { 8 | 9 | public class TextFieldView : BaseView { 10 | public ReactiveProperty Input { get; set; } 11 | 12 | protected GUIStyle labelStyle; 13 | 14 | public TextFieldView() { 15 | labelStyle ??= new GUIStyle(UnityEngine.GUI.skin.label) { 16 | alignment = TextAnchor.MiddleLeft, 17 | wordWrap = false, 18 | }; 19 | } 20 | 21 | public override void Draw() { 22 | using (new GUILayout.HorizontalScope(new GUIContent(Title, Tooltip), GUIStyle.none)) { 23 | GUILayout.Label(Title, labelStyle, GUILayout.ExpandWidth(false)); 24 | Input.Value = GUILayout.TextField(Input.Value); 25 | 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Scripts/View/TextFieldView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dbfcd8ef7f22a48458a958253e7d442c 3 | timeCreated: 1520281134 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/View/VectorView.cs: -------------------------------------------------------------------------------- 1 | using ModelDrivenGUISystem.Extensions.GUIExt; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UniRx; 5 | using UnityEngine; 6 | 7 | namespace ModelDrivenGUISystem.View { 8 | 9 | public class VectorView : BaseView { 10 | public virtual ReactiveCollection Input { get; set; } 11 | 12 | protected GUIStyle labelStyle; 13 | 14 | public VectorView() { 15 | labelStyle ??= new GUIStyle(UnityEngine.GUI.skin.label) { 16 | alignment = TextAnchor.MiddleLeft, 17 | wordWrap = false, 18 | }; 19 | } 20 | 21 | public override void Draw() { 22 | using (new GUILayout.HorizontalScope(new GUIContent(Title, Tooltip), GUIStyle.none)) { 23 | GUILayout.Label(Title, labelStyle, GUILayout.ExpandWidth(false)); 24 | for (var i = 0; i < Input.Count; i++) { 25 | Input[i] = GUILayout.TextField(Input[i]); 26 | } 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Scripts/View/VectorView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: baa1e8c6f42cd364b8c6d03842f7e7f7 3 | timeCreated: 1520281134 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/ViewModel.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3cf2c8aa0a5def64f82ac176537ab1fe 3 | folderAsset: yes 4 | timeCreated: 1520343355 5 | licenseType: Pro 6 | DefaultImporter: 7 | externalObjects: {} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Scripts/ViewModel/ArrayViewModel.cs: -------------------------------------------------------------------------------- 1 | using ModelDrivenGUISystem.Factory; 2 | using ModelDrivenGUISystem.ValueWrapper; 3 | using ModelDrivenGUISystem.View; 4 | using UniRx; 5 | using System.Linq; 6 | using UnityEngine; 7 | using System.Collections.Generic; 8 | using ModelDrivenGUISystem.Extensions.ConstructorExt; 9 | 10 | namespace ModelDrivenGUISystem.ViewModel { 11 | 12 | public class ArrayViewModel : BaseViewModel where T:new() { 13 | 14 | public ReactiveProperty Input { get; set; } 15 | public IReadOnlyReactiveProperty OutputCount { get; set; } 16 | public IReadOnlyReactiveProperty OutputViews { get; set; } 17 | 18 | public ReactiveCommand CommandAdd { get; set; } 19 | public ReactiveCommand CommandRemove { get; set; } 20 | 21 | public ArrayViewModel(IValue model, IViewFactory viewFactory) { 22 | Input = new ReactiveProperty(model.Value); 23 | Input.Subscribe(v => model.Value = v); 24 | 25 | OutputCount = Input.Select(t => string.Format("{0}", t.Length)).ToReactiveProperty(); 26 | OutputViews = Input.Select(ts => { 27 | DisposeViews(); 28 | return ts.SelectMany((t, index) => { 29 | var typeOfField = typeof(T); 30 | var modelFactory = new ArrayElementModelFactory(model.Value, index); 31 | return ClassConfigurator.GenerateFieldView( 32 | modelFactory, viewFactory, 33 | typeOfField, $"{index}"); 34 | }).ToArray(); 35 | }).ToReactiveProperty(); 36 | 37 | CommandAdd = Input.Select(ts => ts != null).ToReactiveCommand(); 38 | CommandAdd.Subscribe(u => { 39 | var currSize = Input.Value.Length; 40 | var inputArray = Input.Value; 41 | System.Array.Resize(ref inputArray, currSize + 1); 42 | inputArray[currSize] = ConstructorExtension.CreateInstanceHierarchy(); 43 | Input.Value = inputArray; 44 | }); 45 | 46 | CommandRemove = Input.Select(ts => ts != null && ts.Length > 0).ToReactiveCommand(); 47 | CommandRemove.Subscribe(u => { 48 | var currSize = Input.Value.Length; 49 | var inputArray = Input.Value; 50 | System.Array.Resize(ref inputArray, currSize - 1); 51 | Input.Value = inputArray; 52 | }); 53 | } 54 | public void DisposeViews() { 55 | if (OutputViews != null && OutputViews.Value != null) 56 | foreach (var v in OutputViews.Value) 57 | v.Dispose(); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Scripts/ViewModel/ArrayViewModel.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ab959056aca1d2946b4c928e6777004d 3 | timeCreated: 1520595911 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/ViewModel/BaseViewModel.cs: -------------------------------------------------------------------------------- 1 | using ModelDrivenGUISystem.View; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Reflection; 5 | using UnityEngine; 6 | 7 | namespace ModelDrivenGUISystem.ViewModel { 8 | 9 | public abstract class BaseViewModel { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Scripts/ViewModel/BaseViewModel.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cc8e84891ad07de4d909c83517dfb2df 3 | timeCreated: 1520343576 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/ViewModel/BypassViewModel.cs: -------------------------------------------------------------------------------- 1 | using ModelDrivenGUISystem.Accessor; 2 | using ModelDrivenGUISystem.ValueWrapper; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using UniRx; 6 | using UnityEngine; 7 | 8 | namespace ModelDrivenGUISystem.ViewModel { 9 | 10 | public class BypassViewModel : BaseViewModel { 11 | public ReactiveProperty Input { get; protected set; } 12 | public ReactiveProperty Output { get; protected set; } 13 | 14 | public IValueAccessor Accessor; 15 | 16 | public BypassViewModel(IValue model) { 17 | Input = new ReactiveProperty(model.Value); 18 | Output = new ReactiveProperty(Input.Value); 19 | 20 | Input.Subscribe(v => { 21 | model.Value = v; 22 | Output.Value = v; 23 | }); 24 | Output.Subscribe(v => Input.Value = v); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Scripts/ViewModel/BypassViewModel.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0c68a17eadbb6dc4fb4f7cd009861dfc 3 | timeCreated: 1520352171 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/ViewModel/ListViewModel.cs: -------------------------------------------------------------------------------- 1 | using ModelDrivenGUISystem.Factory; 2 | using ModelDrivenGUISystem.ValueWrapper; 3 | using ModelDrivenGUISystem.View; 4 | using UniRx; 5 | using System.Linq; 6 | using UnityEngine; 7 | using System.Collections.Generic; 8 | using ModelDrivenGUISystem.Extensions.ConstructorExt; 9 | 10 | namespace ModelDrivenGUISystem.ViewModel { 11 | 12 | public class ListViewModel : BaseViewModel where T:new() { 13 | 14 | public ReactiveProperty> Input { get; set; } 15 | public IReadOnlyReactiveProperty OutputCount { get; set; } 16 | public IReadOnlyReactiveProperty OutputViews { get; set; } 17 | 18 | public ReactiveCommand CommandAdd { get; set; } 19 | public ReactiveCommand CommandRemove { get; set; } 20 | 21 | public ListViewModel(IValue> model, IViewFactory viewFactory) { 22 | Input = new ReactiveProperty>(model.Value); 23 | Input.Subscribe(v => model.Value = v); 24 | 25 | OutputCount = Input.Select(t => string.Format("{0}", t.Count)).ToReactiveProperty(); 26 | OutputViews = Input.Select(ts => { 27 | DisposeViews(); 28 | var views = new List(); 29 | try { 30 | for (var i = 0; i < ts.Count; i++) { 31 | var modelFactory = new ListElementModelFactory(model.Value, i); 32 | views.AddRange( 33 | ClassConfigurator.GenerateFieldView( 34 | modelFactory, viewFactory, 35 | typeof(T), string.Format("{0}", i)) 36 | ); 37 | } 38 | }catch(System.Exception e) { 39 | Debug.LogWarning(e); 40 | } 41 | return views.ToArray(); 42 | }).ToReactiveProperty(); 43 | 44 | CommandAdd = Input.Select(ts => ts != null).ToReactiveCommand(); 45 | CommandAdd.Subscribe(u => { 46 | var currSize = Input.Value.Count; 47 | var inputList = Input.Value; 48 | inputList.Add(ConstructorExtension.CreateInstanceHierarchy()); 49 | Input.SetValueAndForceNotify(inputList); 50 | }); 51 | 52 | CommandRemove = Input.Select(ts => ts != null && ts.Count > 0).ToReactiveCommand(); 53 | CommandRemove.Subscribe(u => { 54 | var currSize = Input.Value.Count; 55 | var inputList = Input.Value; 56 | inputList.RemoveAt(currSize - 1); 57 | Input.SetValueAndForceNotify(inputList); 58 | }); 59 | } 60 | public void DisposeViews() { 61 | if (OutputViews != null && OutputViews.Value != null) 62 | foreach (var v in OutputViews.Value) 63 | v.Dispose(); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Scripts/ViewModel/ListViewModel.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4c5c39ddfebf58c4aa63a87ce20d1c70 3 | timeCreated: 1520595911 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/ViewModel/NumberViewModel.cs: -------------------------------------------------------------------------------- 1 | using ModelDrivenGUISystem.Accessor; 2 | using ModelDrivenGUISystem.ValueWrapper; 3 | using System.Collections; 4 | using System.Collections.Generic; 5 | using UniRx; 6 | using UnityEngine; 7 | 8 | namespace ModelDrivenGUISystem.ViewModel { 9 | 10 | public class NumberViewModel : BaseViewModel { 11 | public ReactiveProperty Input { get; protected set; } 12 | public ReactiveProperty Output { get; protected set; } 13 | 14 | public IValueAccessor Accessor; 15 | 16 | public NumberViewModel(IValue model, IValueAccessor accessor) { 17 | this.Accessor = accessor; 18 | 19 | Input = new ReactiveProperty(model.Value); 20 | Output = new ReactiveProperty(Input.ToString()); 21 | 22 | Input.Subscribe(v => { 23 | model.Value = v; 24 | Output.Value = v.ToString(); 25 | }); 26 | Output.Subscribe(v => { 27 | ValueType nextValue; 28 | if (accessor.TryParse(v, out nextValue)) 29 | Input.Value = nextValue; 30 | }); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /Scripts/ViewModel/NumberViewModel.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e88b66eaf9f3fa54aa793e93c094e365 3 | timeCreated: 1520352171 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | -------------------------------------------------------------------------------- /Scripts/ViewModel/VectorViewModel.cs: -------------------------------------------------------------------------------- 1 | using ModelDrivenGUISystem.Accessor; 2 | using ModelDrivenGUISystem.Extensions.VectorExt; 3 | using ModelDrivenGUISystem.ValueWrapper; 4 | using System.Linq; 5 | using UniRx; 6 | using UnityEngine; 7 | 8 | namespace ModelDrivenGUISystem.ViewModel { 9 | 10 | public class VectorViewModel: BaseViewModel { 11 | public ReactiveProperty Input { get; protected set; } 12 | public ReactiveCollection Output { get; protected set; } 13 | 14 | public IVectorAccessor Accessor; 15 | 16 | public VectorViewModel(IValue model, 17 | IVectorAccessor accessor) { 18 | this.Accessor = accessor; 19 | 20 | Input = new ReactiveProperty(model.Value); 21 | Output = new ReactiveCollection( 22 | accessor.Split(Input.Value).Select(v => v.ToString())); 23 | 24 | Input.Subscribe(vec => { 25 | model.Value = vec; 26 | for (var i = 0; i < accessor.Count; i++) 27 | Output[i] = accessor.GetElement(ref vec, i).ToString(); 28 | }); 29 | Output.ObserveReplace().Subscribe(e => { 30 | VectorElementType next; 31 | if (accessor.TryParse(e.NewValue, out next)) { 32 | var vec = Input.Value; 33 | accessor.SetElement(ref vec, e.Index, next); 34 | Input.Value = vec; 35 | } 36 | }); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Scripts/ViewModel/VectorViewModel.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c6748a6c2cf73744ba47d36ebc52f432 3 | timeCreated: 1520352171 4 | licenseType: Pro 5 | MonoImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | defaultReferences: [] 9 | executionOrder: 0 10 | icon: {instanceID: 0} 11 | userData: 12 | assetBundleName: 13 | assetBundleVariant: 14 | --------------------------------------------------------------------------------