/// <inheritdoc /> public override DragDropEffect OnDragDrop(ref Vector2 location, DragData data) { var result = base.OnDragDrop(ref location, data); if (result != DragDropEffect.None) { return(result); } var args = new DragDropEventArgs { SurfaceLocation = _rootControl.PointFromParent(ref location) }; // Drag assets if (_dragAssets.HasValidDrag) { result = _dragAssets.Effect; // Process items HandleDragDropAssets(_dragAssets.Objects, args); } // Drag parameters else if (_dragParameters.HasValidDrag) { result = _dragParameters.Effect; // Process items HandleDragDropParameters(_dragParameters.Objects, args); } DragHandlers.OnDragDrop(args); return(result); }
/// <inheritdoc /> public override DragDropEffect OnDragDrop(ref Float2 location, DragData data) { var result = base.OnDragDrop(ref location, data); if (result != DragDropEffect.None) { return(result); } if (_dragHandlers.HasValidDrag) { if (_dragScripts.HasValidDrag) { result = _dragScripts.Effect; AddScripts(_dragScripts.Objects); } else if (_dragAssets.HasValidDrag) { result = _dragAssets.Effect; AddScripts(_dragAssets.Objects); } _dragHandlers.OnDragDrop(null); } return(result); }
/// <inheritdoc /> public override DragDropEffect OnDragDrop(ref Vector2 location, DragData data) { ClearDragEffects(); var result = base.OnDragDrop(ref location, data); if (result != DragDropEffect.None) { return(result); } // Check if drag sth Vector3 hitLocation = ViewPosition; SceneGraphNode hit = null; if (DragHandlers.HasValidDrag()) { GetHitLocation(ref location, out hit, out hitLocation); } // Drag assets if (_dragAssets.HasValidDrag) { result = _dragAssets.Effect; // Process items for (int i = 0; i < _dragAssets.Objects.Count; i++) { var item = _dragAssets.Objects[i]; Spawn(item, hit, ref hitLocation); } } // Drag actor type else if (_dragActorType.HasValidDrag) { result = _dragActorType.Effect; // Process items for (int i = 0; i < _dragActorType.Objects.Count; i++) { var item = _dragActorType.Objects[i]; Spawn(item, hit, ref hitLocation); } } DragHandlers.OnDragDrop(new DragDropEventArgs() { Hit = hit, HitLocation = hitLocation }); return(result); }
/// <inheritdoc /> public override DragDropEffect OnDragDrop(ref Vector2 location, DragData data) { var result = base.OnDragDrop(ref location, data); if (result == DragDropEffect.None) { // Drag assets if (_dragAssets != null && _dragAssets.HasValidDrag) { for (int i = 0; i < _dragAssets.Objects.Count; i++) { var item = _dragAssets.Objects[i]; var actor = item.OnEditorDrop(this); actor.Name = item.ShortName; _window.Spawn(actor); } result = DragDropEffect.Move; } // Drag actor type else if (_dragActorType != null && _dragActorType.HasValidDrag) { for (int i = 0; i < _dragActorType.Objects.Count; i++) { var item = _dragActorType.Objects[i]; var actor = item.CreateInstance() as Actor; if (actor == null) { Editor.LogWarning("Failed to spawn actor of type " + item.TypeName); continue; } actor.Name = item.Name; _window.Spawn(actor); } result = DragDropEffect.Move; } _dragHandlers.OnDragDrop(null); } return(result); }
/// <inheritdoc /> protected override DragDropEffect OnDragDropHeader(DragData data) { var result = DragDropEffect.None; Actor myActor = Actor; Actor newParent; int newOrder = -1; // Check if has no actor (only for Root Actor) if (myActor == null) { // Append to the last scene var scenes = Level.Scenes; if (scenes == null || scenes.Length == 0) { throw new InvalidOperationException("No scene loaded."); } newParent = scenes[scenes.Length - 1]; } else { newParent = myActor; // Use drag positioning to change target parent and index if (DragOverMode == DragItemPositioning.Above) { if (myActor.HasParent) { newParent = myActor.Parent; newOrder = myActor.OrderInParent; } } else if (DragOverMode == DragItemPositioning.Below) { if (myActor.HasParent) { newParent = myActor.Parent; newOrder = myActor.OrderInParent + 1; } } } if (newParent == null) { throw new InvalidOperationException("Missing parent actor."); } // Drag actors if (_dragActors != null && _dragActors.HasValidDrag) { bool worldPositionLock = Root.GetKey(KeyboardKeys.Control) == false; var singleObject = _dragActors.Objects.Count == 1; if (singleObject) { var targetActor = _dragActors.Objects[0].Actor; var customAction = targetActor.HasPrefabLink ? new ReparentAction(targetActor) : null; using (new UndoBlock(ActorNode.Root.Undo, targetActor, "Change actor parent", customAction)) { targetActor.SetParent(newParent, worldPositionLock); targetActor.OrderInParent = newOrder; } } else { var targetActors = _dragActors.Objects.ConvertAll(x => x.Actor); var customAction = targetActors.Any(x => x.HasPrefabLink) ? new ReparentAction(targetActors) : null; using (new UndoMultiBlock(ActorNode.Root.Undo, targetActors, "Change actors parent", customAction)) { for (int i = 0; i < targetActors.Count; i++) { var targetActor = targetActors[i]; targetActor.SetParent(newParent, worldPositionLock); targetActor.OrderInParent = newOrder; } } } result = DragDropEffect.Move; } // Drag assets else if (_dragAssets != null && _dragAssets.HasValidDrag) { for (int i = 0; i < _dragAssets.Objects.Count; i++) { var assetItem = _dragAssets.Objects[i]; if (assetItem.IsOfType <SkinnedModel>()) { // Create actor var model = FlaxEngine.Content.LoadAsync <SkinnedModel>(assetItem.ID); var actor = new AnimatedModel(); actor.StaticFlags = Actor.StaticFlags; actor.Name = assetItem.ShortName; actor.SkinnedModel = model; actor.Transform = Actor.Transform; // Spawn ActorNode.Root.Spawn(actor, Actor); } else if (assetItem.IsOfType <Model>()) { // Create actor var model = FlaxEngine.Content.LoadAsync <Model>(assetItem.ID); var actor = new StaticModel(); actor.StaticFlags = Actor.StaticFlags; actor.Name = assetItem.ShortName; actor.Model = model; actor.Transform = Actor.Transform; // Spawn ActorNode.Root.Spawn(actor, Actor); } else if (assetItem.IsOfType <CollisionData>()) { // Create actor var actor = new MeshCollider(); actor.StaticFlags = Actor.StaticFlags; actor.Name = assetItem.ShortName; actor.CollisionData = FlaxEngine.Content.LoadAsync <CollisionData>(assetItem.ID); actor.Transform = Actor.Transform; // Spawn ActorNode.Root.Spawn(actor, Actor); } else if (assetItem.IsOfType <ParticleSystem>()) { // Create actor var actor = new ParticleEffect(); actor.StaticFlags = Actor.StaticFlags; actor.Name = assetItem.ShortName; actor.ParticleSystem = FlaxEngine.Content.LoadAsync <ParticleSystem>(assetItem.ID); actor.Transform = Actor.Transform; // Spawn ActorNode.Root.Spawn(actor, Actor); } else if (assetItem.IsOfType <SceneAnimation>()) { // Create actor var actor = new SceneAnimationPlayer(); actor.StaticFlags = Actor.StaticFlags; actor.Name = assetItem.ShortName; actor.Animation = FlaxEngine.Content.LoadAsync <SceneAnimation>(assetItem.ID); actor.Transform = Actor.Transform; // Spawn ActorNode.Root.Spawn(actor, Actor); } else if (assetItem.IsOfType <AudioClip>()) { // Create actor var actor = new AudioSource(); actor.StaticFlags = Actor.StaticFlags; actor.Name = assetItem.ShortName; actor.Clip = FlaxEngine.Content.LoadAsync <AudioClip>(assetItem.ID); actor.Transform = Actor.Transform; // Spawn ActorNode.Root.Spawn(actor, Actor); break; } else if (assetItem.IsOfType <Prefab>()) { // Create prefab instance var prefab = FlaxEngine.Content.LoadAsync <Prefab>(assetItem.ID); var actor = PrefabManager.SpawnPrefab(prefab, null); actor.StaticFlags = Actor.StaticFlags; actor.Name = assetItem.ShortName; actor.Transform = Actor.Transform; // Spawn ActorNode.Root.Spawn(actor, Actor); } else if (assetItem is VisualScriptItem visualScriptItem && new ScriptType(typeof(Actor)).IsAssignableFrom(visualScriptItem.ScriptType) && visualScriptItem.ScriptType.CanCreateInstance) { // Create actor var actor = (Actor)visualScriptItem.ScriptType.CreateInstance(); actor.StaticFlags = Actor.StaticFlags; actor.Name = assetItem.ShortName; actor.Transform = Actor.Transform; // Spawn ActorNode.Root.Spawn(actor, Actor); } } result = DragDropEffect.Move; } // Drag actor type else if (_dragActorType != null && _dragActorType.HasValidDrag) { for (int i = 0; i < _dragActorType.Objects.Count; i++) { var item = _dragActorType.Objects[i]; // Create actor var actor = item.CreateInstance() as Actor; if (actor == null) { Editor.LogWarning("Failed to spawn actor of type " + item.TypeName); continue; } actor.StaticFlags = Actor.StaticFlags; actor.Name = item.Name; actor.Transform = Actor.Transform; // Spawn ActorNode.Root.Spawn(actor, Actor); } result = DragDropEffect.Move; } // Clear cache _dragHandlers.OnDragDrop(null); // Check if scene has been modified if (result != DragDropEffect.None) { var node = SceneGraphFactory.FindNode(newParent.ID) as ActorNode; node?.TreeNode.Expand(); } return(result); }