public virtual Script AddScript(Script script, bool removeScriptWithSamePath = false) { if (script == null) { return(null); } // If script was already loaded, reload it to last saved state var oldScript = m_LoadedScripts.FirstOrDefault(s => s.Path.Equals(script.Path)); if (oldScript != default(Script) && removeScriptWithSamePath) { // Reload Script var index = m_LoadedScripts.IndexOf(oldScript); UnsubscribeToScriptEvents(oldScript); ScriptGuidMap.RemoveGuidFromMap(m_LoadedScripts[index]); ScriptGuidMap.AddGuidToMapAndGenerateUniqueIfNeeded(script); m_LoadedScripts[index] = script; ScriptModified?.Invoke(script); } else { // Load New Script ScriptGuidMap.AddGuidToMapAndGenerateUniqueIfNeeded(script); m_LoadedScripts.Add(script); ScriptAdded?.Invoke(script); } SubscribeToScriptEvents(script); return(script); }
public virtual Script NewScript(Script clone = null) { Script script; if (clone == null) { script = new Script(); } else { script = (Script)clone.Clone(); ((IHaveGuid)script).RegenerateGuid(); } ScriptGuidMap.AddGuidToMapAndGenerateUniqueIfNeeded(script); m_LoadedScripts.Add(script); SubscribeToScriptEvents(script); script.IsDirty = true; ScriptAdded?.Invoke(script); return(script); }
/// <summary> /// Adds script to script collection. /// </summary> public static void RegisterScript(Script script, string instanceId) { Scripts.TryAdd(instanceId, script); ScriptAdded?.Invoke(script); }