Unity 3D功能主界面C#脚本
来源:互联网 发布:梦幻2卖号网络异常 编辑:程序博客网 时间:2024/06/15 11:00
实现点击按钮进入该功能场景中,点击音乐播放器自动弹出window窗体,并实现音乐的播放和停止的切换、音量大小滚动条、音乐播放上一曲和下一曲的切换。
using UnityEngine;
using System.Collections;
public class HomePage : MonoBehaviour {
//功能按钮
public Texture2D angryBird;
public Texture2D musicBtn;
public Texture2D DrawBool;
public Texture2D vediobtn;
public Texture2D quitbtn;
//歌手图片
public Texture[] photos;
//定义播放器按钮点击次数
protected int i = 0;
//定义是否点击音频播放器按钮,显示音乐播放器winform
public bool result=false;
//音乐播放器功能按钮
public Texture2D musicVolumeSize;
public Texture2D MusicStartorStop;
public Texture2D MusicStart;
public Texture2D MusicStop;
public Texture2D MusicPause;
public Texture2D MusicUp;
public Texture2D MusicNext;
public Texture2D MusicLoop;
//音量
public float musicVolume;
//中文字体
public GUISkin ChineseSkin;
//音频文件
public AudioSource[] MyAudio;
//歌曲名称
public string[] SongNames;
//当前歌曲编号
public string[] SongerNames;
//当前歌曲编号
int SongIndex = 0;
//设定是否循环
bool LoopPlay = true;
//Use this for initialization
voidStart () {
//设置默认音量
musicVolume = 0.5F;
}
//Update is called once per frame
voidUpdate () {
}
void OnGUI() {
//游戏按钮
GUI.TextArea(new Rect(Screen.width * 0.13f, Screen.height * 0.15f,Screen.width * 0.12f, Screen.height * 0.04f), "奋斗的小鸟");
if (GUI.Button(new Rect(Screen.width * 0.1f, Screen.height * 0.2f,Screen.width * 0.18f, Screen.height * 0.18f), angryBird))
{
Application.LoadLevel("welcome");
}
//播放器按钮
GUI.TextArea(new Rect(Screen.width * 0.33f, Screen.height * 0.15f,Screen.width * 0.12f, Screen.height * 0.04f), "音频播放器");
if (GUI.Button(new Rect(Screen.width * 0.3f, Screen.height * 0.2f,Screen.width * 0.18f, Screen.height * 0.18f), musicBtn))
{
result = true;
//Application.LoadLevel("vedio");
}
//window播放器出现
if (result==true)
{
GUI.Window(0, new Rect(Screen.width *0.3f, Screen.height * 0.4f, Screen.width * 0.37f, Screen.height * 0.57f),function1, "我的音乐盒");
}
//涂鸦按钮
GUI.TextArea(new Rect(Screen.width * 0.73f, Screen.height * 0.15f, Screen.width* 0.12f, Screen.height * 0.04f), "涂鸦工具");
if (GUI.Button(new Rect(Screen.width * 0.7f, Screen.height * 0.2f,Screen.width * 0.18f, Screen.height * 0.18f), DrawBool))
{
Application.LoadLevel("DrawTool");
}
//视频播放器按钮
GUI.TextArea(new Rect(Screen.width * 0.53f, Screen.height * 0.15f,Screen.width * 0.12f, Screen.height * 0.04f), "视频播放器");
if (GUI.Button(new Rect(Screen.width * 0.5f, Screen.height * 0.2f,Screen.width * 0.18f, Screen.height * 0.18f), vediobtn))
{
Application.LoadLevel("vedioPlayer");
}
//返回按钮
//GUI.TextArea(new Rect(Screen.width * 0.84f, Screen.height * 0.3f,Screen.width * 0.05f, Screen.height * 0.04f), "返回");
if (GUI.Button(new Rect(Screen.width * 0.94f, Screen.height * 0.05f,Screen.width * 0.05f, Screen.height * 0.08f), quitbtn))
{
Application.LoadLevel("Background");
}
}
void function1(int mywindow){
GUI.skin = ChineseSkin;
//创建一个用于动态修改音乐音量的横向滑动条
musicVolume = GUI.VerticalScrollbar(new Rect(Screen.width * 0.04f,Screen.height * 0.21f, Screen.width * 0.18f, Screen.height * 0.18f),musicVolume, 0.01F, 1.0F, 0.0F);
//音量图标
GUI.Label(new Rect(Screen.width * 0.04f, Screen.height * 0.395f,Screen.width * 0.05f, Screen.height * 0.05f), musicVolumeSize);
//将音量的百分比显示出来
GUI.Label(new Rect(Screen.width * 0.005f, Screen.height * 0.16f,Screen.width * 0.3f, Screen.height * 0.05f), "当前音量:" +(int)(musicVolume * 100) + "%");
if (MyAudio[SongIndex].isPlaying)
{
MyAudio[SongIndex].volume = musicVolume;
}
//歌手图片
GUI.DrawTexture(new Rect(Screen.width * 0.14f, Screen.height * 0.04f,Screen.width * 0.225f, Screen.height * 0.455f), photos[SongIndex]);
if (GUI.Button(new Rect(Screen.width * 0.08f, Screen.height * 0.5f,Screen.width * 0.05f, Screen.height * 0.05f), MusicStartorStop))
{
i++;
if (i%2==1)
{
MyAudio[SongIndex].Play();
MusicStartorStop = MusicPause;
}
else
{
MyAudio[SongIndex].Stop();
MusicStartorStop =MusicStart;
}
}
if (GUI.Button(new Rect(Screen.width * 0.02f, Screen.height * 0.5f,Screen.width * 0.05f, Screen.height * 0.05f), MusicUp))
{
///方法一:停止播放当前音乐
//for (int i = 0; i < MyAudio.Length; i++)
//{
// if (MyAudio[i].isPlaying)
// {
// MyAudio[i].Stop();
// }
//}
//方法二:停止当前播放音乐
if (MyAudio[SongIndex].isPlaying)
{
MyAudio[SongIndex].Stop();
//上一曲
if (SongIndex > 0)
SongIndex--;
else if (LoopPlay)
SongIndex = MyAudio.Length- 1;
//播放当前音乐
MyAudio[SongIndex].Play();
}
else
{
if (SongIndex > 0)
SongIndex--;
else if (LoopPlay)
SongIndex = MyAudio.Length- 1;
//播放当前音乐
MyAudio[SongIndex].Stop();
}
}
if (GUI.Button(new Rect(Screen.width * 0.14f, Screen.height * 0.5f,Screen.width * 0.05f, Screen.height * 0.05f), MusicNext))
{
//方法一:停止播放当前音乐
//for (int i = 0; i < MyAudio.Length; i++)
//{
// if (MyAudio[i].isPlaying)
// {
// MyAudio[i].Stop();
// }
//}
//方法二:停止当前播放音乐
if (MyAudio[SongIndex].isPlaying)
{
MyAudio[SongIndex].Stop();
//下一曲
if (SongIndex <MyAudio.Length - 1)
SongIndex++;
else if (LoopPlay)
SongIndex = 0;
//播放当前音乐
MyAudio[SongIndex].Play();
}
else
{
//下一曲
if (SongIndex < MyAudio.Length- 1)
SongIndex++;
else if (LoopPlay)
SongIndex = 0;
//播放当前音乐
MyAudio[SongIndex].Stop();
}
}
//选择是否进行循环
GUI.contentColor = Color.white;
LoopPlay = GUI.Toggle(new Rect(Screen.width * 0.015f, Screen.height *0.45f, Screen.width * 0.05f, Screen.height * 0.05f), LoopPlay, MusicLoop);
GUI.Label(new Rect(Screen.width * 0.065f, Screen.height * 0.46f,Screen.width * 0.1f, Screen.height * 0.1f),"循环");
string[] mymusic = MyAudio[SongIndex].name.Split('-');
//显示当前歌手和歌曲名称
GUI.Label(new Rect(Screen.width * 0.04f, Screen.height * 0.06f,Screen.width * 0.1f, Screen.height * 0.2f), mymusic[0]);
GUI.Label(new Rect(Screen.width * 0.03f, Screen.height * 0.1f,Screen.width * 0.1f, Screen.height * 0.2f), mymusic[1]);
}
}
- Unity 3D功能主界面C#脚本
- unity 3D登录界面C#脚本
- Unity 3d C#脚本(1)
- Unity 3D Coroutine&yield(C#脚本)
- Unity 3D视频播放器场景C#脚本
- [记录属性]unity 3D c#脚本语句集1
- Unity 3D 脚本参考
- Unity 3d 常用脚本
- Unity 3D中的界面快捷键
- Unity 3d中导入c#脚本时出现 can't add script 如何解决
- unity 3D学习日记:创建一个小场景并编写简单C#移动脚本
- 《Unity 3D脚本编程:使用C#语言开发跨平台游戏》序言
- UNITY 2D学习笔记(二):C#脚本编写
- Unity 2D角色控制脚本C#直接上代码
- Unity 3d脚本加密方案
- Unity 3d脚本加密方案
- Unity 3d脚本加密方案
- unity 3d鼠标拖拽脚本
- thickbox使用
- LeetCode Word Search
- 敏捷日记(2012年3月到2012年5月)
- 图像特征小结
- 判断101-200之间有多少个素数
- Unity 3D功能主界面C#脚本
- perl字符串如何提取数字
- 扩展 Windows Azure 运营能力 – 巴西
- POJ 3278 Catch That Cow(BFS)
- wpf 根据dataTable 自动创建报表显示数据,主要运用DynamicDataDisplay
- Drawable和Bitmap转换
- 图片上传前预览 HTML5实现图片上传预览
- Unity 3D视频播放器场景C#脚本
- 更好地认知Azure