public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { IncludeConfiguration IncludeConfigurationEnum = (IncludeConfiguration)attribute; if (property.propertyType == SerializedPropertyType.Enum) { var targetEnum = SerializableObjectHelper.GetBaseProperty <Enum>(property); if (this.CachedConfigurationEditor == null || this.lastFrameEnum.ToString() != targetEnum.ToString()) { var configuration = (IConfigurationSerialization)AssetFinder.SafeAssetFind("t:" + IncludeConfigurationEnum.ConfigurationType.Name)[0]; var so = configuration.GetEntry(targetEnum); this.CachedConfigurationEditor = DynamicEditorCreation.Get().CreateEditor(so); this.FoldableArea = new FoldableArea(false, so.name, false); } if (CachedConfigurationEditor != null) { this.FoldableArea.OnGUI(() => { this.CachedConfigurationEditor.OnInspectorGUI(); }); } this.lastFrameEnum = targetEnum; } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { Foldable foldableAttribute = (Foldable)attribute; SerializedProperty disablingProperty = null; if (foldableAttribute.CanBeDisabled) { var parentProperty = SerializableObjectHelper.GetParentProperty(property); disablingProperty = parentProperty.FindPropertyRelative(foldableAttribute.DisablingBoolAttribute); if (this.foldableArea == null) { this.foldableArea = new FoldableArea(foldableAttribute.CanBeDisabled, property.name, disablingProperty.boolValue); } } else { if (this.foldableArea == null) { this.foldableArea = new FoldableArea(foldableAttribute.CanBeDisabled, property.name, false); } } EditorGUI.BeginProperty(position, null, property); this.foldableArea.OnGUI(() => { try { foreach (var childPropery in SerializableObjectHelper.GetChildren(property)) { EditorGUILayout.PropertyField(childPropery, true); } } catch (Exception) { } }); if (foldableAttribute.CanBeDisabled) { disablingProperty.boolValue = this.foldableArea.IsEnabled; } EditorGUI.EndProperty(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { CustomEnum searchableEnum = (CustomEnum)attribute; if (property.propertyType == SerializedPropertyType.Enum) { EditorGUI.BeginProperty(position, null, property); var targetEnum = SerializableObjectHelper.GetBaseProperty <Enum>(property); int currentLineNB = 0; if (searchableEnum.IsSearchable) { Rect lineRect = this.GetRectFromLineNb(currentLineNB, position); var labelFieldRect = new Rect(lineRect.x, lineRect.y, lineRect.width / 2, lineRect.height); EditorGUI.LabelField(labelFieldRect, label); var enumPopupRect = new Rect(lineRect.x + lineRect.width / 2, lineRect.y, lineRect.width / 2, lineRect.height); if (EditorGUI.DropdownButton(enumPopupRect, new GUIContent(targetEnum.ToString()), FocusType.Keyboard)) { if (windowInstance == null) { windowInstance = EditorWindow.CreateInstance <EnumSearchGUIWindow>(); windowInstance.Init(targetEnum, (newSelectedEnum) => { property.longValue = (int)Convert.ChangeType(newSelectedEnum, newSelectedEnum.GetTypeCode()); property.serializedObject.ApplyModifiedProperties(); property.serializedObject.Update(); EditorUtility.SetDirty(property.serializedObject.targetObject); }); } var windowRect = new Rect(GUIUtility.GUIToScreenPoint(enumPopupRect.position), new Vector2(0, enumPopupRect.height)); windowInstance.ShowAsDropDown(windowRect, new Vector2(enumPopupRect.width, 500)); } currentLineNB += 1; } if (searchableEnum.ConfigurationType != null) { if (updateConfigurationView) { var foundAssets = AssetFinder.SafeAssetFind("t:" + searchableEnum.ConfigurationType.Name); if (foundAssets != null && foundAssets.Count > 0) { var configuration = (IConfigurationSerialization)foundAssets[0]; configuration.GetEntryTry(targetEnum, out ScriptableObject so); if (so != null) { this.CachedConfigurationEditor = DynamicEditorCreation.Get().CreateEditor(so); this.ConfigurationFoldableArea = new FoldableArea(false, so.name, false, new EditorPersistantBoolVariable(EditorPersistantBoolVariable.BuildKeyFromObject(so, so.name))); } else { this.CachedConfigurationEditor = null; this.ConfigurationFoldableArea = null; } } updateConfigurationView = false; } if (this.lastFrameEnum == null) { this.CachedConfigurationEditor = null; this.ConfigurationFoldableArea = null; } if (CachedConfigurationEditor != null && this.ConfigurationFoldableArea != null) { try { var oldBackGroundColor = GUI.backgroundColor; GUI.backgroundColor = MyColors.HotPink; this.ConfigurationFoldableArea.OnGUI(() => { EditorGUI.BeginDisabledGroup(true); EditorGUILayout.ObjectField(this.CachedConfigurationEditor.target, typeof(ScriptableObject), false); EditorGUI.EndDisabledGroup(); this.CachedConfigurationEditor.OnInspectorGUI(); }); GUI.backgroundColor = oldBackGroundColor; } catch (Exception) { } } else if (CachedConfigurationEditor == null) { try { //We propose creation wizard if (GUILayout.Button("CREATE IN WIZARD")) { GameCreationWizard.InitWithSelected(targetEnum.GetType().Name.Replace("ID", "CreationWizard")); } } catch (Exception) { } } EditorGUILayout.Space(); } updateConfigurationView = this.lastFrameEnum == null || (this.lastFrameEnum != null && this.lastFrameEnum.ToString() != targetEnum.ToString()); if (searchableEnum.OpenToConfiguration) { if (searchableEnum.ConfigurationType != null) { try { if (GUILayout.Button("OPEN CONFIGURATION")) { var gameDesignerEditor = ConfigurationInspector.OpenConfigurationEditor(searchableEnum.ConfigurationType); var currentGameModule = gameDesignerEditor.GetCrrentGameDesignerModule(); if (typeof(IConfigurationModule).IsAssignableFrom(currentGameModule.GetType())) { ((IConfigurationModule)currentGameModule).SetSearchString(targetEnum.ToString()); } } } catch (Exception) { } } } this.lastFrameEnum = targetEnum; EditorGUI.EndProperty(); } }
//This is a very large UI, so certain parts have been compacted //some curly brackets are used to organise the containers to make it more obvious public override VisualElement CreateInspectorGUI() { SerializedObject so = serializedObject; VisualElement container = new VisualElement(); //Edit button // Header: Joint FoldableArea jointContainer = new FoldableArea("Joint"); { // Connected body jointContainer.Add(so.CreatePropertyField("m_ConnectedBody")); //Axis jointContainer.Add(so.CreatePropertyField("m_Axis")); jointContainer.Add(so.CreatePropertyField("m_SecondaryAxis")); //Anchor jointContainer.Add(so.CreatePropertyField("m_AutoConfigureConnectedAnchor")); jointContainer.Add(so.CreatePropertyField("m_Anchor")); } // Header: Linear Motion FoldableArea linearContainer = new FoldableArea("Linear Motion"); { // X Motion Y Motion Z Motion linearContainer.Add(CreateMotionField("m_XMotion")); linearContainer.Add(CreateMotionField("m_YMotion")); linearContainer.Add(CreateMotionField("m_ZMotion")); // Linear Limit linearContainer.Add(so.CreatePropertyField("m_LinearLimit")); // Linear Limit Spring linearContainer.Add(so.CreatePropertyField("m_LinearLimitSpring")); } // Header: Angular Motion FoldableArea angularContainer = new FoldableArea("Angular Motion"); { // X Motion Y Motion Z Motion angularContainer.Add(CreateMotionField("m_AngularXMotion")); angularContainer.Add(CreateMotionField("m_AngularYMotion")); angularContainer.Add(CreateMotionField("m_AngularZMotion")); // Low Angular X Limit angularContainer.Add(so.CreatePropertyField("m_LowAngularXLimit")); // High Angular X Limit angularContainer.Add(so.CreatePropertyField("m_HighAngularXLimit")); // Angular X Limit Spring angularContainer.Add(so.CreatePropertyField("m_AngularXLimitSpring")); // Angular Y Limit angularContainer.Add(so.CreatePropertyField("m_AngularYLimit")); // Angular Z Limit angularContainer.Add(so.CreatePropertyField("m_AngularZLimit")); // Angular YZ Limit Spring angularContainer.Add(so.CreatePropertyField("m_AngularYZLimitSpring")); } // Header: Linear Drive FoldableArea linearDriveContainer = new FoldableArea("Linear Drive"); { //Target Position linearDriveContainer.Add(so.CreatePropertyField("m_TargetPosition")); //Target Velocity linearDriveContainer.Add(so.CreatePropertyField("m_TargetVelocity")); //X Drive linearDriveContainer.Add(so.CreatePropertyField("m_XDrive")); //Y Drive linearDriveContainer.Add(so.CreatePropertyField("m_YDrive")); //Z Drive linearDriveContainer.Add(so.CreatePropertyField("m_ZDrive")); } // Header: Angular Drive FoldableArea angularDriveContainer = new FoldableArea("Angular Drive"); { //Target Rotation angularDriveContainer.Add(so.CreatePropertyField("m_TargetRotation")); //Target Angular Velocity angularDriveContainer.Add(so.CreatePropertyField("m_TargetAngularVelocity")); //Rotation Drive mode angularDriveContainer.Add(so.CreatePropertyField("m_AngularDriveMode")); //Angular X Drive angularDriveContainer.Add(so.CreatePropertyField("m_AngularXDrive")); //Angular YZ Drive angularDriveContainer.Add(so.CreatePropertyField("m_AngularYZDrive")); //Slerp Drive angularDriveContainer.Add(so.CreatePropertyField("m_SlerpDrive")); } // Header: Projection FoldableArea projectionContainer = new FoldableArea("Projection"); { //Projection Mode projectionContainer.Add(so.CreatePropertyField("m_ProjectionMode")); //Projection Distance projectionContainer.Add(so.CreatePropertyField("m_ProjectionDistance")); //Projection Angle projectionContainer.Add(so.CreatePropertyField("m_ProjectionAngle")); } // Header: Joint Settings FoldableArea settingsContainer = new FoldableArea("Settings"); { // Configured in world space settingsContainer.Add(so.CreatePropertyField("m_ConfiguredInWorldSpace")); //Swap Bodies settingsContainer.Add(so.CreatePropertyField("m_SwapBodies")); //Break Force settingsContainer.Add(so.CreatePropertyField("m_BreakForce")); //Break Torque settingsContainer.Add(so.CreatePropertyField("m_BreakTorque")); //Enable Collision settingsContainer.Add(so.CreatePropertyField("m_EnableCollision")); //Enable Preprocessing settingsContainer.Add(so.CreatePropertyField("m_EnablePreprocessing")); //Mass Scale settingsContainer.Add(so.CreatePropertyField("m_MassScale")); //Connected Mass Scale settingsContainer.Add(so.CreatePropertyField("m_ConnectedMassScale")); } container.Add(jointContainer); container.Add(linearContainer); container.Add(angularContainer); container.Add(linearDriveContainer); container.Add(angularDriveContainer); container.Add(projectionContainer); container.Add(settingsContainer); return(container); }