public bool AttachScript(GameObjectScript e , bool fireScriptAttachEvent = false) { lock (AttachedScripts) { if(AttachedScripts.Values.Contains(e)) { return false; } // Add it to the local effects list on the character object AttachedScripts.Add(e.TypeHash, e); // Fire the attached even so that the effect can set itself up and // so that it gets registered with the game event system if (fireScriptAttachEvent) { e.OnAttach(m_OwningObject); } foreach(GameEventType eid in e.ListeningEvents) { SubscribeToEvent(eid, e); } } return true; }
public ScriptWrapper(GameObjectScript newScript, GameObject go, bool initialized = false) { thisScript = newScript(go); State = ScriptState.Running; SleepTime = 0f; IsObjectScript = true; ScriptObject = go; Initialized = initialized; }
public void Execute(GameObjectScript newScript, GameObject go, bool initialized = false) { scripts.Add(new ScriptWrapper(newScript, go, initialized)); }
/// <summary> /// Stop listening to property change notifications on this bag /// </summary> /// <param name="listener">the object to no longer receive notifications</param> private void UnSubscribeFromEvent(GameEventType eventId, GameObjectScript receiver) { lock (ScriptEventReceivers) { List<GameObjectScript> listeners = null; if (ScriptEventReceivers.TryGetValue(eventId, out listeners)) { listeners.Remove(receiver); } } }
/// <summary> /// Lets the script manager know that a GameObjectScript is interested in an event /// </summary> /// <param name="listener">the object to receive the notifications</param> private void SubscribeToEvent(GameEventType eventId, GameObjectScript receiver) { lock(ScriptEventReceivers) { List<GameObjectScript> listeners = null; if(!ScriptEventReceivers.TryGetValue(eventId, out listeners)) { listeners = new List<GameObjectScript>(); listeners.Add(receiver); ScriptEventReceivers.Add(eventId, listeners); } if(!listeners.Contains(receiver)) { listeners.Add(receiver); } } }
public bool DetachScript(GameObjectScript e, bool fireDetachScriptEvent = false) { if (AttachedScripts.Remove(e.TypeHash)) { if (fireDetachScriptEvent) { e.OnDetach(m_OwningObject); } return true; } foreach (GameEventType eid in e.ListeningEvents) { UnSubscribeFromEvent(eid, e); } return false; }