5393人加入学习
(4人评价)
Unity2D 棋牌游戏案例-狼人杀面杀APP(基于FairyGUI)

制作完成于2018年3月19日,基于Unity2017.2

价格 ¥ 291.00
该课程属于 Unity - A计划(永久有效期) 请加入后再学习

按钮点击音设置:

UIConfig.buttonSound = (NAudioClip)UIPackage.GetItemAssetByURL("ui://Res_Main/Tap");

[展开全文]

WolfPanel脚本

1.OnInitPanel函数添加

certainButton.onClick.Add(()=>{

controller.selectedIndex=2;

messageController.selectedIndex=2;

transition.Stop();

killTransition.Play(()=>{

killNumber.text=0.ToString();

AfterAction(UIPanelType.witchPanel);});});

2.HandleGameAction(UIPanelType currentGamePanelType){

if(currentGamePanelType==UIPanelType.WolfPanel){

ToCurrentPanel();transition.Play(-1,0,()=>{});

for((int i=0;i<contentPane.numChildren;i++){

for(int j=0;j<messageManager.deadPlayerNum.Count;j++)

{

if(contentPane.GetChildAt(i).group==numberButtons){GButton gButton=contentPane.GetChildAt(i).asButton;

if(gButton.title==messageManager.deadPlayerNum[j].ToString()){

gButton.grayed=true;gButton.touchable=false;}

}}}}}

[展开全文]

1.public override void HandleGameAciton(UIPanelType currentGamePanelType){if(currentGamePanelType==UIPanelType.WolfPanel){}else{if(nextPanel!null){

nextPanel.HandleGameAction(currentGamePanelType);}}}

2.protected override void OnInitPanel(){base.OnInitPanel();

killNumber=contentPane.GetChild("Tex_KillNumber").asTextField;

numberButtons=contentPane.GetChild("Group_KillNumber").asGroup;

transition=contentPane.GetTransition("t0");

killTransition=contentPane.GetTransition("t1");

for(int i=0;i<contentPane.numChildren;i++){

GButton gButton=contentPane.GetChildAt(i).asButton;

gButton.onClick.Add(()=>{

killNumber.text=gButton.title.ToString();messageManager.wolfKillNumber=System.Convert.ToInt32(gButton.title);});}}

 

[展开全文]

WolfPanel脚本

定义成员变量

GTextField killNumber,GGroup numberButtons,Transition killTransition

[展开全文]

完善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);}

[展开全文]

补充UIManager脚本

1.GameUIManager()

{isGameUIManager=true;

if(UIPanelDict.Count!=0){

ClearDict();}}

2.GamePanel文件夹添加脚本继承GameBasePanel

DayNigth,GuardPanel,Hunter,Prophet,Witch,Wolf;

[展开全文]

GameBasePanel补充

AfterAction(UIPanelType nextPanel){

if(!isDayNightPanel){

controller.selectedIndex=3;

messageController.selectedIndex=3;}

else{

controller.selectedIndex=8;}

ToNextPanel(nextPanel);}

ToNextPanel(UIPanelType nextPanel){

if(!isDayNightPanel){

closeEye.visible=true;

if(firstTimeInThisPanel){

firstTimeInThisPanel=false;

closeEye.onPlayEnd.Add(()=>{ToOtherPanel(nextType);

closeEye.visibl=false;});}

closeEye.SetPlaySettings(1,9,1,9);

closeEye.Playing=true;}

else{

Transition ToNight=contentPane.GetTransition("ToNight");

ToNight.play(()=>{ToOtherPanel(nextType);});}}

[展开全文]

1.GameBasePanel脚本

在构造方法中,加入

messageManager=GameManager.Instance.messageManager;

if(uiPanelType==UIPanelType.DayNightPanel){isDayNightPanel=true;}

2.OnInitPanel方法

if(!isDayNightPanel){

openAnimCom,closeAnimCom,openEye,closeEye,certainButton获取

}

guideMessage,messageController,controller

3.public virtual void HandleGameAction(UIPanelType currentGamePanelType){}

4.public virtual void ToCurrentPanel()

{controller.selectedIndex=0;

messageController.selectedIndex=0;

openEye.visible=true;

closeEye.visible=false;

openEye.SetPlaySettings(1,16,1,1);

openEye.playing=true;

if(firstTimeInThisPanel)

{openEye.onPlayEnd.Add(()=>{controller.selectedIndex=1;messageController.selectedIndex=1;openEye.visible=false;})}

}

[展开全文]

1.Game场景调整Camera设置

2.定义GameBasePanel脚本

protected GComponent openAnimCom,closeAnimCom,guideMessage,

GMovieClip openEye,closeEye

bool firstTimeInThisPanel,isDayNightPanel;

protected GameBasePanel nextPanel;

GameBasePanel SetNextPanel(GameBasePanel nextGamePanel){nextPanel=nextGamePanel;return nextPanel;}

protected Controller messageController,MessageManager messageManager,GButton certainButton;

[展开全文]

1.卡牌翻转效果Turn();

private void Turn()
    {
        if (DOTween.IsTweening(cardButton))
        {
            return;
        }
        toOpen = !toOpen;
        DOTween.To(() => 0, x => 
        {
            if (toOpen)
            {
                cardBack.rotationY = x;
                cardFront.rotationY = -180 + x;
                if (x > 90)
                {
                    cardBack.visible = true;
                    cardFront.visible = false;
                }
            }
            else
            {
                cardBack.rotationY = -180 + x;
                cardFront.rotationY =  x;
                if (x > 90)
                {
                    cardBack.visible = false;
                    cardFront.visible = true;
                }
            }
        }, 180, 0.5f).SetTarget(cardButton).SetEase(Ease.OutQuad);
    }

 

[展开全文]

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.定义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

 

 

[展开全文]

HelpPanel脚本

1.ShowIDInformation(int id)函数

 

[展开全文]

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();});

[展开全文]

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();

}

[展开全文]

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。

[展开全文]

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()

}

[展开全文]

1.UIPanel文件夹下建立文件夹GamePanel和MainPanel;

2.创建BasePanel并引入FairyGUI,继承自Window。

3.创建GamePanel,MainPanel,HelpPanel,SetPanel脚本,并都继承自BasePanel。

[展开全文]

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.那么游戏继续
 

[展开全文]

授课教师

SiKi学院老师

课程特色

视频(97)
下载资料(1)

学员动态

Stormthra 加入学习
史家桐 加入学习
yuanpeng 加入学习
Leo2002 加入学习
123hai 加入学习