private void CreateDrawLists() { foreach (var memberField in getters) { bool valid = memberField.Initialize(); if (!valid) { StratusDebug.Error($"No member has been selected on the target {memberField.member.target.name}", this); continue; } switch (memberField.visualizationMode) { case MemberVisualizationField.VisualizationMode.Scene: AddToDrawList(memberField, sceneDrawList); break; case MemberVisualizationField.VisualizationMode.Game: AddToDrawList(memberField, gameDrawList); break; case MemberVisualizationField.VisualizationMode.SceneGUI: AddToDrawList(memberField, sceneGUIDrawList); break; case MemberVisualizationField.VisualizationMode.GameGUI: AddToDrawList(memberField, gameGUIDrawList); break; default: break; } } }
protected override IList <TreeViewItem> BuildRows(TreeViewItem root) { if (this.treeModel.root == null) { StratusDebug.Error($"Tree model root is null. Was the data set?"); } this.rows.Clear(); // IF there's a search string, build the rows from it if (!string.IsNullOrEmpty(searchString)) { Search(this.treeModel.root, this.searchString, this.rows); } // Build rows from the root else { if (this.treeModel.root.hasChildren) { this.AddChildrenRecursive(this.treeModel.root, 0, this.rows); } } // The child parent information still has to be set for the rows // since the information is used by the treeview internal logic (navigation, dragging, etc) TreeView.SetupParentsAndChildrenFromDepths(this.rootItem, this.rows); return(this.rows); }
//------------------------------------------------------------------------/ // Methods: Public //------------------------------------------------------------------------/ public void LoadState(string label) { if (!stateMap.ContainsKey(label)) { StratusDebug.Error($"The state {label} was not found!", this); } SerializedState state = stateMap[label]; LoadState(state); }
private void AddExtension(int extensionTypeIndex) { Type extensionType = extensionTypes[extensionTypeIndex]; IExtensionBehaviour extension = target.gameObject.AddComponent(extensionType) as IExtensionBehaviour; if (extension == null) { StratusDebug.Error($"Failed to construct extension of type {extensionType.Name}"); return; } StratusDebug.Log($"Adding extension {extensionType.Name}"); target.Add(extension); Undo.RecordObject(target, extensionType.Name); serializedObject.ApplyModifiedProperties(); this.SetExtensionIndex(); this.RefreshExtensions(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // Set the global variables drawIf = attribute as DrawIfAttribute; // Whether the condition has been met bool conditionMet = false; // If we are doing a property comparison if (drawIf.predicate == PredicateMode.PropertyComparison) { comparedField = property.serializedObject.FindProperty(drawIf.comparedPropertyName); // Get the value of the compared field object comparedFieldValue = comparedField.GetValue <object>(); // References to the values as numeric types INumeric numericComparedFieldValue = null; INumeric numericComparedValue = null; // Try to set the numeric types try { numericComparedFieldValue = new INumeric(comparedFieldValue); numericComparedValue = new INumeric(drawIf.comparedValue); } catch (NumericTypeExpectedException) { if (drawIf.comparison != ComparisonType.Equals && drawIf.comparison != ComparisonType.NotEqual) { StratusDebug.Error("The only comparsion types available to type '" + comparedFieldValue.GetType() + "' are Equals and NotEqual. (On object '" + property.serializedObject.targetObject.name + "')", null, true); return; } } // Compare the values to see if the condition has been met switch (drawIf.comparison) { case ComparisonType.Equals: if (comparedFieldValue.Equals(drawIf.comparedValue)) { conditionMet = true; } break; case ComparisonType.NotEqual: if (!comparedFieldValue.Equals(drawIf.comparedValue)) { conditionMet = true; } break; case ComparisonType.Greater: if (numericComparedFieldValue > numericComparedValue) { conditionMet = true; } break; case ComparisonType.Lesser: if (numericComparedFieldValue < numericComparedValue) { conditionMet = true; } break; case ComparisonType.LesserOrEqual: if (numericComparedFieldValue <= numericComparedValue) { conditionMet = true; } break; case ComparisonType.GreaterOrEqual: if (numericComparedFieldValue >= numericComparedValue) { conditionMet = true; } break; } } // Else if we are checking a predicate else if (drawIf.predicate == PredicateMode.Predicate) { //var booly = property.serializedObject..GetProperty<bool>(DrawIf.predicateName); //SerializedProperty predicateProperty = property.serializedObject.FindProperty(DrawIf.predicateName); //if (predicateProperty.propertyType == SerializedPropertyType.Boolean) // conditionMet = predicateProperty.boolValue; MonoBehaviour mb = property.serializedObject.targetObject as MonoBehaviour; MethodInfo predicateMethod = mb.GetType().GetMethod(drawIf.predicateName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (predicateMethod != null) { conditionMet = (bool)predicateMethod.Invoke(mb, null); } else { PropertyInfo predicateProperty = mb.GetType().GetProperty(drawIf.predicateName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (predicateProperty != null) { conditionMet = (bool)predicateProperty.GetValue(mb, null); } else { throw new System.Exception("The component is missing the predicate" + drawIf.predicateName); } } //// Make sure that the right component is present //Component component = Selection.activeGameObject.GetComponent(drawIf.type); //if (component == null) // throw new System.Exception("The component of type " + drawIf.type.Name + " is missing from the selected GameObject"); // //// We can now safely invoke the method on the component //if (drawIf.isProperty) // conditionMet = (bool)drawIf.predicateProperty.GetValue(component, null); //else // conditionMet = (bool)drawIf.predicateMethod.Invoke(component, null); } // The height of the property should be defaulted to the default height propertyHeight = EditorGUI.GetPropertyHeight(property); //propertyHeight = base.GetPropertyHeight(property, label); // If the condition is met, draw the field if (conditionMet) { //EditorGUILayout.PropertyField(property); EditorGUI.PropertyField(position, property, true); } // Otherwise use the default ebhavior else { if (drawIf.defaultBehavior == PropertyDrawingType.ReadOnly) { UnityEngine.GUI.enabled = false; //EditorGUILayout.PropertyField(property); EditorGUI.PropertyField(position, property, true); UnityEngine.GUI.enabled = true; } else { propertyHeight = 0f; } } }