Exemplo n.º 1
0
    static public PUGameObject LoadXML(string xmlPath, GameObject parent)
    {
        PUGameObject loadedGameObject = (PUGameObject)PlanetUnity2.loadXML(PlanetUnityResourceCache.GetAsset <TextAsset>(xmlPath).bytes, parent, null);

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

        return(loadedGameObject);
    }
Exemplo n.º 2
0
    static public PUGameObject LoadXML(string xmlPath, PUGameObject parent)
    {
        PUGameObject loadedGameObject = (PUGameObject)PlanetUnity2.loadXML(PlanetUnityOverride.xmlFromPath(xmlPath), parent, null);

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

        return(loadedGameObject);
    }
Exemplo n.º 3
0
    public virtual void LoadIntoPUGameObject(PUScrollRect parent, object data)
    {
        scrollRect = parent;
        cellData   = data;

        string xmlPath = XmlPath();

        if (xmlPath != null)
        {
            puGameObject = (PUGameObject)PlanetUnity2.loadXML(PlanetUnityResourceCache.GetAsset <TextAsset>(xmlPath).bytes, parent.contentObject, null);

            // Attach all of the PlanetUnity objects
            try {
                FieldInfo field = this.GetType().GetField("scene");
                if (field != null)
                {
                    field.SetValue(this, puGameObject);
                }

                puGameObject.PerformOnChildren(val => {
                    PUGameObject oo = val as PUGameObject;
                    if (oo != null && oo.title != null)
                    {
                        field = this.GetType().GetField(oo.title);
                        if (field != null)
                        {
                            field.SetValue(this, oo);
                        }
                    }
                    return(true);
                });
            } catch (Exception e) {
                UnityEngine.Debug.Log("TableCell error: " + e);
            }

            try {
                // Attach all of the named GameObjects
                FieldInfo[] fields = this.GetType().GetFields();
                foreach (FieldInfo field in fields)
                {
                    if (field.FieldType == typeof(GameObject))
                    {
                        GameObject[] pAllObjects = (GameObject[])Resources.FindObjectsOfTypeAll(typeof(GameObject));

                        foreach (GameObject pObject in pAllObjects)
                        {
                            if (pObject.name.Equals(field.Name))
                            {
                                field.SetValue(this, pObject);
                            }
                        }
                    }
                }
            } catch (Exception e) {
                UnityEngine.Debug.Log("TableCell error: " + e);
            }
        }
        else
        {
            puGameObject = new PUGameObject();
            puGameObject.SetFrame(0, 0, 0, 60, 0, 0, "bottom,left");
            puGameObject.LoadIntoPUGameObject(parent);
            puGameObject.gameObject.transform.SetParent(parent.contentObject.transform, false);
        }

        puGameObject.parent = table;

        // We want to bridge all notifications to my scope; this allows developers to handle notifications
        // at the table cell level, or at the scene controller level, with ease
        NotificationCenter.addObserver(this, "*", puGameObject, (args, name) => {
            NotificationCenter.postNotification(scrollRect.Scope(), name, args);
        });

        cellGameObject        = puGameObject.gameObject;
        cellTransform         = cellGameObject.transform as RectTransform;
        tableTransform        = scrollRect.rectTransform;
        tableContentTransform = scrollRect.contentObject.transform as RectTransform;

        UpdateContents();
    }
Exemplo n.º 4
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 ();
    }