博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【转】Unity3.5 GameCenter基础教程
阅读量:5240 次
发布时间:2019-06-14

本文共 3438 字,大约阅读时间需要 11 分钟。

  1.  
  2. using UnityEngine;
  3. using UnityEngine.
    SocialPlatforms;
  4.  
  5. public
    class Startup :
  6. {
  7.   
    // we'll create some buttons in OnGui, allowing us to bump achievement and
  8.   
    // score values for testing
  9.   
  10.   
    private
    double ach1 =
    0;
  11.   
    private
    double ach2 =
    0;
  12.   
    private
    double ach3 =
    0;
  13.   
    private
    double ach4 =
    0;
  14.   
  15.   
    private
    long score1 =
    1000;
  16.   
    private
    long score2 =
    200;
  17.   
  18.   
    private
    int buttonWidth =
    120;
  19.   
    private
    int buttonHeight =
    50;
  20.   
    private
    int buttonGap =
    10;
  21.   
  22.   
    void
    (
    )
  23.   
    {
  24.      . .
    (HandleAuthenticated
    );
  25.   
    }
  26.   
  27.   
    // authentication
  28.   
  29.   
    private
    void HandleAuthenticated
    (
    bool
    )
  30.   
    {
  31.      .
    (
    "*** HandleAuthenticated: success = " +
    );
  32.     
    if
    (
    )
    {
  33.        . .
    (HandleFriendsLoaded
    );
  34.        .
    (HandleAchievementsLoaded
    );
  35.        .
    (HandleAchievementDescriptionsLoaded
    );
  36.     
    }
  37.   
    }
  38.   
  39.   
    private
    void HandleFriendsLoaded
    (
    bool
    )
  40.   
    {
  41.      .
    (
    "*** HandleFriendsLoaded: success = " +
    );
  42.     
    foreach
    ( friend
    in . .
    )
    {
  43.        .
    (
    "*   friend = " + friend.
    (
    )
    );
  44.     
    }
  45.   
    }
  46.   
  47.   
    private
    void HandleAchievementsLoaded
    (
    [
    ] achievements
    )
  48.   
    {
  49.      .
    (
    "*** HandleAchievementsLoaded"
    );
  50.     
    foreach
    ( achievement
    in achievements
    )
    {
  51.        .
    (
    "*   achievement = " + achievement.
    (
    )
    );
  52.     
    }
  53.   
    }
  54.   
  55.   
    private
    void HandleAchievementDescriptionsLoaded
    (
    [
    ] achievementDescriptions
    )
  56.   
    {
  57.      .
    (
    "*** HandleAchievementDescriptionsLoaded"
    );
  58.     
    foreach
    ( achievementDescription
    in achievementDescriptions
    )
    {
  59.        .
    (
    "*   achievementDescription = " + achievementDescription.
    (
    )
    );
  60.     
    }
  61.   
    }
  62.   
  63.   
    // achievements
  64.   
  65.   
    public
    void
    (
    string achievementId,
    double
    )
  66.   
    {
  67.     
    if
    ( . .
    )
    {
  68.        .
    (achievementId, , HandleProgressReported
    );
  69.     
    }
  70.   
    }
  71.   
  72.   
    private
    void HandleProgressReported
    (
    bool
    )
  73.   
    {
  74.      .
    (
    "*** HandleProgressReported: success = " +
    );
  75.   
    }
  76.   
  77.   
    public
    void ShowAchievements
    (
    )
  78.   
    {
  79.     
    if
    ( . .
    )
    {
  80.        .
    (
    );
  81.     
    }
  82.   
    }
  83.   
  84.   
    // leaderboard
  85.   
  86.   
    public
    void
    (
    string leaderboardId,
    long score
    )
  87.   
    {
  88.     
    if
    ( . .
    )
    {
  89.        .
    (score, leaderboardId, HandleScoreReported
    );
  90.     
    }
  91.   
    }
  92.   
  93.   
    public
    void HandleScoreReported
    (
    bool
    )
  94.   
    {
  95.      .
    (
    "*** HandleScoreReported: success = " +
    );
  96.   
    }
  97.   
  98.   
    public
    void ShowLeaderboard
    (
    )
  99.   
    {
  100.     
    if
    ( . .
    )
    {
  101.        .
    (
    );
  102.     
    }
  103.   
    }
  104.   
  105.   
    // gui
  106.   
  107.   
    public
    void
    (
    )
  108.   
    {
  109.     
    // four buttons, allowing us to bump and test setting achievements
  110.     
    int yDelta = buttonGap;
  111.     
    if
    ( .
    (
    new
    (buttonGap, yDelta, buttonWidth, buttonHeight
    ),
    "Ach 1"
    )
    )
    {
  112.       
    (
    "A0001", ach1
    );
  113.       ach1 =
    (ach1 ==
    100
    ) ?
    0 : ach1 +
    10;
  114.     
    }
  115.     yDelta += buttonHeight + buttonGap;
  116.     
    if
    ( .
    (
    new
    (buttonGap, yDelta, buttonWidth, buttonHeight
    ),
    "Ach 2"
    )
    )
    {
  117.       
    (
    "A0002", ach2
    );
  118.       ach2 =
    (ach2 ==
    100
    ) ?
    0 : ach2 +
    10;
  119.     
    }
  120.     yDelta += buttonHeight + buttonGap;
  121.     
    if
    ( .
    (
    new
    (buttonGap, yDelta, buttonWidth, buttonHeight
    ),
    "Ach 3"
    )
    )
    {
  122.       
    (
    "A0003", ach3
    );
  123.       ach3 =
    (ach3 ==
    100
    ) ?
    0 : ach3 +
    10;
  124.     
    }
  125.     yDelta += buttonHeight + buttonGap;
  126.     
    if
    ( .
    (
    new
    (buttonGap, yDelta, buttonWidth, buttonHeight
    ),
    "Ach 4"
    )
    )
    {
  127.       
    (
    "A0004", ach4
    );
  128.       ach4 =
    (ach4 ==
    100
    ) ?
    0 : ach4 +
    10;
  129.     
    }
  130.     
    // show achievements
  131.     yDelta += buttonHeight + buttonGap;
  132.     
    if
    ( .
    (
    new
    (buttonGap, yDelta, buttonWidth, buttonHeight
    ),
    "Show Achievements"
    )
    )
    {
  133.       ShowAchievements
    (
    );
  134.     
    }
  135.     
  136.     
    // two buttons, allowing us to bump and test setting high scores
  137.     
    int xDelta = .
    width - buttonWidth - buttonGap;
  138.     yDelta = buttonGap;
  139.     
    if
    ( .
    (
    new
    (xDelta, yDelta, buttonWidth, buttonHeight
    ),
    "Score 1"
    )
    )
    {
  140.       
    (
    "L01", score1
    );
  141.       score1 +=
    500;
  142.     
    }
  143.     yDelta += buttonHeight + buttonGap;
  144.     
    if
    ( .
    (
    new
    (xDelta, yDelta, buttonWidth, buttonHeight
    ),
    "Score 2"
    )
    )
    {
  145.       
    (
    "L02", score2
    );
  146.       score2 +=
    100;
  147.     
    }
  148.     
    // show leaderboard
  149.     yDelta += buttonHeight + buttonGap;
  150.     
    if
    ( .
    (
    new
    (xDelta, yDelta, buttonWidth, buttonHeight
    ),
    "Show Leaderboard"
    )
    )
    {
  151.       ShowLeaderboard
    (
    );
  152.     
    }
  153.   
    }
  154. }

转载于:https://www.cnblogs.com/U-tansuo/archive/2012/07/11/GameCenter.html

你可能感兴趣的文章
flash游戏服务器安全策略
查看>>
Eurekalog
查看>>
LeetCode--169--求众数
查看>>
Copy 函数
查看>>
Android服务之Service(其一)
查看>>
网站sqlserver提权操作
查看>>
javascript之聊天室(单机)来自于冷的锋刃
查看>>
3ds max 转换文件格式插件开发
查看>>
PHP变量作用域以及地址引用问题
查看>>
实验四
查看>>
网站迁移时候,发现<head>内容都到body里了
查看>>
Elastic Stack-Elasticsearch使用介绍(三)
查看>>
MacOS copy图标shell脚本
查看>>
怎么打包谷歌商店安装的文件?
查看>>
C陷阱与缺陷--读书笔记7 可移植性缺陷
查看>>
【索引】gtest学习笔记
查看>>
vue-随笔-transition
查看>>
第八章 方法
查看>>
web调用客户端程序
查看>>
IIS项目发布完整流程
查看>>