コード例 #1
0
ファイル: PUCode.cs プロジェクト: KittyMac/PlanetUnity
    public override void gaxb_load(XmlReader reader, object _parent, Hashtable args)
    {
        controller = null;
        GC.Collect();

        base.gaxb_load(reader, _parent, args);

        gameObject.name = _class;
    }
コード例 #2
0
ファイル: PUCode.cs プロジェクト: KittyMac/PlanetUnity
    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 ();
    }
コード例 #3
0
ファイル: PUCode.cs プロジェクト: KittyMac/PlanetUnity
 public void DetachObject()
 {
     controller = null;
 }