Ejemplo n.º 1
0
    public override void gaxb_load(XmlReader reader, object _parent, Hashtable args)
    {
        controller = null;
        GC.Collect();

        base.gaxb_load(reader, _parent, args);

        gameObject.name = _class;
    }
Ejemplo n.º 2
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();
    }
Ejemplo n.º 3
0
 public override void gaxb_init()
 {
     controller = null;
     GC.Collect();
 }
Ejemplo n.º 4
0
 public void DetachObject()
 {
     controller = null;
 }
Ejemplo n.º 5
0
    public void gaxb_loadComplete()
    {
        if (singleton) {
            if (instances [_class] != null && instances [_class] != this) {
                GameObject.Destroy (this.gameObject);
                controller = (IPUCode)instances[_class];
            } else {
                MonoBehaviour.DontDestroyOnLoad(this.gameObject);
                this.gameObject.transform.parent = null;
            }
        }

        if (controller == null && _classExists) {
            // 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)
                                {
                                    field.SetValue (controller, oo);
                                }
                            }
                            return true;
                        });
                }

                if(singleton){
                    Debug.Log("Saving instance class for: "+_class);
                    instances[_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);
            }
        }

        base.gaxb_loadComplete ();
    }
Ejemplo n.º 6
0
 public void DetachObject()
 {
     controller = null;
 }