Пример #1
0
        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;
        }
Пример #2
0
        public ScriptWrapper(GameObjectScript newScript, GameObject go, bool initialized = false)
        {
            thisScript = newScript(go);
            State = ScriptState.Running;
            SleepTime = 0f;

            IsObjectScript = true;
            ScriptObject = go;

            Initialized = initialized;
        }
Пример #3
0
 public void Execute(GameObjectScript newScript, GameObject go, bool initialized = false)
 {
     scripts.Add(new ScriptWrapper(newScript, go, initialized));
 }
Пример #4
0
 /// <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);
         }
     }
 }
Пример #5
0
        /// <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);
                }
            }
        }
Пример #6
0
        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;
        }