首页 > 其他 > 详细

MainMenu

时间:2014-02-13 11:55:44      阅读:446      评论:0      收藏:0      [点我收藏+]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
using UnityEngine;
using System.Collections;
using System.Xml;
/// <summary>
/// 主菜单场景
/// </summary>
public class MainMenu : MonoBehaviour {
     
    Transform Werewolf;//狼人对象
    Animation wolfAnimation;//动画组件
    NavMeshAgent agent;//导航代理
    float stopDistance;//制动距离
    bool isNav;//是否开始导航
    BgMusic bgMusic;//背景音乐管理器
    string index;//读取存档索引
     
    #region 系统设置窗体组件
    Transform WinSetting;
    UIPopupList RunModeUI;
    UISlider SoundEffectsUI;
    UILabel SoundEffectsLabel;
    UISlider BgMusicUI;
    UILabel BgMusicLabel;
    UICheckbox JumpFontUI;
    UICheckbox TopInfoUI;
    UICheckbox WeatherSystemUI;
    #endregion
     
    #region 读取游戏窗体组件
    Transform WinLoad;
    Transform savePic;
    UILabel character;
    UILabel date;
    UILabel level;
    UILabel location;
    UILabel savenum;
    UILabel time;
    #endregion
     
    /// <summary>
    /// 初始化所有组件
    /// </summary>
    void Start () {
        //角色动画组件
        Werewolf = GameObject.Find("Werewolf").transform;
        wolfAnimation = Werewolf.animation;
        wolfAnimation.wrapMode = WrapMode.Loop;
        //导航组件
        agent = Werewolf.GetComponent<NavMeshAgent>();
        stopDistance = agent.stoppingDistance;
        //背景音乐组件
        bgMusic = GameObject.Find("MainUI").GetComponent<BgMusic>();
        BgMusic.PlayMusic("MainMenu");
        BgMusic.SetVolume(1f);
        //初始化窗体组件
        initSetting();
        initLoadUI();
    }
     
    /// <summary>
    /// 初始化系统设置窗体组件
    /// </summary>
    void initSetting(){
        WinSetting = GameObject.Find("Win_Setting").transform;
        RunModeUI = WinSetting.Find("Options/RunMode/Popup List").GetComponent<UIPopupList>();
        SoundEffectsUI = WinSetting.Find("Options/SoundEffects/Slider").GetComponent<UISlider>();
        SoundEffectsLabel = WinSetting.Find("Options/SoundEffects/Slider/Label").GetComponent<UILabel>();
        BgMusicUI = WinSetting.Find("Options/BgMusic/Slider").GetComponent<UISlider>();
        BgMusicLabel = WinSetting.Find("Options/BgMusic/Slider/Label").GetComponent<UILabel>();
        JumpFontUI = WinSetting.Find("Options/JumpFont").GetComponent<UICheckbox>();
        TopInfoUI = WinSetting.Find("Options/TopInfo").GetComponent<UICheckbox>();
        WeatherSystemUI = WinSetting.Find("Options/WeatherSystem").GetComponent<UICheckbox>();
         
        BgMusicUI.sliderValue = 0.5f;
        SoundEffectsUI.sliderValue = 0.5f;
        BgMusicLabel.text = (int)(BgMusicUI.sliderValue * 100) + "%";
        SoundEffectsLabel.text = (int)(SoundEffectsUI.sliderValue * 100) + "%";
        WinSetting.gameObject.SetActive(false);
    }
     
    /// <summary>
    /// 初始化读取游戏窗体组件
    /// </summary>
    public void initLoadUI(){
        WinLoad = GameObject.Find("MainUI/Camera/Anchor/Win_Load").transform;
        savePic = WinLoad.Find("Panel2/SavePic");
        character = WinLoad.Find("Panel2/Labels/character").GetComponent<UILabel>();
        date = WinLoad.Find("Panel2/Labels/date").GetComponent<UILabel>();
        level = WinLoad.Find("Panel2/Labels/level").GetComponent<UILabel>();
        location = WinLoad.Find("Panel2/Labels/location").GetComponent<UILabel>();
        savenum = WinLoad.Find("Panel2/Labels/savenum").GetComponent<UILabel>();
        time = WinLoad.Find("Panel2/Labels/time").GetComponent<UILabel>();
        WinLoad.gameObject.SetActive(false);
    }
     
    /// <summary>
    /// 到达摄像机前,播放动画后,开始游戏
    /// </summary>
    void Update () {
        float distance = agent.remainingDistance;
        if(isNav && distance != 0 && distance <= stopDistance){
            isNav = false;
            agent.Stop();
            wolfAnimation.wrapMode = WrapMode.Once;
            wolfAnimation.Play("Attack");
            StartCoroutine(delayStart());
        }
    }
     
    /// <summary>
    /// 开始延迟,跳转到角色选择场景
    /// </summary>
    IEnumerator delayStart(){
        yield return new WaitForSeconds(2f);
        Application.LoadLevel("Character");
    }
     
    #region 主菜单按钮事件
    /// <summary>
    /// 开始游戏事件
    /// </summary>
    public void StartGame(){
        wolfAnimation.Play("Walk");
        Vector3 dest = GameObject.Find("Main Camera").transform.position;
        agent.SetDestination(dest);
        isNav = true;
    }
     
    /// <summary>
    /// 打开系统设置窗体
    /// </summary>
    public void OpenSetting(){
        if(!WinSetting.gameObject.activeSelf){
            WinLoad.gameObject.SetActive(false);
            WinSetting.gameObject.SetActive(true);
        }else{
            WinSetting.gameObject.SetActive(false);
        }
    }
     
    /// <summary>
    /// 打开读取存档窗体
    /// </summary>
    public void OpenLoading(){
        if(!WinLoad.gameObject.activeSelf){
            WinLoad.gameObject.SetActive(true);
            WinSetting.gameObject.SetActive(false);
            clearRecord();
        }else{
            WinLoad.gameObject.SetActive(false);
        }
    }
     
    /// <summary>
    /// 退出游戏
    /// </summary>
    public void ExitGame(){
        Application.Quit();
    }
    #endregion
     
    #region 读取记录函数
    /// <summary>
    /// 读取存档记录,并显示到UI上
    /// </summary>
    void LoadRecord(string index){
        XmlNodeList recordList = Record.LoadRecord(index);
        if(recordList != null){
            this.index = index;
            string imageName = recordList.Item(1).InnerText;
            if(imageName != null && imageName.Length > 0){
                string path = "file://" + Application.dataPath + "/StreamingAssets/Xml/Persistence/Save/" + imageName + ".png";
                WWW www = new WWW(path);
                Texture image = www.texture;
                savePic.renderer.material.mainTexture = image;
                character.text = recordList.Item(2).InnerText;
                date.text = recordList.Item(3).InnerText;
                level.text = recordList.Item(4).InnerText;
                location.text = recordList.Item(5).InnerText;
                savenum.text = recordList.Item(6).InnerText;
                time.text = recordList.Item(7).InnerText;
            }else{
                clearRecord();
            }
        }
    }
     
    /// <summary>
    /// 选择记录,加载存档记录
    /// </summary>
    public void LoadGame(){
        if(index != null){
            Record.RecordName = index;
            PlayerPrefs.SetString("LevelName","LevelName");
            Application.LoadLevel("Load");
        }else{
            UIMessageBox.ShowMessage("请 选 择 有 效 的 存 档",3f);
        }
    }
     
    /// <summary>
    /// 清空UI存档记录
    /// </summary>
    public void clearRecord(){
        savePic.renderer.material.mainTexture = null;
        character.text = "";
        date.text = "";
        level.text = "";
        location.text = "";
        savenum.text = "";
        time.text = "";
        index = null;
    }
     
    public void LoadRecord1(){LoadRecord("01");}
    public void LoadRecord2(){LoadRecord("02");}
    public void LoadRecord3(){LoadRecord("03");}
    public void LoadRecord4(){LoadRecord("04");}
    public void LoadRecord5(){LoadRecord("05");}
    public void LoadRecord6(){LoadRecord("06");}
    public void LoadRecord7(){LoadRecord("07");}
    public void LoadRecord8(){LoadRecord("08");}
    #endregion
     
    #region 系统设置函数
    /// <summary>
    /// 保存系统设置
    /// </summary>
    public void SaveSetting(){
        Setting setting = new Setting();
        setting.TopInfoEff = TopInfoUI.isChecked;
        setting.JumpFontEff = JumpFontUI.isChecked;
        setting.WeatherEff = WeatherSystemUI.isChecked;
        setting.Window = (RunModeUI.selection == "Window");
        setting.BgMusicVolume = BgMusicUI.sliderValue;
        setting.SoundEffectsVolume = SoundEffectsUI.sliderValue;
        Persistence.Save("Setting",setting);
    }
     
    /// <summary>
    /// 设置背景音量
    /// </summary>
    public void SetVolumeBg(){
        if(BgMusicUI){
            float BgMusicVolume = BgMusicUI.sliderValue;
            BgMusicLabel.text = (int)(BgMusicVolume * 100) + "%";
            BgMusic.SetVolume(BgMusicVolume);
        }
    }
     
    /// <summary>
    /// 设置音效音量
    /// </summary>
    public void SetVolumeEff(){
        if(SoundEffectsUI)
            SoundEffectsLabel.text = (int)(SoundEffectsUI.sliderValue * 100) + "%";
    }
    #endregion
}

  

MainMenu

原文:http://www.cnblogs.com/xiao-wei-wei/p/3547349.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!