补充UIManager脚本
1.GameUIManager()
{isGameUIManager=true;
if(UIPanelDict.Count!=0){
ClearDict();}}
2.GamePanel文件夹添加脚本继承GameBasePanel
DayNigth,GuardPanel,Hunter,Prophet,Witch,Wolf;
补充UIManager脚本
1.GameUIManager()
{isGameUIManager=true;
if(UIPanelDict.Count!=0){
ClearDict();}}
2.GamePanel文件夹添加脚本继承GameBasePanel
DayNigth,GuardPanel,Hunter,Prophet,Witch,Wolf;
完善UIManager
1.GameUIManager()
定义GameBasePanel
dayNightPanel,wolfPanel,guardPanel,witchPanel,prophetPanel,hunterPanel
完善任务链wolfPanel.SetNextPanel(witchPanel).SetNextPanel(prophetPanel).SetNextPanel(hunterPanel).SetNextPanel(defenderPanel).SetNextPanel(dayNightPanel).SetNextPanel(wolfPanel);
字典添加界面内容
UIPanelDict[UIPanelTypeWolfPanel].Show();
GameBasePanel firstPanel=UIPanelDict[UIPanelType.WolfPanel] as GameBasePanel;
firstPanel.EnterPanel();
firstPanel.HandleGameAcition(UIPanel.WolfPanel);
2.BasePanel()
ChangePanelCallBack(UIPanelType otherPanel)函数增加
if(uiManager.isGameUIManager){
GameBasePanel nextPanel=uiManager.UIPanelDict[otherPanel] as GameBasePanel;
nextPanel.HandleGameAction(otherPanel);}
1.GameJudgement方法,返回GameJudgementState;
4神民 4村民 4匹狼
4神民4个int 数
4存民4狼人分别为2个数组
死亡列表,存放所有的死亡玩家
我们有一个判定列表,专门用来判定游戏的
游戏判定的方法:
//狼人是否团灭
1.需要定义一个数作为标杆num(根据它的值来进行游戏的判定)
2.我们要把当前死亡列表里的号码放进判定表列(那是因为我们判定列表每次都要清空,进行更改操作)
3.我们需要定义一个移除列表
4.两个for循环嵌套遍历的方法,来比较当前死亡列表里的int数与狼人数组里的4个数,相等的有几个。
5.如果相等,则num++;把相等的数加入移除列表。
6.如果num==4,那么好人获胜。
//神民是否团灭
7.执行上边的方法
8.num是否等于4,如果等于,那么狼人获胜。
//神民是否团灭
9.判定列表的长度是否等于4.
10.如果是,那么狼人获胜
11.那么游戏继续
1.UIPanel文件夹下建立文件夹GamePanel和MainPanel;
2.创建BasePanel并引入FairyGUI,继承自Window。
3.创建GamePanel,MainPanel,HelpPanel,SetPanel脚本,并都继承自BasePanel。
1.定义BasePanel内所含变量;
protected string packageName,Transition transition,Controller controller,GComponent panelMask,UIPanelType currentUIPanelType,UIManager uiManager;
2.BasePanel构造函数;
public BasePanel(string packageName,UIPanelType uiPanelType,UIManager uiManager)
{this.packageName=packageName;
currentUIPanelType=uiPanelType;
this.uiManager=uiManager;
UIPackage.AddPackage("UI/"+packageName);
}
3.protected override void OnInit()
{contentPanel=UIPackage.CreateObject(packageName,"Main").asCom;
panelMask=this.contentPanel.GetChild("PanelMask").asCom
OnInitPanel()
4.protected virtual void OnInitPanel()
}
按钮点击音设置:
UIConfig.buttonSound = (NAudioClip)UIPackage.GetItemAssetByURL("ui://Res_Main/Tap");
1.UIManager函数定义
bool isGameUIManager;
UIPanelType currentGamePanel;
2.建立字典Dictionary<UIPanelType,BasePanel> UIPanelDict;
构造UIManager时,实例化UIPanelDict=new Dictionary<UIPanelType,BasePanel>();
3.当切换菜单场景和游戏场景时,需要清空字典
ClearDict(){
foreach(var item in UIPanelDict)
{
item.Value.Dispose();}
UIPanelDict.Clear();
}
4.创建GameUIManager和MainUIManager函数,
public void MainUIManager(){
isGameUIManager=false;
if(UIPanelDict.Count!=0){
ClearDict();}
UIPanelDict.Add(UIPanelType.MainPanel,newMainPanel("Panel_Main",UIPanelType.MainPanel,this));
UIPanelDict.Add(UIPanelType.GamePanel,new GamePanel("Panel_Game",UIPanelType.GamePanel,this));
UIPanelDict.Add(UIPanelType.HelpPanel,new HelpPanel("Panel_Help",UIPanelType.HelpPanel,this));
UIPanelDict.Add(UIPanelType.SetPanel,new SetPanel("Panel_Set",UIPanelType.SetPanel,this));
UIPanelDict[UIPanelType.MainPanel].Show();
}
5.GameManager构建UImanager时调用MainUIManager。
BasePanel脚本 进入 退出 跳转功能
1.创建EnterPanel(){
Transition t=panelMask.GetTransition(“MaskShow”);
t.play();}
2.创建protected void ToOtherPanel(UIPanelType otherType){
ExitPanel(()=>{ChangePanelCallback(otherType)});}
3.创建Protected void ExitPanel(PlayCompleteCallback playCompleteCallback){
Transition t=panelMask.GetTransition(“MaskHide”);
t.play(playCompleteCallback);
}
4.protected void ChangePanelCallback(UIPanelType otherType){
uiManager.UIPanelDict[currentUIPanelType].Hide();
uiManager.UIPanelDict[otherType].Show();
uiManager.UIPanelDict[otherType].EnterPanel();
}
MainPanel脚本重写OnInitPanel方法。
transition=contentPane.GetTransition("WhiteMaskAnim");
transition.Play();
Transition t=panelMask.GetTransition("MaskShow");
t.play();
contentPane.GetChild("Btn_StartGame").OnClick.Add(()=>{ToOtherPanel(UIPanelType.GamePanel);
GameManager.Instance.audioSourceManager.ChangeBGM(1);});
contentPane.GetChild("Btn_Help").OnClick.Add(()=>{ToOtherPanel(UIPanelType.HelpPanel);});
contentPane.GetChild("Btn_Set").OnClick.Add(()=>{ToOtherPanel(UIPanelType.SetPanel);});
contentPane.GetChild("Btn_ExitGame").OnClick.Add(()=>{Application.Quit();});
1.在Script下创建分类文件夹,manager和UIpanel。
2.创建AudioSourcesManager,MessageManager,UIManager,UIPanelType脚本。
3.UIPanelType枚举MainPanel,GamePanel,HelpPanel,SetPanel,DayNightPanel,WolfPanel,WitchPanel,ProphetPanel,HunterPanel,GuardPanel。
4.理解从FairyGUI导入的资源的加载顺序,应按资源-组件-面板的顺序加载。
HelpPanel脚本
1.ShowIDInformation(int id)函数
1.在GameManager中,定义AudioSourcesManager(AudioSource,AudioClip[]),MessageManager,UIManager(主界面和游戏中,共2种情况,用bool来区分),并赋值。
2.在GameManager上挂载AudioSource,拖入AudioClip.
1.定义GamePanel成员变量
transition star,loadAnim;GButton cardButton;GObject cardFront,cardBack;GComponent guideMessage;Controller messageController;GTextField tex_Number,tex_ID;bool toOpen=true;
2.1-4为狼,5-8为民,9预言家,10女巫,11猎人,12守卫
int[] RandomList=new in[12];bool isTheSame;int index,wolfIndex,villagersIndex
1.在GameManager脚本的Awake中添加DontDestroyOnLoad(this.gameObject)。
2.加载资源包UIPackage.AddPackage("UI/Res_Main");
UIPackage.AddPackage("UI/Res_Game");
UIPackage.AddPackage("UI/Res_Component");
3.在unity内文件夹FONT下导入汉仪南宫体字体。
UIConfig.defaultFont="汉仪南宫体简";
4.设置屏幕自适应:GRoot.inst.SetContentScaleFactor(1600,900,UIContentScaler.ScreenMatchMode.MatchWidthOrHeight);
5.在Awake中实例化UIManager,AudioSourceManager,MessageManager。
1.GamePanel脚本内变量赋值。
2.ShuffleTheCard(){
int count=0;
while(count<12){
int r=Random.range(1,13);
for(int i=0;i<randomList.Length;i++){
if(randomList[i]==r){
isTheSame=true;
break;
}
}
if(!isTheSame){
randomList[count]=r;
count++;}
isTheSame=false;
}
}
3.定义RotateCard()方法
1.AudioSourceManager脚本编写,构造时传递GameManager;
2.ChangeVolume脚本,控制音量。
3.ChangeBGM脚本,切换及播放声音。
4.StopPlay脚本,停止播放。
MessageManager脚本编写。
1.创建枚举DieType(Zero,One,Two)和GameJudgementState(VillagerWin,WolfWin,GoOn);
2.创建列表存储死亡玩家,List<int> deadPlayerNum;
3.本场游戏对应身份的玩家号码:
int[] wolves,int[] villagers;
int defender,hunter,prophet,witch;
4.操作对象与状态
int wolfKillNumber,witchKillNumber,defendNumber,lastDieNumberOne,lastDieNumberTwo,
bool
canShoot,canSave,canKill,hasSave
5.游戏判定列表
List<int> judgeList
1.初始化方法InitMessage,数据清零。
deadPlayerNum.Clear();
wolves,villagers,defender,hunter,prophet,witch,canShoot=true,canSave=true,canKill=true,InitAction();
2.初始化方法InitAction,行动清零。
hasSave=false,wolfKillNumber,witchKillNumber,defendNumber
1.JudgementOfDeath脚本,返回DieType
GamePanel脚本
RotateCard方法完善