void DrawChildren(Rect listRect, Rect headerRect, Rect sizeRect, Rect visibleRect, EventType previousEvent) { if (Event.current.type == EventType.Used && sizeRect.Contains(Event.current.mousePosition)) { Event.current.type = previousEvent; } EditorGUI.BeginChangeCheck(); EditorGUI.DefaultPropertyField(sizeRect, m_ArraySize, GUIContent.none); EditorGUI.LabelField(sizeRect, new GUIContent("", "Array Size")); if (EditorGUI.EndChangeCheck()) { m_ReorderableList.InvalidateCache(); } if (headerRect.Contains(Event.current.mousePosition)) { if (Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragPerform) { Object[] objReferences = DragAndDrop.objectReferences; foreach (var o in objReferences) { Object validatedObject = EditorGUI.ValidateObjectFieldAssignment(new[] { o }, typeof(Object), m_ReorderableList.serializedProperty, EditorGUI.ObjectFieldValidatorOptions.None); if (validatedObject != null) { DragAndDrop.visualMode = DragAndDropVisualMode.Generic; } else { continue; } if (Event.current.type == EventType.DragPerform) { ReorderableList.defaultBehaviours.DoAddButton(m_ReorderableList, validatedObject); } } DragAndDrop.AcceptDrag(); Event.current.Use(); } } if (Event.current.type == EventType.DragExited) { DragAndDrop.visualMode = DragAndDropVisualMode.None; Event.current.Use(); } if (Property.isExpanded) { listRect.y += m_HeaderHeight + Constants.kHeaderPadding; listRect.height -= m_HeaderHeight + Constants.kHeaderPadding; visibleRect.y -= listRect.y; m_ReorderableList.DoList(listRect, visibleRect); } }
private void DrawBiomeSettings(bool helpEnabled) { m_biomePreset.m_orderNumber = m_editorUtils.IntField("OrderNumber", m_biomePreset.m_orderNumber, helpEnabled); Rect listRect = EditorGUILayout.GetControlRect(true, m_spawnerPresetList.GetHeight()); m_spawnerPresetList.DoList(listRect); m_editorUtils.InlineHelp("SpawnerAdded", helpEnabled); if (m_biomePreset.m_spawnerPresetList.Count == 0) { GUILayout.Space(EditorGUIUtility.singleLineHeight); EditorGUILayout.HelpBox(m_editorUtils.GetTextValue("NoSpawnersYet"), MessageType.Warning); GUILayout.Space(10); if (m_editorUtils.Button("CreateFirstSpawner")) { GameObject spawnerObj = new GameObject("New Spawner"); Spawner spawner = spawnerObj.AddComponent <Spawner>(); spawner.m_createdfromBiomePreset = true; Selection.activeGameObject = spawnerObj; } GUILayout.Space(20); } else { GUILayout.Space(10); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (m_editorUtils.Button("CreateAdditionalSpawner", GUILayout.MaxWidth(200))) { GameObject spawnerObj = new GameObject("New Spawner"); Spawner spawner = spawnerObj.AddComponent <Spawner>(); spawner.m_createdfromBiomePreset = true; Selection.activeGameObject = spawnerObj; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } GUILayout.Space(EditorGUIUtility.singleLineHeight); m_biomePreset.GaiaSceneCullingProfile = (GaiaSceneCullingProfile)m_editorUtils.ObjectField("GaiaSceneCullingProfile", m_biomePreset.GaiaSceneCullingProfile, typeof(GaiaSceneCullingProfile), false, helpEnabled); #if UNITY_POST_PROCESSING_STACK_V2 GUILayout.Space(EditorGUIUtility.singleLineHeight); m_biomePreset.postProcessProfile = (PostProcessProfile)m_editorUtils.ObjectField("PostProcessingProfile", m_biomePreset.postProcessProfile, typeof(PostProcessProfile), false, helpEnabled); #endif GUILayout.Space(EditorGUIUtility.singleLineHeight); serializedObject.ApplyModifiedProperties(); EditorUtility.SetDirty(m_biomePreset); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (!property.isArray) { EditorGUI.HelpBox(position, $"Cannot use ListReorderable on {property.name} because its not an array!", MessageType.Error); return; } Initialize(); for (int i = 0; i < property.arraySize; i++) { Proxy.Add(property.GetArrayElementAtIndex(i)); } LastProp = property; List.DoList(position); }
public override void OnGUI(UnityEngine.Rect position, SerializedProperty property, UnityEngine.GUIContent label) { if (list == null) { var listProperty = property.FindPropertyRelative("List"); list = getList(listProperty); } if (list != null) { list.drawHeaderCallback = rect => { EditorGUI.LabelField(rect, property.name); }; list.DoList(position); } }
public void OnGUI(Rect position) { if (m_ListenersArray == null || !m_ListenersArray.isArray) { return; } m_DummyEvent = GetDummyEvent(m_Prop); if (m_DummyEvent == null) { return; } if (m_ReorderableList != null) { var oldIdentLevel = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; m_ReorderableList.DoList(position); EditorGUI.indentLevel = oldIdentLevel; } }
public override void OnGUI(UnityEngine.Rect position, SerializedProperty property, UnityEngine.GUIContent label) { if (list == null) { var listProperty = property.FindPropertyRelative("List"); list = getList(listProperty); } if (list != null) { list.drawHeaderCallback = rect => { rect.x += 10; mShowList = EditorGUI.Foldout(rect, mShowList, property.name, true); }; list.displayAdd = mShowList; list.displayRemove = mShowList; if (mShowList) { list.DoList(position); } else { if (Event.current.type == EventType.Repaint) { headerBackground.Draw(position, false, false, false, false); } position.x += 16; mShowList = EditorGUI.Foldout(position, mShowList, property.name, true); } } }
void DisplayUpdateGUI() { EditorGUILayout.IntPopup(m_UpdateMode, styles.updateModeStrings, styles.updateModeValues, styles.updateMode); EditorGUI.indentLevel++; if (m_UpdateMode.intValue == (int)CustomRenderTextureUpdateMode.Realtime) { EditorGUILayout.PropertyField(m_UpdatePeriod, styles.updatePeriod); } EditorGUILayout.PropertyField(m_DoubleBuffered, styles.doubleBuffered); EditorGUILayout.PropertyField(m_WrapUpdateZones, styles.wrapUpdateZones); bool isCubemap = true; foreach (Object o in targets) { CustomRenderTexture customRenderTexture = o as CustomRenderTexture; if (customRenderTexture != null && customRenderTexture.dimension != UnityEngine.Rendering.TextureDimension.Cube) { isCubemap = false; } } if (isCubemap) { int newFaceMask = 0; int currentFaceMask = m_CubeFaceMask.intValue; var AllRects = GUILayoutUtility.GetRect(0, EditorGUIUtility.singleLineHeight * 3 + EditorGUIUtility.standardVerticalSpacing * 2); EditorGUI.BeginProperty(AllRects, GUIContent.none, m_CubeFaceMask); Rect toggleRect = AllRects; toggleRect.width = kToggleWidth; toggleRect.height = EditorGUIUtility.singleLineHeight; int faceIndex = 0; { Rect labelRect = AllRects; EditorGUI.LabelField(labelRect, styles.cubemapFacesLabel); EditorGUI.BeginChangeCheck(); for (int i = 0; i < 3; ++i) { toggleRect.x = AllRects.x + EditorGUIUtility.labelWidth - kIndentSize; { for (int j = 0; j < 2; ++j) { bool value = EditorGUI.ToggleLeft(toggleRect, styles.cubemapFaces[faceIndex], (currentFaceMask & (1 << faceIndex)) != 0); if (value) { newFaceMask |= (int)(1 << faceIndex); } faceIndex++; toggleRect.x += kToggleWidth; } } toggleRect.y += EditorGUIUtility.singleLineHeight; } if (EditorGUI.EndChangeCheck()) { m_CubeFaceMask.intValue = newFaceMask; } } EditorGUI.EndProperty(); } EditorGUILayout.IntPopup(m_UpdateZoneSpace, styles.updateZoneSpaceStrings, styles.updateZoneSpaceValues, styles.updateZoneSpace); if (!multipleEditing) { Rect listRect = GUILayoutUtility.GetRect(0.0f, m_RectList.GetHeight() + kRListAddButtonOffset, GUILayout.ExpandWidth(true)); // kRListAddButtonOffset because reorderable list does not take the +/- button at the bottom when computing its Rects making it half occulted by other GUI elements. // Reorderable list seems to not take indentLevel into account properly. float indentSize = kIndentSize; listRect.x += indentSize; listRect.width -= indentSize; m_RectList.DoList(listRect); } else { EditorGUILayout.HelpBox("Update Zones cannot be changed while editing multiple Custom Textures.", MessageType.Info); } EditorGUI.indentLevel--; }
public void Draw(Rect r, Rect visibleArea) { var prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); m_IsNotInPrefabContextModeWithOverrides = prefabStage == null || prefabStage.mode != PrefabStage.Mode.InContext || !PrefabStage.s_PatchAllOverriddenProperties || Selection.objects.All(obj => PrefabUtility.IsPartOfAnyPrefab(obj) && !AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(obj)).Equals(AssetDatabase.AssetPathToGUID(prefabStage.assetPath))); m_ReorderableList.draggable = m_Reorderable && m_IsNotInPrefabContextModeWithOverrides; Rect headerRect = new Rect(r.x, r.y, r.width, m_HeaderHeight); Rect sizeRect = new Rect(headerRect.xMax - Constants.kArraySizeWidth, headerRect.y, Constants.kArraySizeWidth, m_HeaderHeight); EventType prevType = Event.current.type; if (Event.current.type == EventType.MouseUp && sizeRect.Contains(Event.current.mousePosition)) { Event.current.type = EventType.Used; } EditorGUI.BeginChangeCheck(); m_Foldout = EditorGUI.BeginFoldoutHeaderGroup(headerRect, m_Foldout, m_Header); EditorGUI.EndFoldoutHeaderGroup(); if (EditorGUI.EndChangeCheck()) { m_ReorderableList.ClearCacheRecursive(); } if (Event.current.type == EventType.Used && sizeRect.Contains(Event.current.mousePosition)) { Event.current.type = prevType; } EditorGUI.DefaultPropertyField(sizeRect, m_ArraySize, GUIContent.none); EditorGUI.LabelField(sizeRect, new GUIContent("", "Array Size")); if (headerRect.Contains(Event.current.mousePosition)) { if (Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragPerform) { Object[] objReferences = DragAndDrop.objectReferences; foreach (var o in objReferences) { if (EditorGUI.ValidateObjectFieldAssignment(new[] { o }, typeof(Object), m_ReorderableList.serializedProperty, EditorGUI.ObjectFieldValidatorOptions.None) != null) { DragAndDrop.visualMode = DragAndDropVisualMode.Generic; } else { continue; } if (Event.current.type == EventType.DragPerform) { ReorderableList.defaultBehaviours.DoAddButton(m_ReorderableList, o); } } DragAndDrop.AcceptDrag(); Event.current.Use(); } } if (Event.current.type == EventType.DragExited) { DragAndDrop.visualMode = DragAndDropVisualMode.None; Event.current.Use(); } if (m_Foldout) { r.y += m_HeaderHeight + Constants.kHeaderPadding; r.height -= m_HeaderHeight + Constants.kHeaderPadding; visibleArea.y -= r.y; m_ReorderableList.DoList(r, visibleArea); } }
public void DoList(Rect rect) { #if UNITY_EDITOR list.DoList(rect); #endif }
private void OnGUI() { serializerCollectionPath = EditorGUILayout.TextField("SerializerCollection path", serializerCollectionPath); deserializerCollectionPath = EditorGUILayout.TextField("DeserializerCollection path", deserializerCollectionPath); if (GUILayout.Button("Scan for ghosts")) { FindAllGhosts(); } if (m_GhostList == null) { m_GhostList = new UnityEditorInternal.ReorderableList(m_GhostTypes, typeof(GhostType), true, false, false, false); m_GhostList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { m_GhostTypes[index].generate = EditorGUI.Toggle(rect, m_GhostTypes[index].serializerType.Name, m_GhostTypes[index].generate); }; } var listRect = new Rect(0, EditorGUIUtility.singleLineHeight * 6, position.width, EditorGUIUtility.singleLineHeight * (m_GhostTypes.Count + 1)); m_GhostList.DoList(listRect); if (GUILayout.Button("Generate Collection")) { var serializerFile = Path.Combine(Application.dataPath, serializerCollectionPath); var deserializerFile = Path.Combine(Application.dataPath, deserializerCollectionPath); string ghostSerializerInst = ""; string ghostDeserializerInst = ""; string ghostFind = ""; string ghostBeginSerialize = ""; string ghostCalculateImportance = ""; string ghostWantsPredictionDelta = ""; string ghostSnapshotSize = ""; string ghostInvokeSerialize = ""; string ghostSerializerName = ""; string ghostInitializeDeserialize = ""; string ghostBeginDeserialize = ""; string ghostInvokeDeserialize = ""; string ghostInvokeSpawn = ""; for (int i = 0; i < m_GhostTypes.Count; ++i) { if (m_GhostTypes[i].generate) { ghostSerializerInst += GhostSerializerInstanceTemplate .Replace("/*$GHOST_SERIALIZER_TYPE*/", m_GhostTypes[i].serializerType.Name); ghostDeserializerInst += GhostDeserializerInstanceTemplate .Replace("/*$GHOST_SNAPSHOT_TYPE*/", m_GhostTypes[i].snapshotType.Name); ghostFind += GhostFindTemplate .Replace("/*$GHOST_SERIALIZER_TYPE*/", m_GhostTypes[i].serializerType.Name) .Replace("/*$GHOST_SERIALIZER_INDEX*/", i.ToString()); ghostBeginSerialize += GhostBeginSerializeTemplate .Replace("/*$GHOST_SERIALIZER_TYPE*/", m_GhostTypes[i].serializerType.Name); ghostCalculateImportance += GhostCalculateImportanceTemplate .Replace("/*$GHOST_SERIALIZER_TYPE*/", m_GhostTypes[i].serializerType.Name) .Replace("/*$GHOST_SERIALIZER_INDEX*/", i.ToString()); ghostWantsPredictionDelta += GhostWantsPredictionDeltaTemplate .Replace("/*$GHOST_SERIALIZER_TYPE*/", m_GhostTypes[i].serializerType.Name) .Replace("/*$GHOST_SERIALIZER_INDEX*/", i.ToString()); ghostSnapshotSize += GhostSnapshotSizeTemplate .Replace("/*$GHOST_SERIALIZER_TYPE*/", m_GhostTypes[i].serializerType.Name) .Replace("/*$GHOST_SERIALIZER_INDEX*/", i.ToString()); ghostInvokeSerialize += GhostInvokeSerializeTemplate .Replace("/*$GHOST_COLLECTION_PREFIX*/", "") .Replace("/*$GHOST_SNAPSHOT_TYPE*/", m_GhostTypes[i].snapshotType.Name) .Replace("/*$GHOST_SERIALIZER_TYPE*/", m_GhostTypes[i].serializerType.Name) .Replace("/*$GHOST_SERIALIZER_INDEX*/", i.ToString()); ghostSerializerName += GhostSerializerNameTemplate .Replace("/*$GHOST_SERIALIZER_TYPE*/", m_GhostTypes[i].serializerType.Name); ghostInitializeDeserialize += GhostInitializeDeserializeTemplate .Replace("/*$GHOST_SNAPSHOT_TYPE*/", m_GhostTypes[i].snapshotType.Name) .Replace("/*$GHOST_SERIALIZER_INDEX*/", i.ToString()) .Replace("/*$GHOST_SPAWNER_TYPE*/", m_GhostTypes[i].spawnerType.Name); ghostBeginDeserialize += GhostBeginDeserializeTemplate .Replace("/*$GHOST_SNAPSHOT_TYPE*/", m_GhostTypes[i].snapshotType.Name); ghostInvokeDeserialize += GhostInvokeDeserializeTemplate .Replace("/*$GHOST_COLLECTION_PREFIX*/", "") .Replace("/*$GHOST_SNAPSHOT_TYPE*/", m_GhostTypes[i].snapshotType.Name) .Replace("/*$GHOST_SERIALIZER_INDEX*/", i.ToString()); ghostInvokeSpawn += GhostInvokeSpawnTemplate .Replace("/*$GHOST_COLLECTION_PREFIX*/", "") .Replace("/*$GHOST_SNAPSHOT_TYPE*/", m_GhostTypes[i].snapshotType.Name) .Replace("/*$GHOST_SERIALIZER_INDEX*/", i.ToString()); } } string serializerContent = GhostSerializerCollectionTemplate .Replace("/*$GHOST_SERIALIZER_INSTANCES*/", ghostSerializerInst) .Replace("/*$GHOST_DESERIALIZER_INSTANCES*/", ghostDeserializerInst) .Replace("/*$GHOST_FIND_CHECKS*/", ghostFind) .Replace("/*$GHOST_BEGIN_SERIALIZE*/", ghostBeginSerialize) .Replace("/*$GHOST_CALCULATE_IMPORTANCE*/", ghostCalculateImportance) .Replace("/*$GHOST_WANTS_PREDICTION_DELTA*/", ghostWantsPredictionDelta) .Replace("/*$GHOST_SNAPSHOT_SIZE*/", ghostSnapshotSize) .Replace("/*$GHOST_INVOKE_SERIALIZE*/", ghostInvokeSerialize) .Replace("/*$GHOST_SERIALIZER_NAMES*/", ghostSerializerName) .Replace("/*$GHOST_INITIALIZE_DESERIALIZE*/", ghostInitializeDeserialize) .Replace("/*$GHOST_BEGIN_DESERIALIZE*/", ghostBeginDeserialize) .Replace("/*$GHOST_INVOKE_DESERIALIZE*/", ghostInvokeDeserialize) .Replace("/*$GHOST_INVOKE_SPAWN*/", ghostInvokeSpawn) .Replace("/*$GHOST_SERIALIZER_COUNT*/", m_GhostTypes.Count.ToString()) .Replace("/*$GHOST_COLLECTION_PREFIX*/", "") .Replace("/*$GHOST_SYSTEM_PREFIX*/", Application.productName); string deserializerContent = GhostDeserializerCollectionTemplate .Replace("/*$GHOST_SERIALIZER_INSTANCES*/", ghostSerializerInst) .Replace("/*$GHOST_DESERIALIZER_INSTANCES*/", ghostDeserializerInst) .Replace("/*$GHOST_FIND_CHECKS*/", ghostFind) .Replace("/*$GHOST_BEGIN_SERIALIZE*/", ghostBeginSerialize) .Replace("/*$GHOST_CALCULATE_IMPORTANCE*/", ghostCalculateImportance) .Replace("/*$GHOST_WANTS_PREDICTION_DELTA*/", ghostWantsPredictionDelta) .Replace("/*$GHOST_SNAPSHOT_SIZE*/", ghostSnapshotSize) .Replace("/*$GHOST_INVOKE_SERIALIZE*/", ghostInvokeSerialize) .Replace("/*$GHOST_SERIALIZER_NAMES*/", ghostSerializerName) .Replace("/*$GHOST_INITIALIZE_DESERIALIZE*/", ghostInitializeDeserialize) .Replace("/*$GHOST_BEGIN_DESERIALIZE*/", ghostBeginDeserialize) .Replace("/*$GHOST_INVOKE_DESERIALIZE*/", ghostInvokeDeserialize) .Replace("/*$GHOST_INVOKE_SPAWN*/", ghostInvokeSpawn) .Replace("/*$GHOST_SERIALIZER_COUNT*/", m_GhostTypes.Count.ToString()) .Replace("/*$GHOST_COLLECTION_PREFIX*/", "") .Replace("/*$GHOST_SYSTEM_PREFIX*/", Application.productName); File.WriteAllText(serializerFile, serializerContent); File.WriteAllText(deserializerFile, deserializerContent); } }