public override float GetPropertyHeight(ReflectedProperty property) { float height = 0f; height += EditorGUIX.GetChildHeights(property[NameField]); height += EditorGUIX.GetChildHeights(property[ShipTypeField]); height += EditorGUIX.GetChildHeights(property[SceneEntityIdField]); height += EditorGUIX.GetChildHeights(property[GoalsField]); height += EditorGUIX.GetChildHeights(property[BehaviorSetField]); height += EditorGUIX.GetChildHeights(property[StandaloneBehaviorsField]); return(height); }
public override ISet <Namespace> GetStaticDescriptor(Interpreter.AnalysisUnit unit) { ReflectedProperty rp = _value as ReflectedProperty; if (rp != null && (rp.Info.GetGetMethod() ?? rp.Info.GetSetMethod()).IsStatic) { BuiltinClassInfo klass = (BuiltinClassInfo)ProjectState.GetNamespaceFromObjects(rp.PropertyType); return(klass.Instance.SelfSet); } return(base.GetStaticDescriptor(unit)); }
public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label) { guiRect.SetRect(position); float oldLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 100; EditorGUIX.PropertyField(guiRect.GetFieldRect(), property[NameField]); EditorGUIUtility.labelWidth = oldLabelWidth; EditorGUIX.PropertyField(guiRect, property[GoalsField]); }
public static void DrawProperties(ReflectedProperty root, string[] skipList = null) { List <ReflectedProperty> properties = root.GetChildren(); for (int i = 0; i < properties.Count; i++) { ReflectedProperty property = properties[i]; if ((skipList == null || Array.IndexOf(skipList, property.name) == -1)) { Internal_PropertyField(property, property.GUIContent, property.IsHidden); } } }
private static bool AssertCompatible(ReflectedProperty reflectedProperty, Type newContextType) { IContextAware aware = reflectedProperty.Value as IContextAware; if (aware != null) { if (!aware.GetContextType().IsAssignableFrom(newContextType)) { Debug.Log($"Not compatible! {aware.GetContextType().Name} & {newContextType.Name}"); return(false); } } return(true); }
public static void DrawProperties(GUIRect guiRect, ReflectedProperty root, string[] skipList = null) { List <ReflectedProperty> properties = root.GetChildren(); for (int i = 0; i < properties.Count; i++) { ReflectedProperty property = properties[i]; if (!property.IsHidden && (skipList == null || Array.IndexOf(skipList, property.name) == -1)) { float height = property.GetPropertyHeight(); Internal_PropertyField(guiRect.SliceHeight(height), property, property.GUIContent, false); } } }
public static float GetChildHeights(ReflectedProperty property) { float height = 0; if (property.ChildCount > 0) { for (int i = 0; i < property.ChildCount; i++) { ReflectedProperty child = property.ChildAt(i); height += child.Drawer.GetPropertyHeight(child); } } return(height); }
public override float GetPropertyHeight(ReflectedProperty property) { float height = 2f * EditorGUIX.singleLineHeight; if (property.Value != null) { height += GetChildHeights(property, new[] { "curve" }); } if (property.IsExpanded) { height += 8f * EditorGUIUtility.singleLineHeight; } return(height); }
private void DrawHeaderBox(ReflectedProperty property, bool withPreview, ResponseCurve curve) { Rect headerRect = guiRect.GetFieldRect(2); Rect foldoutRect = new Rect(headerRect) { y = headerRect.y + 8f, width = 20f }; Rect texRect = new Rect(headerRect) { x = headerRect.x + 20, width = 64f }; Rect selectRect = new Rect(headerRect) { x = texRect.x + texRect.width + 8, y = texRect.y + 8, height = EditorGUIUtility.singleLineHeight, width = headerRect.width - texRect.width - foldoutRect.width - 8f }; property.IsExpanded = EditorGUI.Foldout(foldoutRect, property.IsExpanded, string.Empty); if (withPreview) { if (Event.current.type == EventType.Repaint) { curve.DrawGraph(graphTexture, 64, 32); } if (Event.current.type == EventType.MouseDown) { if (texRect.Contains(Event.current.mousePosition)) { if (property.Value != null) { property.IsExpanded = true; Event.current.Use(); } } } EditorGUI.DrawPreviewTexture(texRect, graphTexture); } DrawTypeSelect(selectRect, property); }
public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label) { string assetGuid = property.stringValue; GameDatabase db = GameDatabase.ActiveInstance; GameObject current = db.GetPrefabAsset(assetGuid); // IReadonlyListX<ShipTypeGroup> shipTypeGroups = db.GetAssetList<ShipTypeGroup>(); GameObject newValue = EditorGUI.ObjectField(position, "Chassis Prefab", current, typeof(GameObject), false) as GameObject; if (newValue != current) { if (newValue == null) { property.Value = string.Empty; } else { property.Value = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(newValue)); } } // int idx = 0; // int currentId = property.intValue; // int currentIndex = -1; // // shipTypeNames.Clear(); // ids.Clear(); // // for (int i = 0; i < shipTypeGroups.Count; i++) { // ShipTypeGroup shipTypeGroup = shipTypeGroups[i]; // // string groupName = $"[{shipTypeGroup.name}]"; // // for (int j = 0; j < shipTypeGroup.ships.Count; j++) { // ShipType shipType = shipTypeGroup.ships[j]; // // shipTypeNames.Add($"{groupName} {shipType.name}"); // ids.Add(shipType.id); // if (shipType.id == currentId) { // currentIndex = idx; // } // idx++; // } // // } // // int newIndex = EditorGUI.Popup(position, property.Label, currentIndex, shipTypeNames.ToArray()); // if (newIndex != currentIndex) { // property.Value = db.FindAsset<ShipType>(ids[newIndex]).id; // } }
public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label = null) { guiRect.SetRect(position); Initialize(property); int index = -1; int newIndex; if (property.Value != null) { index = Array.IndexOf(subclasses, property.Type); } if (index != -1) { Rect rect = guiRect.GetFieldRect(); float width = EditorGUIUtility.labelWidth; Rect r1 = new Rect(rect) { width = width }; Rect r2 = new Rect(rect) { x = rect.x + width, width = rect.width - width }; property.IsExpanded = EditorGUI.Foldout(r1, property.IsExpanded, property.Label); newIndex = EditorGUI.Popup(r2, index + 1, subclassNames) - 1; } else { newIndex = EditorGUI.Popup(guiRect.GetFieldRect(), property.Label, index + 1, subclassNames) - 1; } if (index != newIndex) { property.SetValueAndCopyCompatibleProperties( newIndex == -1 ? null : EditorReflector.MakeInstance(subclasses[newIndex]) ); property.IsExpanded = newIndex != -1; } if (property.IsExpanded && newIndex != -1) { EditorGUI.indentLevel += 2; EditorGUIX.DrawProperties(guiRect.GetRect(), property); EditorGUI.indentLevel -= 2; } }
public string DisplayName() { var displayNameAttribute = ReflectedProperty.GetAttribute <DisplayNameAttribute>(); var displayAttribute = ReflectedProperty.GetAttribute <DisplayAttribute>(); if (displayNameAttribute != null) { return(displayNameAttribute.DisplayName); } else if (displayAttribute != null) { return(displayAttribute.Name); } else { return(ReflectedProperty.Name); } }
public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label) { MissionDefinition mission = GameDatabase.ActiveInstance.GetCurrentMission(); Debug.Assert(property.DeclaredType == typeof(int), "property.DeclaredType == typeof(int)"); List <FactionDefinition> factions = mission.GetFactions(); entities.Clear(); entityNames.Clear(); int counter = 0; int currentIndex = -1; int currentId = property.intValue; foreach (FactionDefinition faction in factions) { string factionName = $"[{faction.name}]"; foreach (FlightGroupDefinition flightGroup in faction.flightGroups) { string flightGroupName = $"[{flightGroup.name}]"; foreach (EntityDefinition entity in flightGroup.entities) { entityNames.Add($"{factionName}::{flightGroupName} {entity.name}"); if (entity.id == currentId) { currentIndex = counter; } entities.Add(entity); counter++; } } } int newIndex = EditorGUI.Popup(position, property.Label, currentIndex, entityNames.ToArray()); if (currentIndex != newIndex) { property.Value = entities[newIndex].id; } }
public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label) { guiRect.SetRect(position); int entityId = property.intValue; GameDatabase db = GameDatabase.ActiveInstance; Entity sceneEntity = db.FindSceneEntityById(entityId); GameObject current = sceneEntity?.gameObject; GameObject newValue = EditorGUI.ObjectField(position, "Scene Entity", current, typeof(GameObject), true) as GameObject; if (newValue != current) { if (newValue != null) { if (EditorUtility.IsPersistent(newValue)) { Debug.Log("Can only set a scene entity"); return; } Entity newComponent = newValue.GetComponent <Entity>(); if (newComponent == null) { Debug.Log("Need to set a gameobject with an entity component"); return; } EntityDefinition entityDefintion = db.GetEntityDefinitionForSceneEntity(newComponent.id); if (entityDefintion != null) { entityDefintion.sceneEntityId = -1; Debug.Log($"Unassigned Scene Entity for {entityDefintion.name}"); } property.Value = newComponent.id; } else { property.Value = -1; } } }
public bool Scaffold() { var scaffoldAttribute = ReflectedProperty.GetAttribute <ScaffoldColumnAttribute>(); if (IsPrimaryKey()) { return(scaffoldAttribute != null && scaffoldAttribute.Scaffold); } else { if (scaffoldAttribute != null) { return(scaffoldAttribute.Scaffold); } else { return(IsDynamicCollection() || IsSimple() || IsDynamicEntity()); } } }
public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label) { MissionDefinition mission = GameDatabase.ActiveInstance.GetCurrentMission(); Debug.Assert(property.DeclaredType == typeof(int), "property.DeclaredType == typeof(int)"); List <FactionDefinition> factions = mission.GetFactions(); foreach (FactionDefinition faction in factions) { factionNames.Add(faction.name); } int currentIndex = factions.FindIndex((f) => f.id == property.intValue); int newIndex = EditorGUI.Popup(position, property.Label, currentIndex, factionNames.ToArray()); if (currentIndex != newIndex) { property.Value = factions[newIndex].id; } }
private static void Internal_PropertyField(Rect position, ReflectedProperty property, GUIContent label, bool isHidden) { if (isHidden) { return; } if (label == null) { label = property.GUIContent; } Debug.Assert(property.Drawer != null, "property.Drawer != null"); if (!property.Drawer.IsInitialized) { property.Drawer.Initialize(); } GUI.enabled = !property.HasAttribute <ReadOnlyAttribute>(); property.Drawer.OnGUI(position, property, label); GUI.enabled = true; }
private void DrawTypeSelect(Rect selectRect, ReflectedProperty property) { Type newConsiderationType; if (property.Value != null) { considerationType = property.Value.GetType(); newConsiderationType = EditorGUIX.ConstructableTypePopup <Consideration>(selectRect, considerationType, FormatTypeName, style); } else { considerationType = null; newConsiderationType = EditorGUIX.ConstructableTypePopup <Consideration>(selectRect, considerationType, FormatTypeName, style); } if (newConsiderationType != considerationType) { considerationType = newConsiderationType; Consideration instance = EditorReflector.MakeInstance <Consideration>(considerationType); property.SetValueAndCopyCompatibleProperties(instance); } }
public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label) { AssetPointer <Chassis> pointer = (AssetPointer <Chassis>)property.Value; GameObject asset = pointer.GetAsset()?.gameObject; GameObject lastAsset = asset; asset = EditorGUI.ObjectField(position, property.GUIContent, lastAsset, typeof(GameObject), false) as GameObject; if (lastAsset == asset) { return; } if (asset == null || !InResourcePath(asset) || !HasComponent(asset)) { property.Value = new AssetPointer <Chassis>(); return; } string path = AssetDatabase.GetAssetPath(asset.GetInstanceID()); property.Value = new AssetPointer <Chassis>(path); }
public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label = null) { AssetPointer <Texture2D> pointer = (AssetPointer <Texture2D>)property.Value; Texture2D asset = pointer.GetAsset(); Texture2D lastAsset = asset; asset = EditorGUI.ObjectField(position, property.GUIContent, lastAsset, typeof(Texture2D), false) as Texture2D; if (lastAsset == asset) { return; } if (asset == null || !InResourcePath(asset)) { property.Value = new AssetPointer <Texture2D>(); return; } string path = AssetDatabase.GetAssetPath(asset.GetInstanceID()); property.Value = new AssetPointer <Texture2D>(path); }
public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label) { guiRect.SetRect(position); string typeName = $"[{StringUtil.NicifyName(property.Type.Name, "Action")}]"; GUIContent content = EditorGUIX.TempLabel(typeName); Rect rect = guiRect.GetFieldRect(); rect.width *= 0.25f; EditorGUIX.Foldout(rect, property, content); rect.x += rect.width; rect.width = rect.width * 3f; EditorGUIX.PropertyField(rect, property[NameField], GUIContent.none); if (property.IsExpanded) { EditorGUIX.DrawProperties(guiRect, property, SkipList); EditorGUIX.PropertyField(guiRect, property[nameof(AIAction.considerations)]); } }
public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label) { MissionDefinition mission = GameDatabase.ActiveInstance.GetCurrentMission(); Debug.Assert(property.DeclaredType == typeof(int), "property.DeclaredType == typeof(int)"); List <FlightGroupDefinition> flightGroups = mission.GetFlightGroups(); flightGroupNames.Clear(); foreach (FlightGroupDefinition fg in flightGroups) { string factionName = $"[{mission.GetFactionById(fg.factionId).name}]"; flightGroupNames.Add($"{factionName} {fg.name}"); } int index = flightGroups.FindIndex((f) => f.id == property.intValue); int newIndex = EditorGUI.Popup(position, property.Label, index, flightGroupNames.ToArray()); if (index != newIndex) { property.Value = flightGroups[newIndex].id; } }
public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label = null) { if (property[EvaluatorField].Value == null) { // todo -- context should match the decisions context property[EvaluatorField].Value = new Evaluator <EntityContext>(); } GUIRect guiRect = new GUIRect(position); EditorGUIX.PropertyField(guiRect, property[NameField]); EditorGUIX.TypePopup <DecisionContext>(guiRect, EditorGUIX.TempLabel("Context Type"), property[ContextTypeField]); EditorGUIX.PropertyField(guiRect, property[ActionField]); EditorGUIX.PropertyField(guiRect, property[ContextCreatorField]); EditorGUIX.PropertyField(guiRect, property[EvaluatorField]); if (property[ContextTypeField].DidChange) { property.ApplyChanges(); Type newContextType = (Type)property[ContextTypeField].Value; if (!AssertCompatible(property[ActionField], newContextType)) { property[ActionField].Value = null; } if (!AssertCompatible(property[ContextCreatorField], newContextType)) { property[ContextCreatorField].Value = null; } if (!AssertCompatible(property[EvaluatorField], newContextType)) { property[EvaluatorField].SetValueAndCopyCompatibleProperties( EditorReflector.CreateGenericInstance(typeof(Evaluator <>), newContextType) ); // todo -- for each consideration, make sure its compatible with new context type } } }
public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label) { s_guiRect.SetRect(position); EditorGUIX.PropertyField(s_guiRect, property[NameField]); EditorGUIX.PropertyField(s_guiRect, property[ShipTypeField]); EditorGUIX.PropertyField(s_guiRect, property[SceneEntityIdField]); EditorGUIX.PropertyField(s_guiRect, property[GoalsField]); EditorGUIX.PropertyField(s_guiRect, property[BehaviorSetField]); EditorGUIX.PropertyField(s_guiRect, property[StandaloneBehaviorsField]); if (!property.HasModifiedProperties) { return; } GameDatabase db = GameDatabase.ActiveInstance; int sceneEntityId = property[SceneEntityIdField].intValue; Entity sceneEntity = db.FindSceneEntityById(sceneEntityId); property.ApplyChanges(); db.LinkSceneEntity(sceneEntity, property.GetValue <EntityDefinition>()); }
public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label = null) { if (property == null) { return; } guiRect.SetRect(position); Initialize(property); EditorGUIX.Foldout(guiRect, property); property.IsExpanded = true; //temp if (property.IsExpanded) { EditorGUI.indentLevel++; EditorGUIX.PropertyField(guiRect, property[NameField]); EditorGUIX.PropertyField(guiRect, property[WeightField]); EditorGUIX.PropertyField(guiRect, property[BonusCalculatorField]); ReorderableListGUI.ListFieldAbsolute(EditorGUI.IndentedRect(guiRect.GetRect()), adapter); EditorGUI.indentLevel--; } }
internal static ReflectedGetterSetter GetReflectedProperty(PropertyTracker pt, MemberGroup allProperties, bool privateBinding) { ReflectedGetterSetter rp; lock (_propertyCache) { if (_propertyCache.TryGetValue(pt, out rp)) { return(rp); } NameType nt = NameType.PythonProperty; MethodInfo getter = FilterProtectedGetterOrSetter(pt.GetGetMethod(true), privateBinding); MethodInfo setter = FilterProtectedGetterOrSetter(pt.GetSetMethod(true), privateBinding); if ((getter != null && PythonHiddenAttribute.IsHidden(getter, true)) || (setter != null && PythonHiddenAttribute.IsHidden(setter, true))) { nt = NameType.Property; } ExtensionPropertyTracker ept = pt as ExtensionPropertyTracker; if (ept == null) { ReflectedPropertyTracker rpt = pt as ReflectedPropertyTracker; Debug.Assert(rpt != null); if (PythonBinder.IsExtendedType(pt.DeclaringType) || PythonHiddenAttribute.IsHidden(rpt.Property, true)) { nt = NameType.Property; } if (pt.GetIndexParameters().Length == 0) { List <MethodInfo> getters = new List <MethodInfo>(); List <MethodInfo> setters = new List <MethodInfo>(); IList <ExtensionPropertyTracker> overriddenProperties = NewTypeMaker.GetOverriddenProperties((getter ?? setter).DeclaringType, pt.Name); foreach (ExtensionPropertyTracker tracker in overriddenProperties) { MethodInfo method = tracker.GetGetMethod(privateBinding); if (method != null) { getters.Add(method); } method = tracker.GetSetMethod(privateBinding); if (method != null) { setters.Add(method); } } foreach (PropertyTracker propTracker in allProperties) { MethodInfo method = propTracker.GetGetMethod(privateBinding); if (method != null) { getters.Add(method); } method = propTracker.GetSetMethod(privateBinding); if (method != null) { setters.Add(method); } } rp = new ReflectedProperty(rpt.Property, getters.ToArray(), setters.ToArray(), nt); } else { rp = new ReflectedIndexer(((ReflectedPropertyTracker)pt).Property, NameType.Property, privateBinding); } } else { rp = new ReflectedExtensionProperty(new ExtensionPropertyInfo(pt.DeclaringType, getter ?? setter), nt); } _propertyCache[pt] = rp; return(rp); } }
internal IMember MakeObject(object obj) { if (obj == null) { return(null); } lock (this) { IMember res; if (!_members.TryGetValue(obj, out res)) { PythonModule mod = obj as PythonModule; if (mod != null) { // FIXME: name object name; if (!mod.Get__dict__().TryGetValue("__name__", out name) || !(name is string)) { name = ""; } _members[obj] = res = new IronPythonModule(this, mod, (string)name); } PythonType type = obj as PythonType; if (type != null) { _members[obj] = res = GetTypeFromType(type.__clrtype__()); } BuiltinFunction func = obj as BuiltinFunction; if (func != null) { _members[obj] = res = new IronPythonBuiltinFunction(this, func); } BuiltinMethodDescriptor methodDesc = obj as BuiltinMethodDescriptor; if (methodDesc != null) { _members[obj] = res = new IronPythonBuiltinMethodDescriptor(this, methodDesc); } ReflectedField field = obj as ReflectedField; if (field != null) { return(new IronPythonField(this, field)); } ReflectedProperty prop = obj as ReflectedProperty; if (prop != null) { _members[obj] = res = new IronPythonProperty(this, prop); } ReflectedExtensionProperty extProp = obj as ReflectedExtensionProperty; if (extProp != null) { _members[obj] = res = new IronPythonExtensionProperty(this, extProp); } NamespaceTracker ns = obj as NamespaceTracker; if (ns != null) { _members[obj] = res = new IronPythonNamespace(this, ns); } Method method = obj as Method; if (method != null) { _members[obj] = res = new IronPythonGenericMember(this, method, PythonMemberType.Method); } var classMethod = obj as ClassMethodDescriptor; if (classMethod != null) { _members[obj] = res = new IronPythonGenericMember(this, classMethod, PythonMemberType.Method); } var typeSlot = obj as PythonTypeTypeSlot; if (typeSlot != null) { _members[obj] = res = new IronPythonGenericMember(this, typeSlot, PythonMemberType.Property); } ReflectedEvent eventObj = obj as ReflectedEvent; if (eventObj != null) { return(new IronPythonEvent(this, eventObj)); } if (res == null) { var genericTypeSlot = obj as PythonTypeSlot; if (genericTypeSlot != null) { _members[obj] = res = new IronPythonGenericMember(this, genericTypeSlot, PythonMemberType.Property); } } TypeGroup tg = obj as TypeGroup; if (tg != null) { _members[obj] = res = new PythonObject <TypeGroup>(this, tg); } var attrType = (obj != null) ? obj.GetType() : typeof(DynamicNull); if (attrType == typeof(bool) || attrType == typeof(int) || attrType == typeof(Complex) || attrType == typeof(string) || attrType == typeof(long) || attrType == typeof(double) || attrType.IsEnum || obj == null) { _members[obj] = res = new IronPythonConstant(this, obj); } if (res == null) { Debug.Assert(!(obj is bool)); _members[obj] = res = new PythonObject <object>(this, obj); } } return(res); } }
public static void TypePopup <T>(Rect position, ReflectedProperty property) { Type currentType = (Type)property.Value; property.Value = TypePopup <T>(position, currentType); }
public static void TypePopup <T>(GUIRect guiRect, ReflectedProperty property) { Type currentType = (Type)property.Value; property.Value = TypePopup <T>(guiRect.GetFieldRect(), currentType); }
public static void PropertyField(Rect position, ReflectedProperty property, GUIContent label = null) { Internal_PropertyField(position, property, label ?? property.GUIContent, false); }
public ArrayProperty(string InName, ReflectedProperty InnerProperty) : base(InName) { Type = ReflectedType.ARRAY; Inner = InnerProperty; }
/// <summary> /// Returns a string representation of an object hierarchy /// </summary> /// <param name="obj">The object to be reflected</param> /// <param name="name">The name of the object being reflected</param> /// <param name="level">The depth of the <see cref="obj"/> in the object tree</param> /// <returns>a string representation of <see cref="obj"/></returns> private static string ReflectToString(object obj, string name, uint level) { //if object is null return early if (obj == null) { return name + ": null"; } StringBuilder output = new StringBuilder(); output.Append(name + ": " + obj); //if object is primative return early Type type = obj.GetType(); if (type.IsPrimitiveLike()) { return output.ToString(); } //Builds up padding string prefex = ""; for (uint i = 0; i <= level; i++) { prefex = prefex + " | "; } IEnumerable enumerable = obj as IEnumerable; if (enumerable != null) { int i = 0; foreach (var v in enumerable) { ReflectedProperty childProperty = new ReflectedProperty(i.ToString(), v); output.Append("\r\n" + prefex + ReflectToString(childProperty.Value, childProperty.Name, level + 1)); i++; } } //Handles complex case and builds a string representation of all child objects PropertyInfo[] properties = obj.GetType().GetProperties(); foreach (PropertyInfo propertyInfo in properties) { ReflectedProperty property = new ReflectedProperty(propertyInfo, obj); output.Append("\r\n"+prefex + ReflectToString(property.Value, property.Name, level + 1)); } return output.ToString(); }