void create_sub_items(MenuItem topItem, float fParentRadius, float fParentAngleMin, float fParentAngleMax) { float fInnerRadius = fParentRadius + SubItemRadialPadding; float fOuterRadius = fInnerRadius + SubItemRadialWidth; int nItems = topItem.SubItems.Count; //float fParentAngleSpan = fParentAngleMax - fParentAngleMin; float fParentAngleMid = 0.5f * (fParentAngleMax + fParentAngleMin); //float fSubMenuSpan = 180.0f - (WedgePadding * (float)(nItems-1)); //float fWedgeSpan = fSubMenuSpan / (float)nItems; float fWedgeSpan = 45.0f; float fSubMenuSpan = nItems * fWedgeSpan + (float)(nItems - 1) * WedgePadding; int nSlicesPerWedge = 16; float fCurAngle = fParentAngleMid - fSubMenuSpan * 0.5f; for (int i = 0; i < nItems; ++i) { MenuItem item = topItem.SubItems[i]; Mesh m = MeshGenerators.CreatePuncturedDisc(fInnerRadius, fOuterRadius, nSlicesPerWedge, fCurAngle, fCurAngle + fWedgeSpan); float fMidAngleRad = (fCurAngle + fWedgeSpan * 0.5f) * Mathf.Deg2Rad; Vector2 vMid = new Vector2(Mathf.Cos(fMidAngleRad), Mathf.Sin(fMidAngleRad)); GameObject itemGO = AppendMeshGO(item.Label, m, itemMaterial, menuContainer); itemGO.transform.Rotate(Vector3.right, -90.0f); // ?? topItem.SubItems[i].GO = itemGO; // [TODO] this is to improve font centering. Right now we do absolute centering // but visually this looks wrong because weight of font is below center-y. // Right thing would be to align at top of lowercase letters, rather than center-y // (to fix in future) float fudge = 0.0f; if (nItems == 2 && i == 1) { fudge = -0.1f; } TextLabelGenerator textGen = new TextLabelGenerator() { Text = item.Label, Scale = SubItemTextScale, Translate = vMid * (fInnerRadius + (TextCenterPointFactor + fudge) * SubItemRadialWidth), Align = TextLabelGenerator.Alignment.HVCenter }; List <GameObject> vTextElems = textGen.Generate(); AddVisualElements(vTextElems, true); // actually want these GOs to be parented to itemGO UnityUtil.AddChildren(itemGO, vTextElems, true); itemGO.SetVisible(false); if (item.SubItems != null) { create_sub_items(item, fOuterRadius, fCurAngle, fCurAngle + fWedgeSpan); } fCurAngle += WedgePadding + fWedgeSpan; } }
public static fRingGameObject CreateRingGO(string sName, float fInnerRadius, float fOuterRadius, fMaterial material, bool bShareMaterial, bool bCollider) { GameObject go = new GameObject(sName); fMesh ringMesh = MeshGenerators.CreatePuncturedDisc(fInnerRadius, fOuterRadius, 32); initialize_meshgo(go, ringMesh, bCollider, true); go.SetMaterial(material, bShareMaterial); return(new fRingGameObject(go, new fMesh(go.GetSharedMesh()), fOuterRadius, fInnerRadius)); }
public void Create() { menuContainer = new GameObject(UniqueNames.GetNext("HUDRadialMenu")); itemMaterial = MaterialUtil.CreateFlatMaterial(ItemColor); highlightMaterial = MaterialUtil.CreateFlatMaterial(HighlightColor); float fInnerRadius = Radius * DeadZoneRadiusFactor; centerPoint = AppendUnityPrimitiveGO("center_point", PrimitiveType.Sphere, highlightMaterial, menuContainer, false); centerPoint.transform.localScale = fInnerRadius * 0.25f * Vector3.one; int nItems = TopLevelItems.Count; float fWedgeSpan = (AngleSpan / (float)nItems) - WedgePadding; int nSlicesPerWedge = 64 / nItems; float fCurAngle = AngleShift; for (int i = 0; i < nItems; ++i) { Mesh m = MeshGenerators.CreatePuncturedDisc(fInnerRadius, Radius, nSlicesPerWedge, fCurAngle, fCurAngle + fWedgeSpan); float fMidAngleRad = (fCurAngle + fWedgeSpan * 0.5f) * Mathf.Deg2Rad; Vector2 vMid = new Vector2(Mathf.Cos(fMidAngleRad), Mathf.Sin(fMidAngleRad)); TopLevelItems[i].GO = AppendMeshGO(TopLevelItems[i].Label, m, itemMaterial, menuContainer); TopLevelItems[i].GO.transform.Rotate(Vector3.right, -90.0f); // ?? // [TODO] this is to improve font centering. Right now we do absolute centering // but visually this looks wrong because weight of font is below center-y. // Right thing would be to align at top of lowercase letters, rather than center-y // (to fix in future) float fudge = 0.0f; if (nItems == 2 && i == 1) { fudge = -0.1f; } TextLabelGenerator textGen = new TextLabelGenerator() { Text = TopLevelItems[i].Label, Scale = TextScale, Translate = vMid * (TextCenterPointFactor + fudge) * Radius, Align = TextLabelGenerator.Alignment.HVCenter }; AddVisualElements(textGen.Generate(), true); // debug: add red dots at center points to see how well text is aligned... //GameObject tmp = AppendUnityPrimitiveGO("center", PrimitiveType.Sphere, MaterialUtil.CreateStandardMaterial(Color.red), RootGameObject); //tmp.transform.localScale = new Vector3(0.15f, 0.15f, 0.15f); //tmp.transform.position = textGen.Translate; if (TopLevelItems[i].SubItems != null) { create_sub_items(TopLevelItems[i], Radius, fCurAngle, fCurAngle + fWedgeSpan); } fCurAngle += WedgePadding + fWedgeSpan; } }