private void OnPreviewSelected(object userData, string[] options, int selected) { IPreviewable[] array = userData as IPreviewable[]; this.m_SelectedPreview = array[selected]; }
internal static void DrawPreview(IPreviewable defaultPreview, Rect previewArea, Object[] targets) { if (s_Styles == null) { s_Styles = new Styles(); } string infoString = string.Empty; Event current = Event.current; if (targets.Length > 1) { Rect rect = new RectOffset(0x10, 0x10, 20, 0x19).Remove(previewArea); int num = Mathf.Max(1, Mathf.FloorToInt((rect.height + 10f) / 77f)); int num2 = Mathf.Max(1, Mathf.FloorToInt((rect.width + 10f) / 65f)); int num3 = num * num2; int minimumNr = Mathf.Min(targets.Length, 0x19); bool flag = true; int[] numArray = new int[] { num2, num }; if (minimumNr < num3) { numArray = GetGridDivision(rect, minimumNr, 12); flag = false; } int num5 = Mathf.Min(numArray[0] * numArray[1], targets.Length); rect.width += 10f; rect.height += 10f; Vector2 vector = new Vector2((float) Mathf.FloorToInt((rect.width / ((float) numArray[0])) - 10f), (float) Mathf.FloorToInt((rect.height / ((float) numArray[1])) - 10f)); float a = Mathf.Min(vector.x, vector.y - 12f); if (flag) { a = Mathf.Min(a, 55f); } bool flag2 = (((current.type == EventType.MouseDown) && (current.button == 0)) && (current.clickCount == 2)) && previewArea.Contains(current.mousePosition); defaultPreview.ResetTarget(); for (int i = 0; i < num5; i++) { Rect position = new Rect(rect.x + (((i % numArray[0]) * rect.width) / ((float) numArray[0])), rect.y + (((i / numArray[0]) * rect.height) / ((float) numArray[1])), vector.x, vector.y); if (flag2 && position.Contains(Event.current.mousePosition)) { Selection.objects = new Object[] { defaultPreview.target }; } position.height -= 12f; Rect rect3 = new Rect(position.x + ((position.width - a) * 0.5f), position.y + ((position.height - a) * 0.5f), a, a); GUI.BeginGroup(rect3); Editor.m_AllowMultiObjectAccess = false; defaultPreview.OnInteractivePreviewGUI(new Rect(0f, 0f, a, a), s_Styles.preBackgroundSolid); Editor.m_AllowMultiObjectAccess = true; GUI.EndGroup(); position.y = rect3.yMax; position.height = 16f; GUI.Label(position, targets[i].name, s_Styles.previewMiniLabel); defaultPreview.MoveNextTarget(); } defaultPreview.ResetTarget(); if (Event.current.type == EventType.Repaint) { infoString = string.Format("Previewing {0} of {1} Objects", num5, targets.Length); } } else { defaultPreview.OnInteractivePreviewGUI(previewArea, s_Styles.preBackground); if (Event.current.type == EventType.Repaint) { infoString = defaultPreview.GetInfoString(); if (infoString != string.Empty) { infoString = infoString.Replace("\n", " "); infoString = string.Format("{0}\n{1}", defaultPreview.target.name, infoString); } } } if ((Event.current.type == EventType.Repaint) && (infoString != string.Empty)) { float height = s_Styles.dropShadowLabelStyle.CalcHeight(GUIContent.Temp(infoString), previewArea.width); EditorGUI.DropShadowLabel(new Rect(previewArea.x, (previewArea.yMax - height) - 5f, previewArea.width, height), infoString); } }
public IPreviewable GetEditorThatControlsPreview(IPreviewable[] editors) { if (editors.Length == 0) { return null; } if (this.m_SelectedPreview != null) { return this.m_SelectedPreview; } IPreviewable lastInteractedEditor = this.GetLastInteractedEditor(); Type type = (lastInteractedEditor == null) ? null : lastInteractedEditor.GetType(); IPreviewable previewable = null; IPreviewable previewable2 = null; for (int i = 0; i < editors.Length; i++) { IPreviewable previewable3 = editors[i]; if (previewable3 != null && !(previewable3.target == null)) { if (!EditorUtility.IsPersistent(previewable3.target) || !(AssetDatabase.GetAssetPath(previewable3.target) != AssetDatabase.GetAssetPath(editors[0].target))) { if (!(editors[0] is AssetImporterInspector) || previewable3 is AssetImporterInspector) { if (previewable3.HasPreviewGUI()) { if (previewable3 == lastInteractedEditor) { return previewable3; } if (previewable2 == null && previewable3.GetType() == type) { previewable2 = previewable3; } if (previewable == null) { previewable = previewable3; } } } } } } if (previewable2 != null) { return previewable2; } if (previewable != null) { return previewable; } return null; }
protected UnityEngine.Object[] GetTargetsForPreview(IPreviewable previewEditor) { Editor editor = null; Editor[] activeEditors = this.m_Tracker.activeEditors; for (int i = 0; i < activeEditors.Length; i++) { Editor editor2 = activeEditors[i]; if (editor2.target.GetType() == previewEditor.target.GetType()) { editor = editor2; break; } } return editor.targets; }
internal static void DrawPreview(IPreviewable defaultPreview, Rect previewArea, UnityEngine.Object[] targets) { if (ObjectPreview.s_Styles == null) { ObjectPreview.s_Styles = new ObjectPreview.Styles(); } string text = string.Empty; Event current = Event.current; if (targets.Length > 1) { Rect rect = new RectOffset(16, 16, 20, 25).Remove(previewArea); int num = Mathf.Max(1, Mathf.FloorToInt((rect.height + 10f) / 77f)); int num2 = Mathf.Max(1, Mathf.FloorToInt((rect.width + 10f) / 65f)); int num3 = num * num2; int num4 = Mathf.Min(targets.Length, 25); bool flag = true; int[] array = new int[] { num2, num }; if (num4 < num3) { array = ObjectPreview.GetGridDivision(rect, num4, 12); flag = false; } int num5 = Mathf.Min(array[0] * array[1], targets.Length); rect.width += 10f; rect.height += 10f; Vector2 vector = new Vector2((float)Mathf.FloorToInt(rect.width / (float)array[0] - 10f), (float)Mathf.FloorToInt(rect.height / (float)array[1] - 10f)); float num6 = Mathf.Min(vector.x, vector.y - 12f); if (flag) { num6 = Mathf.Min(num6, 55f); } bool flag2 = current.type == EventType.MouseDown && current.button == 0 && current.clickCount == 2 && previewArea.Contains(current.mousePosition); defaultPreview.ResetTarget(); for (int i = 0; i < num5; i++) { Rect position = new Rect(rect.x + (float)(i % array[0]) * rect.width / (float)array[0], rect.y + (float)(i / array[0]) * rect.height / (float)array[1], vector.x, vector.y); if (flag2 && position.Contains(Event.current.mousePosition)) { Selection.objects = new UnityEngine.Object[] { defaultPreview.target }; } position.height -= 12f; Rect position2 = new Rect(position.x + (position.width - num6) * 0.5f, position.y + (position.height - num6) * 0.5f, num6, num6); GUI.BeginGroup(position2); Editor.m_AllowMultiObjectAccess = false; defaultPreview.OnInteractivePreviewGUI(new Rect(0f, 0f, num6, num6), ObjectPreview.s_Styles.preBackgroundSolid); Editor.m_AllowMultiObjectAccess = true; GUI.EndGroup(); position.y = position2.yMax; position.height = 16f; GUI.Label(position, targets[i].name, ObjectPreview.s_Styles.previewMiniLabel); defaultPreview.MoveNextTarget(); } defaultPreview.ResetTarget(); if (Event.current.type == EventType.Repaint) { text = string.Format("Previewing {0} of {1} Objects", num5, targets.Length); } } else { defaultPreview.OnInteractivePreviewGUI(previewArea, ObjectPreview.s_Styles.preBackground); if (Event.current.type == EventType.Repaint) { text = defaultPreview.GetInfoString(); if (text != string.Empty) { text = text.Replace("\n", " "); text = string.Format("{0}\n{1}", defaultPreview.target.name, text); } } } if (Event.current.type == EventType.Repaint && text != string.Empty) { float num7 = ObjectPreview.s_Styles.dropShadowLabelStyle.CalcHeight(GUIContent.Temp(text), previewArea.width); EditorGUI.DropShadowLabel(new Rect(previewArea.x, previewArea.yMax - num7 - 5f, previewArea.width, num7), text); } }
private void OnSelectionChange() { this.m_Previews = null; this.m_SelectedPreview = null; this.m_TypeSelectionList = null; this.m_Parent.ClearKeyboardControl(); ScriptAttributeUtility.ClearGlobalCache(); base.Repaint(); }
internal static void DrawPreview(IPreviewable defaultPreview, Rect previewArea, Object[] targets) { if (ObjectPreview.s_Styles == null) ObjectPreview.s_Styles = new ObjectPreview.Styles(); string str1 = string.Empty; Event current = Event.current; if (targets.Length > 1) { Rect rect = new RectOffset(16, 16, 20, 25).Remove(previewArea); int num1 = Mathf.Max(1, Mathf.FloorToInt((float) (((double) rect.height + 10.0) / 77.0))); int num2 = Mathf.Max(1, Mathf.FloorToInt((float) (((double) rect.width + 10.0) / 65.0))); int num3 = num1 * num2; int minimumNr = Mathf.Min(targets.Length, 25); bool flag1 = true; int[] numArray = new int[2]{ num2, num1 }; if (minimumNr < num3) { numArray = ObjectPreview.GetGridDivision(rect, minimumNr, 12); flag1 = false; } int num4 = Mathf.Min(numArray[0] * numArray[1], targets.Length); rect.width += 10f; rect.height += 10f; Vector2 vector2 = new Vector2((float) Mathf.FloorToInt((float) ((double) rect.width / (double) numArray[0] - 10.0)), (float) Mathf.FloorToInt((float) ((double) rect.height / (double) numArray[1] - 10.0))); float num5 = Mathf.Min(vector2.x, vector2.y - 12f); if (flag1) num5 = Mathf.Min(num5, 55f); bool flag2 = current.type == EventType.MouseDown && current.button == 0 && current.clickCount == 2 && previewArea.Contains(current.mousePosition); defaultPreview.ResetTarget(); for (int index = 0; index < num4; ++index) { Rect position1 = new Rect(rect.x + (float) (index % numArray[0]) * rect.width / (float) numArray[0], rect.y + (float) (index / numArray[0]) * rect.height / (float) numArray[1], vector2.x, vector2.y); if (flag2 && position1.Contains(Event.current.mousePosition)) Selection.objects = new Object[1] { defaultPreview.target }; position1.height -= 12f; Rect position2 = new Rect(position1.x + (float) (((double) position1.width - (double) num5) * 0.5), position1.y + (float) (((double) position1.height - (double) num5) * 0.5), num5, num5); GUI.BeginGroup(position2); Editor.m_AllowMultiObjectAccess = false; defaultPreview.OnInteractivePreviewGUI(new Rect(0.0f, 0.0f, num5, num5), ObjectPreview.s_Styles.preBackgroundSolid); Editor.m_AllowMultiObjectAccess = true; GUI.EndGroup(); position1.y = position2.yMax; position1.height = 16f; GUI.Label(position1, targets[index].name, ObjectPreview.s_Styles.previewMiniLabel); defaultPreview.MoveNextTarget(); } defaultPreview.ResetTarget(); if (Event.current.type == EventType.Repaint) str1 = string.Format("Previewing {0} of {1} Objects", (object) num4, (object) targets.Length); } else { defaultPreview.OnInteractivePreviewGUI(previewArea, ObjectPreview.s_Styles.preBackground); if (Event.current.type == EventType.Repaint) { str1 = defaultPreview.GetInfoString(); if (str1 != string.Empty) { string str2 = str1.Replace("\n", " "); str1 = string.Format("{0}\n{1}", (object) defaultPreview.target.name, (object) str2); } } } if (Event.current.type != EventType.Repaint || !(str1 != string.Empty)) return; float height = ObjectPreview.s_Styles.dropShadowLabelStyle.CalcHeight(GUIContent.Temp(str1), previewArea.width); EditorGUI.DropShadowLabel(new Rect(previewArea.x, (float) ((double) previewArea.yMax - (double) height - 5.0), previewArea.width, height), str1); }
internal static void DrawPreview(IPreviewable defaultPreview, Rect previewArea, UnityEngine.Object[] targets) { if (s_Styles == null) { s_Styles = new Styles(); } string infoString = string.Empty; Event current = Event.current; if (targets.Length > 1) { Rect rect = new RectOffset(0x10, 0x10, 20, 0x19).Remove(previewArea); int num = Mathf.Max(1, Mathf.FloorToInt((rect.height + 10f) / 77f)); int num2 = Mathf.Max(1, Mathf.FloorToInt((rect.width + 10f) / 65f)); int num3 = num * num2; int minimumNr = Mathf.Min(targets.Length, 0x19); bool flag = true; int[] numArray = new int[] { num2, num }; if (minimumNr < num3) { numArray = GetGridDivision(rect, minimumNr, 12); flag = false; } int num5 = Mathf.Min(numArray[0] * numArray[1], targets.Length); rect.width += 10f; rect.height += 10f; Vector2 vector = new Vector2((float)Mathf.FloorToInt((rect.width / ((float)numArray[0])) - 10f), (float)Mathf.FloorToInt((rect.height / ((float)numArray[1])) - 10f)); float a = Mathf.Min(vector.x, vector.y - 12f); if (flag) { a = Mathf.Min(a, 55f); } bool flag2 = (((current.type == EventType.MouseDown) && (current.button == 0)) && (current.clickCount == 2)) && previewArea.Contains(current.mousePosition); defaultPreview.ResetTarget(); for (int i = 0; i < num5; i++) { Rect position = new Rect(rect.x + (((i % numArray[0]) * rect.width) / ((float)numArray[0])), rect.y + (((i / numArray[0]) * rect.height) / ((float)numArray[1])), vector.x, vector.y); if (flag2 && position.Contains(Event.current.mousePosition)) { Selection.objects = new UnityEngine.Object[] { defaultPreview.target }; } position.height -= 12f; Rect rect3 = new Rect(position.x + ((position.width - a) * 0.5f), position.y + ((position.height - a) * 0.5f), a, a); GUI.BeginGroup(rect3); Editor.m_AllowMultiObjectAccess = false; defaultPreview.OnInteractivePreviewGUI(new Rect(0f, 0f, a, a), s_Styles.preBackgroundSolid); Editor.m_AllowMultiObjectAccess = true; GUI.EndGroup(); position.y = rect3.yMax; position.height = 16f; GUI.Label(position, targets[i].name, s_Styles.previewMiniLabel); defaultPreview.MoveNextTarget(); } defaultPreview.ResetTarget(); if (Event.current.type == EventType.Repaint) { infoString = $"Previewing {num5} of {targets.Length} Objects"; } } else { defaultPreview.OnInteractivePreviewGUI(previewArea, s_Styles.preBackground); if (Event.current.type == EventType.Repaint) { infoString = defaultPreview.GetInfoString(); if (infoString != string.Empty) { infoString = infoString.Replace("\n", " "); infoString = $"{defaultPreview.target.name} {infoString}"; } } } if ((Event.current.type == EventType.Repaint) && (infoString != string.Empty)) { float height = s_Styles.dropShadowLabelStyle.CalcHeight(GUIContent.Temp(infoString), previewArea.width); EditorGUI.DropShadowLabel(new Rect(previewArea.x, (previewArea.yMax - height) - 5f, previewArea.width, height), infoString); } }
internal static void DrawPreview(IPreviewable defaultPreview, Rect previewArea, UnityObject[] targets) { if (s_Styles == null) { s_Styles = new Styles(); } string text = string.Empty; Event evt = Event.current; // If multiple targets, draw a grid of previews if (targets.Length > 1) { // Draw the previews inside the region of the background that's solid colored Rect previewPositionInner = new RectOffset(16, 16, 20, 25).Remove(previewArea); // Number of previews to aim at int maxRows = Mathf.Max(1, Mathf.FloorToInt((previewPositionInner.height + kGridSpacing) / (kPreviewMinSize + kGridSpacing + kPreviewLabelHeight))); int maxCols = Mathf.Max(1, Mathf.FloorToInt((previewPositionInner.width + kGridSpacing) / (kPreviewMinSize + kGridSpacing))); int countWithMinimumSize = maxRows * maxCols; int neededCount = Mathf.Min(targets.Length, kGridTargetCount); // Get number of columns and rows bool fixedSize = true; int[] division = new int[2] { maxCols, maxRows }; if (neededCount < countWithMinimumSize) { division = GetGridDivision(previewPositionInner, neededCount, kPreviewLabelHeight); fixedSize = false; } // The available cells in the grid may be slightly higher than what was aimed at. // If the number of targets is also higher, we might as well fill in the remaining cells. int count = Mathf.Min(division[0] * division[1], targets.Length); // Calculations become simpler if we add one spacing to the width and height, // so there is the same number of spaces and previews. previewPositionInner.width += kGridSpacing; previewPositionInner.height += kGridSpacing; Vector2 cellSize = new Vector2( Mathf.FloorToInt(previewPositionInner.width / division[0] - kGridSpacing), Mathf.FloorToInt(previewPositionInner.height / division[1] - kGridSpacing) ); float previewSize = Mathf.Min(cellSize.x, cellSize.y - kPreviewLabelHeight); if (fixedSize) { previewSize = Mathf.Min(previewSize, kPreviewMinSize); } bool selectingOne = (evt.type == EventType.MouseDown && evt.button == 0 && evt.clickCount == 2 && previewArea.Contains(evt.mousePosition)); defaultPreview.ResetTarget(); for (int i = 0; i < count; i++) { Rect r = new Rect( previewPositionInner.x + (i % division[0]) * previewPositionInner.width / division[0], previewPositionInner.y + (i / division[0]) * previewPositionInner.height / division[1], cellSize.x, cellSize.y ); if (selectingOne && r.Contains(Event.current.mousePosition)) { if (defaultPreview.target is AssetImporter) { // The new selection should be the asset itself, not the importer Selection.objects = new[] { AssetDatabase.LoadAssetAtPath <UnityObject>(((AssetImporter)defaultPreview.target).assetPath) } } ; else { Selection.objects = new UnityObject[] { defaultPreview.target } }; } // Make room for label underneath r.height -= kPreviewLabelHeight; // Make preview square Rect rSquare = new Rect(r.x + (r.width - previewSize) * 0.5f, r.y + (r.height - previewSize) * 0.5f, previewSize, previewSize); // Draw preview inside a group to prevent overdraw // @TODO: Make style with solid color that doesn't have overdraw GUI.BeginGroup(rSquare); Editor.m_AllowMultiObjectAccess = false; defaultPreview.OnInteractivePreviewGUI(new Rect(0, 0, previewSize, previewSize), s_Styles.preBackgroundSolid); Editor.m_AllowMultiObjectAccess = true; GUI.EndGroup(); // Draw the name of the object r.y = rSquare.yMax; r.height = 16; GUI.Label(r, targets[i].name, s_Styles.previewMiniLabel); defaultPreview.MoveNextTarget(); } defaultPreview.ResetTarget(); // Remember to reset referenceTargetIndex to prevent following calls to 'editor.target' will return a different target which breaks all sorts of places. Fix for case 600235 if (Event.current.type == EventType.Repaint) { text = string.Format("Previewing {0} of {1} Objects", count, targets.Length); } } // If only a single target, just draw that one else { defaultPreview.OnInteractivePreviewGUI(previewArea, s_Styles.preBackground); if (Event.current.type == EventType.Repaint) { // TODO: This should probably be calculated during import and stored together with the asset somehow. Or maybe not. Not sure, really... text = defaultPreview.GetInfoString(); if (text != string.Empty) { text = text.Replace("\n", " "); text = string.Format("{0}\n{1}", defaultPreview.target.name, text); } } } // Draw the asset info. if (Event.current.type == EventType.Repaint && text != string.Empty) { var textHeight = s_Styles.dropShadowLabelStyle.CalcHeight(GUIContent.Temp(text), previewArea.width); EditorGUI.DropShadowLabel(new Rect(previewArea.x, previewArea.yMax - textHeight - kPreviewLabelPadding, previewArea.width, textHeight), text); } }
protected void DrawPreview() { GUI.color = EditorApplication.isPlayingOrWillChangePlaymode ? HostView.kPlayModeDarken : Color.white; if (m_ParentInspectorWindow == null) { Close(); EditorGUIUtility.ExitGUI(); } Editor.m_AllowMultiObjectAccess = true; // Do we have an editor that supports previews? Null if not. IPreviewable[] editorsWithPreviews = GetEditorsWithPreviews(tracker.activeEditors); IPreviewable editor = GetEditorThatControlsPreview(editorsWithPreviews); bool hasPreview = (editor != null) && editor.HasPreviewGUI(); // Toolbar Rect toolbarRect = EditorGUILayout.BeginHorizontal(GUIContent.none, EditorStyles.toolbar, GUILayout.Height(kBottomToolbarHeight)); { GUILayout.FlexibleSpace(); var labelRect = GUILayoutUtility.GetLastRect(); // Label string label = string.Empty; if ((editor != null)) { label = editor.GetPreviewTitle().text; } GUI.Label(labelRect, label, Styles.preToolbarLabel); if (hasPreview) { editor.OnPreviewSettings(); } } EditorGUILayout.EndHorizontal(); Event evt = Event.current; if (evt.type == EventType.MouseUp && evt.button == 1 && toolbarRect.Contains(evt.mousePosition)) { Close(); evt.Use(); // Don't draw preview if we just closed this window return; } // Preview Rect previewPosition = GUILayoutUtility.GetRect(0, 10240, 64, 10240); // Draw background if (Event.current.type == EventType.Repaint) { Styles.preBackground.Draw(previewPosition, false, false, false, false); } // Draw preview if ((editor != null) && editor.HasPreviewGUI()) { editor.DrawPreview(previewPosition); } }
private void OnPreviewSelected(object userData, string[] options, int selected) { this.m_SelectedPreview = (userData as IPreviewable[])[selected]; }
protected UnityEngine.Object[] GetTargetsForPreview(IPreviewable previewEditor) { Editor editor = (Editor) null; foreach (Editor activeEditor in this.m_Tracker.activeEditors) { if (activeEditor.target.GetType() == previewEditor.target.GetType()) { editor = activeEditor; break; } } return editor.targets; }
public IPreviewable GetEditorThatControlsPreview(IPreviewable[] editors) { if (editors.Length == 0) return (IPreviewable) null; if (this.m_SelectedPreview != null) return this.m_SelectedPreview; IPreviewable interactedEditor = (IPreviewable) this.GetLastInteractedEditor(); System.Type type = interactedEditor == null ? (System.Type) null : interactedEditor.GetType(); IPreviewable previewable1 = (IPreviewable) null; IPreviewable previewable2 = (IPreviewable) null; foreach (IPreviewable editor in editors) { if (editor != null && !(editor.target == (UnityEngine.Object) null) && (!EditorUtility.IsPersistent(editor.target) || !(AssetDatabase.GetAssetPath(editor.target) != AssetDatabase.GetAssetPath(editors[0].target))) && ((!(editors[0] is AssetImporterInspector) || editor is AssetImporterInspector) && editor.HasPreviewGUI())) { if (editor == interactedEditor) return editor; if (previewable2 == null && editor.GetType() == type) previewable2 = editor; if (previewable1 == null) previewable1 = editor; } } return previewable2 ?? previewable1 ?? (IPreviewable) null; }
private void OnSelectionChange() { this.m_Previews = (List<IPreviewable>) null; this.m_SelectedPreview = (IPreviewable) null; this.m_TypeSelectionList = (TypeSelectionList) null; this.m_Parent.ClearKeyboardControl(); ScriptAttributeUtility.ClearGlobalCache(); this.Repaint(); }