Exemplo 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--;
                    }
                }
            }
        }
    }
    // safe to call on a background thread
    static public byte[] GetRawBytesSafe(string s)
    {
        if (PlanetUnityGameObject.IsMainThread())
        {
            return(((TextAsset)PlanetUnityOverride.LoadResource(typeof(TextAsset), s)).bytes);
        }

        // Note: if we get here, we're being called on a background thread.  As such, we need to do a little hairy stuff to make this work
        byte[]         loadedBytes = null;
        AutoResetEvent autoEvent   = new AutoResetEvent(false);

        PlanetUnityGameObject.ScheduleTask(() => {
            loadedBytes = ((TextAsset)PlanetUnityOverride.LoadResource(typeof(TextAsset), s)).bytes;
            autoEvent.Set();
        });

        autoEvent.WaitOne();
        return(loadedBytes);
    }
Exemplo n.º 3
0
    public static void PerformTask(Action block)
    {
        if (System.Object.ReferenceEquals(currentGameObject, null))
        {
            return;
        }

        if (PlanetUnityGameObject.IsMainThread())
        {
            block();
            return;
        }

        AutoResetEvent autoEvent = new AutoResetEvent(false);

        PlanetUnityGameObject.ScheduleTask(() => {
            block();
            autoEvent.Set();
        });

        autoEvent.WaitOne();
    }