public void Start()
 {
     if (xmlPath != null)
     {
         rootObject = PlanetUnityGameObject.LoadXML(xmlPath, gameObject);
     }
 }
Beispiel #2
0
    static void Update()
    {
        bool reloadPreview = false;

        // If we're the editor, and we're in edit mode, and live preview is set...
        GameObject puObject = GameObject.Find("PlanetUnity");

        if (puObject == null)
        {
            return;
        }
        PlanetUnityGameObject script = puObject.GetComponent <PlanetUnityGameObject> ();

        if (script == null)
        {
            return;
        }

        // Monitor changes to and from edit mode
        if (inEditor == true && Application.isPlaying)
        {
            //UnityEngine.Debug.Log ("Switch to play mode");

            inEditor = false;
        }
        else if (inEditor == false && Application.isPlaying == false)
        {
            //UnityEngine.Debug.Log ("Switch to edit mode");

            reloadPreview = true;

            inEditor = true;
        }


        // Monitor changes to the editorPreview variable
        if (script.editorPreview != editorPreviewCache)
        {
            reloadPreview = true;

            editorPreviewCache = script.editorPreview;
        }

        if (inEditor)
        {
            if (reloadPreview)
            {
                script.EditorReloadCanvas();
            }
        }
    }
Beispiel #3
0
    public override void gaxb_complete()
    {
        base.gaxb_complete();

        ScheduleForUpdate();

        if (PlanetUnityGameObject.MainCanvas() != null)
        {
            if (delayedLoad == false)
            {
                Update();
            }
        }
    }
Beispiel #4
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);
    }
Beispiel #6
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();
    }
Beispiel #7
0
    // Use this for initialization
    void Start()
    {
        Application.targetFrameRate = 60;

        currentGameObject = this;

        ReloadCanvas();

                #if UNITY_EDITOR
        NotificationCenter.addObserver(this, PlanetUnity2.EDITORFILEDIDCHANGE, null, (args, name) => {
            string assetPath = args ["path"].ToString();

            if (assetPath.Contains(xmlPath + ".xml") ||
                assetPath.EndsWith(".strings"))
            {
                EditorReloadCanvas();
                PlanetUnityLanguage.ReloadAllLanguages();
                ReloadCanvas();
            }
        });
                #endif
    }
Beispiel #8
0
    private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromPath)
    {
        foreach (string asset in importedAssets)
        {
            NotificationCenter.postNotification(null, PlanetUnity2.EDITORFILEDIDCHANGE, NotificationCenter.Args("path", asset));
        }

        if (Application.isPlaying == false)
        {
            GameObject puObject = GameObject.Find("PlanetUnity");
            if (puObject == null)
            {
                return;
            }
            PlanetUnityGameObject script = puObject.GetComponent <PlanetUnityGameObject> ();
            if (script == null)
            {
                return;
            }

            script.EditorReloadCanvas();
        }
    }