155 lines
5.0 KiB
C#
155 lines
5.0 KiB
C#
#if UNITY_EDITOR
|
|
namespace MusicCubeEditor
|
|
{
|
|
using PhxhSDK;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using UnityEditor;
|
|
using UnityEditor.SceneManagement;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
|
|
public class MusicCubeEditorToolManager :Singlenton<MusicCubeEditorToolManager>
|
|
{
|
|
const string MusicCubeEditorScene = "Assets/musictest.unity";
|
|
public string nowPlayMusicName;
|
|
public void OpenTestScene()
|
|
{
|
|
var scene = SceneManager.GetActiveScene();
|
|
if (scene.path == MusicCubeEditorScene)
|
|
{
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
EditorSceneManager.OpenScene(MusicCubeEditorScene);
|
|
}
|
|
}
|
|
public void ChangeDataToJson(List<float[]> list)
|
|
{
|
|
OneMusicData data = ConvertListarrayToOneMusicData(list);
|
|
data.name = nowPlayMusicName;
|
|
SaveConfig(data);
|
|
}
|
|
public void SetNowMusicName(string name)
|
|
{
|
|
nowPlayMusicName = name;
|
|
}
|
|
public OneMusicData ConvertListarrayToOneMusicData(List<float[]> list)
|
|
{
|
|
OneMusicData data = new OneMusicData(list, nowPlayMusicName);
|
|
return data;
|
|
}
|
|
public List<float[]> ConvertOneMusicDataToListArray(OneMusicData oneMusicData)
|
|
{
|
|
List<float[]>temp=new List<float[]>();
|
|
for (int i = 0; i < oneMusicData.frameDatas.Count; i++)
|
|
{
|
|
float[] temp1 = new float[16];
|
|
for (int j = 0; j < oneMusicData.frameDatas[i].ColData.Count; j++)
|
|
{
|
|
temp1[j] = oneMusicData.frameDatas[i].ColData[j];
|
|
}
|
|
temp.Add(temp1);
|
|
}
|
|
return temp;
|
|
}
|
|
public void SaveConfig(OneMusicData saveData)
|
|
{
|
|
// 保存timeline
|
|
//var director = _cmp.gameObject.GetComponent<PlayableDirector>();
|
|
//var playAsset = director.playableAsset as TimelineAsset;
|
|
// 保存json到本地
|
|
{
|
|
var json = JsonUtility.ToJson(saveData);
|
|
var savePath = "Assets/Config/UISomeAbout/MainPanelMusicCube/";
|
|
var saveName = "music_"+saveData.name + ".json";
|
|
var fullPath = savePath + "/" + saveName;
|
|
var realPath = Application.dataPath + fullPath.Substring(6);
|
|
if (File.Exists(realPath))
|
|
{
|
|
//if (VersionControlUtils.IsPathVersioned(fullPath))
|
|
//{
|
|
// Provider.Checkout(fullPath, CheckoutMode.Both).Wait();
|
|
//}
|
|
File.Delete(realPath);
|
|
}
|
|
File.WriteAllText(realPath, json);
|
|
Debug.Log("json保存成功:" + fullPath);
|
|
}
|
|
|
|
AssetDatabase.Refresh();
|
|
// 弹出对话框提示
|
|
EditorUtility.DisplayDialog("提示", "保存成功", "确定");
|
|
}
|
|
public OneMusicData LoadConfig(string musicName)
|
|
{
|
|
// 检查json
|
|
var savePath = "Assets/Config/UISomeAbout/MainPanelMusicCube/";
|
|
var saveName = "music_" + musicName + ".json";
|
|
var realPath = Application.dataPath + "/Config/UISomeAbout/MainPanelMusicCube/" + saveName;
|
|
|
|
// 先判断存不存在
|
|
if (File.Exists(realPath))
|
|
{
|
|
var jsonStr = File.ReadAllText(realPath);
|
|
return JsonUtility.FromJson<OneMusicData>(jsonStr);
|
|
|
|
}
|
|
else
|
|
{
|
|
// 不存在,进行默认设置
|
|
EditorUtility.DisplayDialog("提示", "文件不存在,请先录制", "确定");
|
|
return new OneMusicData();
|
|
}
|
|
}
|
|
|
|
public class OneMusicData
|
|
{
|
|
public string name;
|
|
public List<OneFrameData> frameDatas = new List<OneFrameData>();
|
|
public OneMusicData()
|
|
{
|
|
name = "fff";
|
|
|
|
for (int i = 0; i < 60; i++)
|
|
{
|
|
frameDatas.Add(new OneFrameData());
|
|
}
|
|
}
|
|
public OneMusicData(List<float[]> list, string musicName)
|
|
{
|
|
name = musicName;
|
|
for (int i = 0; i < list.Count; i++)
|
|
{
|
|
frameDatas.Add(new OneFrameData(list[i]));
|
|
}
|
|
}
|
|
}
|
|
[Serializable]
|
|
|
|
public class OneFrameData
|
|
{
|
|
public List<int> ColData = new List<int>();
|
|
public OneFrameData()
|
|
{
|
|
for (int i = 0; i < 16; i++)
|
|
{
|
|
ColData.Add(0);
|
|
}
|
|
}
|
|
public OneFrameData(float[] s)
|
|
{
|
|
for (int i = 0; i < s.Length; i++)
|
|
{
|
|
ColData.Add(Convert.ToInt16(s[i]));
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
#endif
|