Add controls to the ActorToolbox in the GUI tab. Add dragging and dropping controls from toolbox into scene and prefab trees.
This commit is contained in:
@@ -65,6 +65,7 @@ namespace FlaxEditor.Windows.Assets
|
||||
private PrefabWindow _window;
|
||||
private DragAssets _dragAssets;
|
||||
private DragActorType _dragActorType;
|
||||
private DragControlType _dragControlType;
|
||||
private DragScriptItems _dragScriptItems;
|
||||
private DragHandlers _dragHandlers;
|
||||
|
||||
@@ -83,7 +84,12 @@ namespace FlaxEditor.Windows.Assets
|
||||
|
||||
private static bool ValidateDragActorType(ScriptType actorType)
|
||||
{
|
||||
return true;
|
||||
return Editor.Instance.CodeEditing.Actors.Get().Contains(actorType);
|
||||
}
|
||||
|
||||
private static bool ValidateDragControlType(ScriptType controlType)
|
||||
{
|
||||
return Editor.Instance.CodeEditing.Controls.Get().Contains(controlType);
|
||||
}
|
||||
|
||||
private static bool ValidateDragScriptItem(ScriptItem script)
|
||||
@@ -113,6 +119,13 @@ namespace FlaxEditor.Windows.Assets
|
||||
}
|
||||
if (_dragActorType.OnDragEnter(data))
|
||||
return _dragActorType.Effect;
|
||||
if (_dragControlType == null)
|
||||
{
|
||||
_dragControlType = new DragControlType(ValidateDragControlType);
|
||||
_dragHandlers.Add(_dragControlType);
|
||||
}
|
||||
if (_dragControlType.OnDragEnter(data))
|
||||
return _dragControlType.Effect;
|
||||
if (_dragScriptItems == null)
|
||||
{
|
||||
_dragScriptItems = new DragScriptItems(ValidateDragScriptItem);
|
||||
@@ -176,6 +189,27 @@ namespace FlaxEditor.Windows.Assets
|
||||
}
|
||||
result = DragDropEffect.Move;
|
||||
}
|
||||
// Drag control type
|
||||
else if (_dragControlType != null && _dragControlType.HasValidDrag)
|
||||
{
|
||||
for (int i = 0; i < _dragControlType.Objects.Count; i++)
|
||||
{
|
||||
var item = _dragControlType.Objects[i];
|
||||
var control = item.CreateInstance() as Control;
|
||||
if (control == null)
|
||||
{
|
||||
Editor.LogWarning("Failed to spawn UIControl with control type " + item.TypeName);
|
||||
continue;
|
||||
}
|
||||
var uiControl = new UIControl
|
||||
{
|
||||
Control = control,
|
||||
Name = item.Name,
|
||||
};
|
||||
_window.Spawn(uiControl);
|
||||
}
|
||||
result = DragDropEffect.Move;
|
||||
}
|
||||
// Drag script item
|
||||
else if (_dragScriptItems != null && _dragScriptItems.HasValidDrag)
|
||||
{
|
||||
@@ -207,6 +241,7 @@ namespace FlaxEditor.Windows.Assets
|
||||
_window = null;
|
||||
_dragAssets = null;
|
||||
_dragActorType = null;
|
||||
_dragControlType = null;
|
||||
_dragScriptItems = null;
|
||||
_dragHandlers?.Clear();
|
||||
_dragHandlers = null;
|
||||
|
||||
Reference in New Issue
Block a user