// Use this for initialization void Start() { //menuItemNumbers = items.Count; // Should have Cancel inside if (items.Count == 0) { Debug.Log("Error: Empty Menu."); } else { innerItem = items[0]; innerCircleRadius = innerItem.radius; if (items.Count > 1) { // While debugging, there are some preloaded items. if (isFullCircle) { eachAngle = 360.0f / (items.Count - 1); } else { eachAngle = 180.0f / (items.Count - 1); } } } objCanvasGroup = gameObject.GetComponent <CanvasGroup>(); objCanvasGroup.alpha = 0; //PhysicalPancake.SetActive(false); //cursorObj.SetActive(false); LoadIcons(); //Debug.Log(string.Format("Cursor pos: {0} (local), {1} (global)", cursorObj.transform.localPosition, cursorObj.transform.position)); //InitPieMenu(new List<string>(new string[] { "Cover", "Full Paper" })); }
/// <summary> /// Initialize the pie menu with given array of names. /// The position and rotation of this pie menu should be determined in advance. /// </summary> /// <param name="names"></param> /// <param name="defaultOption">Highlight a default option. If the value is invalid (e.g., -1), igore it</param> public void InitPieMenu(string fName, string[] names, bool[] states, PenOrganizer po, PieMenuType tp, int defaultOption = -1) { gameObject.SetActive(true); FileName = fName; MenuType = tp; if (names.Length != states.Length) { Debug.Log("InitPieMenu Error: the names and states array should have the same length."); return; } for (int i = 1; i < items.Count; ++i) { Destroy(items[i].gameObject); } items.Clear(); items.Add(innerItem); ResetParams(); penOrg = po; // Full Circle, 360 degrees, world-anchored. if (isFullCircle) { // Calculate the basic shapes for this menu eachAngle = 360.0f / names.Length; Debug.Log(string.Format("InitPieMenu (FullCircle): {0} sectors, {1} each, position: {2} (local) and {3} (global), radius: {4}", names.Length, eachAngle, gameObject.transform.localPosition, gameObject.transform.position, PieMenuRadius)); for (int i = 0; i < names.Length; ++i) { string pName = names[i]; float startAngle = i * eachAngle; float bisector = startAngle + eachAngle * 0.5f; GameObject pieMenuItemObj = Instantiate(Resources.Load("PieItem")) as GameObject; pieMenuItemObj.transform.SetParent(gameObject.transform); // Make some blank spaces between the sectors, by pushing them outwards for a bit (handled by PieMenuItem.MoveToAngle now) pieMenuItemObj.transform.localPosition = Vector3.zero; pieMenuItemObj.transform.localEulerAngles = Vector3.zero; pieMenuItemObj.transform.localScale = Vector3.one; //Debug.Log("Item Size:" + pieMenuItemObj.GetComponent<RectTransform>().sizeDelta + "Local Scale:" + pieMenuItemObj.transform.localScale); PieMenuItem pieMenuItem = pieMenuItemObj.GetComponent <PieMenuItem>(); // React to parameters if (states[i]) { pieMenuItem.SetShape(PieMenuRadius, startAngle, eachAngle, NormalColor); pieMenuItem.SetText(pName, NormalFont); pieMenuItem.clickable = true; } else { pieMenuItem.SetShape(PieMenuRadius, startAngle, eachAngle, DisabledColor); pieMenuItem.SetText(pName, DisabledFont); pieMenuItem.clickable = false; Debug.Log(string.Format("[PieMenu] [{0}] {1} is now disabled.", items.Count + 1, pName)); } if (dictIcon.ContainsKey(pName)) { pieMenuItem.SetIcon(dictIcon[pName]); } items.Add(pieMenuItem); } } else { // Semi-circle, bottom half. // Calculate the basic shapes for this menu eachAngle = 180.0f / names.Length; // The transform should have been changed outside. Debug.Log(string.Format("InitPieMenu (SemiCircle): {0} sectors, {1} each, position: {2} (local) and {3} (global), radius: {4}", names.Length, eachAngle, gameObject.transform.localPosition, gameObject.transform.position, PieMenuRadius)); for (int i = 0; i < names.Length; ++i) { string pName = names[i]; float startAngle = 180 + i * eachAngle; float bisector = startAngle + eachAngle * 0.5f; GameObject pieMenuItemObj = Instantiate(Resources.Load("PieItem")) as GameObject; pieMenuItemObj.transform.SetParent(gameObject.transform); // Make some blank spaces between the sectors, by pushing them outwards for a bit (handled by PieMenuItem.MoveToAngle now) pieMenuItemObj.transform.localPosition = Vector3.zero; pieMenuItemObj.transform.localEulerAngles = Vector3.zero; PieMenuItem pieMenuItem = pieMenuItemObj.GetComponent <PieMenuItem>(); // React to parameters if (states[i]) { pieMenuItem.SetShape(PieMenuRadius, startAngle, eachAngle, NormalColor); pieMenuItem.SetText(pName, NormalFont); pieMenuItem.clickable = true; } else { pieMenuItem.SetShape(PieMenuRadius, startAngle, eachAngle, DisabledColor); pieMenuItem.SetText(pName, DisabledFont); pieMenuItem.clickable = false; Debug.Log(string.Format("[PieMenu] [{0}] {1} is now disabled.", items.Count + 1, pName)); } if (dictIcon.ContainsKey(pName)) { pieMenuItem.SetIcon(dictIcon[pName]); } items.Add(pieMenuItem); } } StartCoroutine(PieMenuFade(true)); if (defaultOption >= 0 && defaultOption < items.Count) { Debug.Log("Set Pressed by Default."); SetPressedMenuItem(defaultOption); } }