public void ChangeColorScheme(string newScheme)
        {
            colorScheme = newScheme;

            var colorSchemeFile = XmlLayoutUtilities.LoadResource <TextAsset>(string.Format("Xml/ColorSchemes/{0}", newScheme));

            if (colorSchemeFile == null)
            {
                Debug.LogErrorFormat("[XmlLayout][Example][Color Scheme Manager] Warning: unable to locate color scheme definition '{0}'", newScheme);
                return;
            }

            List <XmlLayout> xmlLayouts = Root.gameObject
                                          .GetComponentsInChildren <XmlLayout>(true)
                                          .ToList();

            foreach (var layout in xmlLayouts)
            {
                // skip this layout
                if (layout == this.xmlLayout)
                {
                    continue;
                }

                if (layout.DefaultsFiles == null)
                {
                    layout.DefaultsFiles = new List <TextAsset>();
                }

                var inactive = !layout.gameObject.activeSelf;

                if (inactive)
                {
                    layout.gameObject.SetActive(true);
                }

                layout.DefaultsFiles.Clear();
                layout.DefaultsFiles.Add(colorSchemeFile);

                layout.RebuildLayout(true);

                if (inactive)
                {
                    // copy the local variable (if we use 'layout' it will reference the foreach variable which changes through each iteration)
                    var layoutTemp = layout;

                    // hide the layout again at the end of the frame
                    XmlLayoutTimer.AtEndOfFrame(() =>
                    {
                        if (layoutTemp == null)
                        {
                            return;
                        }

                        //canvasGroup.alpha = alphaBefore;
                        layoutTemp.gameObject.SetActive(false);
                    }, layoutTemp, true);
                }
            }
        }
示例#2
0
        public virtual void ClassChanged()
        {
            if (currentXmlLayoutInstance.defaultAttributeValues.ContainsKey(this.tagType))
            {
                var defaultAttributesMerged = new AttributeDictionary();

                if (this.currentXmlLayoutInstance.defaultAttributeValues[this.tagType].ContainsKey("all"))
                {
                    defaultAttributesMerged = this.currentXmlLayoutInstance.defaultAttributeValues[this.tagType]["all"];
                }

                if (currentXmlElement.classes != null && currentXmlElement.classes.Any())
                {
                    foreach (var _class in currentXmlElement.classes)
                    {
                        if (currentXmlLayoutInstance.defaultAttributeValues[this.tagType].ContainsKey(_class))
                        {
                            defaultAttributesMerged = XmlLayoutUtilities.MergeAttributes(defaultAttributesMerged, currentXmlLayoutInstance.defaultAttributeValues[this.tagType][_class]);
                        }
                    }
                }

                // remove any class attributes that have been defined directly on the element
                defaultAttributesMerged = new AttributeDictionary(defaultAttributesMerged.Where(a => !currentXmlElement.elementAttributes.Contains(a.Key)).ToDictionary(k => k.Key, v => v.Value));

                // merge in the updated class attributes and apply them
                //currentXmlElement.attributes = XmlLayoutUtilities.MergeAttributes(defaultAttributesMerged, elementAttributes);
                currentXmlElement.ApplyAttributes(defaultAttributesMerged);
            }
        }
示例#3
0
        public void ProcessCustomAttributeGroups()
        {
            var attributeGroupTypes = new List <Type>();

            var assemblies = XmlLayoutUtilities.GetAssemblyNames();

            var customXmlAttributeType = typeof(CustomXmlAttributeGroup);

            foreach (var assembly in assemblies)
            {
                attributeGroupTypes.AddRange(Assembly.Load(assembly)
                                             .GetTypes()
                                             .Where(t => !t.IsAbstract && t.IsSubclassOf(customXmlAttributeType))
                                             .ToList());
            }

            // validate and filter out any invalid entries
            foreach (var attributeGroupType in attributeGroupTypes)
            {
                //var instance = (CustomXmlAttributeGroup)Activator.CreateInstance(attributeGroupType);\
                var instance = GetTestInstance <CustomXmlAttributeGroup>(attributeGroupType);
                if (instance.Validate())
                {
                    this.customAttributeGroupsToAdd.Add(instance);
                }
            }
        }
示例#4
0
        private static GameObject InstantiatePrefab(string name)
        {
            var prefab     = XmlLayoutUtilities.LoadResource <GameObject>(name);
            var gameObject = GameObject.Instantiate(prefab) as GameObject;

            return(gameObject);
        }
        public void ChangeColorSchemeWithoutRebuild(string newScheme)
        {
            colorScheme = newScheme;

            var colorSchemeFile = XmlLayoutUtilities.LoadResource <TextAsset>(string.Format("Xml/ColorSchemes/{0}", newScheme));

            if (colorSchemeFile == null)
            {
                Debug.LogErrorFormat("[XmlLayout][Example][Color Scheme Manager] Warning: unable to locate color scheme definition '{0}'", newScheme);
                return;
            }

            List <XmlLayout> xmlLayouts = Root.gameObject
                                          .GetComponentsInChildren <XmlLayout>(true)
                                          .ToList();

            foreach (var layout in xmlLayouts)
            {
                // skip this layout
                if (layout == this.xmlLayout)
                {
                    continue;
                }

                if (layout.DefaultsFiles == null)
                {
                    layout.DefaultsFiles = new List <TextAsset>();
                }

                layout.DefaultsFiles.Clear();
                layout.DefaultsFiles.Add(colorSchemeFile);
            }
        }
示例#6
0
        public void SetAudioMixerGroup(string path)
        {
            var _details  = path.Split('|');
            var mixerName = _details[0];

            if (_details.Length >= 2)
            {
                var mixer = XmlLayoutUtilities.LoadResource <AudioMixer>(mixerName);

                if (mixer != null)
                {
                    var groupPath = _details[1];
                    var group     = mixer.FindMatchingGroups(groupPath).FirstOrDefault();

                    if (group != null)
                    {
                        AudioSource.outputAudioMixerGroup = group;
                    }
                    else
                    {
                        Debug.LogWarning("[XmlLayout][XmlElement] Warning: Audio Mixer Group with path '" + groupPath + "' was not found in Audio Mixer '" + mixerName + "'.");
                    }
                }
                else
                {
                    Debug.LogWarning("[XmlLayout][XmlElement] Warning: Audio Mixer '" + mixerName + "' was not found. Please note that the Mixer must be accessible to XmlLayout in a Resources folder or Resource Database.");
                }
            }
            else
            {
                Debug.LogWarning("[XmlLayout][XmlElement] Warning: '" + path + "' is an invalid AudioMixerGroup path. Please specify a path to the Audio Mixer followed by the Group name / path, separated by a pipe operator, e.g. Audio/MyAudioMixer|MyAudioMixerGroup. Please note that the Mixer must be accessible to XmlLayout in a Resources folder or Resource Database.");
            }
        }
示例#7
0
        public void ToggleTextMeshPro(bool on)
        {
            if (on)
            {
                // if we're already using TextMeshPro; do nothing
                if (TextComponentWrapper != null &&
                    TextComponentWrapper.xmlElement != null &&
                    TextComponentWrapper.xmlElement.tagType == "TextMeshPro")
                {
                    return;
                }

                var        tmp           = gameObject.GetComponentInChildren <TMPro.TextMeshProUGUI>(true);
                XmlElement tmpXmlElement = null;

                if (tmp == null)
                {
                    // create instance
                    var tagHandler = XmlLayoutUtilities.GetXmlTagHandler("TextMeshPro");
                    tmpXmlElement = tagHandler.GetInstance(this.rectTransform, xmlLayout);
                    tagHandler.SetInstance(tmpXmlElement);
                    tagHandler.ApplyAttributes(new AttributeDictionary());

                    tmp = tmpXmlElement.GetComponent <TMPro.TextMeshProUGUI>();

                    tmp.rectTransform.localScale = Vector3.one;
                }

                tmpXmlElement = tmp.GetComponent <XmlElement>();

                TextComponentWrapper = new TextComponentWrapper(tmp);

                // hide the regular text component
                TextComponent.gameObject.SetActive(false);

                // enable the TMP object if it wasn't already
                tmp.gameObject.SetActive(true);
            }
            else
            {
                if (TextComponentWrapper != null &&
                    TextComponentWrapper.xmlElement != null &&
                    TextComponentWrapper.xmlElement.tagType == "Text")
                {
                    return;
                }

                TextComponentWrapper = new TextComponentWrapper(TextComponent);

                TextComponent.gameObject.SetActive(true);

                var tmp = gameObject.GetComponentInChildren <TMPro.TextMeshProUGUI>();
                if (tmp != null)
                {
                    tmp.gameObject.SetActive(false);
                }
            }
        }
示例#8
0
        void OnEnable()
        {
            controllerNames = XmlLayoutUtilities.GetXmlLayoutControllerNames();
            controllerNames.Insert(0, "Create New");
            controllerNames.Insert(0, "None");

            xmlFileNames = GetAssetsOfType <TextAsset>(".xml").Select(x => AssetDatabase.GetAssetPath(x).Substring("Assets/".Length)).ToList();
            xmlFileNames.Insert(0, "Create New");
            xmlFileNames.Insert(0, "None");
        }
示例#9
0
        /// <summary>
        /// Create an XmlLayout instance using the specified Xml file (view), along with an optional controller type
        /// </summary>
        /// <param name="parent">The RectTransform this XmlLayout will be a child of</param>
        /// <param name="xmlFilePath">The path to the Xml file (in a resources folder)</param>
        /// <param name="controllerType">The type of controller to use (optional)</param>
        /// <param name="hidden">If this is set to true, the XmlLayout will not be visible until you call Show()</param>
        /// <returns></returns>
        public static XmlLayout Instantiate(RectTransform parent, string xmlFilePath, Type controllerType = null, bool hidden = false)
        {
            var xmlLayout = InstantiatePrefab("XmlLayout Prefabs/XmlLayout").GetComponent <XmlLayout>();

            // attach the new XmlLayout to the specified parent
            xmlLayout.transform.SetParent(parent);

            // Unity has a habit of setting seemingly random RectTransform values;
            // this fixes that
            FixInstanceTransform(xmlLayout.transform as RectTransform);

            // assign the xml file
            if (!string.IsNullOrEmpty(xmlFilePath))
            {
                xmlLayout.XmlFile = XmlLayoutUtilities.LoadResource <TextAsset>(xmlFilePath);
            }

            // instantiate the controller if necessary
            if (controllerType != null)
            {
                xmlLayout.gameObject.AddComponent(controllerType);
            }

            xmlLayout.name = "XmlLayout";

            // Load the new Xml file and build the layout
            xmlLayout.ReloadXmlFile();

            if (hidden)
            {
                xmlLayout.XmlElement.Visible = true;

                // If the XmlLayout has a hide animation set, calling Hide() will trigger it
                // But what we really want here is for the XmlLayout to be invisible from the start
                // So what we do here is get/add a CanvasGroup, and set it to be fully transparent
                // Once the hide animation is complete, we then restore it to regular opacity (which the user will not see, as the game object will no longer be active)
                var canvasGroup = xmlLayout.GetComponent <CanvasGroup>();
                if (canvasGroup == null)
                {
                    canvasGroup = xmlLayout.gameObject.AddComponent <CanvasGroup>();
                }

                canvasGroup.alpha          = 0f;
                canvasGroup.blocksRaycasts = false;

                xmlLayout.Hide(() =>
                {
                    canvasGroup.alpha          = 1f;
                    canvasGroup.blocksRaycasts = true;
                });
            }

            return(xmlLayout);
        }
示例#10
0
        void CreateTooltipObject()
        {
            var prefab = XmlLayoutUtilities.LoadResource <GameObject>("XmlLayout Prefabs/Tooltip");

            m_Tooltip = ((GameObject)Instantiate(prefab)).GetComponent <XmlLayoutTooltip>();
            m_Tooltip.transform.SetParent(this.transform);
            m_Tooltip.transform.localPosition = Vector3.zero;
            m_Tooltip.transform.localScale    = Vector3.one;
            m_Tooltip.name = "Tooltip";
            m_Tooltip.gameObject.SetActive(false);
        }
示例#11
0
        public override void Awake()
        {
            base.Awake();

            if (!cursors.ContainsKey(eCursorState.Default))
            {
                SetCursorForState(eCursorState.Default, XmlLayoutUtilities.LoadResource <Texture2D>("Cursors/DefaultCursor"), Vector2.zero);
            }

            CursorState = eCursorState.Default;
        }
示例#12
0
        private void InitialiseXmlElement()
        {
            if (m_XmlElement == null)
            {
                m_XmlElement = this.GetComponent <XmlElement>();
            }

            if (m_XmlElement == null)
            {
                m_XmlElement = this.gameObject.AddComponent <XmlElement>();
                m_XmlElement.Initialise(this, this.transform as RectTransform, XmlLayoutUtilities.GetXmlTagHandler("XmlLayout"));
            }
        }
示例#13
0
        void LoadDefaults(XmlNode node)
        {
            if (node.HasChildNodes)
            {
                foreach (XmlNode childNode in node.ChildNodes)
                {
                    if (childNode.NodeType == XmlNodeType.Text || childNode.NodeType == XmlNodeType.Comment)
                    {
                        continue;
                    }

                    var type = childNode.Name.ToLower();

                    if (type == "tooltip")
                    {
                        HandleDefaultTooltipNode(childNode);
                        continue;
                    }

                    if (XmlLayoutUtilities.GetXmlTagHandler(type) == null)
                    {
                        continue;
                    }

                    var attributes = childNode.Attributes.ToAttributeDictionary();

                    var classes = attributes.ContainsKey("class") ? attributes["class"].Split(',', ' ').Select(s => s.Trim().ToLower()).ToList() : new List <string>()
                    {
                        "all"
                    };

                    foreach (var _class in classes)
                    {
                        if (!defaultAttributeValues.ContainsKey(type))
                        {
                            defaultAttributeValues.Add(type, new ClassAttributeCollectionDictionary());
                        }

                        if (!defaultAttributeValues[type].ContainsKey(_class))
                        {
                            defaultAttributeValues[type].Add(_class, new AttributeDictionary());
                        }

                        defaultAttributeValues[type][_class] = XmlLayoutUtilities.MergeAttributes(defaultAttributeValues[type][_class], attributes);
                        defaultAttributeValues[type][_class].Remove("class");
                    }
                }
            }
        }
        public static Sprite ToSprite(this string str)
        {
            if (String.IsNullOrEmpty(str) || str.ToLower() == "none")
            {
                return(null);
            }

            var sprite = XmlLayoutUtilities.LoadResource <Sprite>(str);

            if (sprite == null)
            {
                Debug.LogError("[XmlLayout] Unable to load sprite '" + str + "'. Please ensure that it is located within a Resources folder or XmlLayout Resource Database.");
            }

            return(sprite);
        }
        public static RuntimeAnimatorController ToRuntimeAnimatorController(this string str)
        {
            if (str.ToLower() == "none")
            {
                return(null);
            }

            var animationController = XmlLayoutUtilities.LoadResource <RuntimeAnimatorController>(str);

            if (animationController == null)
            {
                Debug.Log("Animation Controller '" + str + "' not found. Please ensure that it is located within a Resources folder or XmlLayout Resource Database.");
            }

            return(animationController);
        }
        public static AudioClip ToAudioClip(this string str)
        {
            if (string.IsNullOrEmpty(str) || str.ToLower() == "none")
            {
                return(null);
            }

            var audioClip = XmlLayoutUtilities.LoadResource <AudioClip>(str);

            if (audioClip == null)
            {
                Debug.Log("Audio Clip '" + str + "' not found. Please ensure that it is located within a Resources folder or XmlLayout Resource Database.");
            }

            return(audioClip);
        }
        public static Material ToMaterial(this string str)
        {
            if (str.ToLower() == "none")
            {
                return(null);
            }

            var material = XmlLayoutUtilities.LoadResource <Material>(str);

            if (material == null)
            {
                Debug.Log("Material '" + str + "' not found. Please ensure that it is located within a Resources folder or XmlLayout Resource Database.");
            }

            return(material);
        }
        public static Font ToFont(this string str)
        {
            var font = XmlLayoutUtilities.LoadResource <Font>("Fonts/" + str);

            if (font == null)
            {
                font = XmlLayoutUtilities.LoadResource <Font>(str);
            }

            if (font == null)
            {
                Debug.LogWarning("Font '" + str + "' not found. Please ensure that it is located within a Resources folder or XmlLayout Resource Database. (Reverting to Arial)");

                return(Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font);
            }

            return(font);
        }
示例#19
0
        void Update()
        {
            if (!m_waitingForCompilation)
            {
                return;
            }

            if (!EditorApplication.isCompiling)
            {
                var gameObject = (GameObject)EditorUtility.InstanceIDToObject(m_xmlLayoutInstanceId);
                var type       = XmlLayoutUtilities.GetXmlLayoutControllerType(m_xmlLayoutControllerName);

                gameObject.AddComponent(type);

                m_waitingForCompilation = false;
                this.Close();
            }
        }
示例#20
0
        protected RectTransform Instantiate(RectTransform parent, string name = "")
        {
            var           prefab     = XmlLayoutUtilities.LoadResource <GameObject>(name);
            GameObject    gameObject = null;
            RectTransform transform  = null;

            if (prefab != null)
            {
                gameObject = GameObject.Instantiate <GameObject>(prefab);
                transform  = gameObject.GetComponent <RectTransform>();

                transform.SetParent(parent);

                FixInstanceTransform(prefab.transform as RectTransform, transform);
            }
            else
            {
                if (!String.IsNullOrEmpty(name))
                {
                    Debug.Log("Warning: prefab '" + name + "' not found.");
                }
                gameObject = new GameObject(name);
            }

            if (transform == null)
            {
                transform = gameObject.AddComponent <RectTransform>();
            }

            if (name != null && name.Contains("/") && !name.EndsWith("/"))
            {
                name = name.Substring(name.LastIndexOf("/") + 1);
            }

            gameObject.name = name ?? "Xml Element";

            if (transform.parent != parent)
            {
                transform.SetParent(parent);
            }

            return(transform);
        }
示例#21
0
        /// <summary>
        /// Convert custom attributes (that aren't found via reflection, e.g. width/height) into useable values
        /// </summary>
        /// <param name="attributes"></param>
        /// <returns></returns>
        protected AttributeDictionary HandleCustomAttributes(AttributeDictionary attributes)
        {
            var elementName = XmlLayoutUtilities.GetTagName(GetType());
            //var elementName = this.GetType().Name.Replace("TagHandler", String.Empty);
            var customAttributes = attributes.Where(k => XmlLayoutUtilities.IsCustomAttribute(k.Key)).ToList();

            foreach (var attribute in customAttributes)
            {
                var customAttribute = XmlLayoutUtilities.GetCustomAttribute(attribute.Key);

                if (customAttribute.RestrictToPermittedElementsOnly)
                {
                    if (!customAttribute.PermittedElements.Contains(elementName, StringComparer.OrdinalIgnoreCase))
                    {
                        continue;
                    }
                }

                if (customAttribute.UsesConvertMethod)
                {
                    attributes = XmlLayoutUtilities.MergeAttributes(
                        attributes,
                        customAttribute.Convert(attribute.Value, attributes.AsReadOnly(), this.currentXmlElement));
                }

                if (customAttribute.UsesApplyMethod)
                {
                    customAttribute.Apply(currentXmlElement, attribute.Value, attributes.AsReadOnly());
                }

                if (customAttribute.UsesApplyMethod && !defaultAttributeValues.ContainsKey(attribute.Key))
                {
                    defaultAttributeValues.Add(attribute.Key, customAttribute.DefaultValue);
                }

                if (!customAttribute.KeepOriginalTag)
                {
                    attributes.Remove(attribute.Key);
                }
            }

            return(attributes);
        }
示例#22
0
        void LoadInlineIncludeFile(XmlNode node, RectTransform parent)
        {
            var path = node.Attributes["path"].Value;

            // strip out the file extension, if provided
            path = path.Replace(".xml", "");

            var xmlFile = XmlLayoutUtilities.LoadResource <TextAsset>(path);

            if (xmlFile == null)
            {
                Debug.LogError(String.Format("[XmlLayout][{0}] Error locating include file : '{1}'.", this.name, path));
                return;
            }

            var xmlDoc = new XmlDocument();

            try
            {
                xmlDoc.LoadXml(xmlFile.text);
            }
            catch (XmlException e)
            {
                var message = String.Format("[XmlLayout][{0}] Error parsing XML data: {1}", this.name, e.Message);
                Debug.LogError(message);

                return;
            }

            if (!IncludedFiles.Contains(path))
            {
                IncludedFiles.Add(path);
            }

            var rootNode = xmlDoc.FirstChild;

            foreach (XmlNode childNode in rootNode)
            {
                ParseNode(childNode, parent);
            }
        }
示例#23
0
        public static GameObject InstantiatePrefab(string name, bool playMode = false, bool generateUndo = true)
        {
            var prefab = XmlLayoutUtilities.LoadResource <GameObject>(name);

            if (prefab == null)
            {
                throw new UnityException(String.Format("Could not find prefab '{0}'!", name));
            }

            Transform parent = null;

#if UNITY_EDITOR
            if (!playMode)
            {
                parent = UnityEditor.Selection.activeTransform;
            }
#endif
            var gameObject = GameObject.Instantiate(prefab) as GameObject;
            gameObject.name = name;

            if (parent == null || !(parent is RectTransform))
            {
                parent = GetCanvasTransform();
            }

            gameObject.transform.SetParent(parent);

            var transform       = (RectTransform)gameObject.transform;
            var prefabTransform = (RectTransform)prefab.transform;

            FixInstanceTransform(prefabTransform, transform);

#if UNITY_EDITOR
            if (generateUndo)
            {
                UnityEditor.Undo.RegisterCreatedObjectUndo(gameObject, "Created " + name);
            }
#endif

            return(gameObject);
        }
示例#24
0
        public void ProcessCustomTags()
        {
            var tags        = XmlLayoutUtilities.GetXmlTagHandlerNames();
            var groupedTags = new Dictionary <string, Dictionary <string, ElementTagHandler> >();

            foreach (var tag in tags)
            {
                var tagHandler = XmlLayoutUtilities.GetXmlTagHandler(tag);

                if (!tagHandler.isCustomElement)
                {
                    continue;
                }

                if (!groupedTags.ContainsKey(tagHandler.elementGroup))
                {
                    groupedTags.Add(tagHandler.elementGroup, new Dictionary <string, ElementTagHandler>());
                }

                groupedTags[tagHandler.elementGroup].Add(tag, tagHandler);
            }

            foreach (var group in groupedTags)
            {
                var existingTags = GetElementGroup(group.Key);

                foreach (var tag in group.Value)
                {
                    if (!existingTags.Contains(tag.Key, StringComparer.OrdinalIgnoreCase))
                    {
                        if (!customElementTagHandlersToAdd.ContainsKey(group.Key))
                        {
                            customElementTagHandlersToAdd.Add(group.Key, new Dictionary <string, ElementTagHandler>());
                        }

                        customElementTagHandlersToAdd[group.Key].Add(tag.Key, tag.Value);
                    }
                }
            }
        }
示例#25
0
        public void ProcessCustomAttributes()
        {
            var customAttributes = XmlLayoutUtilities.GetGroupedCustomAttributeNames();

            foreach (var group in customAttributes)
            {
                var existingAttributes = GetAttributeGroup(group.Key);

                foreach (var attributeName in group.Value)
                {
                    var _attributeName = Char.ToLower(attributeName[0]) + attributeName.Substring(1);
                    var attribute      = XmlLayoutUtilities.GetCustomAttribute(attributeName);

                    if (attribute.RestrictToPermittedElementsOnly)
                    {
                        // add attribute to permitted elements
                        foreach (var element in attribute.PermittedElements)
                        {
                            if (!customAttributesToAddByElement.ContainsKey(element))
                            {
                                customAttributesToAddByElement.Add(element, new Dictionary <string, CustomXmlAttribute>());
                            }

                            customAttributesToAddByElement[element].Add(_attributeName, attribute);
                        }
                    }
                    else if (!existingAttributes.Contains(attributeName, StringComparer.OrdinalIgnoreCase))
                    {
                        // add attribute to group
                        if (!customAttributesToAddByGroup.ContainsKey(group.Key))
                        {
                            customAttributesToAddByGroup.Add(group.Key, new Dictionary <string, CustomXmlAttribute>());
                        }

                        customAttributesToAddByGroup[group.Key].Add(_attributeName, attribute);
                    }
                }
            }
        }
示例#26
0
        public void ProcessCustomAttributes()
        {
            var customAttributes = XmlLayoutUtilities.GetGroupedCustomAttributeNames();

            foreach (var group in customAttributes)
            {
                var existingAttributes = GetAttributeGroup(group.Key);

                foreach (var attribute in group.Value)
                {
                    if (!existingAttributes.Contains(attribute, StringComparer.OrdinalIgnoreCase))
                    {
                        if (!customAttributesToAdd.ContainsKey(group.Key))
                        {
                            customAttributesToAdd.Add(group.Key, new Dictionary <string, CustomXmlAttribute>());
                        }

                        customAttributesToAdd[group.Key].Add(Char.ToLower(attribute[0]) + attribute.Substring(1), XmlLayoutUtilities.GetCustomAttribute(attribute));
                    }
                }
            }
        }
示例#27
0
        IEnumerator Preload_Internal()
        {
            var tagHandlerNames = XmlLayoutUtilities.GetXmlTagHandlerNames();

            var customAttributeNames = XmlLayoutUtilities.GetCustomAttributeNames();

            foreach (var tagHandlerName in tagHandlerNames)
            {
                // instantiate the tag handler (which will create an instance of it we can use later)
                var tagHandler = XmlLayoutUtilities.GetXmlTagHandler(tagHandlerName);

                // load the prefab (this will cache it)
                XmlLayoutUtilities.LoadResource <GameObject>(tagHandler.prefabPath);
            }

            foreach (var customAttributeName in customAttributeNames)
            {
                // Load the custom attribute (which will create an instance of it we can use later)
                XmlLayoutUtilities.GetCustomAttribute(customAttributeName);
            }

            yield return(null);
        }
示例#28
0
        void Preload_Internal()
        {
            var tagHandlerNames = XmlLayoutUtilities.GetXmlTagHandlerNames();

            var customAttributeNames = XmlLayoutUtilities.GetCustomAttributeNames();

            foreach (var tagHandlerName in tagHandlerNames)
            {
                // instantiate the tag handler (which will create an instance of it we can use later)
                var tagHandler = XmlLayoutUtilities.GetXmlTagHandler(tagHandlerName);

                // load the prefab (this will cache it)
                XmlLayoutUtilities.LoadResource <GameObject>(tagHandler.prefabPath);
            }

            foreach (var customAttributeName in customAttributeNames)
            {
                // Load the custom attribute (which will create an instance of it we can use later)
                XmlLayoutUtilities.GetCustomAttribute(customAttributeName);
            }

            /*foreach (var entry in XmlLayoutResourceDatabase.instance.entries)
             * {
             *  XmlLayoutResourceDatabase.instance.GetResource<UnityEngine.Object>(entry.path);
             * }
             *
             * var resourceDatabases = XmlLayoutResourceDatabase.instance.customResourceDatabases;
             *
             * foreach (var resourceDatabase in resourceDatabases)
             * {
             *  foreach(var entry in resourceDatabase.entries)
             *  {
             *      XmlLayoutResourceDatabase.instance.GetResource<UnityEngine.Object>(entry.path);
             *  }
             * }*/
        }
示例#29
0
        void OnGUI()
        {
            float spaceRemaining = 74;

            var style = new GUIStyle();

            style.margin = new RectOffset(10, 10, 10, 10);

            GUILayout.BeginVertical(style);

            // a) Choose whether or not to use an Xml file
            //      i) Create a new one
            //      ii) Use an existing one

            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Xml File", GUILayout.Width(200));
            int xmlIndex = EditorGUILayout.Popup(xmlFileNames.IndexOf(xmlFileName), xmlFileNames.ToArray());

            xmlFileName = xmlFileNames[xmlIndex];
            GUILayout.EndHorizontal();

            GUILayout.Space(4);

            if (xmlFileName == "Create New")
            {
                GUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("New Xml File Name", GUILayout.Width(200));
                newXmlFileName = EditorGUILayout.TextField(newXmlFileName);
                GUILayout.EndHorizontal();
                GUILayout.Space(4);

                spaceRemaining -= 20;
            }

            // b) Choose whether to use an XmlLayoutController
            //      i)  Create a new one
            //      ii) Use an existing one
            GUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Xml Layout Controller", GUILayout.Width(200));
            int index = EditorGUILayout.Popup(controllerNames.IndexOf(controllerName), controllerNames.ToArray());

            controllerName = controllerNames[index];
            GUILayout.EndHorizontal();

            GUILayout.Space(4);

            if (controllerName == "Create New")
            {
                GUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("New Xml Layout Controller Name", GUILayout.Width(200));
                newControllerName = EditorGUILayout.TextField(newControllerName);
                GUILayout.EndHorizontal();
                GUILayout.Space(4);

                spaceRemaining -= 20;
            }

            EditorGUILayout.HelpBox("Both the 'Xml File' and 'Xml Layout Controller' fields are optional.", MessageType.Info);

            if (xmlFileName == "Create New" || controllerName == "Create New")
            {
                EditorGUILayout.HelpBox("Please be advised that the file(s) will be created in the Assets/ folder and will need to be manually moved to the folder(s) of your choice.", MessageType.Info);
                spaceRemaining -= 32;
            }

            // Buttons
            GUILayout.Space(spaceRemaining);

            if (GUILayout.Button("Add Xml Layout"))
            {
                if (xmlFileName == "Create New")
                {
                    // Create the new xml file
                    xmlFileName = XmlLayoutMenuItems.NewXmlLayoutXmlFile(newXmlFileName, false).Substring("Assets/".Length);

                    AssetDatabase.Refresh();
                }

                bool newController = false;
                if (controllerName == "Create New")
                {
                    // Create the new controller file
                    XmlLayoutMenuItems.NewXmlLayoutController(newControllerName, false).Substring("Assets/".Length);

                    newController = true;
                }

                var xmlLayout = InstantiatePrefab("XmlLayout Prefabs/XmlLayout").GetComponent <XmlLayout>();

                if (xmlFileName == "None")
                {
                    // expand the xml editor by default
                    xmlLayout.editor_showXml = true;
                }

                xmlLayout.name = "XmlLayout";

                Selection.activeGameObject = xmlLayout.gameObject;

                if (xmlFileName != "None")
                {
                    var xmlFile = AssetDatabase.LoadAssetAtPath <TextAsset>("Assets/" + xmlFileName);
                    xmlLayout.XmlFile = xmlFile;

                    xmlLayout.ReloadXmlFile();
                }

                if (controllerName != "None")
                {
                    if (!newController)
                    {
                        var controllerType = XmlLayoutUtilities.GetXmlLayoutControllerType(controllerName);

                        if (controllerType != null)
                        {
                            xmlLayout.gameObject.AddComponent(controllerType);
                        }
                    }
                    else
                    {
                        AssetDatabase.Refresh();

                        var window = EditorWindow.GetWindow <XmlLayoutSetControllerWindow>();
                        window.SetAction(xmlLayout.gameObject.GetInstanceID(), newControllerName);
                    }
                }

                this.Close();
            }

            if (GUILayout.Button("Cancel"))
            {
                this.Close();
            }

            GUILayout.EndVertical();
        }
示例#30
0
        private void Start()
        {
            if (started)
            {
                return;
            }

            TextComponentWrapper = new TextComponentWrapper(TextComponent);
            TextComponentWrapper.xmlElement.Initialise(xmlLayout, TextComponentWrapper.xmlElement.rectTransform, XmlLayoutUtilities.GetXmlTagHandler("Text"));

            contentSizeFitter = this.GetComponent <ContentSizeFitter>();

            started = true;
        }