Esempio n. 1
0
    public override void gaxb_complete()
    {
        ScheduleForStart();

        bool shouldCallSingletonStart = false;

        // If we're in live editor mode, we don't want to load controllers
        if (Application.isPlaying == false)
        {
            base.gaxb_complete();
            return;
        }

        if (gameObject != null)
        {
            gameObject.name = _class;
        }

        if (singleton)
        {
            IPUCode tempClassInstance = (IPUCode)instances [_class];
            if (tempClassInstance != null && !tempClassInstance.Equals(this))
            {
                GameObject.DestroyImmediate(this.gameObject);
                controller = (IPUCode)tempClassInstance;
                shouldCallSingletonStart = true;
            }
            else
            {
                MonoBehaviour.DontDestroyOnLoad(this.gameObject);
                this.gameObject.transform.SetParent(null);
            }
        }


        if (controller == null && _class != null)
        {
            // Attach all of the PlanetUnity objects
            try {
                controller = (IPUCode)gameObject.AddComponent(Type.GetType(_class, true));

                PUGameObject scene = Scope() as PUGameObject;
                if (scene != null)
                {
                    FieldInfo field = controller.GetType().GetField("scene");
                    if (field != null)
                    {
                        field.SetValue(controller, scene);
                    }

                    field = controller.GetType().GetField("puGameObject");
                    if (field != null)
                    {
                        field.SetValue(controller, this);
                    }

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

                if (singleton)
                {
                    Debug.Log("Saving instance class for: " + _class);
                    instances[_class] = controller;
                }
                else
                {
                    normalInstances[_class] = controller;
                }
            }
            catch (Exception e) {
                UnityEngine.Debug.Log("Controller error: " + e);
            }
        }

        if (controller != null)
        {
            try {
                // Attach all of the named GameObjects
                FieldInfo[] fields = controller.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(controller, pObject);
                            }
                        }
                    }
                }
            } catch (Exception e) {
                UnityEngine.Debug.Log("Controller error: " + e);
            }

            foreach (PUNotification subscribe in Notifications)
            {
                NotificationCenter.addObserver(controller, subscribe.name, Scope(), subscribe.name);
            }
        }

        if (shouldCallSingletonStart)
        {
            GameObject singletonGameObject = GameObject.Find(_class);
            if (singletonGameObject != null)
            {
                singletonGameObject.SendMessage("MarkForCallStart");
            }
        }

        base.gaxb_complete();
    }
Esempio n. 2
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();
    }
Esempio 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 (PlanetUnityOverride.xmlFromPath (xmlPath), 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,stretch");
            puGameObject.LoadIntoPUGameObject (parent);
            puGameObject.gameObject.transform.SetParent(parent.contentObject.transform, false);
        }

        if (IsHeader () && this is PUSimpleTableCell == false) {
            PUTableHeaderScript script = (PUTableHeaderScript)puGameObject.gameObject.AddComponent (typeof(PUTableHeaderScript));
            script.table = table;
            script.tableCell = this;
        }

        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 ();
    }