void HandleSpan(X3DParse.Node node, Transform canvas, CssStyle cssStyle) { CheckAttributes(node, cssStyle); CheckTextNode(node, canvas, cssStyle.Clone()); foreach (X3DParse.Node child in node.Children.FindAll(x => x.NodeType == X3DParse.NodeType.Element)) { HandleCommonElements(child, canvas, cssStyle.Clone()); } }
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()); } }
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; } }
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()); } }