how do i create a calendar gui in unity, so that i can select a specific date? thanks, flexrails
Check msdn for custom formatting of date strings and play around with how the GUI system works in general to e.g. browse around a calendar using conditional buttons or toggles.
using UnityEngine;
using System.Collections;
using System; //Unity does not add this by default when creating a new script
public class CalendarGUI : MonoBehaviour
{
private string[] Months;
void Start()
{
//fill an array with the names of the months
Months = new string[12];
System.DateTime iMonth = new System.DateTime(2009,1,1);
for (int i = 0; i < 12; ++i)
{
iMonth = new System.DateTime(2009, i+1, 1);
Months *= iMonth.ToString("MMMM");*
* }*
* }*
* void OnGUI ()*
* {*
* //show the months in a grid and select the current month*
* GUILayout.SelectionGrid(System.DateTime.Now.Month-1, Months, 3);*
* }*
*}*
*```*
*<p>It can easily be modified to show weekdays, dates and virtually anything from System.DateTime.</p>*
*<p>Have fun! I'm looking forward to see what you come up with.</p>*
Start with designing and capturing requirements for what you want to be the end product. Then I suppose it's just a bunch of buttons and states, and listing which days are found for a given month (or how you want to present the view of the calendar). I think you can find some helping methods in the .NET DateTime class.
But first and foremost, make clear for yourself how you want the calendar to look, feel and behave.
For the GUI I suggest you take look at GUILayout.SelectionGrid which can provide you with an easy way of setting up your buttons in the calendar, after that, it is just design which varies a lot from calendar to calendar.
I don’t have much time for a more complete answer, unfortunately, but I’d try uitable to create a table and to define the CellSelectionCallback to get the date.
Here's a bit to get you started:
dates = calendar;
dates(~any(dates,2),:) = [];
fh = figure;
uh = uitable('parent',fh,'data',dates,'ColumnWidth',repmat({20},1,7),...
'ColumnName',{'S','M','T','W','T','F','S'});
Anyway, this reminds of the C# calendar, I read through all the calendar control tutorial, but nothing found for the for the date selection.