Ejemplo n.º 1
0
        Attributes CheckAttributes(X3DParse.Node node, CssStyle cssStyle)
        {
            Attributes at = new Attributes();

            foreach (X3DParse.Node child in node.Children.FindAll(x => x.NodeType == X3DParse.NodeType.Attribute))
            {
                string name = child.Name.ToLower();
                // var a = 1;
                switch (name)
                {
                case "style":
                    HandleStyle(child, cssStyle);
                    break;

                case "scr":
                    at.Src = child.Value;
                    break;

                case "title":
                    cssStyle.ToolTip = child.Value;
                    break;

                case "href":
                    cssStyle.Href = child.Value;
                    break;
                }
            }
            return(at);
        }
Ejemplo n.º 2
0
        void HandleAnchor(X3DParse.Node node, Transform canvas, CssStyle cssStyle)
        {
            var at = CheckAttributes(node, cssStyle);

            foreach (X3DParse.Node child in node.Children.FindAll(x => x.NodeType == X3DParse.NodeType.Element))
            {
                HandleCommonElements(child, canvas, cssStyle.Clone());
            }
        }
Ejemplo n.º 3
0
        void HandleXml(string text)
        {
            X3DParse.X3DParse parser = new X3DParse.X3DParse();
            X3DParse.Node     root   = parser.Parse(text);

            if (root != null)
            {
                Slam.Instance.HandleCommunication(root);
            }
        }
Ejemplo n.º 4
0
 public void HandleHtml(X3DParse.Node node, Transform parent)
 {
     foreach (X3DParse.Node child in node.Children.FindAll(x => x.NodeType == X3DParse.NodeType.Element))
     {
         string name = child.Name.ToLower();
         // var a = 1;
         switch (name)
         {
         case "body":
             HandleBody(child, parent);
             break;
         }
     }
 }
Ejemplo n.º 5
0
        void HandleImg(X3DParse.Node node, Transform canvas, CssStyle cssStyle)
        {
            GameObject panel = new GameObject("Img");
            var        rt    = panel.AddComponent <RectTransform>();

            SetAnchorAndPivot(rt.transform);

            var at = CheckAttributes(node, cssStyle);


            var cr = panel.AddComponent <CanvasRenderer>();

            Image i = panel.AddComponent <Image>();

            panel.transform.parent = canvas;
            Slam.Instance.AddTexture(panel, at.Src);
            ApplyCssStyle(panel, cssStyle);
        }
Ejemplo n.º 6
0
        void HandleBody(X3DParse.Node node, Transform parent)
        {
            //add canvas
            GameObject g = new GameObject("Canvas");

            g.transform.parent = parent;
            var canvas = g.AddComponent <Canvas>();

            canvas.renderMode = RenderMode.WorldSpace;
            SetAnchorAndPivot(canvas.transform);
            CanvasScaler cs = g.AddComponent <CanvasScaler>();

            cs.scaleFactor          = 1.0f;
            cs.dynamicPixelsPerUnit = 10f;
            CssStyle cssStyle = new CssStyle();

            foreach (X3DParse.Node child in node.Children.FindAll(x => x.NodeType == X3DParse.NodeType.Element))
            {
                HandleCommonElements(child, g.transform, cssStyle.Clone());
            }
        }
Ejemplo n.º 7
0
        void AddNodelIstItem(X3DParse.Node child, int count)
        {
            var newItem            = GameObject.Instantiate(nodePrefab, transform);
            ClickableTextSpec spec = ClickableTextSpec.FromX3dParseNode(child);

            var firstCollider = newItem.gameObject.GetComponentInChildren <Collider>();

            if (firstCollider != null)
            {
                var so = firstCollider.gameObject.GetComponent <SlamObject>();
                if (so == null)
                {
                    so = firstCollider.gameObject.AddComponent <SlamObject>();
                }
                so.Target  = spec.Target;
                so.Href    = spec.Href;
                so.ToolTip = spec.Tooltip;
                so.name    = "lbItem" + count.ToString();
            }
            //text
            if (!string.IsNullOrEmpty(spec.Text))
            {
                var textMeshObj = newItem.GetComponentInChildren <TMPro.TextMeshPro>();
                if (textMeshObj == null)
                {
                    textMeshObj = Slam.Instance.GetTextMeshObject(spec.Text, 10, 1, 15);
                    textMeshObj.gameObject.transform.SetTheParent(newItem.transform);
                    textMeshObj.gameObject.transform.localPosition = new Vector3(7, 0, 0);
                    textMeshObj.gameObject.transform.localRotation = Quaternion.Euler(0, 0, 0);
                    textMeshObj.alignment = TMPro.TextAlignmentOptions.Left;
                    textMeshObj.color     = Color.black;
                }
                else
                {
                    textMeshObj.text = spec.Text;
                }
            }
            items.Add(newItem);
            newItem.SetActive(false);
        }
Ejemplo n.º 8
0
 void CheckTextNode(X3DParse.Node node, Transform canvas, CssStyle cssStyle)
 {
     if (!string.IsNullOrEmpty(node.Value))
     {
         GameObject g2 = new GameObject();
         g2.name             = "Text";
         g2.transform.parent = canvas;
         var t = g2.AddComponent <TMPro.TextMeshProUGUI>();
         g2.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 3.0f);
         g2.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 3.0f);
         SetAnchorAndPivot(g2.transform);
         ApplyCssStyle(g2, cssStyle);
         t.alignment    = TMPro.TextAlignmentOptions.TopLeft;
         t.overflowMode = TMPro.TextOverflowModes.Ellipsis;
         t.fontSize     = cssStyle.FontSize;
         t.text         = node.Value;
         t.enabled      = true;
         t.color        = cssStyle.Color;
         t.margin       = new Vector4(cssStyle.Margin_left, cssStyle.Margin_top, cssStyle.Margin_bottom, cssStyle.Margin_right);
         t.extraPadding = true;
     }
 }
Ejemplo n.º 9
0
        void HandleDiv(X3DParse.Node node, Transform canvas, CssStyle cssStyle)
        {
            CheckAttributes(node, cssStyle);
            GameObject panel = new GameObject("Panel");
            var        rt    = panel.AddComponent <RectTransform>();

            SetAnchorAndPivot(rt.transform);



            var cr = panel.AddComponent <CanvasRenderer>();

            Image i = panel.AddComponent <Image>();

            panel.transform.parent = canvas;
            ApplyCssStyle(panel, cssStyle);
            CheckTextNode(node, rt, cssStyle.Clone());
            foreach (X3DParse.Node child in node.Children.FindAll(x => x.NodeType == X3DParse.NodeType.Element))
            {
                HandleCommonElements(child, rt, cssStyle.Clone());
            }
        }
Ejemplo n.º 10
0
        void HandleCommonElements(X3DParse.Node node, Transform canvas, CssStyle cssStyle)
        {
            string name = node.Name.ToLower();

            // var a = 1;
            switch (name)
            {
            case "div":
                HandleDiv(node, canvas, cssStyle.Clone());
                break;

            case "span":
                HandleSpan(node, canvas, cssStyle.Clone());
                break;

            case "img":
                HandleImg(node, canvas, cssStyle.Clone());
                break;

            case "a":
                HandleAnchor(node, canvas, cssStyle.Clone());
                break;
            }
        }
Ejemplo n.º 11
0
        public static ClickableTextSpec FromX3dParseNode(X3DParse.Node node)
        {
            ClickableTextSpec spec = new ClickableTextSpec();

            if (node != null)
            {
                foreach (var child in node.Children.FindAll(x => x.NodeType == X3DParse.NodeType.Attribute))
                {
                    string name = child.Name.ToLower();
                    switch (name)
                    {
                    case "text":
                        spec.Text = child.Value;
                        break;

                    case "slm:href":
                    case "href":
                        spec.Href = child.Value;
                        break;

                    case "slm:tooltip":
                    case "tooltip":
                        spec.Tooltip = child.Value;
                        break;

                    case "slm:target":
                    case "target":
                        Target t = Target._blank;
                        Statics.TryGetTarget(child.Value, out t);
                        spec.Target = t;
                        break;
                    }
                }
            }
            return(spec);
        }
Ejemplo n.º 12
0
        void HandleStyle(X3DParse.Node node, CssStyle cssStyle)
        {
            var styles = node.Value.Split(System.Convert.ToChar(";"));

            foreach (var p in styles)
            {
                var styleP = p.Split(System.Convert.ToChar(":"));
                if (styleP.Length == 2)
                {
                    var style = styleP[0].Trim().ToLower();
                    var val   = styleP[1].Trim();
                    switch (style)
                    {
                    case "top":
                        cssStyle.Top += TryFloatValue(val);
                        break;

                    case "left":
                        cssStyle.Left += TryFloatValue(val);
                        break;

                    case "width":
                        cssStyle.Width = TryFloatValue(val);
                        break;

                    case "margin-top":
                        cssStyle.Margin_top = TryFloatValue(val);
                        break;

                    case "margin-bottom":
                        cssStyle.Margin_bottom = TryFloatValue(val);
                        break;

                    case "margin-left":
                        cssStyle.Margin_left = TryFloatValue(val);
                        break;

                    case "margin-right":
                        cssStyle.Margin_right = TryFloatValue(val);
                        break;

                    case "margin":
                        cssStyle.Margin = TryFloatValue(val);
                        break;

                    case "height":
                        cssStyle.Height = TryFloatValue(val);
                        break;

                    case "color":
                        cssStyle.Color = TryColorValue(val, Color.black);
                        break;

                    case "background-color":
                        cssStyle.BackGroundColor = TryColorValue(val, Color.white);
                        break;

                    case "font-size":
                        cssStyle.FontSize = TryIntValue(val, 5);
                        break;
                    }
                }
            }
        }
Ejemplo n.º 13
0
 public LateGameObject(X3DParse.Node shapeNode, Transform parent, LateGameObjectType lateGameObjectType = LateGameObjectType.ShapeNode)
 {
     ShapeNode          = shapeNode;
     Parent             = parent;
     LateGameObjectType = lateGameObjectType;
 }