For That We need to Declare Number of System File Like :
using UnityEngine;
using System.Collections;
using System.Runtime.Serialization.Formatters.Binary;
using System;
using System.Runtime.Serialization;
using System.Reflection;
using System.Text;
using System.IO;
Then Declere Number of ScreenID which U need In Your Game Like :
public class MainMenu: MonoBehaviour
{
enum ScreenIDS
{
LOGOSCREEN ,//0
LOADINGSCREEN,//1
MAINMENU,//2
CAREER,//3
LOAD,//4
CHOOSEPLAYER,//5
CAREERINFO1,//6
CAREERINFO2,//7
CAREERINFO3,//8
CUSTOMIZE,//9
FREESURF,//10
SOCIALNETWORKING,//11
OPTION,//12
LOADPLAYER,//13
BOARDS ,//14
CLOTHS,//15
MAKEOVER,//16
LOADEDCAREERSTATE,//17
LEVEL1,//18
SAVEQUITCAREER,//19
LEVEL2,//20
LEVEL3,//21
FSLEVEL1,//22
FSLEVEL2,//23
FSLEVEL3,//24
//NEXTBOARD,//25
//NEXTDRESS,//26
STATGAME,//25
QUIT,//26
QUIT1,//27
LOADCAREER//28
};
Now Declere Number Veriable You Need In Your Game Menu :
So After All That You Need To Declere main Class Void Init GUI () Like :
So if You want to Download Full Code Then You Can Download if from Here
--
Vivek P Shah
Game Developer in Unity3d and Cocos2d
using UnityEngine;
using System.Collections;
using System.Runtime.Serialization.Formatters.Binary;
using System;
using System.Runtime.Serialization;
using System.Reflection;
using System.Text;
using System.IO;
Then Declere Number of ScreenID which U need In Your Game Like :
public class MainMenu: MonoBehaviour
{
enum ScreenIDS
{
LOGOSCREEN ,//0
LOADINGSCREEN,//1
MAINMENU,//2
CAREER,//3
LOAD,//4
CHOOSEPLAYER,//5
CAREERINFO1,//6
CAREERINFO2,//7
CAREERINFO3,//8
CUSTOMIZE,//9
FREESURF,//10
SOCIALNETWORKING,//11
OPTION,//12
LOADPLAYER,//13
BOARDS ,//14
CLOTHS,//15
MAKEOVER,//16
LOADEDCAREERSTATE,//17
LEVEL1,//18
SAVEQUITCAREER,//19
LEVEL2,//20
LEVEL3,//21
FSLEVEL1,//22
FSLEVEL2,//23
FSLEVEL3,//24
//NEXTBOARD,//25
//NEXTDRESS,//26
STATGAME,//25
QUIT,//26
QUIT1,//27
LOADCAREER//28
};
Now Declere Number Veriable You Need In Your Game Menu :
float currentTimer = 0.0f;
float currentDir = -1.0f;
float LOADINGSCREENTIME = 5.0f;
float COMPANYLOGOSCREEN = 10.0f;
byte Camflag = 0;
int loadGameLevel = 1;
public byte TextureCount;
Vector3 CamPosition;
DataPersistance dataPersistance; /// Persistance Object : Read/Write to file.
GameConfig gameConfig=null; ///object to for game settings info.
public PlayersData playerData = new PlayersData(); ///PlayerNames and PlayerScores
public PlayersData leveldata = new PlayersData(); // Levelname and Current Level
public PlayersData Boarddata = new PlayersData();
public PlayersData Dressddata = new PlayersData();
public PlayersData Hairdata = new PlayersData();
float currentDir = -1.0f;
float LOADINGSCREENTIME = 5.0f;
float COMPANYLOGOSCREEN = 10.0f;
byte Camflag = 0;
int loadGameLevel = 1;
public byte TextureCount;
Vector3 CamPosition;
DataPersistance dataPersistance; /// Persistance Object : Read/Write to file.
GameConfig gameConfig=null; ///object to for game settings info.
public PlayersData playerData = new PlayersData(); ///PlayerNames and PlayerScores
public PlayersData leveldata = new PlayersData(); // Levelname and Current Level
public PlayersData Boarddata = new PlayersData();
public PlayersData Dressddata = new PlayersData();
public PlayersData Hairdata = new PlayersData();
Now Go Into Void Start () And Declere it like :
void Start ()
{
////Load GameConfiguration....
dataPersistance = new DataPersistance();
gameConfig = dataPersistance.LoadInfo();
if(starts > 0)
screenID = gameConfig.screenID;
starts++;
//soundFXValue=gameConfig.fxLevel;
//soundVolume=gameConfig.volumeLevel;
//difficultyLevel=gameConfig.difficultyLevel;
levelname = gameConfig.LevelName;
stringToEdit = gameConfig.playerName;
level = gameConfig.Level;
board = gameConfig.Board;
dress = gameConfig.Dress;
hair = gameConfig.Hair;
////Debug.Log("Player Name = " +stringToEdit);
screenID = 0;
MaxPlayer = playerData.LoadPlayerData();
level = playerData.LoadPlayerLevelInfo();
dress = playerData.LoadDressInfo();
hair = playerData.LoadHairInfo();
board = playerData.LoadBoardInfo();
}
{
////Load GameConfiguration....
dataPersistance = new DataPersistance();
gameConfig = dataPersistance.LoadInfo();
if(starts > 0)
screenID = gameConfig.screenID;
starts++;
//soundFXValue=gameConfig.fxLevel;
//soundVolume=gameConfig.volumeLevel;
//difficultyLevel=gameConfig.difficultyLevel;
levelname = gameConfig.LevelName;
stringToEdit = gameConfig.playerName;
level = gameConfig.Level;
board = gameConfig.Board;
dress = gameConfig.Dress;
hair = gameConfig.Hair;
////Debug.Log("Player Name = " +stringToEdit);
screenID = 0;
MaxPlayer = playerData.LoadPlayerData();
level = playerData.LoadPlayerLevelInfo();
dress = playerData.LoadDressInfo();
hair = playerData.LoadHairInfo();
board = playerData.LoadBoardInfo();
}
So After All That You Need To Declere main Class Void Init GUI () Like :
public void initGui()
{
//GUI.Label (new Rect (screenWidth, screenHeight, 100, 20), "Brain Vita Main Menu");
switch (screenID)
{
case 0: //ScreenIDS.LOGOSCREEN
GUI.Box (new Rect (0, 0, 480, 320), "", GameSkin.GetStyle("splashscreen"));
currentTimer += Time.deltaTime;
if(COMPANYLOGOSCREEN< currentTimer)
{
currentTimer = 0.0f;
screenID++;
}
break;
case 1: //ScreenIDS.LOADINGSCREEN
GUI.Box (new Rect (0, 0, 480, 320), "", GameSkin.GetStyle("loadingscreen"));
/* int j=0;
for(float i = 0.0f; i< currentTimer; i=i+0.4f)
{
GUI.Button (new Rect ( 80 + (j++ * 20), 190, 20, 23), "",GameSkin.GetStyle("SmallStar"));
} */
currentTimer += Time.deltaTime;
if(LOADINGSCREENTIME< currentTimer)
{
currentTimer = 0.0f;
screenID++;
}
break;
case 2: // ScreenIDS.MAINMENU
//First menu to be displayed to user.
GUI.Box (new Rect (0, 0, 480, 320), "", GameSkin.GetStyle("MainMenu"));
if(GUI.Button (new Rect ( 330, 20, 151, 100), "",GameSkin.GetStyle("career")))
{
screenID = (int)ScreenIDS.CHOOSEPLAYER;
}
if(GUI.Button (new Rect (340, 90, 129, 97), "",GameSkin.GetStyle("freesurf")))
{
screenID = (int)ScreenIDS.FREESURF;
}
if(GUI.Button (new Rect (320, 130, 150, 137), "",GameSkin.GetStyle("load")))
{
screenID = (int)ScreenIDS.LOAD;
}
if(GUI.Button (new Rect (300, 195, 173, 99), "",GameSkin.GetStyle("setting")))
{
screenID = (int)ScreenIDS.OPTION;
//Debug.Log("On Click oF Stting Button"+screenID);
}
if(GUI.Button (new Rect (215, 255, 214, 67), "",GameSkin.GetStyle("buy")))
{
//screenID = (int)ScreenIDS.OPTION;
}
if(GUI.Button (new Rect (440, 280, 36, 34), "",GameSkin.GetStyle("About")))
{
//screenID = (int)ScreenIDS.OPTION;
}
break;
case 3://ScreenIDS.CAREER
GUI.Box (new Rect (0, 0, 480, 320), "", GameSkin.GetStyle("MainMenu"));
if(GUI.Button (new Rect ( 330, 30, 102, 72), "",GameSkin.GetStyle("selectplayer")))
{
screenID = (int)ScreenIDS.CHOOSEPLAYER;
}
if(GUI.Button (new Rect (285, 90, 198, 77), "",GameSkin.GetStyle("customplayer")))
{
Camflag = 1;
screenID = (int)ScreenIDS.BOARDS;
}
if(GUI.Button (new Rect (300, 150, 182, 114), "",GameSkin.GetStyle("loadplayer")))
{
screenID = (int)ScreenIDS.LOADPLAYER;
}
if(GUI.Button (new Rect (300, 255,98, 71), "",GameSkin.GetStyle("back")))
{
screenID = (int)ScreenIDS.MAINMENU;
}
if(GUI.Button (new Rect (400, 255, 91, 75), "",GameSkin.GetStyle("ok")))
{
rotationCount = (byte)playerData.LoadBoardInfo();
rotationCount = (byte)playerData.LoadBoardInfo();
rotationCount = (byte)playerData.LoadBoardInfo();
FSLEVEL = playerData.LoadPlayerLevelInfo();
screenID = (int)ScreenIDS.STATGAME;
}
break;
case 4: // ScreenIDS.LOAD
GUI.Box (new Rect (0, 0, 480, 320), "", GameSkin.GetStyle("LoadCareer"));
MaxPlayer = playerData.LoadPlayerData();
//Debug.Log("MaxPlayer = "+MaxPlayer);
for(int i=0 ;i <MaxPlayer; i++)
{
if(GUI.Button(new Rect (200, nameplace, 228,20), (i+1) + " ) " + "\""+PlayerPrefs.GetString("PlayerName"+i)+"\" "+PlayerPrefs.GetString ("PlayerCreateDate"+i)+"\" "+PlayerPrefs.GetInt("Score"+i)+"\" "+PlayerPrefs.GetInt("Level"+i),GameSkin.GetStyle("Player")))
{
//Debug.Log("Button Clicked.................................................................................................................");
}
nameplace = nameplace + 20;
if(i == (MaxPlayer - 1))
{
nameplace = 30;
}
}
rotationCount = (byte)playerData.LoadBoardInfo();
if(GUI.Button (new Rect (50, 150,98, 71), "",GameSkin.GetStyle("back")))
{
screenID = (int)ScreenIDS.MAINMENU;
}
if(GUI.Button (new Rect (120, 150, 91, 75), "",GameSkin.GetStyle("ok")))
{
screenID = (int)ScreenIDS.LOADEDCAREERSTATE;
}
case 5: //ScreenIDS.CHOOSEPLAYER
GUI.Box (new Rect (0, 0, 480, 320), "", GameSkin.GetStyle("ChoosePlayer"));
GUI.Box (new Rect (95, 130, 102, 72), "", GameSkin.GetStyle("selectplayer"));
GUI.Box (new Rect (30, 20, 67, 214), "", GameSkin.GetStyle("Male"));
GUI.Box (new Rect (190, 20, 61, 202), "", GameSkin.GetStyle("Female"));
if(GUI.Button (new Rect (90, 200, 43, 18), "",GameSkin.GetStyle(MaleplayerSelection)))
{
MaleplayerSelection = "lefthandclick";
FemaleplayerSelection = "righthand";
//screenID = (int)ScreenIDS.CHOOSEPLAYER;
}
if(GUI.Button (new Rect (155, 200, 39,19), "",GameSkin.GetStyle(FemaleplayerSelection)))
{
MaleplayerSelection = "lefthand";
FemaleplayerSelection = "righthandclick";
//screenID = (int)ScreenIDS.CAREER;
}
if(GUI.Button (new Rect (325, 220,98, 71), "",GameSkin.GetStyle("back")))
{
screenID = (int)ScreenIDS.MAINMENU;
}
if(GUI.Button (new Rect (400, 215,91, 75), "",GameSkin.GetStyle("ok")))
{
playerData.SavePlayerInfo(stringToEdit,100,FSLEVEL);
screenID = (int)ScreenIDS.CAREERINFO1;
//Debug.Log("Player Name = " +stringToEdit);
}
GUI.Box (new Rect (0, 230, 334, 81), "", GameSkin.GetStyle("EnterPlayerName"));
stringToEdit= GUI.TextField (new Rect (185,243,150,60), stringToEdit, 25,GameSkin.GetStyle("textfield"));
break;
case 6: // career mode info1
GUI.Box (new Rect (0, 0, 480, 320), "", GameSkin.GetStyle("info1"));
currentTimer += Time.deltaTime;
if(LOADINGSCREENTIME< currentTimer)
{
currentTimer = 0.0f;
screenID++;
}
/* if(GUI.Button (new Rect (380, 250, 50, 30), "NEXT",GameSkin.GetStyle("BackButton")))
{
Camflag = 1;
screenID = (int)ScreenIDS.CAREER3;
} */
break;
case 7: //career mode info2
// GUI.Box (new Rect (0, 0, 480, 320), "Localize", GameSkin.GetStyle("box"));
GUI.Box (new Rect (0, 0, 480, 320), "", GameSkin.GetStyle("info2"));
currentTimer += Time.deltaTime;
if(LOADINGSCREENTIME< currentTimer)
{
currentTimer = 0.0f;
screenID++;
}
/* if(GUI.Button (new Rect (380, 250, 50, 30), "NEXT",GameSkin.GetStyle("BackButton")))
{
Camflag = 1;
screenID = (int)ScreenIDS.CAREER3;
} */
break;
case 8: //career mode info3
// GUI.Box (new Rect (0, 0, 480, 320), "Localize", GameSkin.GetStyle("box"));
GUI.Box (new Rect (0, 0, 480, 320), "", GameSkin.GetStyle("info3"));
currentTimer += Time.deltaTime;
if(LOADINGSCREENTIME< currentTimer)
{
currentTimer = 0.0f;
screenID = (int)ScreenIDS.CAREER;
}
break;
case 9:
break;
case 10: //ScreenIDS.FREESURFMENU
GUI.Box (new Rect (0, 0, 480, 320), "", GameSkin.GetStyle("BoxPlay2"));
if(GUI.Button (new Rect (25, 240,98, 71), "",GameSkin.GetStyle("back")))
{
screenID = (int)ScreenIDS.MAINMENU;
}
if(GUI.Button (new Rect (140, 235,91, 75), "",GameSkin.GetStyle("ok")))
{
FSLEVEL = playerData.LoadPlayerLevelInfo();
//Debug.Log(" FSLEVEL = "+FSLEVEL);
screenID = (int)ScreenIDS.CHOOSEPLAYER;
}
}
{
//GUI.Label (new Rect (screenWidth, screenHeight, 100, 20), "Brain Vita Main Menu");
switch (screenID)
{
case 0: //ScreenIDS.LOGOSCREEN
GUI.Box (new Rect (0, 0, 480, 320), "", GameSkin.GetStyle("splashscreen"));
currentTimer += Time.deltaTime;
if(COMPANYLOGOSCREEN< currentTimer)
{
currentTimer = 0.0f;
screenID++;
}
break;
case 1: //ScreenIDS.LOADINGSCREEN
GUI.Box (new Rect (0, 0, 480, 320), "", GameSkin.GetStyle("loadingscreen"));
/* int j=0;
for(float i = 0.0f; i< currentTimer; i=i+0.4f)
{
GUI.Button (new Rect ( 80 + (j++ * 20), 190, 20, 23), "",GameSkin.GetStyle("SmallStar"));
} */
currentTimer += Time.deltaTime;
if(LOADINGSCREENTIME< currentTimer)
{
currentTimer = 0.0f;
screenID++;
}
break;
case 2: // ScreenIDS.MAINMENU
//First menu to be displayed to user.
GUI.Box (new Rect (0, 0, 480, 320), "", GameSkin.GetStyle("MainMenu"));
if(GUI.Button (new Rect ( 330, 20, 151, 100), "",GameSkin.GetStyle("career")))
{
screenID = (int)ScreenIDS.CHOOSEPLAYER;
}
if(GUI.Button (new Rect (340, 90, 129, 97), "",GameSkin.GetStyle("freesurf")))
{
screenID = (int)ScreenIDS.FREESURF;
}
if(GUI.Button (new Rect (320, 130, 150, 137), "",GameSkin.GetStyle("load")))
{
screenID = (int)ScreenIDS.LOAD;
}
if(GUI.Button (new Rect (300, 195, 173, 99), "",GameSkin.GetStyle("setting")))
{
screenID = (int)ScreenIDS.OPTION;
//Debug.Log("On Click oF Stting Button"+screenID);
}
if(GUI.Button (new Rect (215, 255, 214, 67), "",GameSkin.GetStyle("buy")))
{
//screenID = (int)ScreenIDS.OPTION;
}
if(GUI.Button (new Rect (440, 280, 36, 34), "",GameSkin.GetStyle("About")))
{
//screenID = (int)ScreenIDS.OPTION;
}
break;
case 3://ScreenIDS.CAREER
GUI.Box (new Rect (0, 0, 480, 320), "", GameSkin.GetStyle("MainMenu"));
if(GUI.Button (new Rect ( 330, 30, 102, 72), "",GameSkin.GetStyle("selectplayer")))
{
screenID = (int)ScreenIDS.CHOOSEPLAYER;
}
if(GUI.Button (new Rect (285, 90, 198, 77), "",GameSkin.GetStyle("customplayer")))
{
Camflag = 1;
screenID = (int)ScreenIDS.BOARDS;
}
if(GUI.Button (new Rect (300, 150, 182, 114), "",GameSkin.GetStyle("loadplayer")))
{
screenID = (int)ScreenIDS.LOADPLAYER;
}
if(GUI.Button (new Rect (300, 255,98, 71), "",GameSkin.GetStyle("back")))
{
screenID = (int)ScreenIDS.MAINMENU;
}
if(GUI.Button (new Rect (400, 255, 91, 75), "",GameSkin.GetStyle("ok")))
{
rotationCount = (byte)playerData.LoadBoardInfo();
rotationCount = (byte)playerData.LoadBoardInfo();
rotationCount = (byte)playerData.LoadBoardInfo();
FSLEVEL = playerData.LoadPlayerLevelInfo();
screenID = (int)ScreenIDS.STATGAME;
}
break;
case 4: // ScreenIDS.LOAD
GUI.Box (new Rect (0, 0, 480, 320), "", GameSkin.GetStyle("LoadCareer"));
MaxPlayer = playerData.LoadPlayerData();
//Debug.Log("MaxPlayer = "+MaxPlayer);
for(int i=0 ;i <MaxPlayer; i++)
{
if(GUI.Button(new Rect (200, nameplace, 228,20), (i+1) + " ) " + "\""+PlayerPrefs.GetString("PlayerName"+i)+"\" "+PlayerPrefs.GetString ("PlayerCreateDate"+i)+"\" "+PlayerPrefs.GetInt("Score"+i)+"\" "+PlayerPrefs.GetInt("Level"+i),GameSkin.GetStyle("Player")))
{
//Debug.Log("Button Clicked.................................................................................................................");
}
nameplace = nameplace + 20;
if(i == (MaxPlayer - 1))
{
nameplace = 30;
}
}
rotationCount = (byte)playerData.LoadBoardInfo();
if(GUI.Button (new Rect (50, 150,98, 71), "",GameSkin.GetStyle("back")))
{
screenID = (int)ScreenIDS.MAINMENU;
}
if(GUI.Button (new Rect (120, 150, 91, 75), "",GameSkin.GetStyle("ok")))
{
screenID = (int)ScreenIDS.LOADEDCAREERSTATE;
}
case 5: //ScreenIDS.CHOOSEPLAYER
GUI.Box (new Rect (0, 0, 480, 320), "", GameSkin.GetStyle("ChoosePlayer"));
GUI.Box (new Rect (95, 130, 102, 72), "", GameSkin.GetStyle("selectplayer"));
GUI.Box (new Rect (30, 20, 67, 214), "", GameSkin.GetStyle("Male"));
GUI.Box (new Rect (190, 20, 61, 202), "", GameSkin.GetStyle("Female"));
if(GUI.Button (new Rect (90, 200, 43, 18), "",GameSkin.GetStyle(MaleplayerSelection)))
{
MaleplayerSelection = "lefthandclick";
FemaleplayerSelection = "righthand";
//screenID = (int)ScreenIDS.CHOOSEPLAYER;
}
if(GUI.Button (new Rect (155, 200, 39,19), "",GameSkin.GetStyle(FemaleplayerSelection)))
{
MaleplayerSelection = "lefthand";
FemaleplayerSelection = "righthandclick";
//screenID = (int)ScreenIDS.CAREER;
}
if(GUI.Button (new Rect (325, 220,98, 71), "",GameSkin.GetStyle("back")))
{
screenID = (int)ScreenIDS.MAINMENU;
}
if(GUI.Button (new Rect (400, 215,91, 75), "",GameSkin.GetStyle("ok")))
{
playerData.SavePlayerInfo(stringToEdit,100,FSLEVEL);
screenID = (int)ScreenIDS.CAREERINFO1;
//Debug.Log("Player Name = " +stringToEdit);
}
GUI.Box (new Rect (0, 230, 334, 81), "", GameSkin.GetStyle("EnterPlayerName"));
stringToEdit= GUI.TextField (new Rect (185,243,150,60), stringToEdit, 25,GameSkin.GetStyle("textfield"));
break;
case 6: // career mode info1
GUI.Box (new Rect (0, 0, 480, 320), "", GameSkin.GetStyle("info1"));
currentTimer += Time.deltaTime;
if(LOADINGSCREENTIME< currentTimer)
{
currentTimer = 0.0f;
screenID++;
}
/* if(GUI.Button (new Rect (380, 250, 50, 30), "NEXT",GameSkin.GetStyle("BackButton")))
{
Camflag = 1;
screenID = (int)ScreenIDS.CAREER3;
} */
break;
case 7: //career mode info2
// GUI.Box (new Rect (0, 0, 480, 320), "Localize", GameSkin.GetStyle("box"));
GUI.Box (new Rect (0, 0, 480, 320), "", GameSkin.GetStyle("info2"));
currentTimer += Time.deltaTime;
if(LOADINGSCREENTIME< currentTimer)
{
currentTimer = 0.0f;
screenID++;
}
/* if(GUI.Button (new Rect (380, 250, 50, 30), "NEXT",GameSkin.GetStyle("BackButton")))
{
Camflag = 1;
screenID = (int)ScreenIDS.CAREER3;
} */
break;
case 8: //career mode info3
// GUI.Box (new Rect (0, 0, 480, 320), "Localize", GameSkin.GetStyle("box"));
GUI.Box (new Rect (0, 0, 480, 320), "", GameSkin.GetStyle("info3"));
currentTimer += Time.deltaTime;
if(LOADINGSCREENTIME< currentTimer)
{
currentTimer = 0.0f;
screenID = (int)ScreenIDS.CAREER;
}
break;
case 9:
break;
case 10: //ScreenIDS.FREESURFMENU
GUI.Box (new Rect (0, 0, 480, 320), "", GameSkin.GetStyle("BoxPlay2"));
if(GUI.Button (new Rect (25, 240,98, 71), "",GameSkin.GetStyle("back")))
{
screenID = (int)ScreenIDS.MAINMENU;
}
if(GUI.Button (new Rect (140, 235,91, 75), "",GameSkin.GetStyle("ok")))
{
FSLEVEL = playerData.LoadPlayerLevelInfo();
//Debug.Log(" FSLEVEL = "+FSLEVEL);
screenID = (int)ScreenIDS.CHOOSEPLAYER;
}
}
So if You want to Download Full Code Then You Can Download if from Here
--
Vivek P Shah
Game Developer in Unity3d and Cocos2d
Have you tried searching for "MenuPackage for Unity" on google?
ReplyDeletey u say like this ??
ReplyDeleteI had develop menu using this code only ..!!
Tell me in detail ..
And ya u talking about that MenuPackage for unity is not available for free .. so i have make menu myself and i thought it is far batter ..
ReplyDeleteCan you show a screen shot of what this menu looks like?
ReplyDeleteAlso, does this code work on iOS devices? How do you use this? Do you just drag and drop onto a GameObject? Is this C#?
haz ne1 rly evar tryed to maek decided to be as far to even go wnat to do more like this menu?
ReplyDelete