// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
using System;
using FlaxEngine;
namespace FlaxEditor.Content
{
///
/// Content item that contains data.
///
///
public sealed class PrefabItem : JsonAssetItem
{
///
/// Initializes a new instance of the class.
///
/// The asset path.
/// The asset identifier.
public PrefabItem(string path, Guid id)
: base(path, id, PrefabProxy.AssetTypename)
{
}
///
public override bool OnEditorDrag(object context)
{
return true;
}
///
public override Actor OnEditorDrop(object context)
{
return PrefabManager.SpawnPrefab(FlaxEngine.Content.LoadAsync(ID), null);
}
///
public override ContentItemType ItemType => ContentItemType.Asset;
///
public override ContentItemSearchFilter SearchFilter => ContentItemSearchFilter.Prefab;
///
public override SpriteHandle DefaultThumbnail => SpriteHandle.Invalid;
private string _cachedTypeDescription = null;
///
public override string TypeDescription
{
get
{
if (_cachedTypeDescription != null)
return _cachedTypeDescription;
Prefab prefab = FlaxEngine.Content.LoadAsync(ID);
if (prefab.WaitForLoaded(5000))
{
_cachedTypeDescription = "Prefab";
}
Actor root = prefab.GetDefaultInstance();
if (root is UIControl or UICanvas)
_cachedTypeDescription = "Widget";
else
_cachedTypeDescription = "Prefab";
return _cachedTypeDescription;
}
}
///
public override bool IsOfType(Type type)
{
return type.IsAssignableFrom(typeof(Prefab));
}
}
}