资源简介
基于Unity2017.3.0f3的音乐(节拍)demo,可更换音乐快速搭建游戏原型。
代码片段和文件信息
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
[CustomEditor( typeof( SongData ) )]
public class SongDataEditor : Editor
{
//Needed to draw 2D lines and rectangles
private static Texture2D _coloredLineTexture;
private static Color _coloredLineColor;
private Gameobject Guitarobject;
private AudioSource MetronomeSource;
private SongPlayer SongPlayer;
private AudioClip LastAudioClip;
//Dimensions of the editor
//Song View is the one with the black background where you can add notes etc.
//ProgressBar or Progress View is the small preview on the right where you can navigate through the song
private Rect SongViewRect;
private float SongViewProgressBarWidth = 20f;
private float SongViewHeight = 400f;
//Metronome Vars
private static bool UseMetronome;
private float LastMetronomeBeat = Mathf.NegativeInfinity;
//Helper vars to handle mouse clicks
private Vector2 MouseUpPosition = Vector2.zero;
private bool LastClickWasRightMouseButton;
//Currently selected note index
private int SelectedNote = -1;
//Song overview texture (the one on the right which you can use to navigate)
private Texture2D ProgressViewTexture;
//Timer to calculate editor performance
Timer PerformanceTimer = new Timer();
[MenuItem( “Assets/Create/Song“ )]
public static void CreateNewSongAsset()
{
SongData asset = scriptableobject.CreateInstance();
AssetDatabase.CreateAsset( asset “Assets/NewSong.asset“ );
EditorUtility.FocusProjectWindow();
Selection.activeobject = asset;
}
protected void OnEnable()
{
//Setup object references
Guitarobject = Gameobject.Find( “Guitar“ );
if( Guitarobject == null )
{
return;
}
SongPlayer = Guitarobject.GetComponentyer>();
MetronomeSource = Gameobject.Find( “Metronome“ ).GetComponent();
LastAudioClip = SongPlayer.Song.BackgroundTrack;
//Prepare playback
SongPlayer.SetSong( (SongData)target );
LastMetronomeBeat = -Mathf.Ceil( SongPlayer.Song.AudioStartBeatOffset );
RedrawProgressViewTexture();
}
protected void RedrawProgressViewTexture()
{
int width = (int)SongViewProgressBarWidth;
int height = (int)SongViewHeight;
if( !ProgressViewTexture )
{
//Create empty texture if it doesn‘t exist
ProgressViewTexture = new Texture2D( width height );
ProgressViewTexture.wrapMode = TextureWrapMode.Clamp;
}
//Draw Background Color
Color[] BackgroundColor = new Color[ width * height ];
for( int i = 0; i < width * height; ++i )
{
BackgroundColor[ i ] = new Color( 0.13f 0.1f 0.26f );
}
ProgressViewTexture.SetPixels( 0 0 width height BackgroundColor );
//Calculate the scale in which the notes are drawn so they all fit into the progress view
float totalBeats = SongPlayer.Song.GetLengthInBeats();
float heightOfOneBeat = 1f / totalBeats * (float)height;
//Dr
- 上一篇:精馏塔资料
- 下一篇:R语言Igraph软件包0.7.1
相关资源
- PlayMaker_中文手册
- Unity海底气泡效果
- UNITY自动寻路插件 A* Pathfinding Project
- unity3D demo
- Unity3D从入门到精通高清PDF共231页全
- QT4简洁音乐播放器
- MeshTerrainEditorPro.unitypackage
- Snowify插件,unity下雪插件,特效
- Smart AI Car
- 数字电子钟外加播放功能
- unity3d 赛车DEMO
- ios显示歌词的本地音乐播放器
- Unity无限酷跑游戏源码
- unity 黄金矿工源码
- unity制作2D的灯光阴影
- unity3d鱼类游动AI demo
- [Unity] 建筑可视化开发 Unity 实现 英
- 2d toolkit
- 毕业设计安卓音乐播放器
- 仿qq音乐的
- 可视化动态迷宫带音乐,可自定义迷
- STM8蜂鸣器音乐演奏
- Unity3D UGUI官方案例
- UGUI 滑动插件 支持多种模式
- 网易云音乐NCM格式转换 10.28
- Unity3D超炫的水效果
- [嵌入式Linux项目实战开发]基于QT4.7.
- unity网络五子棋源代码
- ios豆瓣音乐播放器 含图片、代码等资
- OpenGL写的一个带背景音乐的场景
评论
共有 条评论