public virtual void Broadcast(Packet p) { if (p == null || CurrentMap == null) { return; } for (int i = CurrentMap.Players.Count - 1; i >= 0; i--) { PlayerObject player = CurrentMap.Players[i]; if (player == this || player.Observer) { continue; } if (Functions.InRange(CurrentLocation, player.CurrentLocation, Globals.DataRange)) { player.Enqueue(p); } } for (int i = CurrentMap.Observers.Count - 1; i >= 0; i--) { ObserverObject observer = CurrentMap.Observers[i]; if (observer == this) { continue; } if (Functions.InRange(CurrentLocation, observer.CurrentLocation, Globals.DataRange)) { observer.Enqueue(p); } } }
private void printWrongSignatureError(Exception e, ObserverObject obj) { Debug.Log("ERROR: Wrong signature on method " + obj.methodString + ". Method should have signature: functionName(Dictionary<string, object> data) "); Debug.Log("Stacktrace: "); Debug.Log(e); }
private void printTargetInvocationError(Exception e, ObserverObject obj) { if (e.InnerException is MissingReferenceException) { Debug.Log("ERROR: Calling method " + obj.methodString + ". Tried to post to a null observer, did you forget to remove observer when destroying an object?"); } Debug.Log("Stacktrace: "); Debug.Log(e); }
/** * observer: Object interested in event * forKey: Event key * method: Method name that should be executed on Listener when event is picked up */ public void addObserver(object observer, string forKey, string method) { //retrieve list List <ObserverObject> currentList; this.events.TryGetValue(forKey, out currentList); currentList = currentList != null ? currentList : new List <ObserverObject>(); //add observer ObserverObject observerObject = new ObserverObject(); observerObject.observer = observer; observerObject.methodString = method; currentList.Add(observerObject); this.events.Remove(forKey); this.events.Add(forKey, currentList); }
//PRIVATE private bool postNotification(ObserverObject obj, Dictionary <string, object> data) { Type type = obj.observer.GetType(); MethodInfo method = type.GetMethod(obj.methodString); object[] signature = new object[1]; signature[0] = data; try { method.Invoke(obj.observer, signature); } catch (TargetParameterCountException e) { this.printWrongSignatureError(e, obj); } catch (TargetInvocationException e) { this.printTargetInvocationError(e, obj); } catch (Exception e) { Debug.Log(e); } return(true); }
public abstract void SendHealth(ObserverObject observer);
public virtual void Add(ObserverObject observer) { observer.Enqueue(GetInfo()); }
public virtual void Remove(ObserverObject observer) { observer.Enqueue(new S.ObjectRemove { ObjectID = ObjectID }); }
public override void SendHealth(ObserverObject observer) { throw new NotSupportedException(); }