Ejemplo n.º 1
0
    public static void postNotification(object scope, string name, Hashtable args)
    {
        // do not allow notifications from background threads
        if (PlanetUnityGameObject.IsMainThread() == false)
        {
            return;
        }

        if (name == null)
        {
            UnityEngine.Debug.Log("Warning: NotificationCenter.postNotification() called with null notification name");
            return;
        }

        if (scope == null)
        {
            scope = globalScope;
        }

        if (name.StartsWith("GLOBAL::", StringComparison.OrdinalIgnoreCase))
        {
            scope = globalScope;
            name  = name.Substring(8);
        }

        List <NotificationObserver> list;

        if (observersByScope.TryGetValue(scope, out list))
        {
            for (int i = 0; i < list.Count; i++)
            {
                NotificationObserver o = list [i];
                if (o.name.Equals(name) || o.name.Equals("*"))
                {
                    if (!o.callObserver(args, name))
                    {
                        list.RemoveAt(i);
                        i--;
                    }
                }
            }
        }
    }