//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
//**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************//
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using bs;
namespace bs.Editor
{
/** @addtogroup GUI-Editor
* @{
*/
///
/// GUI element that displays all scene objects in the current scene as a tree view.
///
public sealed class GUISceneTreeView : GUIElement
{
///
/// Creates a new scene tree view element.
///
/// Optional style to use for the element. Style controls the look of the element, as well as
/// default layout options. Style will be retrieved from the active GUISkin. If not specified
/// default element style is used.
/// Options that allow you to control how is the element positioned and sized. This will
/// override any similar options set by style.
public GUISceneTreeView(string style = "", params GUIOption[] options)
{
Internal_CreateInstance(this, style, options);
}
///
/// Creates a new scene tree view element.
///
/// Options that allow you to control how is the element positioned and sized. This will
/// override any similar options set by style.
public GUISceneTreeView(params GUIOption[] options)
{
Internal_CreateInstance(this, "", options);
}
///
/// Updates the contents of the tree view with most recent scene data. Should be called once per frame.
///
public void Update()
{
Internal_Update(mCachedPtr);
}
///
/// Cuts the currently selected scene object.
///
public void CutSelection()
{
Internal_CutSelection(mCachedPtr);
}
///
/// Copies the currently selected scene object.
///
public void CopySelection()
{
Internal_CopySelection(mCachedPtr);
}
///
/// Pastes the scene object(s) that were previously cut or copied.
///
public void PasteToSelection()
{
Internal_PasteToSelection(mCachedPtr);
}
///
/// Deletes currently selected scene objects.
///
public void DeleteSelection()
{
Internal_DeleteSelection(mCachedPtr);
}
///
/// Duplicates currently selected scene objects.
///
public void DuplicateSelection()
{
Internal_DuplicateSelection(mCachedPtr);
}
///
/// Starts the rename operation for the currently selected scene objects.
///
public void RenameSelection()
{
Internal_RenameSelection(mCachedPtr);
}
///
/// Triggered by the runtime when the scene is modified from the native scene tree view.
///
private void Internal_DoOnModified()
{
EditorApplication.SetSceneDirty();
}
///
/// Triggered by the runtime when a resource is dropped on the scene tree view.
///
private void Internal_DoOnResourceDropped(SceneObject parent, string[] resourcePaths)
{
if (resourcePaths == null)
return;
List addedObjects = new List();
for (int i = 0; i < resourcePaths.Length; i++)
{
ResourceMeta meta = ProjectLibrary.GetMeta(resourcePaths[i]);
if (meta == null)
continue;
if (meta.ResType == ResourceType.Mesh)
{
if (!string.IsNullOrEmpty(resourcePaths[i]))
{
string meshName = Path.GetFileNameWithoutExtension(resourcePaths[i]);
Mesh mesh = ProjectLibrary.Load(resourcePaths[i]);
if (mesh == null)
continue;
SceneObject so = UndoRedo.CreateSO(meshName, "Created a new Renderable \"" + meshName + "\"");
so.Parent = parent;
Renderable renderable = so.AddComponent();
renderable.Mesh = mesh;
addedObjects.Add(so);
}
}
else if (meta.ResType == ResourceType.Prefab)
{
if (!string.IsNullOrEmpty(resourcePaths[i]))
{
Prefab prefab = ProjectLibrary.Load(resourcePaths[i]);
SceneObject so = UndoRedo.Instantiate(prefab, "Instantiating " + prefab.Name);
so.Parent = parent;
addedObjects.Add(so);
}
}
}
if(addedObjects.Count > 0)
EditorApplication.SetSceneDirty();
Selection.SceneObjects = addedObjects.ToArray();
}
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_CreateInstance(GUISceneTreeView instance, string style, GUIOption[] options);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_Update(IntPtr thisPtr);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_CutSelection(IntPtr thisPtr);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_CopySelection(IntPtr thisPtr);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_PasteToSelection(IntPtr thisPtr);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_DeleteSelection(IntPtr thisPtr);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_DuplicateSelection(IntPtr thisPtr);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_RenameSelection(IntPtr thisPtr);
}
/** @} */
}