Exemple #1
0
        public override void ApplyAttributes(AttributeDictionary attributesToApply)
        {
            MatchParentDimensions();

            var _currentXmlElement = currentXmlElement;

            _currentXmlElement.name = this.tagType;

            base.ApplyAttributes(attributesToApply);

            var childLayout = _currentXmlElement.GetComponent <XmlLayout>();

            if (childLayout == null)
            {
                childLayout = _currentXmlElement.gameObject.AddComponent <XmlLayout>();
                childLayout.ForceRebuildOnAwake = false;
            }

            var oldXml = childLayout.Xml;

            childLayout.Xml = Xml;

            if (!childLayout.Xml.Contains("<XmlLayout"))
            {
                childLayout.Xml = "<XmlLayout>" + childLayout.Xml + " </XmlLayout>";
            }

            if (PrimaryComponentType != null)
            {
                var _primaryComponent = _currentXmlElement.GetComponent(PrimaryComponentType);
                if (_primaryComponent == null)
                {
                    _currentXmlElement.gameObject.AddComponent(PrimaryComponentType);
                }
            }

            if (ControllerType != null)
            {
                if (ControllerType.IsSubclassOf(typeof(XmlLayoutController)))
                {
                    var controller = _currentXmlElement.GetComponent <XmlLayoutController>();
                    if (controller == null)
                    {
                        _currentXmlElement.gameObject.AddComponent(ControllerType);
                    }
                }
                else
                {
                    Debug.LogWarning("[XmlLayout][" + this.GetType().Name + "][Warning]:: Type '" + ControllerType.Name + "' is not inherited XmlLayoutController.");
                }
            }

            // only rebuild if necessary
            if (oldXml != childLayout.Xml)
            {
                childLayout.RebuildLayout();
            }

            if (!String.IsNullOrEmpty(XmlPath))
            {
                currentXmlLayoutInstance.ChildElementXmlFiles.Add(XmlPath);
            }
        }