//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
//**************** Copyright (c) 2016 Marko Pintera (marko.pintera@gmail.com). All rights reserved. **********************//
using System;
using System.Runtime.CompilerServices;
using bs;
namespace bs.Editor
{
/** @addtogroup Settings
* @{
*/
///
/// Contains various settings that are applied globally per project. Settings will persist through editor sessions.
///
internal static class ProjectSettings
{
///
/// Contains the path to the last open scene. Path is relative to the project's resources folder.
///
public static string LastOpenScene
{
get { return Internal_GetLastOpenScene(); }
set { Internal_SetLastOpenScene(value); }
}
///
/// Contains a hash value that is updated whenever one of the properties in this object is updated. This allows
/// external systems to track when they might need to reload the settings.
///
public static int Hash
{
get { return Internal_GetHash(); }
}
///
/// Sets a generic floating point property.
///
/// Name to record the property under.
/// Value of the property.
public static void SetFloat(string name, float value)
{
Internal_SetFloat(name, value);
}
///
/// Sets a generic integer property.
///
/// Name to record the property under.
/// Value of the property.
public static void SetInt(string name, int value)
{
Internal_SetInt(name, value);
}
///
/// Sets a generic boolean property.
///
/// Name to record the property under.
/// Value of the property.
public static void SetBool(string name, bool value)
{
Internal_SetBool(name, value);
}
///
/// Sets a generic string property.
///
/// Name to record the property under.
/// Value of the property.
public static void SetString(string name, String value)
{
Internal_SetString(name, value);
}
///
/// Sets a generic object property. Any object marked with attribute can be provided,
/// excluding components and resources.
///
/// Name to record the property under.
/// Value of the property.
public static void SetObject(string name, object value)
{
Internal_SetObject(name, value);
}
///
/// Retrieves a generic floating point property.
///
/// Name of the property to retrieve.
/// Default value to return if property cannot be found.
/// Value of the property if it exists, otherwise the default value.
public static float GetFloat(string name, float defaultValue = 0.0f)
{
return Internal_GetFloat(name, defaultValue);
}
///
/// Retrieves a generic integer property.
///
/// Name of the property to retrieve.
/// Default value to return if property cannot be found.
/// Value of the property if it exists, otherwise the default value.
public static int GetInt(string name, int defaultValue = 0)
{
return Internal_GetInt(name, defaultValue);
}
///
/// Retrieves a generic boolean property.
///
/// Name of the property to retrieve.
/// Default value to return if property cannot be found.
/// Value of the property if it exists, otherwise the default value.
public static bool GetBool(string name, bool defaultValue = false)
{
return Internal_GetBool(name, defaultValue);
}
///
/// Retrieves a generic string property.
///
/// Name of the property to retrieve.
/// Default value to return if property cannot be found.
/// Value of the property if it exists, otherwise the default value.
public static string GetString(string name, string defaultValue = "")
{
return Internal_GetString(name, defaultValue);
}
///
/// Retrieves a generic object property.
///
/// Name of the property to retrieve.
///
/// Value of the property if it exists, otherwise an empty instance of the object. Returns null if the tyoe of
/// the stored object doesn't match the requested type.
///
public static T GetObject(string name) where T : class, new()
{
object obj = Internal_GetObject(name);
if (obj == null)
return new T();
return obj as T;
}
///
/// Checks does a generic property with the specified name exists.
///
/// Name of the property to check.
/// True if the property exists, false otherwise.
public static bool HasKey(string name)
{
return Internal_HasKey(name);
}
///
/// Deletes a generic property with the specified name.
///
/// Name of the property to delete.
public static void DeleteKey(string name)
{
Internal_DeleteKey(name);
}
///
/// Deletes all generic properties.
///
public static void DeleteAllKeys()
{
Internal_DeleteAllKeys();
}
///
/// Saves project settings to the disk.
///
public static void Save()
{
Internal_Save();
}
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern string Internal_GetLastOpenScene();
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetLastOpenScene(string value);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetFloat(string name, float value);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetInt(string name, int value);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetBool(string name, bool value);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetString(string name, string value);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_SetObject(string name, object value);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern float Internal_GetFloat(string name, float defaultValue);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern int Internal_GetInt(string name, int defaultValue);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern bool Internal_GetBool(string name, bool defaultValue);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern string Internal_GetString(string name, string defaultValue);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern object Internal_GetObject(string name);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern bool Internal_HasKey(string name);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_DeleteKey(string name);
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_DeleteAllKeys();
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern int Internal_GetHash();
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern void Internal_Save();
}
/** @} */
}