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