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);
                }
            }
        }
        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);
            }
        }
Exemple #3
0
        private static GameObject InstantiatePrefab(string name)
        {
            var prefab     = XmlLayoutUtilities.LoadResource <GameObject>(name);
            var gameObject = GameObject.Instantiate(prefab) as GameObject;

            return(gameObject);
        }
Exemple #4
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.");
            }
        }
Exemple #5
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;
        }
Exemple #6
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);
        }
Exemple #7
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);
        }
        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);
        }
Exemple #13
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);
        }
        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);
        }
Exemple #15
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);
            }
        }
Exemple #16
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);
        }
Exemple #17
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);
             *  }
             * }*/
        }
 public static Transform ToTransform(this string str)
 {
     return(XmlLayoutUtilities.LoadResource <Transform>(str));
 }