Exemplo n.º 1
0
    private static bool CheckCondition(GameObject g, UssStyleCondition c)
    {
        if (c.target == UssSelectorType.All)
        {
            return(true);
        }
        else if (c.target == UssSelectorType.Name)
        {
            if (g.name != c.name)
            {
                return(false);
            }
        }
        else if (c.target == UssSelectorType.Component)
        {
            if (g.GetComponent(c.name) == null)
            {
                return(false);
            }
        }
        else if (c.target == UssSelectorType.Class)
        {
            var klass = g.GetComponent <UssClass>();
            if (klass == null)
            {
                return(false);
            }
            if (klass.classes.Split(' ').Contains(c.name) == false)
            {
                return(false);
            }
        }

        return(true);
    }
Exemplo n.º 2
0
    private void ParseConditions(UssToken token)
    {
        if (token.IsIgnoreable)
        {
            return;
        }

        if (token.type == UssTokenType.LeftBracket)
        {
            state    = ParsingState.Properties;
            nodeType = CurrentNodeType.Style;
            return;
        }

        // Every types of token can be accepted here
        // since name of the Unity's gameobject can contain almost characters.
        // (ex: Zu!ZU##!)
        var rawCondition   = token.body;
        var styleCondition = new UssStyleCondition();

        // CLASS
        if (rawCondition[0] == '.')
        {
            styleCondition.target = UssStyleTarget.Class;
            styleCondition.name   = rawCondition.Substring(1);
        }
        // NAME
        else if (rawCondition[0] == '#')
        {
            styleCondition.target = UssStyleTarget.Name;
            styleCondition.name   = rawCondition.Substring(1);
        }
        else
        {
            styleCondition.target = UssStyleTarget.Component;
            styleCondition.name   = rawCondition;
        }

        conditions.Add(styleCondition);
    }
Exemplo n.º 3
0
    private void ParseConditions(UssToken token)
    {
        if (token.IsIgnoreable)
        {
            return;
        }

        if (token.type == UssTokenType.LeftBracket)
        {
            state    = ParsingState.Properties;
            nodeType = CurrentNodeType.Style;
            return;
        }

        if (token.type == UssTokenType.RightArrow)
        {
            if (conditions.Count == 0)
            {
                throw new UssUnexpectedTokenException(token);
            }

            nextConditionType = UssStyleConditionType.DirectDescendant;
            return;
        }
        if (token.type == UssTokenType.Colon)
        {
            if (conditions.Count == 0)
            {
                throw new UssUnexpectedTokenException(token);
            }
            if (GetNextToken(true).type != UssTokenType.Id)
            {
                throw new UssUnexpectedTokenException(GetNextToken(), UssTokenType.Id);
            }

            conditions.Last().targetState = GetNextToken().body;
            WasteNextToken();
            return;
        }

        // Every types of token can be accepted here
        // since name of the Unity's gameobject can contain almost characters.
        // (ex: Zu!ZU##!)
        var rawCondition   = token.body;
        var styleCondition = new UssStyleCondition();

        if (rawCondition[0] == '*')
        {
            styleCondition.target = UssSelectorType.All;
            styleCondition.name   = "*";
        }
        // CLASS
        else if (rawCondition[0] == '.')
        {
            styleCondition.target = UssSelectorType.Class;
            styleCondition.name   = rawCondition.Substring(1);
        }
        // NAME
        else if (rawCondition[0] == '#')
        {
            styleCondition.target = UssSelectorType.Name;
            styleCondition.name   = rawCondition.Substring(1);
        }
        else
        {
            styleCondition.target = UssSelectorType.Component;
            styleCondition.name   = rawCondition;
        }

        styleCondition.type = nextConditionType;
        conditions.Add(styleCondition);
        nextConditionType = UssStyleConditionType.None;
    }