Exemplo n.º 1
0
        void Awake()
        {
            m_awake = true;

            if (Application.isPlaying)
            {
                if (PreloadXmlLayoutCache)
                {
                    HandlePreload();
                }

                if (ForceRebuildOnAwake)
                {
                    if (XmlFile != null && ForceReloadXmlFileOnAwake)
                    {
                        ReloadXmlFile();
                    }
                    else
                    {
                        RebuildLayout(true);
                    }
                }
            }

#if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                if (XmlFile != null)
                {
                    if (Xml != XmlFile.text)
                    {
                        Debug.Log("[XmlLayout] : '" + XmlFile.name + "' has changed - reloading file and rebuilding layout.");

                        ReloadXmlFile();

                        // Calling MarkSceneDirty here doesn't seem to work, but delaying the call to the end of the frame does
                        XmlLayoutTimer.AtEndOfFrame(() => UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(this.gameObject.scene), this);
                    }
                }
            }
#endif

            if (Application.isPlaying && !ForceRebuildOnAwake)
            {
                SetupElementEventHandlers();
                if (XmlLayoutController != null)
                {
                    XmlLayoutTimer.DelayedCall(0.1f, () => XmlLayoutController.LayoutRebuilt(ParseXmlResult.Changed), this);
                }
            }

            IsReady = true;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Clear the contents of this XmlLayout and rebuild it (using the Xml value)
        /// Call this after changing the Xml value for changes to take effect
        /// </summary>
        public void RebuildLayout(bool forceEvenIfXmlUnchanged = false, bool throwExceptionIfXmlIsInvalid = false)
        {
            if (!forceEvenIfXmlUnchanged && (!this.gameObject.activeInHierarchy || !m_awake))
            {
                return;
            }
            if (rebuildInProgress)
            {
                return;
            }

            rebuildInProgress = true;

            // Clear the child collection
            this.XmlElement.childElements.Clear();

            var parseResult = ParseXml(null, true, true, forceEvenIfXmlUnchanged, throwExceptionIfXmlIsInvalid);

            // Notify the XmlLayoutController that the Layout has been rebuilt
            if (XmlLayoutController != null)
            {
                XmlLayoutController.ViewModelUpdated(false);
                XmlLayoutController.NotifyXmlElementReferencesOfLayoutRebuild();
                XmlLayoutController.PreLayoutRebuilt();
                XmlLayoutController.LayoutRebuilt(parseResult);
                XmlLayoutController.PostLayoutRebuilt();
            }

#if UNITY_EDITOR
            if (!Application.isPlaying && parseResult != ParseXmlResult.Unchanged)
            {
                UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(this.gameObject.scene);
            }
#endif

            rebuildInProgress = false;
        }