protected override DragAndDropVisualMode HandleDragAndDrop(DragAndDropArgs args) { DragAndDropVisualMode visualMode = DragAndDropVisualMode.None; var draggedIDs = DragAndDrop.GetGenericData("BuildPlayerSceneTreeViewItem") as List <int>; if (draggedIDs != null && draggedIDs.Count > 0) { visualMode = DragAndDropVisualMode.Move; if (args.performDrop) { int newIndex = FindDropAtIndex(args); var result = new List <TreeViewItem>(); int toInsert = 0; foreach (var item in rootItem.children) { if (toInsert == newIndex) { foreach (var id in draggedIDs) { result.Add(FindItem(id, rootItem)); } } toInsert++; if (!draggedIDs.Contains(item.id)) { result.Add(item); } } if (result.Count < rootItem.children.Count) //must be appending. { foreach (var id in draggedIDs) { result.Add(FindItem(id, rootItem)); } } rootItem.children = result; EditorBuildSettings.scenes = GetSceneList(); ReloadAndSelect(draggedIDs); Repaint(); } } else if (DragAndDrop.paths != null && DragAndDrop.paths.Length > 0) { visualMode = DragAndDropVisualMode.Copy; if (args.performDrop) { var scenes = new List <EditorBuildSettingsScene>(EditorBuildSettings.scenes); var scenesToAdd = new List <EditorBuildSettingsScene>(); var selection = new List <int>(); foreach (var path in DragAndDrop.paths) { if (AssetDatabase.GetMainAssetTypeAtPath(path) == typeof(SceneAsset)) { var guid = new GUID(AssetDatabase.AssetPathToGUID(path)); selection.Add(guid.GetHashCode()); bool unique = true; foreach (var scene in scenes) { if (scene.path == path) { unique = false; break; } } if (unique) { scenesToAdd.Add(new EditorBuildSettingsScene(path, true)); } } } int newIndex = FindDropAtIndex(args); scenes.InsertRange(newIndex, scenesToAdd); EditorBuildSettings.scenes = scenes.ToArray(); ReloadAndSelect(selection); Repaint(); } } return(visualMode); }
protected override DragAndDropVisualMode HandleDragAndDrop(TreeView.DragAndDropArgs args) { DragAndDropVisualMode result = DragAndDropVisualMode.None; List <int> list = DragAndDrop.GetGenericData("BuildPlayerSceneTreeViewItem") as List <int>; if (list != null && list.Count > 0) { result = DragAndDropVisualMode.Move; if (args.performDrop) { int num = this.FindDropAtIndex(args); List <TreeViewItem> list2 = new List <TreeViewItem>(); int num2 = 0; foreach (TreeViewItem current in base.rootItem.children) { if (num2 == num) { foreach (int current2 in list) { list2.Add(base.FindItem(current2, base.rootItem)); } } num2++; if (!list.Contains(current.id)) { list2.Add(current); } } if (list2.Count < base.rootItem.children.Count) { foreach (int current3 in list) { list2.Add(base.FindItem(current3, base.rootItem)); } } base.rootItem.children = list2; EditorBuildSettings.scenes = this.GetSceneList(); this.ReloadAndSelect(list); base.Repaint(); } } else if (DragAndDrop.paths != null && DragAndDrop.paths.Length > 0) { result = DragAndDropVisualMode.Copy; if (args.performDrop) { List <EditorBuildSettingsScene> list3 = new List <EditorBuildSettingsScene>(EditorBuildSettings.scenes); List <EditorBuildSettingsScene> list4 = new List <EditorBuildSettingsScene>(); List <int> list5 = new List <int>(); string[] paths = DragAndDrop.paths; for (int i = 0; i < paths.Length; i++) { string text = paths[i]; if (AssetDatabase.GetMainAssetTypeAtPath(text) == typeof(SceneAsset)) { GUID gUID = new GUID(AssetDatabase.AssetPathToGUID(text)); list5.Add(gUID.GetHashCode()); bool flag = true; foreach (EditorBuildSettingsScene current4 in list3) { if (current4.path == text) { flag = false; break; } } if (flag) { list4.Add(new EditorBuildSettingsScene(text, true)); } } } int index = this.FindDropAtIndex(args); list3.InsertRange(index, list4); EditorBuildSettings.scenes = list3.ToArray(); this.ReloadAndSelect(list5); base.Repaint(); } } return(result); }
internal static void DrawHint(Rect hintTriggerRect, Vector2 mousePosition, AssetReference assetReference) { if (!hintTriggerRect.Contains(mousePosition) || !GUIClip.visibleRect.Contains(mousePosition)) { return; } string assetPath = AssetDatabase.GUIDToAssetPath(assetReference.guid); var assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath); if (assetType == null) //this means the object or its base script has been deleted and is "Missing" { return; } var hintGenerators = TypeCache.GetMethodsWithAttribute <DynamicHintGeneratorAttribute>(); if (assetType.IsSubclassOf(typeof(ScriptableObject))) { DynamicHintContent hint = GetDynamicHintContentOf(hintGenerators, assetType, assetPath); if (hint != null) { DrawMouseTooltip(hint, hintTriggerRect); } return; } if (assetType == typeof(GameObject)) { /* GameObjects can have multiple components with custom tooltips * so for now we'll just display the first one. * If needed, we could: * 1) Implement a "priority system" (like OrderedCallbacks) * 2) Display one big tooltip made up with all elements from custom tooltip */ GameObject assetGameObject = (GetLoadedObjectFromInstanceID(assetReference.instanceID) as GameObject); if (!assetGameObject) { /* this seems to happen non-deterministically at project startup depending of what the user is hovering when the editor opens, * or while the user is scrolling a list of objects and hovers one of them casually, even if the object hovered is actually a * GameObject. * */ return; } foreach (var component in assetGameObject.GetComponents <Component>()) { if (component == null) { continue; } //this means its script has been deleted and is "Missing" DynamicHintContent hint = GetDynamicHintContentOf(hintGenerators, component.GetType(), string.Empty, component); if (hint == null) { continue; } DrawMouseTooltip(hint, hintTriggerRect); return; } } }