// creates a button in the desired geometry shape public void Create() { entry = GameObjectFactory.CreateParentGO(UniqueNames.GetNext("HUDLabel")); bgMesh = new fGameObject(AppendMeshGO("background", make_background_mesh(), MaterialUtil.CreateFlatMaterialF(BackgroundColor), entry)); bgMesh.RotateD(Vector3f.AxisX, -90.0f); BoxPosition horzAlign = BoxPosition.CenterLeft; if (AlignmentHorz == HorizontalAlignment.Center) { horzAlign = BoxPosition.Center; } else if (AlignmentHorz == HorizontalAlignment.Right) { horzAlign = BoxPosition.CenterRight; } textMesh = GameObjectFactory.CreateTextMeshGO( "text", Text, TextColor, TextHeight, horzAlign, SceneGraphConfig.TextLabelZOffset); Vector2f toPos = BoxModel.GetBoxPosition(this, horzAlign); BoxModel.Translate(textMesh, Vector2f.Zero, toPos); AppendNewGO(textMesh, entry, false); }
public override void Setup() { measureGO = GameObjectFactory.CreateParentGO("dimension"); measureGO.SetLayer(FPlatform.WidgetOverlayLayer); textGO = GameObjectFactory.CreateTextMeshGO("text", "1.0", Colorf.Black, TextHeight.SceneValuef); UnityUtil.AddChild(measureGO, textGO, false); textGO.SetLayer(FPlatform.WidgetOverlayLayer); }
// actually create GO elements, etc public void Create() { entry = GameObjectFactory.CreateParentGO(UniqueNames.GetNext("HUDPopupMessage")); bgMesh = AppendMeshGO("background", make_background_mesh(), MaterialUtil.CreateFlatMaterialF(BackgroundColor), entry); bgMesh.RotateD(Vector3f.AxisX, -90.0f); IBoxModelElement contentArea = BoxModel.PaddedBounds(this, Padding); BoxPosition titleBoxPos = BoxModel.ToPosition(TitleAlignment, VerticalAlignment.Top); titleTextMesh = (titleText == "") ? null : GameObjectFactory.CreateTextMeshGO( "title", TitleText, TextColor, TitleTextHeight, titleBoxPos, SceneGraphConfig.TextLabelZOffset); float fTitleHeight = 0; if (titleTextMesh != null) { Vector2f titleToPos = BoxModel.GetBoxPosition(contentArea, titleBoxPos); BoxModel.Translate(titleTextMesh, Vector2f.Zero, titleToPos); AppendNewGO(titleTextMesh, entry, false); fTitleHeight = TitleTextHeight; } IBoxModelElement messageArea = BoxModel.PaddedBounds(contentArea, 0, 0, 0, Padding + fTitleHeight); Vector2f textDims = messageArea.Size2D; BoxPosition textBoxPos = BoxModel.ToPosition(Alignment, VerticalAlignment.Top); textMesh = GameObjectFactory.CreateTextAreaGO( "message", Text, TextColor, TextHeight, textDims, Alignment, textBoxPos, SceneGraphConfig.TextLabelZOffset); Vector2f textToPos = BoxModel.GetBoxPosition(messageArea, textBoxPos); BoxModel.Translate(textMesh, Vector2f.Zero, textToPos); AppendNewGO(textMesh, entry, false); if (EnableClickToDismiss) { footerTextMesh = GameObjectFactory.CreateTextMeshGO( "footer", DismissText, DismissTextColor, TextHeight * 0.5f, BoxPosition.CenterBottom, SceneGraphConfig.TextLabelZOffset); BoxModel.Translate(footerTextMesh, Vector2f.Zero, BoxModel.GetBoxPosition(contentArea, BoxPosition.CenterBottom)); AppendNewGO(footerTextMesh, entry, false); } }
// creates a button in the desired geometry shape public void Create() { entry = GameObjectFactory.CreateParentGO(UniqueNames.GetNext("HUDLabel")); bgMesh = AppendMeshGO("background", HUDUtil.MakeBackgroundMesh(Shape), MaterialUtil.CreateFlatMaterialF(BackgroundColor), entry); bgMesh.RotateD(Vector3f.AxisX, -90.0f); if (EnableBorder) { HUDShape borderShape = Shape; borderShape.Radius += BorderWidth; borderShape.Height += 2 * BorderWidth; borderShape.Width += 2 * BorderWidth; border = AppendMeshGO("border", HUDUtil.MakeBackgroundMesh(borderShape), MaterialUtil.CreateFlatMaterialF(BorderColor), entry); border.RotateD(Vector3f.AxisX, -90.0f); border.Translate(-0.001f * Vector3f.AxisY, true); } BoxPosition horzAlign = BoxPosition.CenterLeft; if (AlignmentHorz == HorizontalAlignment.Center) { horzAlign = BoxPosition.Center; } else if (AlignmentHorz == HorizontalAlignment.Right) { horzAlign = BoxPosition.CenterRight; } textMesh = GameObjectFactory.CreateTextMeshGO( "text", Text, TextColor, TextHeight, horzAlign, SceneGraphConfig.TextLabelZOffset); textMesh.TextObject.SetFixedWidth(Shape.Width); textMesh.TextObject.SetOverflowMode(TextOverflowMode.Ellipses); Vector2f toPos = BoxModel.GetBoxPosition(this, horzAlign); BoxModel.Translate(textMesh, Vector2f.Zero, toPos); AppendNewGO(textMesh, entry, false); MaterialUtil.DisableShadows(RootGameObject); }
void UpdateText() { if (button == null) { return; } if (labelMesh == null && text.Length > 0) { labelMesh = GameObjectFactory.CreateTextMeshGO( "label", Text, TextColor, TextHeight, BoxPosition.Center, SceneGraphConfig.TextLabelZOffset); BoxModel.Translate(labelMesh, Vector2f.Zero, this.Bounds2D.Center); AppendNewGO(labelMesh, button, false); } if (labelMesh != null) { labelMesh.SetColor(TextColor); labelMesh.SetText(Text); } }
// creates a button in the desired geometry shape public void Create() { entry = new GameObject(UniqueNames.GetNext("HUDTextEntry")); Mesh mesh = MeshGenerators.CreateTrivialRect(Width, Height, MeshGenerators.UVRegionType.FullUVSquare); backgroundMaterial = MaterialUtil.CreateFlatMaterialF(BackgroundColor); activeBackgroundMaterial = MaterialUtil.CreateFlatMaterialF(ActiveBackgroundColor); bgMesh = AppendMeshGO("background", mesh, backgroundMaterial, entry); bgMesh.transform.Rotate(Vector3.right, -90.0f); // ?? BoxPosition horzAlign = BoxPosition.CenterLeft; if (AlignmentHorz == HorizontalAlignment.Center) { horzAlign = BoxPosition.Center; } else if (AlignmentHorz == HorizontalAlignment.Right) { horzAlign = BoxPosition.CenterRight; } textMesh = GameObjectFactory.CreateTextMeshGO( "text", Text, TextColor, TextHeight, horzAlign, SceneGraphConfig.TextLabelZOffset); Vector2f toPos = BoxModel.GetBoxPosition(this, horzAlign); BoxModel.Translate(textMesh, Vector2f.Zero, toPos); AppendNewGO(textMesh, entry, false); cursor = GameObjectFactory.CreateRectangleGO("cursor", Height * 0.1f, Height * 0.8f, Colorf.VideoBlack, false); BoxModel.Translate(cursor, Vector2f.Zero, this.Bounds2D.CenterLeft, -Height * 0.1f); cursor.RotateD(Vector3f.AxisX, -90.0f); AppendNewGO(cursor, entry, false); cursor.SetVisible(false); }
// [TODO] currently only allows for left-justified text. // Can support center/right, but the translate block needs to be rewritten // (can we generalize as target-center of 2D bbox?? public static fTextGameObject CreateTextMeshProGO( string sName, string sText, Colorf textColor, float fTextHeight, BoxPosition textOrigin = BoxPosition.Center, float fOffsetZ = -0.01f) { GameObject textGO = new GameObject(sName); TextMeshProExt tm = textGO.AddComponent <TextMeshProExt>(); //tm.isOrthographic = false; tm.alignment = TextAlignmentOptions.TopLeft; tm.enableWordWrapping = false; tm.autoSizeTextContainer = true; tm.fontSize = 16; tm.text = sText; tm.color = textColor; // ignore material changes when we add to GameObjectSet textGO.AddComponent <IgnoreMaterialChanges>(); textGO.AddComponent <TextMeshProAlphaMultiply>(); // use our textmesh material instead //MaterialUtil.SetTextMeshDefaultMaterial(tm); // convert TextContainerAnchor (which refers to TextContainer, that was deprecated) to // pivot point, which we will set on rectTransform Vector2f pivot = GetTextMeshProPivot(TextContainerAnchors.TopLeft); if (textOrigin == BoxPosition.Center) { pivot = GetTextMeshProPivot(TextContainerAnchors.Middle); tm.alignment = TextAlignmentOptions.Center; } else if (textOrigin == BoxPosition.BottomLeft) { pivot = GetTextMeshProPivot(TextContainerAnchors.BottomLeft); tm.alignment = TextAlignmentOptions.BottomLeft; } else if (textOrigin == BoxPosition.TopRight) { pivot = GetTextMeshProPivot(TextContainerAnchors.TopRight); tm.alignment = TextAlignmentOptions.TopRight; } else if (textOrigin == BoxPosition.BottomRight) { pivot = GetTextMeshProPivot(TextContainerAnchors.BottomRight); tm.alignment = TextAlignmentOptions.BottomRight; } else if (textOrigin == BoxPosition.CenterLeft) { pivot = GetTextMeshProPivot(TextContainerAnchors.Left); tm.alignment = TextAlignmentOptions.Left; } else if (textOrigin == BoxPosition.CenterRight) { pivot = GetTextMeshProPivot(TextContainerAnchors.Right); tm.alignment = TextAlignmentOptions.Right; } else if (textOrigin == BoxPosition.CenterTop) { pivot = GetTextMeshProPivot(TextContainerAnchors.Top); tm.alignment = TextAlignmentOptions.Top; } else if (textOrigin == BoxPosition.CenterBottom) { pivot = GetTextMeshProPivot(TextContainerAnchors.Bottom); tm.alignment = TextAlignmentOptions.Bottom; } tm.rectTransform.pivot = pivot; tm.ForceMeshUpdate(); // read out bounds so we can know size (does this matter? why does fTextGO have size field?) AxisAlignedBox3f bounds = tm.bounds; Vector2f size = new Vector2f(bounds.Width, bounds.Height); tm.fontSizeYScale = GetYScale(tm); tm.SetTextSizeFromHeight(fTextHeight); float fScale = tm.GetTextScaleForHeight(fTextHeight); float fTextWidth = fScale * size.x; // set rendering queue (?) textGO.GetComponent <Renderer>().material.renderQueue = SceneGraphConfig.TextRendererQueue; fTextGameObject go = new fTextGameObject(textGO, new fText(tm, TextType.TextMeshPro), new Vector2f(fTextWidth, fTextHeight)); if (fOffsetZ != 0) { Vector3f pos = go.GetLocalPosition(); pos.z += fOffsetZ; go.SetLocalPosition(pos); } return(go); }