Added RemoveScript(Script) for Scripts and GameObjects

This commit is contained in:
Kah Wei 2023-01-31 17:28:24 +08:00
parent b46d2135bc
commit 53f599a238
5 changed files with 25 additions and 1 deletions

View File

@ -259,6 +259,13 @@ namespace SHADE
ScriptStore::RemoveScript<T>(entity); ScriptStore::RemoveScript<T>(entity);
} }
void GameObject::RemoveScript(Script^ script)
{
if (!valid)
throw gcnew System::NullReferenceException();
ScriptStore::RemoveScript(entity, script);
}
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Scene Graph Functions */ /* Scene Graph Functions */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/

View File

@ -259,6 +259,12 @@ namespace SHADE
/// <typeparam name="T">Type of Scripts to remove.</typeparam> /// <typeparam name="T">Type of Scripts to remove.</typeparam>
generic<typename T> where T : ref class, Script generic<typename T> where T : ref class, Script
void RemoveScript(); void RemoveScript();
/// <summary>
/// Removes a specific script from this script's parent.
/// </summary>
/// <param name="script">The script to remove.</param>
/// <returns>True if successfully removed. False otherwise.</returns>
void RemoveScript(Script^ script);
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Scene Graph Functions */ /* Scene Graph Functions */

View File

@ -126,6 +126,11 @@ namespace SHADE
ScriptStore::RemoveScript<T>(owner.GetEntity()); ScriptStore::RemoveScript<T>(owner.GetEntity());
} }
void Script::RemoveScript(Script^ script)
{
ScriptStore::RemoveScript(owner.GetEntity(), script);
}
Script::operator bool(Script^ s) Script::operator bool(Script^ s)
{ {
return s != nullptr; return s != nullptr;

View File

@ -198,6 +198,12 @@ namespace SHADE
/// </typeparam> /// </typeparam>
generic<typename T> where T : ref class, Script generic<typename T> where T : ref class, Script
void RemoveScript(); void RemoveScript();
/// <summary>
/// Removes a specific script from this script's parent.
/// </summary>
/// <param name="script">The script to remove.</param>
/// <returns>True if successfully removed. False otherwise.</returns>
void RemoveScript(Script^ script);
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Operator Overloads */ /* Operator Overloads */

View File

@ -203,7 +203,7 @@ namespace SHADE
generic<typename T> where T : ref class, Script generic<typename T> where T : ref class, Script
static void RemoveScript(Entity entity); static void RemoveScript(Entity entity);
/// <summary> /// <summary>
/// Removes a specific script from the /// Removes a specific script from the specified entity.
/// </summary> /// </summary>
/// <param name="entity">The entity to remove the script from.</param> /// <param name="entity">The entity to remove the script from.</param>
/// <param name="script">The script to remove.</param> /// <param name="script">The script to remove.</param>