static bool CreateAnimation(GameObject gameObject, Object[] frames, ShowFileDialogDelegate saveFileDialog) { saveFileDialog = saveFileDialog ?? EditorUtility.SaveFilePanelInProject; // Use same name compare as when we sort in the backend: See AssetDatabase.cpp: SortChildren System.Array.Sort(frames, (a, b) => EditorUtility.NaturalCompare(a.name, b.name)); Animator animator = AnimationWindowUtility.EnsureActiveAnimationPlayer(gameObject) ? AnimationWindowUtility.GetClosestAnimatorInParents(gameObject.transform) : null; bool createSuccess = animator != null; if (animator != null) { // Go forward with presenting user a save clip dialog string message = string.Format(SpriteUtilityStrings.saveAnimDialogMessage.text, gameObject.name); string newClipDirectory = ProjectWindowUtil.GetActiveFolderPath(); string newClipPath = saveFileDialog(SpriteUtilityStrings.saveAnimDialogTitle.text, SpriteUtilityStrings.saveAnimDialogName.text, "anim", message, newClipDirectory); if (string.IsNullOrEmpty(newClipPath)) { Undo.ClearUndo(animator); Object.DestroyImmediate(animator); return(false); } else { AnimationClip newClip = AnimationWindowUtility.CreateNewClipAtPath(newClipPath); if (newClip != null) { AddSpriteAnimationToClip(newClip, frames); createSuccess = AnimationWindowUtility.AddClipToAnimatorComponent(animator, newClip); } } } if (createSuccess == false) { Debug.LogError(SpriteUtilityStrings.failedToCreateAnimationError.text); } return(createSuccess); }
public int GetInsertAfterItemIDForNewItem(string newName, TreeViewItem parentItem) { int result = parentItem.id; if (!parentItem.hasChildren) { return(result); } for (int i = 0; i < parentItem.children.Count; i++) { int id = parentItem.children[i].id; string assetPath = AssetDatabase.GetAssetPath(id); if (EditorUtility.NaturalCompare(Path.GetFileNameWithoutExtension(assetPath), newName) > 0) { break; } result = id; } return(result); }
static public void Show(Rect buttonRect, string[] classNames, int initialSelectedInstanceID) { var menu = new GenericMenu(); var objs = FindAssetsOfType(classNames); if (objs.Any()) { objs.Sort((result1, result2) => EditorUtility.NaturalCompare(result1.name, result2.name)); foreach (var obj in objs) { var assetName = new GUIContent(obj.name); bool selected = obj.GetInstanceID() == initialSelectedInstanceID; menu.AddItem(assetName, selected, SelectCallback, obj); } } else { menu.AddDisabledItem(EditorGUIUtility.TrTextContent("No Audio Mixers found in this project")); } menu.DropDown(buttonRect); }
public int GetInsertAfterItemIDForNewItem(string newName, TreeViewItem parentItem) { int num = parentItem.id; if (!parentItem.hasChildren) { return(num); } for (int index = 0; index < parentItem.children.Count; ++index) { int id = parentItem.children[index].id; if (EditorUtility.NaturalCompare(Path.GetFileNameWithoutExtension(AssetDatabase.GetAssetPath(id)), newName) <= 0) { num = id; } else { break; } } return(num); }
public int GetInsertAfterItemIDForNewItem(string newName, TreeViewItem parentItem, bool isCreatingNewFolder, bool foldersFirst) { if (!parentItem.hasChildren) { return(parentItem.id); } // Find pos under parent int insertAfterID = parentItem.id; for (int idx = 0; idx < parentItem.children.Count; ++idx) { int instanceID = parentItem.children[idx].id; bool isFolder = parentItem.children[idx] is FolderTreeItem; // Skip folders when inserting a normal asset if folders is sorted first if (foldersFirst && isFolder && !isCreatingNewFolder) { insertAfterID = instanceID; continue; } // When inserting a folder in folders first list break when we reach normal assets if (foldersFirst && !isFolder && isCreatingNewFolder) { break; } // Use same name compare as when we sort in the backend: See AssetDatabase.cpp: SortChildren string propertyPath = AssetDatabase.GetAssetPath(instanceID); if (EditorUtility.NaturalCompare(Path.GetFileNameWithoutExtension(propertyPath), newName) > 0) { break; } insertAfterID = instanceID; } return(insertAfterID); }
public int Compare(TreeViewItem x, TreeViewItem y) { int result; if (x == y) { result = 0; } else if (x == null) { result = -1; } else if (y == null) { result = 1; } else { result = EditorUtility.NaturalCompare(x.displayName, y.displayName); } return(result); }
void Sort(IList <TreeViewItem> rows, int sortIdx) { Debug.Assert(sortIdx >= 0); bool ascend = multiColumnHeader.IsSortedAscending(sortIdx); var comp = Col(sortIdx).compareDelegate; var myRows = rows as List <TreeViewItem>; System.Comparison <TreeViewItem> sortAscend, sortDescend; if (comp == null) { return; } else if (comp == DefaultDelegates.CompareName) // special case for sorting by the object name { sortAscend = (TreeViewItem lhs, TreeViewItem rhs) => { return(EditorUtility.NaturalCompare(((SerializedPropertyItem)lhs).GetData().name, ((SerializedPropertyItem)rhs).GetData().name)); }; sortDescend = (TreeViewItem lhs, TreeViewItem rhs) => { return(-EditorUtility.NaturalCompare(((SerializedPropertyItem)lhs).GetData().name, ((SerializedPropertyItem)rhs).GetData().name)); }; } else { sortAscend = (TreeViewItem lhs, TreeViewItem rhs) => { return(comp(((SerializedPropertyItem)lhs).GetData().properties[sortIdx], ((SerializedPropertyItem)rhs).GetData().properties[sortIdx])); }; sortDescend = (TreeViewItem lhs, TreeViewItem rhs) => { return(-comp(((SerializedPropertyItem)lhs).GetData().properties[sortIdx], ((SerializedPropertyItem)rhs).GetData().properties[sortIdx])); }; } myRows.Sort(ascend ? sortAscend : sortDescend); }
public int GetInsertAfterItemIDForNewItem(string newName, TreeViewItem parentItem, bool isCreatingNewFolder, bool foldersFirst) { int result; if (!parentItem.hasChildren) { result = parentItem.id; } else { int num = parentItem.id; for (int i = 0; i < parentItem.children.Count; i++) { int id = parentItem.children[i].id; bool flag = parentItem.children[i] is AssetsTreeViewDataSource.FolderTreeItem; if (foldersFirst && flag && !isCreatingNewFolder) { num = id; } else { if (foldersFirst && !flag && isCreatingNewFolder) { break; } string assetPath = AssetDatabase.GetAssetPath(id); if (EditorUtility.NaturalCompare(Path.GetFileNameWithoutExtension(assetPath), newName) > 0) { break; } num = id; } } result = num; } return(result); }
private void Sort(IList <TreeViewItem> rows, int sortIdx) { bool flag = base.multiColumnHeader.IsSortedAscending(sortIdx); SerializedPropertyTreeView.Column.CompareEntry comp = this.Col(sortIdx).compareDelegate; List <TreeViewItem> list = rows as List <TreeViewItem>; if (comp != null) { Comparison <TreeViewItem> comparison; Comparison <TreeViewItem> comparison2; if (comp == SerializedPropertyTreeView.DefaultDelegates.s_CompareName) { comparison = ((TreeViewItem lhs, TreeViewItem rhs) => EditorUtility.NaturalCompare(((SerializedPropertyTreeView.SerializedPropertyItem)lhs).GetData().name, ((SerializedPropertyTreeView.SerializedPropertyItem)rhs).GetData().name)); comparison2 = ((TreeViewItem lhs, TreeViewItem rhs) => - EditorUtility.NaturalCompare(((SerializedPropertyTreeView.SerializedPropertyItem)lhs).GetData().name, ((SerializedPropertyTreeView.SerializedPropertyItem)rhs).GetData().name)); } else { comparison = ((TreeViewItem lhs, TreeViewItem rhs) => comp(((SerializedPropertyTreeView.SerializedPropertyItem)lhs).GetData().properties[sortIdx], ((SerializedPropertyTreeView.SerializedPropertyItem)rhs).GetData().properties[sortIdx])); comparison2 = ((TreeViewItem lhs, TreeViewItem rhs) => - comp(((SerializedPropertyTreeView.SerializedPropertyItem)lhs).GetData().properties[sortIdx], ((SerializedPropertyTreeView.SerializedPropertyItem)rhs).GetData().properties[sortIdx])); } list.Sort((!flag) ? comparison2 : comparison); } }
void FolderBrowsing() { // We are not concerned with assets being added multiple times as we only show the contents // of each selected folder. This is an issue when searching recursively into child folders. List <FilterResult> list = new List <FilterResult>(); HierarchyProperty property; foreach (string folderPath in m_SearchFilter.folders) { if (folderPath == PackageManager.Folders.GetPackagesPath()) { var packages = PackageManagerUtilityInternal.GetAllVisiblePackages(m_SearchFilter.skipHidden); foreach (var package in packages) { var packageFolderInstanceId = AssetDatabase.GetMainAssetOrInProgressProxyInstanceID(package.assetPath); property = new HierarchyProperty(package.assetPath); if (property.Find(packageFolderInstanceId, null)) { FilterResult result = new FilterResult(); CopyPropertyData(ref result, property); result.name = !string.IsNullOrEmpty(package.displayName) ? package.displayName : package.name; list.Add(result); } } continue; } if (m_SearchFilter.skipHidden && !PackageManagerUtilityInternal.IsPathInVisiblePackage(folderPath)) { continue; } int folderInstanceID = AssetDatabase.GetMainAssetOrInProgressProxyInstanceID(folderPath); property = new HierarchyProperty(folderPath); property.SetSearchFilter(m_SearchFilter); int folderDepth = property.depth; int[] expanded = { folderInstanceID }; Dictionary <string, List <FilterResult> > subAssets = new Dictionary <string, List <FilterResult> >(); List <FilterResult> parentAssets = new List <FilterResult>(); while (property.Next(expanded)) { if (property.depth <= folderDepth) { break; // current property is outside folder } FilterResult result = new FilterResult(); CopyPropertyData(ref result, property); //list.Add(result); // Fetch sub assets by expanding the main asset (ignore folders) if (property.hasChildren && !property.isFolder) { parentAssets.Add(result); List <FilterResult> subAssetList = new List <FilterResult>(); subAssets.Add(result.guid, subAssetList); System.Array.Resize(ref expanded, expanded.Length + 1); expanded[expanded.Length - 1] = property.instanceID; } else { List <FilterResult> subAssetList; if (subAssets.TryGetValue(result.guid, out subAssetList)) { subAssetList.Add(result); subAssets[result.guid] = subAssetList; } else { parentAssets.Add(result); } } } parentAssets.Sort((result1, result2) => EditorUtility.NaturalCompare(result1.name, result2.name)); foreach (FilterResult result in parentAssets) { list.Add(result); List <FilterResult> subAssetList; if (subAssets.TryGetValue(result.guid, out subAssetList)) { subAssetList.Sort((result1, result2) => EditorUtility.NaturalCompare(result1.name, result2.name)); foreach (FilterResult subasset in subAssetList) { list.Add(subasset); } } } } m_Results = list.ToArray(); }
public static void Show(Rect buttonRect, string[] classNames, int initialSelectedInstanceID) { GenericMenu genericMenu = new GenericMenu(); List <UnityEngine.Object> list = AssetSelectionPopupMenu.FindAssetsOfType(classNames); if (list.Any <UnityEngine.Object>()) { list.Sort((UnityEngine.Object result1, UnityEngine.Object result2) => EditorUtility.NaturalCompare(result1.name, result2.name)); foreach (UnityEngine.Object current in list) { GUIContent content = new GUIContent(current.name); bool on = current.GetInstanceID() == initialSelectedInstanceID; genericMenu.AddItem(content, on, new GenericMenu.MenuFunction2(AssetSelectionPopupMenu.SelectCallback), current); } } else { genericMenu.AddDisabledItem(new GUIContent("No Audio Mixers found in this project")); } genericMenu.DropDown(buttonRect); }
private static bool CreateAnimation(GameObject gameObject, UnityEngine.Object[] frames) { Array.Sort <UnityEngine.Object>(frames, (UnityEngine.Object a, UnityEngine.Object b) => EditorUtility.NaturalCompare(a.name, b.name)); string message = string.Format("Create a new animation for the game object '{0}':", gameObject.name); string directoryName = Path.GetDirectoryName(AssetDatabase.GetAssetPath(frames[0])); string text = EditorUtility.SaveFilePanelInProject("Create New Animation", "New Animation", "anim", message, directoryName); if (string.IsNullOrEmpty(text)) { return(false); } AnimationClip animationClip = AnimationSelection.AllocateAndSetupClip(true); AssetDatabase.CreateAsset(animationClip, text); AnimationSelection.AddClipToAnimatorComponent(gameObject, animationClip); animationClip.frameRate = 12f; ObjectReferenceKeyframe[] array = new ObjectReferenceKeyframe[frames.Length]; for (int i = 0; i < array.Length; i++) { array[i] = default(ObjectReferenceKeyframe); array[i].value = SpriteUtility.RemapObjectToSprite(frames[i]); array[i].time = (float)i / animationClip.frameRate; } EditorCurveBinding binding = EditorCurveBinding.PPtrCurve(string.Empty, typeof(SpriteRenderer), "m_Sprite"); AnimationUtility.SetObjectReferenceCurve(animationClip, binding, array); return(true); }
public void ResultsChanged() { this.m_Results = new FilteredHierarchy.FilterResult[0]; if (this.m_SearchFilter.GetState() != SearchFilter.State.EmptySearchFilter) { HierarchyProperty property = new HierarchyProperty(this.m_HierarchyType); property.SetSearchFilter(this.m_SearchFilter); this.AddResults(property); if (this.m_SearchFilter.IsSearching()) { Array.Sort <FilteredHierarchy.FilterResult>(this.m_Results, (Comparison <FilteredHierarchy.FilterResult>)((result1, result2) => EditorUtility.NaturalCompare(result1.name, result2.name))); } if (!this.foldersFirst) { return; } for (int sourceIndex = 0; sourceIndex < this.m_Results.Length; ++sourceIndex) { if (!this.m_Results[sourceIndex].isFolder) { for (int index = sourceIndex + 1; index < this.m_Results.Length; ++index) { if (this.m_Results[index].isFolder) { FilteredHierarchy.FilterResult result = this.m_Results[index]; int length = index - sourceIndex; Array.Copy((Array)this.m_Results, sourceIndex, (Array)this.m_Results, sourceIndex + 1, length); this.m_Results[sourceIndex] = result; break; } } } } } else { if (this.m_HierarchyType != HierarchyType.GameObjects) { return; } new HierarchyProperty(HierarchyType.GameObjects).SetSearchFilter(this.m_SearchFilter); } }
public static void Show(Rect buttonRect, string[] classNames, int initialSelectedInstanceID) { GenericMenu genericMenu = new GenericMenu(); List <UnityEngine.Object> assetsOfType = AssetSelectionPopupMenu.FindAssetsOfType(classNames); if (assetsOfType.Any <UnityEngine.Object>()) { assetsOfType.Sort((Comparison <UnityEngine.Object>)((result1, result2) => EditorUtility.NaturalCompare(result1.name, result2.name))); using (List <UnityEngine.Object> .Enumerator enumerator = assetsOfType.GetEnumerator()) { while (enumerator.MoveNext()) { UnityEngine.Object current = enumerator.Current; GUIContent content = new GUIContent(current.name); bool on = current.GetInstanceID() == initialSelectedInstanceID; genericMenu.AddItem(content, on, new GenericMenu.MenuFunction2(AssetSelectionPopupMenu.SelectCallback), (object)current); } } } else { genericMenu.AddDisabledItem(new GUIContent("No Audio Mixers found in this project")); } genericMenu.DropDown(buttonRect); }
private static bool CreateAnimation(GameObject gameObject, UnityEngine.Object[] frames, SpriteUtility.ShowFileDialogDelegate saveFileDialog) { SpriteUtility.ShowFileDialogDelegate arg_26_0; if ((arg_26_0 = saveFileDialog) == null) { if (SpriteUtility.< > f__mg$cache1 == null) { SpriteUtility.< > f__mg$cache1 = new SpriteUtility.ShowFileDialogDelegate(EditorUtility.SaveFilePanelInProject); } arg_26_0 = SpriteUtility.< > f__mg$cache1; } saveFileDialog = arg_26_0; Array.Sort <UnityEngine.Object>(frames, (UnityEngine.Object a, UnityEngine.Object b) => EditorUtility.NaturalCompare(a.name, b.name)); Animator animator = (!AnimationWindowUtility.EnsureActiveAnimationPlayer(gameObject)) ? null : AnimationWindowUtility.GetClosestAnimatorInParents(gameObject.transform); bool flag = animator != null; bool result; if (animator != null) { string message = string.Format(SpriteUtility.SpriteUtilityStrings.saveAnimDialogMessage.text, gameObject.name); string activeFolderPath = ProjectWindowUtil.GetActiveFolderPath(); string text = saveFileDialog(SpriteUtility.SpriteUtilityStrings.saveAnimDialogTitle.text, SpriteUtility.SpriteUtilityStrings.saveAnimDialogName.text, "anim", message, activeFolderPath); if (string.IsNullOrEmpty(text)) { UnityEngine.Object.DestroyImmediate(animator); result = false; return(result); } AnimationClip animationClip = AnimationWindowUtility.CreateNewClipAtPath(text); if (animationClip != null) { SpriteUtility.AddSpriteAnimationToClip(animationClip, frames); flag = AnimationWindowUtility.AddClipToAnimatorComponent(animator, animationClip); } } if (!flag) { Debug.LogError(SpriteUtility.SpriteUtilityStrings.failedToCreateAnimationError.text); } result = flag; return(result); }
public void ResultsChanged() { this.m_Results = new FilteredHierarchy.FilterResult[0]; if (this.m_SearchFilter.GetState() != SearchFilter.State.EmptySearchFilter) { HierarchyProperty hierarchyProperty = new HierarchyProperty(this.m_HierarchyType, false); hierarchyProperty.SetSearchFilter(this.m_SearchFilter); this.AddResults(hierarchyProperty); if (this.m_SearchFilter.IsSearching()) { Array.Sort <FilteredHierarchy.FilterResult>(this.m_Results, (FilteredHierarchy.FilterResult result1, FilteredHierarchy.FilterResult result2) => EditorUtility.NaturalCompare(result1.name, result2.name)); } if (this.foldersFirst) { for (int i = 0; i < this.m_Results.Length; i++) { if (!this.m_Results[i].isFolder) { for (int j = i + 1; j < this.m_Results.Length; j++) { if (this.m_Results[j].isFolder) { FilteredHierarchy.FilterResult filterResult = this.m_Results[j]; int length = j - i; Array.Copy(this.m_Results, i, this.m_Results, i + 1, length); this.m_Results[i] = filterResult; break; } } } } } } else if (this.m_HierarchyType == HierarchyType.GameObjects) { HierarchyProperty hierarchyProperty2 = new HierarchyProperty(HierarchyType.GameObjects, false); hierarchyProperty2.SetSearchFilter(this.m_SearchFilter); } }
private static bool CreateAnimation(GameObject gameObject, UnityEngine.Object[] frames) { Array.Sort <UnityEngine.Object>(frames, (UnityEngine.Object a, UnityEngine.Object b) => EditorUtility.NaturalCompare(a.name, b.name)); if (!AnimationWindowUtility.EnsureActiveAnimationPlayer(gameObject)) { return(false); } Animator closestAnimatorInParents = AnimationWindowUtility.GetClosestAnimatorInParents(gameObject.transform); if (closestAnimatorInParents == null) { return(false); } AnimationClip animationClip = AnimationWindowUtility.CreateNewClip(gameObject.name); if (animationClip == null) { return(false); } SpriteUtility.AddSpriteAnimationToClip(animationClip, frames); return(AnimationWindowUtility.AddClipToAnimatorComponent(closestAnimatorInParents, animationClip)); }
public int Compare(object o1, object o2) { UnityEngine.Object @object = o1 as UnityEngine.Object; UnityEngine.Object object2 = o2 as UnityEngine.Object; return(EditorUtility.NaturalCompare(@object.name, object2.name)); }
public static void Show(Rect buttonRect, string[] classNames, int initialSelectedInstanceID) { GenericMenu genericMenu = new GenericMenu(); List <UnityEngine.Object> list = AssetSelectionPopupMenu.FindAssetsOfType(classNames); if (list.Any <UnityEngine.Object>()) { list.Sort((UnityEngine.Object result1, UnityEngine.Object result2) => EditorUtility.NaturalCompare(result1.name, result2.name)); foreach (UnityEngine.Object current in list) { GUIContent gUIContent = new GUIContent(current.name); bool flag = current.GetInstanceID() == initialSelectedInstanceID; GenericMenu arg_8E_0 = genericMenu; GUIContent arg_8E_1 = gUIContent; bool arg_8E_2 = flag; if (AssetSelectionPopupMenu.< > f__mg$cache0 == null) { AssetSelectionPopupMenu.< > f__mg$cache0 = new GenericMenu.MenuFunction2(AssetSelectionPopupMenu.SelectCallback); } arg_8E_0.AddItem(arg_8E_1, arg_8E_2, AssetSelectionPopupMenu.< > f__mg$cache0, current); } } else { genericMenu.AddDisabledItem(new GUIContent("No Audio Mixers found in this project")); } genericMenu.DropDown(buttonRect); }
public int Compare(object o1, object o2) { return(EditorUtility.NaturalCompare((o1 as UnityEngine.Object).name, (o2 as UnityEngine.Object).name)); }