private static void AddLabelSystemView(PropertyInfo propertyInfo, IControllableMemberGeneratable view) { var labelSystemView = AddElement <LabelSystemViewBehaviour>(LabelSystemViewPrefab, view); labelSystemView.SchemaProvider = view.SchemaProvider; labelSystemView.LabelSystem = propertyInfo.GetValue(view.Model, null) as LabelSystem.LabelSystem; }
public static void GenerateControllableUiElements(IControllableMemberGeneratable view) { if (view.ControllableUiItems.Any()) { throw new InvalidOperationException("Trying to add controllable elements to a view, but it already has controllable elements."); } var controllableMembers = view.Model.GetType() .GetMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) .Where(m => Attribute.IsDefined(m, typeof(ControllableAttribute))); //.OrderBy( m => ( ((ControllableAttribute)m.GetCustomAttributes( typeof( ControllableAttribute ), true )[0]).Order ) ); foreach (var m in controllableMembers) { //var timer = DiagnosticTimer.Start( "AddPropertyorwhaweetetercure" ); if (m is PropertyInfo) { AddProperty(m as PropertyInfo, view); } else if (m is MethodInfo) { AddMethod(m as MethodInfo, view); } else { Debug.LogWarning("Member found, not Property or Method but " + m.MemberType + ": " + m.Name); } //Debug.Log( timer.Stop().Conclusion ); } }
private static void AddMethod(MethodInfo methodInfo, IControllableMemberGeneratable view) { var button = AddElement <ButtonBehaviour>(ButtonPrefab, view); button.LabelText = ControllableUtility.GetControllableLabel(methodInfo); button.Clicked += () => methodInfo.Invoke(view.Model, null); }
public static void DestroyControllableUiElements(IControllableMemberGeneratable view) { foreach (var c in view.ControllableUiItems) { DestroyImmediate(c.gameObject); } view.ControllableUiItems.Clear(); }
private static void AddMutableScope(PropertyInfo propertyInfo, IControllableMemberGeneratable view) { if (view.SchemaProvider == null) { AddLabel("SchemaProvider missing at init.", view); return; } var mutableScopeView = AddElement <MutableScopeView>(MutableScopeViewPrefab, view); mutableScopeView.Initialize(propertyInfo, view.Model, view.SchemaProvider); }
private static void AddTextBox(PropertyInfo propertyInfo, IControllableMemberGeneratable view) { var textBox = AddElement <TextBoxBehaviour>(TextBoxPrefab, view); textBox.TextSubmitted += s => { propertyInfo.SetValue(view.Model, s, null); }; textBox.Text = propertyInfo.GetValue(view.Model, null) as string; textBox.LabelText = ControllableUtility.GetControllableLabel(propertyInfo); }
private static void AddReadOnlyObjectBox(PropertyInfo propertyInfo, IControllableMemberGeneratable view) { var textBox = AddElement <TextBoxBehaviour>(TextBoxPrefab, view); textBox.Interactable = false; // object-type text boxes are read-only ( interactable is false) textBox.TextSubmitted += s => { }; textBox.Text = propertyInfo.GetValue(view.Model, null).ToString(); textBox.LabelText = ControllableUtility.GetControllableLabel(propertyInfo); }
private static T AddElement <T>(GameObject prefab, IControllableMemberGeneratable view) where T : MonoBehaviour { var go = Instantiate(prefab, view.ControllableUiItemRoot.transform); go.transform.localScale = Vector3.one; // Universal element touching here //go.transform.SetParent( view.ControllableUiItemRoot.transform, false ); var newView = go.GetComponent <T>(); view.ControllableUiItems.Add(newView); return(newView); }
private static void AddPayloadExpression(PropertyInfo propertyInfo, IControllableMemberGeneratable controllable) { // set up a payload expression ... var foundObj = propertyInfo.GetValue(controllable.Model, null); var expression = foundObj as PayloadExpression; var view = AddElement <PayloadExpressionControllableViewBehaviour>(PayloadExpressionControllablePrefab, controllable); //var view = go.GetComponent<PayloadExpressionControllableViewBehaviour>(); //view.transform.SetParent(OptionsRootTransform, false); //view.transform.SetAsLastSibling(); view.PropertyName = ControllableUtility.GetControllableLabel(propertyInfo); view.PayloadExpression = expression; view.ExternalSchemaProvider = controllable.SchemaProvider; }
private static void AddProperty(PropertyInfo propertyInfo, IControllableMemberGeneratable view) { //try //{ if (MutableFieldTester.IsMutableField(propertyInfo.PropertyType)) { AddMutableBox(propertyInfo, view); } else if (propertyInfo.PropertyType == typeof(MutableTarget)) { AddMutableTarget(propertyInfo, view); } else if (propertyInfo.PropertyType == typeof(MutableScope)) { AddMutableScope(propertyInfo, view); } else if (propertyInfo.PropertyType == typeof(LabelSystem.LabelSystem)) { AddLabelSystemView(propertyInfo, view); } else if (propertyInfo.PropertyType == typeof(string)) { AddTextBox(propertyInfo, view); } else if (propertyInfo.PropertyType == typeof(PayloadExpression)) { AddPayloadExpression(propertyInfo, view); } else { Debug.LogErrorFormat("Controllable attribute does not support type {0}. Use a mutable field.", propertyInfo.PropertyType); AddReadOnlyObjectBox(propertyInfo, view); } //} //catch ( InvalidOperationException ex ) //{ // Debug.LogError( "ERROR! " + ex ); // throw; //} }
public static T AddCustomElement <T>(GameObject prefab, IControllableMemberGeneratable view) where T : MonoBehaviour { return(AddElement <T>(prefab, view)); }
private static void AddLabel(string text, IControllableMemberGeneratable view) { var label = AddElement <LabelBehaviour>(LabelPrefab, view); label.Text = text; }