示例#1
0
    public void OnSelectorChanged(string text)
    {
        var conditions = UssParser.ParseConditions(text);
        var go         = UssStyleModifier.FindObjects(
            UssRoot.FindRootInScene().gameObject, conditions);

        foreach (var c in prevObjects)
        {
            if (go.Contains(c.gameObject))
            {
                continue;
            }
            c.CrossFadeColor(Color.white, 0, true, true);
        }
        prevObjects.Clear();

        foreach (var g in go)
        {
            foreach (var c in g.GetComponentsInChildren <Graphic>())
            {
                c.CrossFadeColor(new Color32(255, 64, 64, 255), 0.5f, true, true);
                prevObjects.Add(c);
            }
        }

        selectedObjects.text = go.Length + " object(s)";
    }
示例#2
0
    public static void LoadUss(string uss)
    {
        loaded = true;

        try
        {
            UssValues.Reset();
            var result = UssParser.Parse(uss);
            styles = new List <UssStyleDefinition>(result.styles);
            foreach (var pair in result.values)
            {
                UssValues.SetValue(pair.Key, pair.Value);
            }

            Apply(UssRoot.FindRootInScene().gameObject);

            hasError = false;
            applied  = true;

#if UNITY_EDITOR
            UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(
                UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
#endif
        }
        catch (Exception e)
        {
            hasError = true;
            Debug.LogException(e);
        }
    }
示例#3
0
    void OnGUI()
    {
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("INSTANT EVAL");
        if (GUILayout.Button("run!"))
        {
            /*
             * var result = UssParser.Parse(script);
             * UssStyleModifier.Apply(
             *  UssRoot.FindRootInScene().gameObject,
             *  result.styles);
             */
            UssStyleModifier.LoadUss(script);
        }
        EditorGUILayout.EndHorizontal();

        script = GUI.TextArea(new Rect(0, 30, position.width, 300), script);

        var editor = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);

        if (string.IsNullOrEmpty(editor.SelectedText) == false)
        {
            if (prevSelectionText == editor.SelectedText)
            {
                return;
            }

            var result = UssParser.ParseConditions(editor.SelectedText);
            Selection.objects = UssStyleModifier.FindObjects(
                UssRoot.FindRootInScene().gameObject,
                result);

            prevSelectionText = editor.SelectedText;
        }
    }
示例#4
0
    public void OnStyleSheetChanged(string text)
    {
        try
        {
            var styles = UssParser.Parse(text);
            UssStyleModifier.Apply(
                UssRoot.FindRootInScene().gameObject, styles.styles);

            errorMessage.CrossFadeColor(Color.white, 0.5f, true, true);
            errorMessage.text = "SUCCESS";
        }
        catch (Exception e)
        {
            errorMessage.CrossFadeColor(Color.red, 0.5f, true, true);
            errorMessage.text = e.Message;
        }
    }
示例#5
0
    void OnGUI()
    {
        EditorGUILayout.BeginHorizontal(GUI.skin.FindStyle("Toolbar"));
        query = GUILayout.TextField(query, GUI.skin.FindStyle("ToolbarSeachTextField"));
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Space();

        EditorGUILayout.LabelField(selections + " object(s) found.");

        if (GUI.changed && string.IsNullOrEmpty(query) == false)
        {
            var conditions = UssParser.ParseConditions(query);
            if (conditions.Length == 0)
            {
                return;
            }

            Selection.objects = UssStyleModifier.FindObjects(
                UssRoot.FindRootInScene().gameObject, conditions);

            selections = Selection.objects.Length;
        }
    }
示例#6
0
文件: UtmlRoot.cs 项目: pjc0247/uilab
    public void Rebuild(string doc)
    {
        for (int i = 0; i < transform.childCount; i++)
        {
            DestroyImmediate(transform.GetChild(0).gameObject);
        }

        var html = new HtmlDocument();

        html.LoadHtml(doc);

        inlineStyle = "";
        foreach (var child in html.DocumentNode.ChildNodes)
        {
            ComposeNode(child, transform);
        }

        if (string.IsNullOrEmpty(inlineStyle) == false)
        {
            UssStyleModifier.ApplyUss(inlineStyle);
        }
        UssStyleModifier.LoadUss(UssRoot.FindRootInScene().ucssPath);
    }
示例#7
0
    public void OnGUI()
    {
        UssAutoRefresh.EnsureLastUcssLoaded();

        tab = GUILayout.Toolbar(tab, new string[] { "Color", "Number", "String" });
        EditorGUILayout.BeginHorizontal(GUI.skin.FindStyle("Toolbar"));
        query = GUILayout.TextField(query, GUI.skin.FindStyle("ToolbarSeachTextField"));
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Space();

        queryResults = 0;
        if (tab == 0)
        {
            DrawColors();
        }
        else if (tab == 1)
        {
            DrawNumbers();
        }
        else if (tab == 2)
        {
            DrawStrings();
        }

        if (queryResults == 0)
        {
            GUILayout.Box(noResultTex, GUILayout.Width(100), GUILayout.Height(100));
            EditorGUILayout.LabelField("No results");
        }

        if (GUI.changed)
        {
            var root = UssRoot.FindRootInScene();
            UssStyleModifier.Apply(root.gameObject);
            EditorUtility.SetDirty(root.gameObject);
        }
    }