Exemplo n.º 1
0
    public void RemoveCanvas()
    {
        if (canvas != null)
        {
            canvas.unload();
            canvas = null;
        }

        SafeRemoveAllChildren();
    }
Exemplo n.º 2
0
    public void RemoveCanvas()
    {
        if (canvas != null)
        {
            canvas.PerformOnChildren(val => {
                MethodInfo method = val.GetType().GetMethod("gaxb_unload");
                if (method != null)
                {
                    method.Invoke(val, null);
                }
                return(true);
            });

            canvas.gaxb_unload();

            canvas.unload();

            DestroyImmediate(canvas.gameObject);
            canvas = null;
        }

        SafeRemoveAllChildren();
    }
Exemplo n.º 3
0
    public void LoadCanvasXML(string xml)
    {
        if (xmlPath == null || PlanetUnityOverride.xmlFromPath(xmlPath) == null)
        {
            return;
        }

        RemoveCanvas();

        Stopwatch sw = Stopwatch.StartNew();

        planetUnityContainer = GameObject.Find("PlanetUnityContainer");
        if (planetUnityContainer == null)
        {
            planetUnityContainer = new GameObject("PlanetUnityContainer");

            rootCanvas = planetUnityContainer.AddComponent <Canvas> ();
        }

        //UnityEngine.Debug.Log ("LoadCanvasXML");
        PUGameObject rootObject = (PUGameObject)PlanetUnity2.loadXML(System.Text.Encoding.UTF8.GetBytes(xml), planetUnityContainer, null);

        if (rootObject is PUCanvas)
        {
            canvas = rootObject as PUCanvas;
        }
        else
        {
            canvas = new PUCanvas(PlanetUnity2.CanvasRenderMode.ScreenSpaceCamera, false, 100);
            canvas.LoadIntoGameObject(planetUnityContainer);
            rootObject.LoadIntoPUGameObject(canvas);
        }


        // This is kind of silly, but we need to do this because we want the root canvas to match
        // the canvas of the loaded scene, but we can't just grab the contents of the sub canvas
        // because unity sets it to inherited and those contents don't persist
        if (canvas.renderMode == PlanetUnity2.CanvasRenderMode.ScreenSpaceOverlay)
        {
            rootCanvas.renderMode = RenderMode.ScreenSpaceOverlay;
        }
        if (canvas.renderMode == PlanetUnity2.CanvasRenderMode.ScreenSpaceCamera)
        {
            GameObject puCamera = GameObject.Find("PUCamera");
            if (puCamera != null)
            {
                rootCanvas.worldCamera = puCamera.GetComponent <Camera> ();
            }
            else
            {
                rootCanvas.worldCamera = Camera.main;
            }
            rootCanvas.renderMode = RenderMode.ScreenSpaceCamera;
        }
        if (canvas.renderMode == PlanetUnity2.CanvasRenderMode.WorldSpace)
        {
            rootCanvas.renderMode = RenderMode.WorldSpace;
        }
        rootCanvas.pixelPerfect  = canvas.pixelPerfect;
        rootCanvas.planeDistance = canvas.planeDistance.Value;
        // End silly section

        // Unity 5.3: if this canvas does not override sorting, then it doesn't render in the editor (which is annoying)
        canvas.canvas.overrideSorting = true;

                #if UNITY_EDITOR
        if (planetUnityContainer != null)
        {
            foreach (Transform t in planetUnityContainer.GetComponentsInChildren <Transform>())
            {
                t.gameObject.hideFlags = HideFlags.DontSave;
            }
        }
                #endif

        sw.Stop();

                #if !UNITY_EDITOR
        UnityEngine.Debug.Log("[" + sw.Elapsed.TotalMilliseconds + "ms] Loading canvas " + xmlPath + ".xml");
                #endif

        //Profile.PrintResults ();
        //Profile.Reset ();
    }