private static void UpdateSchedulers() { Dictionary <int, Panel> .Enumerator panelsIterator = UIElementsUtility.GetPanelsIterator(); while (panelsIterator.MoveNext()) { KeyValuePair <int, Panel> current = panelsIterator.Current; Panel value = current.Value; if (value.contextType == ContextType.Editor) { IScheduler scheduler = value.scheduler; value.timerEventScheduler.UpdateScheduledEvents(); DataWatchService dataWatchService = value.dataWatch as DataWatchService; dataWatchService.ProcessNotificationQueue(); if (value.visualTree.IsDirty(ChangeType.Repaint)) { GUIView gUIView = EditorUtility.InstanceIDToObject(value.instanceID) as GUIView; if (gUIView != null) { gUIView.Repaint(); } } } } }
public void SaveStateFromHierarchy(SceneHierarchyWindow hierarchy, StageNavigationItem stage) { var lastClickedGameObject = EditorUtility.InstanceIDToObject(hierarchy.sceneHierarchy.treeViewState.lastClickedID) as GameObject; if (stage.isMainStage) { m_LastClickedInstanceID = lastClickedGameObject != null?lastClickedGameObject.GetInstanceID() : 0; m_ExpandedSceneGameObjectInstanceIDs = hierarchy.sceneHierarchy.treeViewState.expandedIDs; } else { m_LastClickedFileID = lastClickedGameObject != null?GetOrGenerateFileID(lastClickedGameObject) : 0; m_ExpandedPrefabGameObjectFileIDs = GetExpandedGameObjectFileIDs(hierarchy); } m_ScrollY = hierarchy.sceneHierarchy.treeViewState.scrollPos.y; if (SceneHierarchy.s_DebugPersistingExpandedState) { DebugLog("Saving", stage); } }
// Selection changes when calling BeginNewAsset if it succeeds public bool BeginNewAssetCreation(int instanceID, EndNameEditAction newAssetEndAction, string filePath, Texture2D icon, string newAssetResourceFile) { //Sanitize input string sanitizedFilePath = filePath != null?filePath.ConvertSeparatorsToUnity() : filePath; string sanitizedNewAssetResourceFile = newAssetResourceFile != null?newAssetResourceFile.ConvertSeparatorsToUnity() : newAssetResourceFile; string uniquePath; if (!sanitizedFilePath.StartsWith("assets/", System.StringComparison.CurrentCultureIgnoreCase) && !sanitizedFilePath.StartsWith("packages/", System.StringComparison.CurrentCultureIgnoreCase)) { // If sanitizedFilePath is not already a full asset path, we need to get the full path uniquePath = AssetDatabase.GetUniquePathNameAtSelectedPath(sanitizedFilePath); } else { uniquePath = AssetDatabase.GenerateUniqueAssetPath(sanitizedFilePath); } if (!IsPathDataValid(uniquePath)) { Debug.LogErrorFormat("Invalid generated unique path '{0}' (input path '{1}')", uniquePath, sanitizedFilePath); Clear(); return(false); } m_InstanceID = instanceID; m_Path = uniquePath; m_Icon = icon; m_EndAction = newAssetEndAction; m_ResourceFile = sanitizedNewAssetResourceFile; // Change selection to none or instanceID Selection.activeObject = EditorUtility.InstanceIDToObject(instanceID); return(true); }
public ComponentDropdownElement(string name, string menuPath, string command) : base(name) { this.m_MenuPath = menuPath; this.m_Command = command; this.m_IsLegacy = menuPath.Contains("Legacy"); if (command.StartsWith("SCRIPT")) { int instanceID = int.Parse(command.Substring(6)); UnityEngine.Object obj = EditorUtility.InstanceIDToObject(instanceID); Texture2D miniThumbnail = AssetPreview.GetMiniThumbnail(obj); this.m_Content = new GUIContent(name, miniThumbnail); } else { int classID = int.Parse(command); this.m_Content = new GUIContent(name, AssetPreview.GetMiniTypeThumbnailFromClassID(classID)); } this.m_ContentWhenSearching = new GUIContent(this.m_Content); if (this.m_IsLegacy) { GUIContent expr_A4 = this.m_ContentWhenSearching; expr_A4.text += " (Legacy)"; } }
public bool BeginNewAssetCreation(int instanceID, EndNameEditAction newAssetEndAction, string filePath, Texture2D icon, string newAssetResourceFile) { string text; if (!filePath.StartsWith("assets/", StringComparison.CurrentCultureIgnoreCase)) { text = AssetDatabase.GetUniquePathNameAtSelectedPath(filePath); } else { text = AssetDatabase.GenerateUniqueAssetPath(filePath); } bool result; if (!CreateAssetUtility.IsPathDataValid(text)) { Debug.LogErrorFormat("Invalid generated unique path '{0}' (input path '{1}')", new object[] { text, filePath }); this.Clear(); result = false; } else { this.m_InstanceID = instanceID; this.m_Path = text; this.m_Icon = icon; this.m_EndAction = newAssetEndAction; this.m_ResourceFile = newAssetResourceFile; Selection.activeObject = EditorUtility.InstanceIDToObject(instanceID); result = true; } return(result); }
internal static IEnumerable <Object> DuplicateAssets(IEnumerable <int> instanceIDs) { return(DuplicateAssets(instanceIDs.Select(id => EditorUtility.InstanceIDToObject(id)))); }
private string GetItemcontent(RowGUIArgs args, int column) { if (m_AllCanvasesItem != null && args.item.id == m_AllCanvasesItem.id) { switch ((Column)column) { case Column.TotalBatchCount: return(m_AllCanvasesItem.totalBatchCount.ToString()); case Column.TotalVertexCount: return(m_AllCanvasesItem.totalVertexCount.ToString()); case Column.GameObjectCount: return(m_AllCanvasesItem.gameObjectCount.ToString()); default: return(null); } } var batchItem = args.item as BatchTreeViewItem; if (batchItem != null) { var info = batchItem.info; switch ((Column)column) { case Column.VertexCount: return(info.vertexCount.ToString()); case Column.TotalVertexCount: return(info.totalVertexCount.ToString()); case Column.BatchBreakingReason: if (info.batchBreakingReason != BatchBreakingReason.NoBreaking) { return(FormatBatchBreakingReason(info)); } break; case Column.GameObjectCount: return(info.instanceIDsCount.ToString()); case Column.InstanceIds: if (batchItem.instanceIDs.Length <= 5) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < batchItem.instanceIDs.Length; i++) { if (i != 0) { sb.Append(", "); } int iid = batchItem.instanceIDs[i]; var o = EditorUtility.InstanceIDToObject(iid); if (o == null) { sb.Append(iid); } else { sb.Append(o.name); } } return(sb.ToString()); } return(string.Format("{0} objects", batchItem.instanceIDs.Length)); case Column.Element: case Column.BatchCount: case Column.TotalBatchCount: break; case Column.Rerender: return(info.renderDataIndex.ToString()); default: return("Missing"); } return(null); } var canvasItem = args.item as CanvasTreeViewItem; if (canvasItem != null) { UISystemProfilerInfo info = canvasItem.info; switch ((Column)column) { case Column.BatchCount: return(info.batchCount.ToString()); case Column.TotalBatchCount: return(info.totalBatchCount.ToString()); case Column.TotalVertexCount: return(info.totalVertexCount.ToString()); case Column.GameObjectCount: return(info.instanceIDsCount.ToString()); case Column.VertexCount: case Column.BatchBreakingReason: case Column.InstanceIds: case Column.Element: break; case Column.Rerender: return(info.renderDataIndex + " : " + info.renderDataCount); default: return("Missing"); } return(null); } return(null); }
public static UnityObject GetCurrentObject() { return(EditorUtility.InstanceIDToObject(ObjectSelector.get.GetSelectedInstanceID())); }
private string GetItemcontent(TreeView.RowGUIArgs args, int column) { string result; if (this.m_AllCanvasesItem != null && args.item.id == this.m_AllCanvasesItem.id) { switch (column) { case 2: result = this.m_AllCanvasesItem.totalBatchCount.ToString(); return(result); case 4: result = this.m_AllCanvasesItem.totalVertexCount.ToString(); return(result); case 6: result = this.m_AllCanvasesItem.gameObjectCount.ToString(); return(result); } result = null; } else { UISystemProfilerTreeView.BatchTreeViewItem batchTreeViewItem = args.item as UISystemProfilerTreeView.BatchTreeViewItem; if (batchTreeViewItem != null) { UISystemProfilerInfo info = batchTreeViewItem.info; switch (column) { case 0: case 1: case 2: break; case 3: result = info.vertexCount.ToString(); return(result); case 4: result = info.totalVertexCount.ToString(); return(result); case 5: if (info.batchBreakingReason != BatchBreakingReason.NoBreaking) { result = UISystemProfilerTreeView.FormatBatchBreakingReason(info); return(result); } break; case 6: result = info.instanceIDsCount.ToString(); return(result); case 7: if (batchTreeViewItem.instanceIDs.Length <= 5) { StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < batchTreeViewItem.instanceIDs.Length; i++) { if (i != 0) { stringBuilder.Append(", "); } int num = batchTreeViewItem.instanceIDs[i]; UnityEngine.Object @object = EditorUtility.InstanceIDToObject(num); if (@object == null) { stringBuilder.Append(num); } else { stringBuilder.Append(@object.name); } } result = stringBuilder.ToString(); return(result); } result = string.Format("{0} objects", batchTreeViewItem.instanceIDs.Length); return(result); case 8: result = info.renderDataIndex.ToString(); return(result); default: result = "Missing"; return(result); } result = null; } else { UISystemProfilerTreeView.CanvasTreeViewItem canvasTreeViewItem = args.item as UISystemProfilerTreeView.CanvasTreeViewItem; if (canvasTreeViewItem != null) { UISystemProfilerInfo info2 = canvasTreeViewItem.info; switch (column) { case 0: case 3: case 5: case 7: result = null; break; case 1: result = info2.batchCount.ToString(); break; case 2: result = info2.totalBatchCount.ToString(); break; case 4: result = info2.totalVertexCount.ToString(); break; case 6: result = info2.instanceIDsCount.ToString(); break; case 8: result = info2.renderDataIndex + " : " + info2.renderDataCount; break; default: result = "Missing"; break; } } else { result = null; } } } return(result); }
internal static IEnumerable <UnityEngine.Object> DuplicateAssets(IEnumerable <int> instanceIDs) { return(ProjectWindowUtil.DuplicateAssets(from id in instanceIDs select EditorUtility.InstanceIDToObject(id))); }
public static UnityEngine.Object GetCurrentObject() => EditorUtility.InstanceIDToObject(get.GetSelectedInstanceID());
public override void OnGUI(Rect rect) { if (editorWindow.position.y != targetPositionY) { editorWindow.position = new Rect(editorWindow.position) { y = targetPositionY } } ; // Escape closes the window if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape) { editorWindow.Close(); GUIUtility.ExitGUI(); } if (!DrawHeader()) { return; } float height = k_HeaderHeight; if (target.isVariant) { height += DrawVariantHierarchy(); } height += DrawChildrenLabel(height); if (displayChildren) { DrawChildren(height); } if (materialEditor.convertState == ConvertAction.Flatten) { materialEditor.convertState = ConvertAction.None; Undo.RecordObject(target, "Flatten Material Variant"); target.parent = null; Init(); } } bool DrawHeader() { Rect headerRect = GUILayoutUtility.GetRect(20, windowWidth, k_HeaderHeight, k_HeaderHeight); EditorGUI.DrawRect(headerRect, Colors.headerBackground); var headerLabel = target.isVariant ? Styles.variantLabel : Styles.instanceLabel; float labelSize = Styles.boldRightAligned.CalcSize(headerLabel).x; Rect labelRect = new Rect(k_OffsetX, headerRect.y + k_Padding, labelSize, EditorGUIUtility.singleLineHeight); Rect contentRect = new Rect(labelRect.x + labelRect.width + k_Padding, labelRect.y, windowWidth, labelRect.height); GUI.Label(labelRect, headerLabel, Styles.boldRightAligned); DoObjectLabel(contentRect, target, EditorStyles.boldLabel); labelRect.y = labelRect.height + 2 * k_Padding; if (materialEditor.convertState == ConvertAction.None) { int result; labelRect.width = k_ConvertLabelWidth; using (new EditorGUI.DisabledScope(!enabled)) result = EditorGUI.Popup(labelRect, target.isVariant ? 1 : 0, Styles.headerPopupOptions); if (result == 0 && target.isVariant) { materialEditor.convertState = ConvertAction.Flatten; targetPositionY = singleLinePositionY; } if (result == 1 && !target.isVariant) { materialEditor.convertState = ConvertAction.Convert; targetPositionY = singleLinePositionY + k_PositionShiftY; } } else if (materialEditor.convertState == ConvertAction.Convert) { GUI.enabled = false; labelRect.width = 200f; EditorGUI.Button(labelRect, Styles.convertingLabel); GUI.enabled = true; // Conversion helper labelRect.y = k_HeaderHeight; labelRect.width = windowWidth; EditorGUI.LabelField(labelRect, Styles.conversionHelpLabel); labelRect.x = windowWidth - 14; if (GUI.Button(labelRect, GUIContent.none, EditorStyles.toolbarSearchFieldCancelButton)) { materialEditor.convertState = ConvertAction.None; targetPositionY = singleLinePositionY; materialEditor.Repaint(); } labelRect.x = k_OffsetX; var oldLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 70; EditorGUI.BeginChangeCheck(); var parent = target.parent; materialEditor.ParentField(new Rect(k_OffsetX, labelRect.yMax + k_Padding, windowWidth - 2 * k_OffsetX, k_EntryHeight)); if (EditorGUI.EndChangeCheck() && parent != target.parent) { materialEditor.convertState = ConvertAction.None; Init(); } EditorGUIUtility.labelWidth = oldLabelWidth; return(false); } return(true); } float DrawVariantHierarchy() { // Draw table header Rect entryRect = new Rect(0, k_HeaderHeight, windowWidth, k_EntryHeight); EditorGUI.DrawRect(entryRect, Colors.rowBackground(0)); var labelRect = entryRect; labelRect.x = k_TitleWidth; GUI.Label(labelRect, Styles.ancestorLabel, EditorStyles.miniLabel); labelRect.x = overridesX + k_Padding; GUI.Label(labelRect, Styles.overridesLabel, EditorStyles.miniLabel); labelRect.x = locksX + k_Padding; GUI.Label(labelRect, Styles.locksLabel, EditorStyles.miniLabel); float tableHeight = Mathf.Min(numRows, k_MaxTableRows) * k_EntryHeight + (namesWidth > maxNameWidth ? k_ScrollbarHeight : 0); float realHeight = numRows * k_EntryHeight + (namesWidth > maxNameWidth ? k_ScrollbarHeight : 0); var tableRect = new Rect(0, k_HeaderHeight + k_EntryHeight, windowWidth - 1, tableHeight); scroll.y = GUI.BeginScrollView(tableRect, scroll, new Rect(tableRect) { width = tableRect.width - k_ScrollbarWidth, height = realHeight }).y; // Draw overrides and locks table int i = numRows; Material current = target; while (current != null) { entryRect.y = k_HeaderHeight + i * k_EntryHeight; EditorGUI.DrawRect(entryRect, Colors.rowBackground(i--)); DisplayOverridesAndLocks(entryRect, current); current = current.parent; } var scrollRect = new Rect(k_TitleWidth, k_HeaderHeight + k_EntryHeight, Mathf.Min(namesWidth, maxNameWidth), numRows * k_EntryHeight); scroll.x = GUI.BeginScrollView(new Rect(scrollRect) { height = scrollRect.height + k_ScrollbarHeight }, scroll, new Rect(scrollRect) { width = namesWidth }).x; // Draw scrollable table i = numRows; current = target; entryRect.x = k_TitleWidth; while (i != 0) { entryRect.y = k_HeaderHeight + i-- *k_EntryHeight; if (current == null) { GUI.Label(entryRect, EditorGUIUtility.TempContent("Missing (Material)")); break; } DoObjectLabel(entryRect, current); current = current.parent; } GUI.EndScrollView(); float height = tableHeight + k_EntryHeight; // Draw selected label labelRect.x = k_OffsetX; labelRect.y = k_HeaderHeight + numRows * k_EntryHeight; labelRect.width = k_TitleWidth - labelRect.x; GUI.Label(labelRect, Styles.selectedLabel); // Draw parent label labelRect.y = k_HeaderHeight + (numRows - 1) * k_EntryHeight; GUI.Label(labelRect, Styles.parentLabel); // Draw root label if (labelRect.y != k_HeaderHeight + k_EntryHeight) { labelRect.y = k_HeaderHeight + k_EntryHeight; GUI.Label(labelRect, Styles.rootLabel); } // Draw vertical splits Rect splitBar = new Rect(overridesX - k_SplitWidth, k_HeaderHeight, k_SplitWidth, (numRows + 1) * k_EntryHeight); EditorGUI.DrawRect(splitBar, Colors.headerBackground); splitBar.x = locksX - k_SplitWidth; EditorGUI.DrawRect(splitBar, Colors.headerBackground); GUI.EndScrollView(); return(height); } float DrawChildrenLabel(float yMin) { var labelRect = new Rect(k_OffsetX, yMin, 100, k_EntryHeight); if (target.isVariant) { displayChildren = EditorGUI.Foldout(labelRect, displayChildren, Styles.childrenLabel, true); } else { EditorGUI.LabelField(labelRect, Styles.childrenLabel); } if (displayChildren) { if (listArea == null) { InitListArea(); } labelRect = new Rect(labelRect.x + 58 + (target.isVariant ? 12 : 0), labelRect.y + 2, k_SliderWidth, EditorGUI.kSingleLineHeight); if (results.Length != 0) { EditorGUI.LabelField(labelRect, results.Length.ToString(), Styles.boldNumber); } EditorGUI.BeginChangeCheck(); labelRect.x = windowWidth - k_OffsetX - k_SliderWidth; var newGridSize = (int)GUI.HorizontalSlider(labelRect, listArea.gridSize, listArea.minGridSize, listArea.maxGridSize); if (EditorGUI.EndChangeCheck()) { listArea.gridSize = newGridSize; } } return(k_EntryHeight); } void DrawChildren(float yMin) { var backgroundRect = new Rect(0, yMin, windowWidth, k_SearchHeight); GUI.Label(backgroundRect, GUIContent.none, Styles.searchBackground); EditorGUI.BeginChangeCheck(); var searchRect = new Rect(k_OffsetX + k_Padding, backgroundRect.y + k_Padding, windowWidth - 2 * k_OffsetX - k_Padding, Styles.searchFieldStyle.fixedHeight); searchFilterString = EditorGUI.ToolbarSearchField(searchRect, searchFilterString, false); if (EditorGUI.EndChangeCheck()) { debounce.Execute(); } if (enumerator != null) { Search(); } yMin = searchRect.height + (listArea.gridSize < k_MinIconSize ? 11f : 0f); var listRect = new Rect(k_Padding, searchRect.y + yMin, windowWidth - 2 * k_Padding, k_SearchHeight - yMin - k_Padding); int listKeyboardControlID = GUIUtility.GetControlID(FocusType.Keyboard); listArea.OnGUI(listRect, listKeyboardControlID); if (enumerator == null && results.Length == 0) { var labelRect = new Rect(noResultsX, backgroundRect.y + 69f, windowWidth, EditorGUI.kSingleLineHeight); EditorGUI.LabelField(backgroundRect, searchFilter.nameFilter.Length == 0 ? Styles.noChildrenLabel : Styles.noResultsLabel, Styles.centered); } } void InitListArea() { listArea = new ObjectListArea(s_ListAreaState, editorWindow, false) { allowDeselection = true, allowMultiSelect = false, allowRenaming = false, allowBuiltinResources = true, }; listArea.itemSelectedCallback += (bool doubleClicked) => { if (listArea.GetSelection().Length == 0) { return; } var selection = listArea.GetSelection()[0]; GUIUtility.keyboardControl = GUIUtility.GetControlID(FocusType.Keyboard); if (doubleClicked) { Selection.SetActiveObjectWithContext(EditorUtility.InstanceIDToObject(selection), null); Event.current.Use(); editorWindow.Close(); GUIUtility.ExitGUI(); } else { EditorGUIUtility.PingObject(selection); Event.current.Use(); } }; SearchFilterChanged(); }