Beispiel #1
0
        protected void ParseHead(Tag tag)
        {
            for (int i = 0; i < tag.attributes.Count; i += 1)
            {
                Tag.Attribute attribute = tag.attributes[i];
                switch (attribute.name)
                {
                case "skin":
                    GUISkin skin = AssetDatabase.LoadAssetAtPath <GUISkin>(attribute.data);
                    if (skin == null)
                    {
                        Debug.LogWarning("There was no GUISkin found at path: " + attribute.data);
                    }
                    else
                    {
                        _windowTarget.skin = skin;
                    }

                    break;

                case "repaint-on-scene-change":
                case "auto-repaint":
                case "autorepaint":
                case "auto-repaint-on-scene-change":
                    _windowTarget.autoRepaintOnSceneChange = bool.Parse(attribute.data);
                    break;

                case "wantsmousemove":
                case "wants-mouse-move":
                    _windowTarget.wantsMouseMove = bool.Parse(attribute.data);
                    break;

                case "background-color":
                    _windowTarget.body.style["background-color"] = ColorUtility.ReadColor(attribute.data);
                    Debug.Log("bg detected" + _windowTarget.body.style[attribute.name]);
                    break;

                case "background":
                    Texture texture = AssetDatabase.LoadAssetAtPath <Texture>(attribute.data);
                    if (texture == null)
                    {
                        Debug.LogWarning("There was no Texture found at path: " + attribute.data);
                    }
                    else
                    {
                        _windowTarget.body.style[attribute.name] = texture;
                    }
                    break;

                case "font":
                    Font font = AssetDatabase.LoadAssetAtPath <Font>(attribute.data);
                    if (font == null)
                    {
                        Debug.LogWarning("There was no Font found at path: " + attribute.data);
                    }
                    else
                    {
                        _windowTarget.body.style[attribute.name] = font;
                    }

                    break;

                default:
                    break;
                }
            }
        }
Beispiel #2
0
        protected void ApplyAttribute(Tag.Attribute attribute, Element elem)
        {
            string name = attribute.name.ToLower();

            switch (name)
            {
            case "name":
                elem.name = attribute.data;
                break;

            case "font-style":
            case "alignment":
            case "position":
                elem.style[name] = attribute.data;
                break;

            case "width":
            case "height":
            case "top":
            case "bottom":
            case "right":
            case "left":
            case "min-width":
            case "min-height":
            case "max-width":
            case "max-height":
                elem.style[name] = System.Single.Parse(attribute.data);
                break;

            case "expand-width":
            case "expand-height":
                elem.style[name] = (attribute.data.ToLower() == "false") ? false : true;
                break;

            case "background-color":
            case "color":
                elem.style[name] = ColorUtility.ReadColor(attribute.data);
                break;

            case "padding":
            case "margin":
                elem.style[name] = attribute.data;
                break;

            case "background":
                Texture texture = AssetDatabase.LoadAssetAtPath <Texture>(attribute.data);
                if (texture == null)
                {
                    Debug.LogWarning("There was no Texture found at path: " + attribute.data);
                }
                else
                {
                    elem.style[attribute.name] = texture;
                }
                break;

            case "font":
                Font font = AssetDatabase.LoadAssetAtPath <Font>(attribute.data);
                if (font == null)
                {
                    Debug.LogWarning("There was no Font found at path: " + attribute.data);
                }
                else
                {
                    elem.style[attribute.name] = font;
                }
                break;

            case "load":
            case "click":
            case "change":
            case "mousedown":
            case "mouseup":
            case "mouseenter":
            case "mouseleave":
            case "mousedrag":
            case "mousemove":
            case "keyup":
            case "keydown":
                EventCallback callback = CreateEventCallback(attribute.data);
                if (callback != null)
                {
                    elem.AddEventListener(name, callback);
                }
                break;

            default:
                if (!elem.SetProperty(attribute.name, attribute.data))
                {
                    Debug.LogWarning("Cannot apply attribute " + name + " to tag of type " + elem.GetType().Name);
                }

                break;
            }
        }