unity战斗卡牌视频教程 第九课 – 数据模型 及 好友模块

前言

我不说话。我只是发个图片而已

2

 

1

 视频长度:58分钟

教程下载地址

系列教程目录汇总:http://www.bobsong.net/886.html

脚本代码

好友场景

using UnityEngine;
using System.Collections;

public class SceneFriends : SceneBase
{
    #region 界面加载相关
    protected override void OnInitFront()
    {
        base.OnInitFront();
        _type = SceneType.SceneFriends;
    }
    protected override void OnInitSkinFront()
    {
        base.OnInitSkinFront();
        SetMainSkinPath("Game/Friends/SceneFriends");
    }
    protected override void OnInitDone()
    {
        base.OnInitDone();
        InitData();

    }
    protected override void OnDestroyDone()
    {
        base.OnDestroyDone();

    }
    protected override void OnDestroyFront()
    {
        base.OnDestroyFront();
        
    }
    protected override void OnClick(GameObject target)
    {
        base.OnClick(target);
        ButtonClick(target);
    }

    public override void OnInit(params object[] sceneArgs)
    {
        base.OnInit(sceneArgs);
    }
    public override void OnShowed()
    {
        base.OnShowed();

    }
    #endregion

    #region 数据定义
    private GameObject mItem;
    private GameObject mBtnFriends;
    private GameObject mBtnInfo;
    private GameObject mBtnFind;
    private GameObject mNowClickButon;
    private UIInput mInputFriendID;
    private UILabel mContent;
    #endregion

    #region UI逻辑

    void InitData()
    {
        mBtnFriends = skinTransform.Find("Back/BtnFriends").gameObject;
        mBtnInfo = skinTransform.Find("Back/BtnInfo").gameObject;
        mBtnFind = skinTransform.Find("Back/BtnFind").gameObject;
        mInputFriendID = skinTransform.Find("Back/InputFriendID").GetComponent<UIInput>();
        mContent = skinTransform.Find("Back/Content").GetComponent<UILabel>();

        mNowClickButon = mBtnFriends;
    }

    #endregion

    #region 点击事件

    void ButtonClick(GameObject click)
    {
        if(click.name.Equals("BtnFriends"))
        {
            SwitchButtonType(click,2);
        }
        else if (click.name.Equals("BtnInfo"))
        {
            SwitchButtonType(click,2);
        }
        else if (click.name.Equals("BtnFind"))
        {
            SwitchButtonType(click,3);
        }
    }


    void SwitchButtonType(GameObject click,int type)
    {
        GameObject sprite = click.transform.Find("Sprite").gameObject;
        BoxCollider box = click.GetComponent<BoxCollider>();
        sprite.SetActive(true);
        box.enabled = false;

        sprite = mNowClickButon.transform.Find("Sprite").gameObject;
        box = mNowClickButon.GetComponent<BoxCollider>();
        sprite.SetActive(false);
        box.enabled = true;

        mNowClickButon = click;

        if(type == 3)
        {
            mContent.gameObject.SetActive(false);
            mInputFriendID.gameObject.SetActive(true);
        }
        else if(type == 2)
        {
            mContent.gameObject.SetActive(true);
            mInputFriendID.gameObject.SetActive(false);
            mContent.text = "这是显示想要加你为好友的玩家!";
        }
        else
        {
            mContent.gameObject.SetActive(true);
            mInputFriendID.gameObject.SetActive(false);
            mContent.text = "结交好友,互赠体力,还可获得成就奖励呢!";
        }

    }
    #endregion

    #region 服务器返回
    #endregion
}

好友列表服务器脚本

using GameServer.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZyGames.Framework.Cache.Generic;
using ZyGames.Framework.Game.Cache;
using ZyGames.Framework.Game.Contract.Action;
using ZyGames.Framework.Game.Service;
using ZyGames.Framework.Common;
using ZyGames.Framework.Net;

namespace GameServer.CsScript.Action
{

    /// <summary>
    /// 可添加好友列表
    /// </summary>
    /// <remarks>继续BaseStruct类:允许无身份认证的请求;AuthorizeAction:需要身份认证的请求</remarks>
    public class Action9102 : AuthorizeAction
    {
        /// <summary>
        /// 
        /// </summary>
        private int _pageIndex;
        /// <summary>
        /// 
        /// </summary>
        private int _pageSize;
        /// <summary>
        /// 
        /// </summary>
        private int _pageCount;
        /// <summary>
        /// 
        /// </summary>
        private List<UserProInfo> gameUserList = new List<UserProInfo>();


        public Action9102(ActionGetter actionGetter)
            : base((short)9102, actionGetter)
        {

        }

        /// <summary>
        /// 检查的Action是否需要授权访问
        /// </summary>
        protected override bool IgnoreActionId
        {
            get { return true; }
        }

        /// <summary>
        /// 客户端请求的参数较验
        /// </summary>
        /// <returns>false:中断后面的方式执行并返回Error</returns>
        public override bool GetUrlElement()
        {
            if (httpGet.GetInt("PageIndex", ref _pageIndex)
                && httpGet.GetInt("PageSize", ref _pageSize))
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 业务逻辑处理
        /// </summary>
        /// <returns>false:中断后面的方式执行并返回Error</returns>
        public override bool TakeAction()
        {
            //List<GameUser> friendArray = new List<GameUser>();

            GameUser gameuser = PersonalCacheStruct.Get<GameUser>(Current.UserId.ToString());

            List<UserProInfo> userFriendsesArray = new ShareCacheStruct<UserProInfo>().FindAll(m => m.Lv == gameuser.Lv);


            gameUserList = userFriendsesArray.GetPaging(_pageIndex, _pageSize, out _pageCount);


            return true;
        }

        /// <summary>
        /// 下发给客户的包结构数据
        /// </summary>
        public override void BuildPacket()
        {
            this.PushIntoStack(_pageCount);
            this.PushIntoStack(gameUserList.Count);
            foreach (var item in gameUserList)
            {
                DataStruct dsItem = new DataStruct();
                dsItem.PushIntoStack(item.UserID);
                dsItem.PushIntoStack(item.NickName);
                dsItem.PushIntoStack(item.Sex);
                dsItem.PushIntoStack(item.Lv);
                dsItem.PushIntoStack(item.LoginTime);
                this.PushIntoStack(dsItem);
            }

        }

    }
}

 

 

 

 

本文链接:

https://www.bobsong.net/933.html
1 + 4 =
快来做第一个评论的人吧~