/// <summary> /// Tries to parse the drag data to extract <see cref="Type"/> collection. /// </summary> /// <param name="data">The data.</param> /// <returns>Gathered objects or empty array if cannot get any valid.</returns> public static Type[] ParseData(DragDataText data) { if (data.Text.StartsWith(DragPrefix)) { // Remove prefix and parse splited names var types = data.Text.Remove(0, DragPrefix.Length).Split('\n'); var results = new List <Type>(types.Length); var assembly = Utils.GetAssemblyByName("FlaxEngine"); if (assembly != null) { for (int i = 0; i < types.Length; i++) { // Find type var obj = assembly.GetType(types[i]); if (obj != null) { results.Add(obj); } } return(results.ToArray()); } else { Editor.LogWarning("Failed to get FlaxEngine assembly to spawn actor type"); } } return(new Type[0]); }
/// <summary> /// Tries to parse the drag data to extract <see cref="ActorNode"/> collection. /// </summary> /// <param name="data">The data.</param> /// <returns>Gathered objects or empty array if cannot get any valid.</returns> public static ActorNode[] ParseData(DragDataText data) { if (data.Text.StartsWith(DragPrefix)) { // Remove prefix and parse splited names var ids = data.Text.Remove(0, DragPrefix.Length).Split('\n'); var results = new List <ActorNode>(ids.Length); for (int i = 0; i < ids.Length; i++) { // Find element Guid id; if (Guid.TryParse(ids[i], out id)) { var obj = Editor.Instance.Scene.GetActorNode(id); // Check it if (obj != null) { results.Add(obj); } } } return(results.ToArray()); } return(new ActorNode[0]); }
/// <summary> /// Tries to parse the drag data to validate if it has valid scripts darg. /// </summary> /// <param name="data">The data.</param> /// <returns>True if drag data has valid scripts, otherwise false.</returns> public static bool IsValidData(DragDataText data) { if (data.Text.StartsWith(DragPrefix)) { // Remove prefix and parse splited names var ids = data.Text.Remove(0, DragPrefix.Length).Split('\n'); for (int i = 0; i < ids.Length; i++) { // Find element Guid id; if (Guid.TryParse(ids[i], out id)) { var obj = FlaxEngine.Object.Find <Script>(ref id); // Check it if (obj != null) { return(true); } } } } return(false); }
/// <summary> /// Tries to parse the drag data to extract <see cref="Script"/> collection. /// </summary> /// <param name="data">The data.</param> /// <returns>Gathered objects or empty array if cannot get any valid.</returns> public static Script[] ParseData(DragDataText data) { if (data.Text.StartsWith(DragPrefix)) { // Remove prefix and parse splited names var ids = data.Text.Remove(0, DragPrefix.Length).Split('\n'); var results = new List <Script>(ids.Length); for (int i = 0; i < ids.Length; i++) { // Find element Guid id; if (Guid.TryParse(ids[i], out id)) { var obj = FlaxEngine.Object.Find <Script>(ref id); // Check it if (obj != null) { results.Add(obj); } } } return(results.ToArray()); } return(new Script[0]); }
/// <inheritdoc /> protected override void GetherObjects(DragDataText data, Func <ContentItem, bool> validateFunc) { var items = ParseData(data); for (int i = 0; i < items.Length; i++) { if (validateFunc(items[i])) { Objects.Add(items[i]); } } }
/// <summary> /// Gethers the objects from the drag data (text). /// </summary> /// <param name="data">The data.</param> /// <param name="validateFunc">The validate function. Check if gathered object is valid to drop it.</param> protected virtual void GetherObjects(DragDataText data, Func <string, bool> validateFunc) { if (data.Text.StartsWith(DragPrefix)) { // Remove prefix and parse splited names var name = data.Text.Remove(0, DragPrefix.Length); if (validateFunc(name)) { Parameter = name; } } }
internal DragDropEffect Internal_OnDragDrop(ref Vector2 mousePos, bool isText, string[] data) { DragData dragData; if (isText) { dragData = new DragDataText(data[0]); } else { dragData = new DragDataFiles(data); } Vector2 pos = mousePos / _dpiScale; return(GUI.OnDragDrop(ref pos, dragData)); }
internal DragDropEffect Internal_OnDragOver(ref Float2 mousePos, bool isText, string[] data) { DragData dragData; if (isText) { dragData = new DragDataText(data[0]); } else { dragData = new DragDataFiles(data); } var pos = mousePos / DpiScale; return(GUI.OnDragMove(ref pos, dragData)); }
/// <summary> /// Tries to parse the drag data to extract <see cref="ContentItem"/> collection. /// </summary> /// <param name="data">The data.</param> /// <returns>Gathered objects or empty array if cannot get any valid.</returns> public static ContentItem[] ParseData(DragDataText data) { if (data.Text.StartsWith(DragPrefix)) { // Remove prefix and parse splited names var paths = data.Text.Remove(0, DragPrefix.Length).Split('\n'); var results = new List <ContentItem>(paths.Length); for (int i = 0; i < paths.Length; i++) { // Find element var obj = Editor.Instance.ContentDatabase.Find(paths[i]); // Check it if (obj != null) { results.Add(obj); } } return(results.ToArray()); } return(new ContentItem[0]); }
/// <summary> /// Gethers the objects from the drag data (text). /// </summary> /// <param name="data">The data.</param> /// <param name="validateFunc">The validate function.</param> protected virtual void GetherObjects(DragDataText data, Func <T, bool> validateFunc) { }