public OnInteractivePreviewGUI ( |
||
r | Rectangle in which to draw the preview. | |
background | Background image. | |
Résultat | void |
public void OnGUI() { if (mat == null || mat.Material == null) { return; } IsOpen = EditorGUILayout.Foldout(IsOpen, mat.Material.name); if (IsOpen && Editor == null) { Editor = UnityEditor.Editor.CreateEditor(mat.Material, typeof(MaterialEditor)); } if (!IsOpen && Editor != null) { Destroy(); return; } if (IsOpen) { EditorGUILayout.LabelField(mat.Material.shader.name); Editor.OnInteractivePreviewGUI( GUILayoutUtility.GetRect(EditorGUIUtility.currentViewWidth - 32, 128), EditorStyles.helpBox); } }
public void OnInteractivePreviewGUI(Rect r, GUIStyle background) { if (editor != null) { editor.OnInteractivePreviewGUI(r, background); } }
private void OnGUI() { // Display create new options GUILayout.Label("Cubemap Creator", EditorStyles.boldLabel); resolution = Mathf.NextPowerOfTwo(EditorGUILayout.DelayedIntField("Cubemap Resolution", resolution)); if (GUILayout.Button("Create New")) { if (map != null) { map.Destroy(); } map = new CubeMapper(); map.Create(cam.FieldOfView, resolution); Stamp(); } // Stamping options GUILayout.Label("Options", EditorStyles.boldLabel); fovModifier = EditorGUILayout.Slider("Stamp FOV modifier", fovModifier, 1, 4); overrideGyro = EditorGUILayout.Toggle("Override gyro direction", overrideGyro); EditorGUI.BeginDisabledGroup(!overrideGyro); overrideDir = EditorGUILayout.Vector3Field("Override direction", overrideDir); EditorGUI.EndDisabledGroup(); // Display options for the current cubemap GUILayout.Label("Current cubemap", EditorStyles.boldLabel); if (map != null) { if (GUILayout.Button("Stamp from camera")) { Stamp(); } } // Show an interactive preview if we have one Rect r = EditorGUILayout.GetControlRect(GUILayout.ExpandHeight(true)); if (previewAsset != null) { if (previewEditor == null) { previewEditor = UnityEditor.Editor.CreateEditor(previewAsset); } previewEditor.OnInteractivePreviewGUI(r, previewStyle); } else { EditorGUI.DrawRect(r, new Color(0, 0, 0, 0.1f)); } }
protected override void OnInspecstorGUI(Dictionary <string, Action <SerializedProperty> > overrides) { DrawWithOrder(10, () => { var t = (UnityEquippableItemDefinition)target; EditorGUILayout.LabelField(new GUIContent("Equippable item info"), General2.Editors.EditorStyles.titleStyle); using (new VerticalLayoutBlock(General2.Editors.EditorStyles.boxStyle)) { DrawPropertyOrOverride(_equipmentType, t.equipmentType, overrides); DrawPropertyOrOverride(_mountPoint, t.mountPoint, overrides); DrawPropertyOrOverride(_equipmentModel, t.equipmentModel, overrides); UnityEditor.Editor.CreateCachedEditor(t.equipmentModel, null, ref equipmentModelPreviewEditor); equipmentModelPreviewEditor?.OnInteractivePreviewGUI(GUILayoutUtility.GetRect(500, 250), UnityEditor.EditorStyles.helpBox); } }); base.OnInspecstorGUI(overrides); }
/// <summary> /// Helper script for rendering an object field to set the 3D app launcher model in an editor window. /// </summary> /// <remarks>See <see href="https://docs.microsoft.com/en-us/windows/mixed-reality/distribute/3d-app-launcher-design-guidance">3D app launcher design guidance</see> for more information.</remarks> public static void DrawAppLauncherModelField(bool showInteractivePreview = true) { using (new EditorGUILayout.HorizontalScope()) { GltfAsset newGlbModel; bool appLauncherChanged = false; // 3D launcher model string curAppLauncherModelLocation = BuildDeployPreferences.AppLauncherModelLocation; var curGlbModel = AssetDatabase.LoadAssetAtPath(curAppLauncherModelLocation, typeof(GltfAsset)); using (new EditorGUILayout.VerticalScope()) { EditorGUILayout.LabelField(AppLauncherModelLabel); newGlbModel = EditorGUILayout.ObjectField(curGlbModel, typeof(GltfAsset), false, GUILayout.MaxWidth(256)) as GltfAsset; string newAppLauncherModelLocation = AssetDatabase.GetAssetPath(newGlbModel); if (newAppLauncherModelLocation != curAppLauncherModelLocation) { BuildDeployPreferences.AppLauncherModelLocation = newAppLauncherModelLocation; appLauncherChanged = true; } } // The preview GUI has a problem during the build, so we don't render it if (newGlbModel != null && newGlbModel.Model != null && showInteractivePreview && !isBuilding) { if (gameObjectEditor == null || appLauncherChanged) { gameObjectEditor = UnityEditor.Editor.CreateEditor(newGlbModel.Model); } if (appLauncherPreviewBackgroundColor == null) { appLauncherPreviewBackgroundColor = new GUIStyle(); appLauncherPreviewBackgroundColor.normal.background = EditorGUIUtility.whiteTexture; } gameObjectEditor.OnInteractivePreviewGUI(GUILayoutUtility.GetRect(128, 128), appLauncherPreviewBackgroundColor); } } }
protected override void OnInspecstorGUI(Dictionary <string, Action <SerializedProperty> > overrides) { if (overrides.ContainsKey("m_Script") == false) { // Hides the m_Script overrides["m_Script"] = (obj) => { }; } EditorGUILayout.LabelField(new GUIContent("Type: " + target.GetType().Name)); var t = (UnityItemDefinition)target; DoDrawWithOrder(0, 9); EditorGUILayout.LabelField(new GUIContent("General item info"), General2.Editors.EditorStyles.titleStyle); using (new VerticalLayoutBlock(General2.Editors.EditorStyles.boxStyle)) { DrawPropertyOrOverride(_parent, t.parent, overrides); if (Equals(_parent.objectReferenceValue, t) || ReferenceEquals(_parent.objectReferenceValue, t) || t.Equals(_parent.objectReferenceValue)) { _parent.objectReferenceValue = null; } DrawReadOnlyPropertyOrOverride(_guid, t.ID, overrides); DrawPropertyOrOverride(_name, t.name, overrides); DrawPropertyOrOverride(_description, t.description, overrides); DrawPropertyOrOverride(_icon, t.icon, overrides); if (t.icon != null) { DrawSprite(GUILayoutUtility.GetRect(32, 32), t.icon); } DrawPropertyOrOverride(_worldModel, t.worldModel, overrides); UnityEditor.Editor.CreateCachedEditor(t.worldModel, null, ref modelPreviewEditor); modelPreviewEditor?.OnInteractivePreviewGUI(GUILayoutUtility.GetRect(500, 250), UnityEditor.EditorStyles.helpBox); } DoDrawWithOrder(10, 19); EditorGUILayout.LabelField(new GUIContent("Item specific"), General2.Editors.EditorStyles.titleStyle); using (new VerticalLayoutBlock(General2.Editors.EditorStyles.boxStyle)) { DrawPropertiesExcluding(serializedObject, overrides.Keys.Concat(properties.Select(o => o.name)).ToArray()); } DoDrawWithOrder(20, 29); EditorGUILayout.LabelField(new GUIContent("Logistics"), General2.Editors.EditorStyles.titleStyle); using (new VerticalLayoutBlock(General2.Editors.EditorStyles.boxStyle)) { DrawPropertyOrOverride(_layoutShape, t.layoutShape, overrides); DrawPropertyOrOverride(_maxStackSize, t.maxStackSize, overrides); _maxStackSize.intValue = Mathf.Clamp(_maxStackSize.intValue, 1, 9999); DrawPropertyOrOverride(_weight, t.weight, overrides); _weight.floatValue = Mathf.Clamp(_weight.floatValue, 0f, 9999f); } DoDrawWithOrder(30, 39); EditorGUILayout.LabelField(new GUIContent("Financial"), General2.Editors.EditorStyles.titleStyle); using (new VerticalLayoutBlock(General2.Editors.EditorStyles.boxStyle)) { if (_buyPrice.arraySize == 0) { GUI.color = new Color(1f, 0.6f, 0f, GUI.color.a); } DrawPropertyOrOverride(_buyPrice, t.buyPrice, overrides); GUI.color = Color.white; if (_sellPrice.arraySize == 0) { GUI.color = new Color(1f, 0.6f, 0f, GUI.color.a); } DrawPropertyOrOverride(_sellPrice, t.sellPrice, overrides); GUI.color = Color.white; } DoDrawWithOrder(40, 49); }
protected override void OnInspecstorGUI(Dictionary <string, Action <SerializedProperty> > overrides) { if (overrides.ContainsKey("m_Script") == false) { // Hides the m_Script overrides["m_Script"] = (obj) => { }; } var t = (UnityItemDefinition)target; GUI.enabled = string.IsNullOrEmpty(t.name) == false; if (GUILayout.Button("Update asset name")) { AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(t), t.name + " - " + t.ID.ToString().Substring(0, 8)); } GUI.enabled = true; EditorGUILayout.LabelField(new GUIContent("Type: " + target.GetType().Name)); DoDrawWithOrder(0, 9); EditorGUILayout.LabelField(new GUIContent("General item info"), General2.Editors.EditorStyles.titleStyle); using (new VerticalLayoutBlock(General2.Editors.EditorStyles.boxStyle)) { DrawPropertyOrOverride(_parent, t.parent, overrides); if (Equals(_parent.objectReferenceValue, t) || ReferenceEquals(_parent.objectReferenceValue, t) || t.Equals(_parent.objectReferenceValue)) { _parent.objectReferenceValue = null; } DrawReadOnlyPropertyOrOverride(_guid, t.ID, overrides); DrawPropertyOrOverride(_name, t.name, overrides); DrawPropertyOrOverride(_description, t.description, overrides); DrawPropertyOrOverride(_icon, t.icon, overrides); if (t.icon != null) { DrawSprite(GUILayoutUtility.GetRect(32, 32), t.icon); } DrawPropertyOrOverride(_worldModel, t.worldModel, overrides); UnityEditor.Editor.CreateCachedEditor(t.worldModel, null, ref modelPreviewEditor); if (modelPreviewEditor != null) { modelPreviewEditor.OnInteractivePreviewGUI(GUILayoutUtility.GetRect(500, 250), UnityEditor.EditorStyles.helpBox); } } DoDrawWithOrder(10, 19); EditorGUILayout.LabelField(new GUIContent("Item specific"), General2.Editors.EditorStyles.titleStyle); using (new VerticalLayoutBlock(General2.Editors.EditorStyles.boxStyle)) { // var keys = overrides.Keys.Concat(properties.Select(o => o.name)); // foreach (var key in keys) // { // SerializedProperty prop; // GetPropertyWithoutAdding(key, out prop); // // if (prop != null) // { // var r = ReflectionUtility.GetFieldInherited() // DrawPropertyOrOverride(prop, , overrides); // } // } var propertyToExclude = overrides.Keys.Concat(properties.Select(o => o.name)).ToArray(); var iterator = serializedObject.GetIterator(); bool enterChildren = true; while (iterator.NextVisible(enterChildren)) { enterChildren = false; if (propertyToExclude.Contains <string>(iterator.name) == false) { var n = iterator.name.Replace("_", ""); var val = t.GetValue(o => { var prop = ReflectionUtility.GetPropertyInherited(t.GetType(), n); if (prop != null) { return(prop.GetValue(t)); } return(null); }); DrawPropertyOrOverride(iterator, val, overrides); } } // overrides.Keys.Concat(properties.Select(o => o.name).Where(o => properties.Contains(o) == false)) // DrawPropertiesExcluding(serializedObject, ); } DoDrawWithOrder(20, 29); EditorGUILayout.LabelField(new GUIContent("Logistics"), General2.Editors.EditorStyles.titleStyle); using (new VerticalLayoutBlock(General2.Editors.EditorStyles.boxStyle)) { DrawPropertyOrOverride(_layoutShape, t.layoutShape, overrides); DrawPropertyOrOverride(_maxStackSize, t.maxStackSize, overrides); _maxStackSize.intValue = Mathf.Clamp(_maxStackSize.intValue, 1, 9999); DrawPropertyOrOverride(_weight, t.weight, overrides); _weight.floatValue = Mathf.Clamp(_weight.floatValue, 0f, 9999f); } DoDrawWithOrder(30, 39); EditorGUILayout.LabelField(new GUIContent("Financial"), General2.Editors.EditorStyles.titleStyle); using (new VerticalLayoutBlock(General2.Editors.EditorStyles.boxStyle)) { if (_buyPrice.arraySize == 0) { GUI.color = new Color(1f, 0.6f, 0f, GUI.color.a); } DrawPropertyOrOverride(_buyPrice, t.buyPrice, overrides); GUI.color = Color.white; if (_sellPrice.arraySize == 0) { GUI.color = new Color(1f, 0.6f, 0f, GUI.color.a); } DrawPropertyOrOverride(_sellPrice, t.sellPrice, overrides); GUI.color = Color.white; } DoDrawWithOrder(40, 49); }