// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using System;
using FlaxEditor.Content.Create;
using FlaxEditor.Content.Settings;
using FlaxEngine;
namespace FlaxEditor.Content
{
///
/// Content proxy for json settings assets (e.g or ).
///
///
[ContentContextMenu("New/Settings")]
public class SettingsProxy : JsonAssetProxy
{
private readonly Type _type;
private readonly SpriteHandle _thumbnail;
///
/// Gets the settings type.
///
public Type Type => _type;
///
/// Initializes a new instance of the class.
///
/// The settings asset type (must be subclass of SettingsBase type).
/// Asset icon.
public SettingsProxy(Type type, SpriteHandle thumbnail)
{
_type = type;
TypeName = type.FullName;
_thumbnail = thumbnail;
}
///
public override string Name => "Settings";
//public override string Name { get; } = Utilities.Utils.GetPropertyNameUI(_type.Name);
///
public override bool CanCreate(ContentFolder targetLocation)
{
// Use proxy only for GameSettings for creating
if (_type != typeof(GameSettings))
return false;
return targetLocation.CanHaveAssets;
}
///
public override void Create(string outputPath, object arg)
{
Editor.Instance.ContentImporting.Create(new SettingsCreateEntry(outputPath));
}
///
public override AssetItem ConstructItem(string path, string typeName, ref Guid id)
{
return new JsonAssetItem(path, id, typeName, _thumbnail);
}
///
public override bool IsProxyFor()
{
return typeof(T) == _type;
}
///
public override string TypeName { get; }
}
///
/// Content proxy for custom json settings assets.
///
///
///
public class CustomSettingsProxy : SettingsProxy
{
///
/// The custom settings name.
///
public readonly string CustomName;
///
/// Initializes a new instance of the class.
///
/// The settings asset type (must be subclass of SettingsBase type).
/// The name of the entry in the custom settings (via ).
public CustomSettingsProxy(Type type, string name)
: this(type, name, Editor.Instance.Icons.Document128)
{
}
///
/// Initializes a new instance of the class.
///
/// The settings asset type (must be subclass of SettingsBase type).
/// The name of the entry in the custom settings (via ).
/// Asset icon.
public CustomSettingsProxy(Type type, string name, SpriteHandle thumbnail)
: base(type, thumbnail)
{
CustomName = name;
}
}
}