Replace naudio.dll with code

This commit is contained in:
CroakFang
2022-09-10 16:59:44 +08:00
parent 3c17d8770d
commit 19dbe75b53
1113 changed files with 50280 additions and 182 deletions
@@ -0,0 +1,92 @@
/****************************************************************************
*
* Copyright (c) 2011 CRI Middleware Co., Ltd.
*
****************************************************************************/
using UnityEngine;
using UnityEditor;
using System;
namespace CriWare {
[CustomEditor(typeof(CriAtom))]
public class CriAtomEditor : UnityEditor.Editor
{
#region Variables
private CriAtom atom = null;
#endregion
#region GUI Functions
private void OnEnable()
{
atom = (CriAtom)base.target;
}
public override void OnInspectorGUI()
{
if (atom == null) {
return;
}
Undo.RecordObject(target, null);
GUI.changed = false;
{
atom.acfFile = EditorGUILayout.TextField("ACF File", atom.acfFile);
atom.dspBusSetting = EditorGUILayout.TextField("DSP Bus Setting", atom.dspBusSetting);
for (int i = 0; i < atom.cueSheets.Length; i++) {
var cueSheet = atom.cueSheets[i];
EditorGUILayout.BeginVertical("HelpBox");
EditorGUILayout.BeginHorizontal();
EditorGUILayout.PrefixLabel("Cue Sheet");
if (GUILayout.Button("Remove")) {
atom.RemoveCueSheetInternal(cueSheet.name);
break;
}
EditorGUILayout.EndHorizontal();
EditorGUI.indentLevel++;
cueSheet.name = EditorGUILayout.TextField("Name", cueSheet.name);
cueSheet.acbFile = EditorGUILayout.TextField("ACB File", cueSheet.acbFile);
cueSheet.awbFile = EditorGUILayout.TextField("AWB File", cueSheet.awbFile);
EditorGUI.indentLevel--;
EditorGUILayout.EndVertical();
}
if (GUILayout.Button("Add CueSheet")) {
atom.AddCueSheetInternal("", "", "", null);
}
atom.dontRemoveExistsCueSheet = EditorGUILayout.Toggle("Dont Remove Exists CueSheet", atom.dontRemoveExistsCueSheet);
atom.dontDestroyOnLoad = EditorGUILayout.Toggle("Dont Destroy On Load", atom.dontDestroyOnLoad);
}
if (GUI.changed) {
EditorUtility.SetDirty(atom);
}
}
#endregion
#region Editor Utilities
/**
* \deprecated
* This is a deprecated API that will be removed.
* Please consider using CriAtomEditorUtilities.InitializeLibrary() instead.
*/
[Obsolete("Consider using CriAtomEditorUtilities.InitializeLibrary() instead.")]
public static void InitializePluginForEditor() {
CriWare.Editor.CriAtomEditorUtilities.InitializeLibrary();
}
/**
* \deprecated
* This is a deprecated API that will be removed.
* Please consider using CriAtomEditorUtilities.PreviewPlayer instead.
*/
[Obsolete("Consider using CriAtomEditorUtilities.PreviewPlayer instead.")]
public class PreviewPlayer : CriWare.Editor.CriAtomEditorUtilities.PreviewPlayer { }
#endregion
} // end of class
} //namespace CriWare
/* end of file */
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4580729b648468042bc67394cbfe5c75
timeCreated: 1433816076
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,153 @@
/****************************************************************************
*
* Copyright (c) CRI Middleware Co., Ltd.
*
****************************************************************************/
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace CriWare.Editor {
public class CriAtomEditorSettingsProvider : SettingsProvider
{
static readonly string settingPath = "Project/CRIWARE/Editor/Atom Preview";
public CriAtomEditorSettingsProvider(string path, SettingsScope scope) : base(path, scope) { }
public override void OnGUI(string searchContext) {
EditorGUI.indentLevel++;
EditorGUILayout.Space();
EditorGUILayout.LabelField("Library Initialization Settings for Audio Previewing in the Editor", EditorStyles.boldLabel);
EditorGUI.indentLevel++;
EditorGUILayout.Space();
CriAtomEditorSettings.Instance.EditorInstance.OnInspectorGUI();
EditorGUI.indentLevel -= 2;
}
[SettingsProvider]
static SettingsProvider Create() {
var provider = new CriAtomEditorSettingsProvider(settingPath, SettingsScope.Project);
return provider;
}
} //class CriAtomEditorSettingsProvider
public class CriAtomEditorSettings : ScriptableObject
{
static readonly string SettingsDirPath = "Assets/CriData/Settings";
static CriAtomEditorSettings instance = null;
private UnityEditor.Editor editorInstance = null;
internal UnityEditor.Editor EditorInstance {
get {
if (editorInstance == null) {
editorInstance = UnityEditor.Editor.CreateEditor(this);
}
return editorInstance;
}
}
private bool hasSettingsChanged = false;
internal void SetChangeFlag() { hasSettingsChanged = true; }
internal bool GetChangeStatusOnce() {
bool currentChangeStatus = hasSettingsChanged;
hasSettingsChanged = false;
return currentChangeStatus;
}
[SerializeField]
private bool trySceneSettings = false;
internal bool TrySceneSettings { get { return trySceneSettings; } }
[SerializeField]
private CriAtomConfig atomConfig = new CriAtomConfig();
internal CriAtomConfig AtomConfig { get { return atomConfig; } }
internal static CriAtomEditorSettings Instance {
get {
if (instance == null) {
var guids = AssetDatabase.FindAssets("t:" + typeof(CriAtomEditorSettings).Name);
if (guids.Length <= 0) {
if (!System.IO.Directory.Exists(SettingsDirPath)) {
System.IO.Directory.CreateDirectory(SettingsDirPath);
}
instance = CreateInstance<CriAtomEditorSettings>();
AssetDatabase.CreateAsset(instance, System.IO.Path.Combine(SettingsDirPath, typeof(CriAtomEditorSettings).Name + ".asset"));
} else {
var assetPath = AssetDatabase.GUIDToAssetPath(guids[0]);
if (guids.Length > 1) {
Debug.LogWarning("[CRIWARE] Multiple setting files founded. Using " + assetPath);
}
instance = AssetDatabase.LoadAssetAtPath<CriAtomEditorSettings>(assetPath);
}
}
return instance;
}
}
internal void ResetConfig() {
atomConfig = new CriAtomConfig();
}
} //class CriAtomEditorSettings
[CustomEditor(typeof(CriAtomEditorSettings))]
public class CriAtomEditorSettingsEditor : UnityEditor.Editor
{
private SerializedProperty trySceneSettingsProp;
private List<SerializedProperty> atomConfigProps = new List<SerializedProperty>();
private void OnEnable() {
trySceneSettingsProp = serializedObject.FindProperty("trySceneSettings");
atomConfigProps.Add(serializedObject.FindProperty("atomConfig.maxVirtualVoices"));
atomConfigProps.Add(serializedObject.FindProperty("atomConfig.maxVoiceLimitGroups"));
atomConfigProps.Add(serializedObject.FindProperty("atomConfig.maxCategories"));
atomConfigProps.Add(serializedObject.FindProperty("atomConfig.maxSequenceEventsPerFrame"));
atomConfigProps.Add(serializedObject.FindProperty("atomConfig.maxBeatSyncCallbacksPerFrame"));
atomConfigProps.Add(serializedObject.FindProperty("atomConfig.maxCueLinkCallbacksPerFrame"));
atomConfigProps.Add(serializedObject.FindProperty("atomConfig.standardVoicePoolConfig"));
atomConfigProps.Add(serializedObject.FindProperty("atomConfig.hcaMxVoicePoolConfig"));
atomConfigProps.Add(serializedObject.FindProperty("atomConfig.outputSamplingRate"));
atomConfigProps.Add(serializedObject.FindProperty("atomConfig.serverFrequency"));
atomConfigProps.Add(serializedObject.FindProperty("atomConfig.asrOutputChannels"));
atomConfigProps.Add(serializedObject.FindProperty("atomConfig.useRandomSeedWithTime"));
atomConfigProps.Add(serializedObject.FindProperty("atomConfig.categoriesPerPlayback"));
atomConfigProps.Add(serializedObject.FindProperty("atomConfig.maxFaders"));
atomConfigProps.Add(serializedObject.FindProperty("atomConfig.maxBuses"));
atomConfigProps.Add(serializedObject.FindProperty("atomConfig.maxParameterBlocks"));
atomConfigProps.Add(serializedObject.FindProperty("atomConfig.vrMode"));
atomConfigProps.Add(serializedObject.FindProperty("atomConfig.pcBufferingTime"));
}
public override void OnInspectorGUI() {
const float LABEL_WIDTH = 250;
float prevLabelWidth;
serializedObject.Update();
prevLabelWidth = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = LABEL_WIDTH;
EditorGUILayout.PropertyField(trySceneSettingsProp);
if (trySceneSettingsProp.boolValue) {
EditorGUILayout.HelpBox("Will use project settings if CriLibraryInitializer does not exist in the scene.", MessageType.Info);
}
EditorGUILayout.Space();
foreach (var prop in atomConfigProps) {
EditorGUILayout.PropertyField(prop);
}
EditorGUIUtility.labelWidth = prevLabelWidth;
if (serializedObject.hasModifiedProperties) {
(target as CriAtomEditorSettings).SetChangeFlag();
}
serializedObject.ApplyModifiedProperties();
EditorGUILayout.Space();
if (GUILayout.Button("Reset to Default")) {
(target as CriAtomEditorSettings).ResetConfig();
(target as CriAtomEditorSettings).SetChangeFlag();
}
}
} //class CriAtomEditorSettingsEditor
} //namespace CriWare.Editor
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bdb0b816a0bf0284282bd91a06a57a05
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,192 @@
/****************************************************************************
*
* Copyright (c) 2021 CRI Middleware Co., Ltd.
*
****************************************************************************/
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;
/**
* \addtogroup CRIWARE_EDITOR_UTILITY
* @{
*/
/**
* <summary>CriWare.Editor namespace</summary>
* <remarks>
* <para header='Description'>This is a namespace which includes a collection of classes that can be used in the Unity Editor environment.</para>
* </remarks>
*/
namespace CriWare.Editor {
/**
* <summary>Class for the editor-only features of CRI Atom</summary>
* <remarks>
* <para header='Description'>Class that contains the editor-specific functions of CRI Atom.</para>
* <para header='Note'>When using this class with the Assembly Definition version plug-in,<br/>
* it is necessary to reference the following assembly definitions:<br/>
* - CriMw.CriWare.Editor<br/>
* - CriMw.CriWare.Runtime<br/></para>
* </remarks>
*/
public class CriAtomEditorUtilities
{
/**
* <summary>Initialize the CRI Atom library in the editor</summary>
* <returns>Whether the initialization process was executed</returns>
* <remarks>
* <para header='Description'>This method is used to initialize the CRI Atom library dedicated to the Edit mode. <br/>
* The Atom library will be initialized according to the Atom editor settings in the project settings. <br/>
* Depending on the project settings, it is also possible to initialize
* using the settings of the CriWareInitializer component in the currently loaded scene.</para>
* </remarks>
*/
public static bool InitializeLibrary() {
bool settingChanged = CriAtomEditorSettings.Instance.GetChangeStatusOnce();
if (CriAtomPlugin.IsLibraryInitialized() && settingChanged == false) {
return false;
}
if (settingChanged) {
CriAtomPlugin.FinalizeLibrary();
}
CriAtomConfig atomConfigEditor;
if (CriAtomEditorSettings.Instance.TrySceneSettings == false) {
atomConfigEditor = CriAtomEditorSettings.Instance.AtomConfig;
} else {
CriWareInitializer criInitializer = GameObject.FindObjectOfType<CriWareInitializer>();
if (criInitializer != null) {
atomConfigEditor = criInitializer.atomConfig;
} else {
atomConfigEditor = CriAtomEditorSettings.Instance.AtomConfig;
Debug.Log("[CRIWARE] Atom Preview: No CriWareInitializer component found in current scene. " +
"Using project settings instead.");
}
}
return CriWareInitializer.InitializeAtom(atomConfigEditor);
}
/**
* <summary>Audio player dedicated to previewing in the editor</summary>
* <remarks>
* <para header='Description'>This class is used to preview the playback of ADX2 audio in the Edit mode. <br/>
* The loading of the relevant ACB data must be managed externally.</para>
* </remarks>
*/
public class PreviewPlayer : CriDisposable {
public CriAtomExPlayer player { get; private set; }
private bool finalizeSuppressed = false;
private bool isPlayerReady = false;
private void Initialize() {
CriAtomEditorUtilities.InitializeLibrary();
if (CriAtomPlugin.IsLibraryInitialized() == false) { return; }
player = new CriAtomExPlayer();
if (player == null) { return; }
player.SetPanType(CriAtomEx.PanType.Pan3d);
player.UpdateAll();
isPlayerReady = true;
CriDisposableObjectManager.Register(this, CriDisposableObjectManager.ModuleType.Atom);
if (finalizeSuppressed) {
GC.ReRegisterForFinalize(this);
}
}
/**
* <summary>Initialization of the player</summary>
*/
public PreviewPlayer() {
Initialize();
}
/**
* <summary>Destroying the player</summary>
*/
public override void Dispose() {
this.dispose();
GC.SuppressFinalize(this);
finalizeSuppressed = true;
}
private void dispose() {
CriDisposableObjectManager.Unregister(this);
if (player != null) {
player.Dispose();
player = null;
}
this.isPlayerReady = false;
}
~PreviewPlayer() {
this.dispose();
}
/**
* <summary>Set the audio data and play</summary>
* <param name='acb'>ACB data</param>
* <param name='cueName'>Cue name</param>
* <remarks>
* <para header='Description'>Specify the ACB data and Cue name and then play.</para>
* </remarks>
*/
public void Play(CriAtomExAcb acb, string cueName) {
if (isPlayerReady == false) {
this.Initialize();
}
if (acb != null) {
if (player != null) {
player.SetCue(acb, cueName);
player.Start();
} else {
Debug.LogWarning("[CRIWARE] Player is not ready. Please try reloading the inspector / editor window");
}
} else {
Debug.LogWarning("[CRIWARE] ACB data is not set for previewing playback");
}
}
/**
* <summary>Stops the playback</summary>
* <param name='withoutRelease'>Whether to stop without release time</param>
* <remarks>
* <para header='Description'>Stops all audio playback.</para>
* </remarks>
*/
public void Stop(bool withoutRelease = false) {
if (player != null) {
if (withoutRelease) {
player.StopWithoutReleaseTime();
} else {
player.Stop();
}
}
}
/**
* <summary>Resets the parameters of the player</summary>
*/
public void ResetPlayer() {
player.SetVolume(1f);
player.SetPitch(0);
player.Loop(false);
}
}
} // end of class
} //namespace CriWare.Editor
/**
* @}
*/
/* end of file */
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 15f32809ca2a1cf40982c3336cc81366
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,18 @@
/****************************************************************************
*
* Copyright (c) 2011 CRI Middleware Co., Ltd.
*
****************************************************************************/
using UnityEditor;
namespace CriWare {
[CustomEditor(typeof(CriAtomListener))]
public class CriAtomListenerEditor : UnityEditor.Editor
{
} // end of class
} //namespace CriWare
/* end of file */
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f7ddeb461d32378408896179255bf0cd
timeCreated: 1433816082
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,133 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace CriWare {
public abstract class CriAtomSourceBaseEditor : UnityEditor.Editor
{
#region Variables
protected CriAtomSourceBase source = null;
private bool showAndroidConfig;
private GUIStyle style;
private SerializedProperty m_followsOriginalSource;
private SerializedProperty m_calculationType;
private SerializedProperty m_calculationParameters;
#endregion
#region Functions
protected virtual void OnEnable()
{
this.source = (CriAtomSourceBase)base.target;
this.style = new GUIStyle();
m_followsOriginalSource = serializedObject.FindProperty("randomize3dConfig.followsOriginalSource");
m_calculationType = serializedObject.FindProperty("randomize3dConfig.calculationType");
m_calculationParameters = serializedObject.FindProperty("randomize3dConfig.calculationParameters");
}
protected abstract void InspectorCueReferenceGUI();
protected abstract void InspectorPreviewGUI();
public override void OnInspectorGUI()
{
if (this.source == null)
{
return;
}
Undo.RecordObject(target, null);
GUI.changed = false;
{
EditorGUI.indentLevel++;
InspectorCueReferenceGUI();
InspectorPreviewGUI();
this.source.playOnStart = EditorGUILayout.Toggle("Play On Start", this.source.playOnStart);
EditorGUILayout.Space();
this.source.volume = EditorGUILayout.Slider("Volume", this.source.volume, 0.0f, 1.0f);
this.source.pitch = EditorGUILayout.Slider("Pitch", this.source.pitch, -1200f, 1200);
this.source.loop = EditorGUILayout.Toggle("Loop", this.source.loop);
if (this.source.use3dPositioning = EditorGUILayout.Toggle("3D Positioning", this.source.use3dPositioning))
{
EditorGUI.indentLevel++;
this.source.freezeOrientation = EditorGUILayout.Toggle("Freeze Orientation", this.source.freezeOrientation);
this.source.regionOnStart = EditorGUILayout.ObjectField("Region On Start", this.source.regionOnStart, typeof(CriAtomRegion), true) as CriAtomRegion;
this.source.listenerOnStart = EditorGUILayout.ObjectField("Listener On Start", this.source.listenerOnStart, typeof(CriAtomListener), true) as CriAtomListener;
bool tempRandomizeSetting = EditorGUILayout.Toggle("3D Randomization", this.source.use3dRandomization);
if (tempRandomizeSetting != this.source.use3dRandomization)
{
this.source.use3dRandomization = tempRandomizeSetting;
}
if (this.source.use3dRandomization)
{
EditorGUILayout.BeginVertical("HelpBox");
EditorGUI.indentLevel++;
EditorGUI.BeginChangeCheck();
this.m_followsOriginalSource.boolValue = EditorGUILayout.Toggle("Follow origin", this.m_followsOriginalSource.boolValue);
var calcType = (int)(CriAtomEx.Randomize3dCalcType)EditorGUILayout.EnumPopup("Type", (CriAtomEx.Randomize3dCalcType)this.m_calculationType.intValue);
if (calcType != this.m_calculationType.intValue)
{
this.m_calculationType.intValue = calcType;
/* set new parameter to 1 */
for (int i = 0; i < CriAtomEx.Randomize3dConfig.NumOfCalcParams; ++i)
{
if (this.m_calculationParameters.GetArrayElementAtIndex(i).floatValue <= 0f)
{
this.m_calculationParameters.GetArrayElementAtIndex(i).floatValue = 1f;
}
}
}
for (int i = 0; i < CriAtomEx.Randomize3dConfig.NumOfCalcParams; ++i)
{
var paramType = CriAtomEx.randomize3dParamTable[(CriAtomEx.Randomize3dCalcType)m_calculationType.intValue][i];
if (paramType == CriAtomEx.Randomize3dParamType.None)
{
this.m_calculationParameters.GetArrayElementAtIndex(i).floatValue = 0f;
continue;
}
this.m_calculationParameters.GetArrayElementAtIndex(i).floatValue = EditorGUILayout.FloatField(paramType.ToString(), this.m_calculationParameters.GetArrayElementAtIndex(i).floatValue);
}
switch ((CriAtomEx.Randomize3dCalcType)m_calculationType.intValue)
{
case CriAtomEx.Randomize3dCalcType.List:
var templength = (uint)Mathf.Abs(EditorGUILayout.IntField("Max length of list", (int)this.source.randomPositionListMaxLength));
if (templength != this.source.randomPositionListMaxLength)
{
this.source.randomPositionListMaxLength = templength;
}
EditorGUILayout.HelpBox("Please set the list of positions by using CriAtomSource.SetRandomPositionList()", MessageType.Info);
break;
default:
break;
}
if (EditorGUI.EndChangeCheck())
{
serializedObject.ApplyModifiedProperties();
this.source.use3dRandomization = this.source.use3dRandomization; /* apply change */
}
EditorGUI.indentLevel--;
EditorGUILayout.EndVertical();
}
EditorGUI.indentLevel--;
}
this.showAndroidConfig = EditorGUILayout.Foldout(this.showAndroidConfig, "Android Config");
if (this.showAndroidConfig)
{
EditorGUI.indentLevel++;
EditorGUILayout.BeginHorizontal();
style.stretchWidth = true;
this.source.androidUseLowLatencyVoicePool = EditorGUILayout.Toggle("Low Latency Playback", this.source.androidUseLowLatencyVoicePool);
EditorGUILayout.EndHorizontal();
EditorGUI.indentLevel--;
}
}
if (GUI.changed)
{
EditorUtility.SetDirty(this.source);
}
}
#endregion
} // end of class
} // namespace CriWare
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b656357d81bf0d0408dc264ac483ccf4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,117 @@
/****************************************************************************
*
* Copyright (c) 2014 CRI Middleware Co., Ltd.
*
****************************************************************************/
#define CRI_UNITY_EDITOR_PREVIEW
using UnityEngine;
using UnityEditor;
using System.IO;
namespace CriWare {
[CustomEditor(typeof(CriAtomSource))]
public class CriAtomSourceEditor : CriAtomSourceBaseEditor {
#region Variables
#if CRI_UNITY_EDITOR_PREVIEW
public CriAtom atomComponent;
private CriWare.Editor.CriAtomEditorUtilities.PreviewPlayer previewPlayer;
private string strPreviewAcb = null;
private string strPreviewAwb = null;
private CriAtomExAcb previewAcb = null;
private string lastCuesheet = "";
#endif
#endregion
#region Functions
protected override void OnEnable()
{
base.OnEnable();
#if CRI_UNITY_EDITOR_PREVIEW
/* シーンからCriAtomコンポーネントを見つけ出す */
atomComponent = (CriAtom)FindObjectOfType(typeof(CriAtom));
#endif
previewPlayer = new CriWare.Editor.CriAtomEditorUtilities.PreviewPlayer();
}
private void OnDisable() {
if (previewAcb != null) {
previewAcb.Dispose();
previewAcb = null;
}
lastCuesheet = "";
if (previewPlayer != null) {
previewPlayer.Dispose();
previewPlayer = null;
}
}
protected override void InspectorCueReferenceGUI()
{
(source as CriAtomSource).cueSheet = EditorGUILayout.TextField("Cue Sheet", (source as CriAtomSource).cueSheet);
(source as CriAtomSource).cueName = EditorGUILayout.TextField("Cue Name", (source as CriAtomSource).cueName);
}
protected override void InspectorPreviewGUI()
{
#if CRI_UNITY_EDITOR_PREVIEW
GUI.enabled = false;
atomComponent = (CriAtom)EditorGUILayout.ObjectField("CriAtom Object", atomComponent, typeof(CriAtom), true);
GUI.enabled = (atomComponent != null);
GUILayout.BeginHorizontal();
{
EditorGUILayout.LabelField("Preview", GUILayout.MaxWidth(EditorGUIUtility.labelWidth - 5));
if (GUILayout.Button("Play", GUILayout.MaxWidth(60))) {
this.StartPreviewPlayer();
}
if (GUILayout.Button("Stop", GUILayout.MaxWidth(60))) {
this.previewPlayer.Stop();
}
}
GUILayout.EndHorizontal();
GUI.enabled = true;
#endif
}
#if CRI_UNITY_EDITOR_PREVIEW
/* プレビュ用:音声データ設定・再生関数 */
private void StartPreviewPlayer() {
if (previewPlayer == null) {
return;
}
if (lastCuesheet != (source as CriAtomSource).cueSheet) {
if (previewAcb != null) {
previewAcb.Dispose();
previewAcb = null;
}
foreach (var cuesheet in atomComponent.cueSheets) {
if (cuesheet.name == (source as CriAtomSource).cueSheet) {
strPreviewAcb = Path.Combine(CriWare.Common.streamingAssetsPath, cuesheet.acbFile);
strPreviewAwb = (cuesheet.awbFile == null) ? null : Path.Combine(CriWare.Common.streamingAssetsPath, cuesheet.awbFile);
previewAcb = CriAtomExAcb.LoadAcbFile(null, strPreviewAcb, strPreviewAwb);
lastCuesheet = cuesheet.name;
}
}
}
if (previewAcb != null) {
previewPlayer.player.SetVolume(this.source.volume);
previewPlayer.player.SetPitch(this.source.pitch);
previewPlayer.player.Loop(this.source.loop);
previewPlayer.Play(previewAcb, (source as CriAtomSource).cueName);
} else {
Debug.LogWarning("[CRIWARE] Specified cue sheet could not be found");
}
}
#endif
#endregion
}
} //namespace CriWare
/* end of file */
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b7ba25dde88df304ea6345254cb82626
timeCreated: 1433816076
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,221 @@
/****************************************************************************
*
* Copyright (c) 2020 CRI Middleware Co., Ltd.
*
****************************************************************************/
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace CriWare {
[CustomEditor(typeof(CriAtomTransceiver)), CanEditMultipleObjects]
public class CriAtomTransceiverEditor : UnityEditor.Editor {
/* parameters */
private SerializedProperty m_regionOnStart;
private SerializedProperty m_useDedicatedInput;
private SerializedProperty m_dedicatedInput;
private SerializedProperty m_outputVolume;
private SerializedProperty m_directAudioRadius;
private SerializedProperty m_crossFadeDistance;
private SerializedProperty m_coneInsideAngle;
private SerializedProperty m_coneOutsideAngle;
private SerializedProperty m_coneOutsideVolume;
private SerializedProperty m_transceiverRadius;
private SerializedProperty m_interiorDistance;
private SerializedProperty m_minAttenuation;
private SerializedProperty m_maxAttenuation;
private SerializedProperty m_globalAisacName;
private SerializedProperty m_maxAngleAisacDelta;
private SerializedProperty m_distanceAisacControlId;
private SerializedProperty m_listenerAzimuthAisacControlId;
private SerializedProperty m_listenerElevationAisacControlId;
private SerializedProperty m_outputAzimuthAisacControlId;
private SerializedProperty m_outputElevationAisacControlId;
private MethodInfo m_applyParametersMethod;
static private readonly GUIContent cUseDedicatedInputLabel = new GUIContent("Use Dedicated Input", "Use another game object as input position");
static private readonly GUIContent cTranceiverRadiusLabel = new GUIContent("Non-Panning Radius");
static private readonly GUIContent cConeInsideAngleLabel = new GUIContent("Inside");
static private readonly GUIContent cConeOutsideAngle = new GUIContent("Outside");
static private readonly GUIContent cDistanceAisacLabel = new GUIContent("Distance");
static private readonly GUIContent cListenerAzimuthAisacLabel = new GUIContent("Listener Azimuth Angle");
static private readonly GUIContent cListenerElevationAisacLabel = new GUIContent("Listener Elevation Angle");
static private readonly GUIContent cOutputAzimuthAisacLabel = new GUIContent("Output Azimuth Angle");
static private readonly GUIContent cOutputElevationAisacLabel = new GUIContent("Output Elevation Angle");
private void OnEnable() {
m_regionOnStart = serializedObject.FindProperty("regionOnStart");
m_useDedicatedInput = serializedObject.FindProperty("useDedicatedInput");
m_dedicatedInput = serializedObject.FindProperty("dedicatedInput");
m_outputVolume = serializedObject.FindProperty("outputVolume");
m_directAudioRadius = serializedObject.FindProperty("directAudioRadius");
m_crossFadeDistance = serializedObject.FindProperty("crossFadeDistance");
m_coneInsideAngle = serializedObject.FindProperty("coneInsideAngle");
m_coneOutsideAngle = serializedObject.FindProperty("coneOutsideAngle");
m_coneOutsideVolume = serializedObject.FindProperty("coneOutsideVolume");
m_transceiverRadius = serializedObject.FindProperty("transceiverRadius");
m_interiorDistance = serializedObject.FindProperty("interiorDistance");
m_minAttenuation = serializedObject.FindProperty("minAttenuation");
m_maxAttenuation = serializedObject.FindProperty("maxAttenuation");
m_globalAisacName = serializedObject.FindProperty("globalAisacName");
m_maxAngleAisacDelta = serializedObject.FindProperty("maxAngleAisacDelta");
m_distanceAisacControlId = serializedObject.FindProperty("distanceAisacControlId");
m_listenerAzimuthAisacControlId = serializedObject.FindProperty("listenerAzimuthAisacControlId");
m_listenerElevationAisacControlId = serializedObject.FindProperty("listenerElevationAisacControlId");
m_outputAzimuthAisacControlId = serializedObject.FindProperty("outputAzimuthAisacControlId");
m_outputElevationAisacControlId = serializedObject.FindProperty("outputElevationAisacControlId");
m_applyParametersMethod = typeof(CriAtomTransceiver).GetMethod("ApplyParameters", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance);
}
public override void OnInspectorGUI() {
var targetObj = target as CriAtomTransceiver;
EditorGUILayout.PropertyField(m_regionOnStart);
EditorGUILayout.Space();
EditorGUILayout.PropertyField(m_useDedicatedInput, cUseDedicatedInputLabel);
if (m_useDedicatedInput.boolValue) {
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_dedicatedInput);
EditorGUI.indentLevel--;
}
EditorGUILayout.Space();
EditorGUILayout.PropertyField(m_outputVolume);
EditorGUILayout.Space();
EditorGUILayout.LabelField("Transceiving");
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_directAudioRadius);
EditorGUILayout.PropertyField(m_crossFadeDistance);
EditorGUI.indentLevel--;
EditorGUILayout.Space();
EditorGUILayout.LabelField("Cone Angles");
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_coneInsideAngle, cConeInsideAngleLabel);
EditorGUILayout.PropertyField(m_coneOutsideAngle, cConeOutsideAngle);
using (var hScope = new EditorGUILayout.HorizontalScope()) {
EditorGUILayout.PrefixLabel(" ");
if (GUILayout.Button("Set to Omni-Directional", GUILayout.Width(150))) {
m_coneInsideAngle.floatValue = 360f;
m_coneOutsideAngle.floatValue = 360f;
}
}
EditorGUI.indentLevel--;
EditorGUILayout.PropertyField(m_coneOutsideVolume);
EditorGUILayout.Space();
EditorGUILayout.LabelField("Panning");
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_transceiverRadius, cTranceiverRadiusLabel);
EditorGUILayout.PropertyField(m_interiorDistance);
EditorGUI.indentLevel--;
EditorGUILayout.Space();
EditorGUILayout.LabelField("Attenuation");
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_minAttenuation);
EditorGUILayout.PropertyField(m_maxAttenuation);
EditorGUI.indentLevel--;
EditorGUILayout.Space();
if (targetObj.inspectorAisacSettingFoldout = EditorGUILayout.Foldout(targetObj.inspectorAisacSettingFoldout, "AISAC")) {
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_globalAisacName);
EditorGUILayout.PropertyField(m_maxAngleAisacDelta);
EditorGUILayout.LabelField("AISAC Control IDs");
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_distanceAisacControlId, cDistanceAisacLabel);
EditorGUILayout.PropertyField(m_listenerAzimuthAisacControlId, cListenerAzimuthAisacLabel);
EditorGUILayout.PropertyField(m_listenerElevationAisacControlId, cListenerElevationAisacLabel);
EditorGUILayout.PropertyField(m_outputAzimuthAisacControlId, cOutputAzimuthAisacLabel);
EditorGUILayout.PropertyField(m_outputElevationAisacControlId, cOutputElevationAisacLabel);
EditorGUI.indentLevel -= 2;
}
if (GUI.changed) {
ValidateParameters();
serializedObject.ApplyModifiedProperties();
if (m_applyParametersMethod != null) {
m_applyParametersMethod.Invoke(targetObj, null);
}
}
}
private void ValidateParameters() {
if (m_outputVolume.floatValue < 0) { m_outputVolume.floatValue = 0; }
if (m_directAudioRadius.floatValue < 0) { m_directAudioRadius.floatValue = 0; }
if (m_crossFadeDistance.floatValue < 0) { m_crossFadeDistance.floatValue = 0; }
m_coneInsideAngle.floatValue = Mathf.Clamp(m_coneInsideAngle.floatValue, 0, 360);
m_coneOutsideAngle.floatValue = Mathf.Clamp(m_coneOutsideAngle.floatValue, 0, 360);
m_coneInsideAngle.floatValue = Mathf.Min(m_coneInsideAngle.floatValue, m_coneOutsideAngle.floatValue);
if (m_coneOutsideVolume.floatValue < 0) { m_coneOutsideVolume.floatValue = 0; }
if (m_transceiverRadius.floatValue < 0) { m_transceiverRadius.floatValue = 0; }
if (m_interiorDistance.floatValue < 0) { m_interiorDistance.floatValue = 0; }
if (m_minAttenuation.floatValue < 0) { m_minAttenuation.floatValue = 0; }
if (m_maxAttenuation.floatValue < 0) { m_maxAttenuation.floatValue = 0; }
m_minAttenuation.floatValue = Mathf.Min(m_minAttenuation.floatValue, m_maxAttenuation.floatValue);
if (m_maxAngleAisacDelta.floatValue < 0) { m_maxAngleAisacDelta.floatValue = 0; }
}
private void OnSceneGUI() {
var targetObj = target as CriAtomTransceiver;
if (targetObj.enabled == false) { return; }
var transformObj = targetObj.transform;
var outsideArcStartVector = Quaternion.AngleAxis(-m_coneOutsideAngle.floatValue / 2f, transformObj.up) * transformObj.forward;
var insideArcStartVector = Quaternion.AngleAxis(-m_coneInsideAngle.floatValue / 2f, transformObj.up) * transformObj.forward;
float screenSpaceConstant = Mathf.Min(HandleUtility.GetHandleSize(transformObj.position) * 3, targetObj.maxAttenuation);
var dedicatedInput = m_dedicatedInput.objectReferenceValue as GameObject;
Handles.color = new Color(1, 1, 1, 0.3f);
Handles.DrawDottedLine(transformObj.position, transformObj.position + transformObj.forward * screenSpaceConstant, 5f);
Handles.color = new Color(1, 1, 1, 0.03f);
if (m_coneInsideAngle.floatValue < 360) {
Handles.DrawSolidArc(transformObj.position, transformObj.up, outsideArcStartVector, m_coneOutsideAngle.floatValue, screenSpaceConstant);
Handles.DrawSolidArc(transformObj.position, transformObj.up, insideArcStartVector, m_coneInsideAngle.floatValue, screenSpaceConstant);
}
Handles.color = new Color(0.627f, 0.890f, 0.388f);
Handles.DrawWireArc(transformObj.position, transformObj.up, outsideArcStartVector, m_coneOutsideAngle.floatValue, m_transceiverRadius.floatValue);
Handles.color = new Color(1f, 0.537f, 0);
Handles.DrawWireArc(transformObj.position, transformObj.up, outsideArcStartVector, m_coneOutsideAngle.floatValue, m_transceiverRadius.floatValue + m_interiorDistance.floatValue);
Handles.color = new Color(0.890f, 0.862f, 0.388f, 0.1f);
if (m_useDedicatedInput.boolValue && dedicatedInput != null) {
Handles.DrawSolidDisc(dedicatedInput.transform.position, dedicatedInput.transform.up, m_directAudioRadius.floatValue);
} else {
Handles.DrawSolidDisc(transformObj.position, transformObj.up, m_directAudioRadius.floatValue);
}
Handles.color = new Color(0.290f, 0.556f, 0.827f, 0.1f);
if (m_useDedicatedInput.boolValue && dedicatedInput != null) {
Handles.DrawSolidDisc(dedicatedInput.transform.position, dedicatedInput.transform.up, m_directAudioRadius.floatValue + m_crossFadeDistance.floatValue);
} else {
Handles.DrawSolidDisc(transformObj.position, transformObj.up, m_directAudioRadius.floatValue + m_crossFadeDistance.floatValue);
}
using (var changeScope = new EditorGUI.ChangeCheckScope()) {
Handles.color = new Color(0.3317462f, 0.6611561f, 0.990566f, 0.7f);
float minAtt = Handles.RadiusHandle(Quaternion.identity, transformObj.position, targetObj.minAttenuation);
float maxAtt = Handles.RadiusHandle(Quaternion.identity, transformObj.position, targetObj.maxAttenuation);
if (changeScope.changed) {
Undo.RecordObject(target, "Change Transceiver Attenuation");
minAtt = Mathf.Min(minAtt, maxAtt);
targetObj.minAttenuation = minAtt;
targetObj.maxAttenuation = maxAtt;
EditorUtility.SetDirty(target);
if (m_applyParametersMethod != null) {
m_applyParametersMethod.Invoke(targetObj, null);
}
}
}
}
}
} //namespace CriWare
/* end of file */
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 79840c63aad7bb44f948a5b0fb1b81d3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,89 @@
/****************************************************************************
*
* Copyright (c) 2021 CRI Middleware Co., Ltd.
*
****************************************************************************/
using System.Runtime.InteropServices;
/**
* \addtogroup CRIWARE_EDITOR_UTILITY
* @{
*/
namespace CriWare.Editor {
/**
* <summary>This is a class used for bouncing the audio output to a file.</summary>
* <remarks>
* <para header='Description'>This class can be used to bounce the audio output from the ASR.</para>
* </remarks>
*/
public static class CriAtomWaveFile
{
/**
* <summary>Starts the bouncing</summary>
* <param name='path'>File path for the bouncing output</param>
* <param name='numChannels'>Number of channels in the bounced output file (1, 2, 4, 6 or 8)</param>
* <returns>Whether the bouncing has been started</returns>
* <remarks>
* <para header='Description'>Starts bouncing with the specified parameters.<br/>
* 1, 2, 4, 6 or 8 can be specified for numChannels.<br/>
* If numChannels is less than the number of ASR output channels, it will be automatically downmixed to the specified number of channels before bouncing.<br/>
* If the number of numChannels is larger than the number of output channels of ASR, silence will be recorded for the extra channels.<br/></para>
* </remarks>
* <seealso cref='CriWare.Editor.CriAtomWaveFile.StopBounce'/>
*/
public static bool StartBounce(string path, uint numChannels)
{
return criAtomWaveFile_StartBounce(path, numChannels);
}
/**
* <summary>Stops the bouncing</summary>
* <remarks>
* <para header='Description'>Stops the bouncing initiated by CriWare.Editor.CriAtomWaveFile.StartBounce .</para>
* </remarks>
* <seealso cref='CriWare.Editor.CriAtomWaveFile.StartBounce'/>
*/
public static void StopBounce()
{
criAtomWaveFile_StopBounce();
}
/**
* <summary>Acquiring the duration (expressed in ms) of the bounced waveform</summary>
* <returns>Duration of the bounced waveform</returns>
* <remarks>
* <para header='Description'>Gets the duration of the bounced waveform, expressed in milliseconds.</para>
* </remarks>
*/
public static uint GetBounceTime()
{
return criAtomWaveFile_GetBounceTime();
}
#region DLL Import
#if (UNITY_EDITOR && !UNITY_EDITOR_LINUX) && !CRIWARE_ENABLE_HEADLESS_MODE
[DllImport(CriWare.Common.pluginName, CallingConvention = CriWare.Common.pluginCallingConvention)]
private static extern bool criAtomWaveFile_StartBounce(string path, System.UInt32 num_channels);
[DllImport(CriWare.Common.pluginName, CallingConvention = CriWare.Common.pluginCallingConvention)]
private static extern void criAtomWaveFile_StopBounce();
[DllImport(CriWare.Common.pluginName, CallingConvention = CriWare.Common.pluginCallingConvention)]
private static extern System.UInt32 criAtomWaveFile_GetBounceTime();
#else
private static bool criAtomWaveFile_StartBounce(string path, System.UInt32 num_channels) { return false; }
private static void criAtomWaveFile_StopBounce() { }
private static System.UInt32 criAtomWaveFile_GetBounceTime() { return 0; }
#endif
#endregion
}
} //namespace CriWare.Editor
/**
* @}
*/
/* end of file */
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3b84f2ec5e0ac4724ac25c0df9625a72
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,743 @@
/****************************************************************************
*
* Copyright (c) 2011 CRI Middleware Co., Ltd.
*
****************************************************************************/
#if UNITY_2017 && UNITY_EDITOR_WIN
#define OPENFOLDERPANEL_IS_BROKEN
#endif
using UnityEngine;
using UnityEditor;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace CriWare {
public sealed class CriAtomWindow : EditorWindow
{
#region Variables
private int selectedAcfId = 0;
private int selectedDspBusSettingId = 0;
private int selectedCueInfoIndex = 0;
private int selectedCueSheetId = 0;
private string lastLoadedAcbGuid = null;
private string lastLoadedAcfGuid = null;
private bool isCueSheetListInitiated = false;
private int lastPreviewCueSheetId = -1;
private Vector2 scrollPosCueSheetList;
private Vector2 scrollPosCueList;
private Vector2 scrollPosWindow;
private bool useCopyAssetsFromCriAtomCraft = false;
private string[] popupAcfList = null;
private Color currentGuiColor;
private float cuesheetListWidth = 200;
private float cueIdListWidth = 70;
private bool isResizingLeftSplitter = false;
private bool isResizingRightSplitter = false;
private Vector2 lastMousePosLeftSplitter = new Vector2();
private Vector2 lastMousePosRightSplitter = new Vector2();
private GameObject targetObject = null;
private CriAtomSource targetAtomSource = null;
private CriWare.Editor.CriAtomEditorUtilities.PreviewPlayer previewPlayer = null;
private CriAtomExAcb previewAcb = null;
/* @cond excludele */
private ulong acbKey = 0;
private ulong lastAcbKey = 0;
private string lastSelectedAcbGuid = null;
/* @endcond */
[SerializeField] private string searchPath = "";
[SerializeField] private CriAtomWindowInfo projInfo = new CriAtomWindowInfo();
[SerializeField] private CriAtomWindowPrefs criAtomWindowPrefs = null;
[SerializeField] private GUIStyle toolBarButtonStyle = null;
[SerializeField] private bool showPrivateCue = false;
#endregion
#region Functions
[MenuItem("Window/CRIWARE/Atom Browser", false, 100)]
static void OpenWindow()
{
EditorWindow.GetWindow<CriAtomWindow>(false, "Atom Browser");
}
private void OnEnable() {
searchPath = Application.streamingAssetsPath;
criAtomWindowPrefs = CriAtomWindowPrefs.Load();
/* @cond excludele */
if (criAtomWindowPrefs.useCommonKey) {
var initializerObj = FindObjectOfType<CriWareInitializer>();
ulong parsedKey = 0;
if (initializerObj != null && initializerObj.useDecrypter == true && initializerObj.decrypterConfig != null
&& ulong.TryParse(initializerObj.decrypterConfig.key, out parsedKey)) {
criAtomWindowPrefs.SetOrRenewKeyThenSave("any", parsedKey);
}
}
/* @endcond */
if (Selection.gameObjects.Length > 0) {
targetObject = Selection.gameObjects[0];
targetAtomSource = targetObject.GetComponent<CriAtomSource>();
}
ReloadAcbInfo();
}
private void OnDisable() {
if (previewAcb != null) {
previewAcb.Dispose();
previewAcb = null;
}
lastLoadedAcbGuid = null;
if (previewPlayer != null) {
previewPlayer.Dispose();
previewPlayer = null;
}
}
private void OnSelectionChange() {
if (Selection.gameObjects.Length > 0) {
targetObject = Selection.gameObjects[0];
targetAtomSource = targetObject.GetComponent<CriAtomSource>();
}
Repaint();
}
private void OnLostFocus() {
StopPreview();
if (previewAcb != null) {
previewAcb.Dispose();
previewAcb = null;
}
lastLoadedAcbGuid = null;
}
private void OnGUI() {
if (toolBarButtonStyle == null) {
toolBarButtonStyle = new GUIStyle(EditorStyles.toolbarButton);
toolBarButtonStyle.alignment = TextAnchor.MiddleLeft;
}
currentGuiColor = GUI.color;
this.scrollPosWindow = GUILayout.BeginScrollView(this.scrollPosWindow);
{
GUISearchAndReload();
GUIACFSettings();
GUICueList();
EditorGUILayout.Space();
GUIImportAssetsFromAtomCraft();
EditorGUILayout.Space();
}
GUILayout.EndScrollView();
GUI.color = currentGuiColor;
}
private void ReloadAcbInfo() {
TryInitializePlugin();
projInfo.GetAcfInfoList(true, searchPath);
projInfo.GetAcbInfoList(true, searchPath);
selectedAcfId = 0;
selectedDspBusSettingId = 0;
selectedCueSheetId = 0;
selectedCueInfoIndex = 0;
ResetDataRecord();
}
private void ResetDataRecord() {
lastLoadedAcfGuid = null;
lastLoadedAcbGuid = null;
}
private void PlayPreview(CriAtomExAcb acb, string cuename) {
if (previewPlayer == null) {
previewPlayer = new CriWare.Editor.CriAtomEditorUtilities.PreviewPlayer();
}
previewPlayer.Play(acb, cuename);
}
private void StopPreview(bool withoutRelease = true) {
if (previewPlayer != null) {
previewPlayer.Stop(withoutRelease);
}
}
private void TryInitializePlugin() {
if (CriAtomPlugin.IsLibraryInitialized() == false) {
previewAcb = null;
}
if (CriWare.Editor.CriAtomEditorUtilities.InitializeLibrary()) {
ResetDataRecord();
}
}
private void GUISearchAndReload()
{
EditorGUILayout.BeginHorizontal();
{
this.searchPath = EditorGUILayout.TextField("Path to Search", this.searchPath);
#if !OPENFOLDERPANEL_IS_BROKEN
if (GUILayout.Button("...", EditorStyles.miniButton, GUILayout.Width(50)))
{
string pathTemp = EditorUtility.OpenFolderPanel("Select folder to search", this.searchPath, "");
if (string.IsNullOrEmpty(pathTemp) == false) {
if (pathTemp.Contains(Application.dataPath)) {
this.searchPath = pathTemp;
ReloadAcbInfo();
} else {
Debug.LogWarning("[CRIWARE] Selected folder should be inside this project. Search path will not be changed.");
}
}
}
#endif
if (GUILayout.Button("Reload Info", EditorStyles.miniButton, GUILayout.Width(100))) {
ReloadAcbInfo();
}
}
EditorGUILayout.EndHorizontal();
}
private void GUIACFSettings()
{
var acfInfo = projInfo.GetAcfInfoList(false, this.searchPath);
popupAcfList = new string[acfInfo.Count];
for (int i = 0; i < acfInfo.Count; i++) {
popupAcfList[i] = acfInfo[i].filePath;
}
if (acfInfo.Count > 0) {
selectedAcfId = EditorGUILayout.Popup("ACF Files", selectedAcfId, popupAcfList);
selectedDspBusSettingId = EditorGUILayout.Popup("DSPBusSettings", selectedDspBusSettingId, acfInfo[selectedAcfId].dspBusSettingsList.ToArray());
} else {
EditorGUILayout.LabelField("ACF Files", "No ACF has been found");
EditorGUILayout.LabelField("DSPBusSettings", "-");
}
}
private void GUICueList()
{
const int cCueListItemHeight = 18;
var acfInfoList = projInfo.GetAcfInfoList(false, this.searchPath);
var acbInfoList = projInfo.GetAcbInfoList(false, searchPath);
bool isAcfInfoAvailable = (selectedAcfId > acfInfoList.Count) && (selectedDspBusSettingId > acfInfoList[selectedAcfId].dspBusSettingsList.Count);
bool isCueSheetAvailable = false;
Rect splitterRect;
if (isCueSheetListInitiated == true) {
lastPreviewCueSheetId = this.selectedCueSheetId;
} else {
isCueSheetListInitiated = true;
}
EditorGUILayout.BeginHorizontal();
/* cuesheet list */
using (var cuesheetListScope = new EditorGUILayout.VerticalScope("CN Box", GUILayout.Width(cuesheetListWidth))) {
using (var horizontalScope = new EditorGUILayout.HorizontalScope()) {
if (GUILayout.Button("Cue Sheet", toolBarButtonStyle)) {
projInfo.SortCueSheet();
this.selectedCueSheetId = 0;
}
}
using (var cuesheetScrollViewScope = new EditorGUILayout.ScrollViewScope(scrollPosCueSheetList)) {
scrollPosCueSheetList = cuesheetScrollViewScope.scrollPosition;
int listLengthInView = (int)position.height / cCueListItemHeight;
int idFirstItemInView = Mathf.Clamp((int)scrollPosCueSheetList.y / cCueListItemHeight, 0, Mathf.Max(0, acbInfoList.Count - listLengthInView));
GUILayout.Space(idFirstItemInView * cCueListItemHeight);
for (int i = idFirstItemInView; i < Mathf.Min(idFirstItemInView + listLengthInView, acbInfoList.Count); i++) {
GUI.color = (this.lastPreviewCueSheetId == i) ? Color.yellow : currentGuiColor;
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button(acbInfoList[i].name, EditorStyles.label)) {
this.selectedCueSheetId = i;
}
EditorGUILayout.EndHorizontal();
}
GUILayout.Space(Mathf.Max(0, acbInfoList.Count - idFirstItemInView - listLengthInView) * cCueListItemHeight);
GUI.color = currentGuiColor;
}
}
splitterRect = EditorGUILayout.GetControlRect(false, 2, "CN Box", GUILayout.Width(2), GUILayout.ExpandHeight(true));
cuesheetListWidth += GUILayoutResizeHandler(splitterRect, true, ref lastMousePosLeftSplitter, ref isResizingLeftSplitter).x;
if (this.selectedCueSheetId != lastPreviewCueSheetId) {
this.selectedCueInfoIndex = 0;
}
isCueSheetAvailable = (acbInfoList.Count > this.selectedCueSheetId);
using (var cueListAndInfoScope = new EditorGUILayout.VerticalScope("CN Box")) {
bool playButtonPushed = false;
bool isCueAvailable = false;
CriAtomWindowInfo.CueInfo selectedCueInfo = null;
/* @cond excludele */
bool saveKeyButtonPushed = false;
bool commonKeyToggled = false;
/* @endcond */
/* list title */
using (var cueListTitleScope = new EditorGUILayout.HorizontalScope()) {
if (GUILayout.Button("Cue Name", toolBarButtonStyle)) {
if (isCueSheetAvailable) {
acbInfoList[selectedCueSheetId].SortCueInfo(CriAtomWindowInfo.CueSortType.Name);
this.selectedCueInfoIndex = 0;
}
}
splitterRect = EditorGUILayout.GetControlRect(false, 20, toolBarButtonStyle, GUILayout.Width(2));
cueIdListWidth -= GUILayoutResizeHandler(splitterRect, true, ref lastMousePosRightSplitter, ref isResizingRightSplitter).x;
if (GUILayout.Button("Cue ID", toolBarButtonStyle, GUILayout.Width(cueIdListWidth + 20))) {
if (isCueSheetAvailable) {
acbInfoList[selectedCueSheetId].SortCueInfo(CriAtomWindowInfo.CueSortType.Id);
this.selectedCueInfoIndex = 0;
}
}
}
/* cue list */
using (var cueListScope = new EditorGUILayout.ScrollViewScope(scrollPosCueList, GUILayout.ExpandHeight(true))) {
scrollPosCueList = cueListScope.scrollPosition;
if (isCueSheetAvailable) {
var acbInfo = acbInfoList[this.selectedCueSheetId];
List<CriAtomWindowInfo.CueInfo> currentList;
if (this.showPrivateCue) {
currentList = acbInfo.cueInfoList;
} else {
currentList = acbInfo.publicCueInfoList;
}
if (currentList.Count <= 0) {
EditorGUILayout.HelpBox("Nothing to be shown here.\nTry push the \"Reload Info\" button to refresh the list.", MessageType.Error);
} else {
int listLengthInView = (int)position.height / cCueListItemHeight;
int idFirstCueInView = Mathf.Clamp((int)scrollPosCueList.y / cCueListItemHeight, 0, Mathf.Max(0, currentList.Count - listLengthInView));
GUILayout.Space(idFirstCueInView * cCueListItemHeight);
for (int i = idFirstCueInView; i < Mathf.Min(idFirstCueInView + listLengthInView, currentList.Count); ++i) {
GUI.color = (this.selectedCueInfoIndex == i) ? Color.yellow : currentGuiColor;
using (var cueItemScope = new EditorGUILayout.HorizontalScope(GUILayout.Height(cCueListItemHeight))) {
if (GUILayout.Button(EditorGUIUtility.IconContent("Animation.Play"), EditorStyles.miniButton, GUILayout.Width(30))) {
this.selectedCueInfoIndex = i;
playButtonPushed = true;
}
if (GUILayout.Button(currentList[i].name + " (" + (currentList[i].length < 0 ? "loop" : Ms2String(currentList[i].length)) + ")", EditorStyles.label)) {
if (selectedCueInfoIndex != i) {
StopPreview();
}
this.selectedCueInfoIndex = i;
}
GUILayout.Label(currentList[i].id.ToString(), GUILayout.Width(cueIdListWidth));
}
}
GUILayout.Space(Mathf.Max(0, currentList.Count - idFirstCueInView - listLengthInView) * cCueListItemHeight);
GUI.color = currentGuiColor;
}
isCueAvailable = currentList.Count > this.selectedCueInfoIndex;
if (isCueAvailable) {
selectedCueInfo = currentList[selectedCueInfoIndex];
}
} else {
EditorGUILayout.HelpBox("No cue sheet is found.\nPlease check the search path. Press \"Reload Info\" button to refresh the list.", MessageType.Info);
}
}
/* @cond excludele */
if (isCueSheetAvailable) {
var acbInfo = acbInfoList[selectedCueSheetId];
if (acbInfo.assetGuid != lastSelectedAcbGuid) {
this.lastAcbKey = criAtomWindowPrefs.GetKey(acbInfo.assetGuid);
this.acbKey = this.lastAcbKey;
GUI.FocusControl(null);
}
this.lastSelectedAcbGuid = acbInfo.assetGuid;
}
/* @endcond */
EditorGUILayout.BeginHorizontal(EditorStyles.toolbar,GUILayout.ExpandWidth(true));
{
{
var tempToggleVal = GUILayout.Toggle(this.showPrivateCue, "Show Private Cue", GUILayout.Width(120));
if (tempToggleVal != this.showPrivateCue) {
/* Clear cue selection when change setting */
this.selectedCueInfoIndex = 0;
}
this.showPrivateCue = tempToggleVal;
}
if (GUILayout.Button("Stop All", EditorStyles.toolbarButton, GUILayout.Width(100))) {
StopPreview();
}
}
EditorGUILayout.EndHorizontal();
/* @cond excludele */
EditorGUILayout.BeginHorizontal(EditorStyles.toolbar,GUILayout.ExpandWidth(true));
{
GUILayout.Label("Decryption Key:", GUILayout.Width(100));
this.acbKey = (ulong)Math.Abs(EditorGUILayout.LongField("", (long)this.acbKey, EditorStyles.miniTextField, GUILayout.Width(100)));
if (GUILayout.Button("Save", EditorStyles.toolbarButton, GUILayout.Width(40))) { saveKeyButtonPushed = true; GUI.FocusControl(null);}
{
var tempToggleVal = GUILayout.Toggle(criAtomWindowPrefs.useCommonKey, "Common Key", GUILayout.Width(100));
if (tempToggleVal != criAtomWindowPrefs.useCommonKey) {
commonKeyToggled = true;
}
criAtomWindowPrefs.useCommonKey = tempToggleVal;
}
if (GUILayout.Button("Clear", EditorStyles.toolbarButton, GUILayout.Width(50))) { this.acbKey = 0; saveKeyButtonPushed = true; }
if (GUILayout.Button("Clear All Saved", EditorStyles.toolbarButton, GUILayout.Width(100))) { this.acbKey = 0; saveKeyButtonPushed = true; criAtomWindowPrefs.ClearKeysAndSave(); }
}
EditorGUILayout.EndHorizontal();
/* @endcond */
EditorGUILayout.Space();
EditorGUILayout.BeginHorizontal("AppToolbar");
{
GUILayout.Label("Cue Information");
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.LabelField("Cue ID", (isCueSheetAvailable && isCueAvailable) ? selectedCueInfo.id.ToString() : "N/A");
string cueName = "N/A";
string userData = "";
if (isCueSheetAvailable && isCueAvailable) {
cueName = selectedCueInfo.name;
userData = selectedCueInfo.comment;
}
GUILayout.BeginHorizontal();
GUILayout.Label("Cue Name", GUILayout.Width(145));
GUILayout.Label(cueName, GUILayout.ExpandWidth(false));
if (GUILayout.Button("Copy", GUILayout.Width(100))) {
GUIUtility.systemCopyBuffer = cueName;
}
GUILayout.EndHorizontal();
EditorGUILayout.LabelField("User Data", userData, EditorStyles.wordWrappedLabel, GUILayout.Height(28));
if (GUI.changed && isCueSheetAvailable) {
CriAtomWindowInfo.AcfInfo acfInfo = null;
var acbInfo = acbInfoList[selectedCueSheetId];
if (isAcfInfoAvailable) {
acfInfo = acfInfoList[selectedAcfId];
}
/* @cond excludele */
if (commonKeyToggled) {
this.acbKey = criAtomWindowPrefs.GetKey(acbInfo.assetGuid);
this.lastAcbKey = this.acbKey;
if (previewAcb != null) {
previewAcb.Dispose();
}
previewAcb = null;
lastLoadedAcbGuid = null;
}
if (saveKeyButtonPushed && acbKey != lastAcbKey) {
criAtomWindowPrefs.SetOrRenewKeyThenSave(acbInfoList[selectedCueSheetId].assetGuid, this.acbKey);
this.lastAcbKey = this.acbKey;
if (previewAcb != null) {
previewAcb.Dispose();
}
previewAcb = null;
lastLoadedAcbGuid = null;
}
/* @endcond */
if (playButtonPushed && isCueAvailable) {
StopPreview();
TryInitializePlugin();
if (isAcfInfoAvailable == false) {
CriAtomEx.UnregisterAcf();
lastLoadedAcfGuid = null;
selectedDspBusSettingId = 0;
} else if (lastLoadedAcfGuid != acfInfo.assetGuid) {
CriAtomEx.UnregisterAcf();
CriAtomEx.RegisterAcf(null, Path.Combine(CriWare.Common.streamingAssetsPath, acfInfo.filePath));
lastLoadedAcfGuid = acfInfo.assetGuid;
selectedDspBusSettingId = 0;
}
if (lastLoadedAcbGuid != acbInfo.assetGuid) {
if (previewAcb != null) {
previewAcb.Dispose();
}
previewAcb = CriAtomExAcb.LoadAcbFile(
null,
Path.Combine(CriWare.Common.streamingAssetsPath, acbInfo.acbPath),
string.IsNullOrEmpty(acbInfo.awbPath) ? null : Path.Combine(CriWare.Common.streamingAssetsPath, acbInfo.awbPath)
);
/* @cond excludele */
if (this.acbKey != 0) {
previewAcb.Decrypt(this.acbKey, 0);
}
/* @endcond */
lastLoadedAcbGuid = acbInfo.assetGuid;
}
if (previewAcb != null) {
CriAtomEx.DetachDspBusSetting();
if (isAcfInfoAvailable) {
CriAtomEx.AttachDspBusSetting(acfInfo.dspBusSettingsList[selectedDspBusSettingId]);
}
PlayPreview(previewAcb, selectedCueInfo.name);
}
}
}
/* edit buttons */
GUIEdit();
} /* cueListAndInfoScope */
EditorGUILayout.EndHorizontal();
}
private void GUIEdit()
{
EditorGUILayout.BeginHorizontal();
{
if (GUILayout.Button("Create GameObject", GUILayout.Height(22))) {
this.CreateAtomSourceGameObject(true);
}
if (this.targetObject == null) {
GUI.enabled = false;
}
if (GUILayout.Button("Add Component", GUILayout.Height(22))) {
if (targetObject != null) {
if (targetAtomSource != null) {
if (EditorUtility.DisplayDialog("Duplicate Component", "CriAtomSource Component already exists. \nDo you really want to add more?", "Yes", "Cancel")) {
this.CreateAtomSourceGameObject(false);
}
} else {
this.CreateAtomSourceGameObject(false);
}
}
}
if (this.targetAtomSource == null) {
GUI.enabled = false;
}
if (GUILayout.Button("Update Component", GUILayout.Height(22))) {
if (targetAtomSource != null) {
var acbInfoList = projInfo.GetAcbInfoList(false, searchPath);
if (acbInfoList.Count > this.selectedCueSheetId) {
var acbInfo = acbInfoList[this.selectedCueSheetId];
var cueInfo = acbInfo.cueInfoList[this.selectedCueInfoIndex];
Undo.RegisterCompleteObjectUndo(targetAtomSource, "AtomSource Update");
targetAtomSource.cueSheet = acbInfo.name;
targetAtomSource.cueName = cueInfo.name;
Selection.activeGameObject = targetObject;
}
}
}
GUI.enabled = true;
}
EditorGUILayout.EndHorizontal();
}
private void GUIImportAssetsFromAtomCraft()
{
if (criAtomWindowPrefs == null) {
criAtomWindowPrefs = CriAtomWindowPrefs.Load();
}
useCopyAssetsFromCriAtomCraft = CriFoldout(useCopyAssetsFromCriAtomCraft, "Import Assets from Atom Craft Project");
if (useCopyAssetsFromCriAtomCraft) {
EditorGUI.indentLevel++;
GUILayout.BeginHorizontal();
{
if (criAtomWindowPrefs != null) {
criAtomWindowPrefs.outputAssetsRoot = EditorGUILayout.TextField("Import From:", criAtomWindowPrefs.outputAssetsRoot);
}
#if !OPENFOLDERPANEL_IS_BROKEN
if (GUILayout.Button("...", EditorStyles.miniButton, GUILayout.Width(50))) {
string tmpPath = "";
string errorMsg;
tmpPath = EditorUtility.OpenFolderPanel("Select CRI Atom Craft output Assets Folder", criAtomWindowPrefs.outputAssetsRoot, "");
if (CheckPathIsAtomCraftAssetRoot(tmpPath, out errorMsg)) {
criAtomWindowPrefs.outputAssetsRoot = tmpPath;
criAtomWindowPrefs.Save();
} else {
Debug.LogWarning(errorMsg);
}
}
#endif
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
{
GUI.color = Color.yellow;
EditorGUILayout.PrefixLabel(" ");
if (GUILayout.Button("Import Assets", GUILayout.Width(160), GUILayout.Height(40))) {
string errorMsg;
if (CheckPathIsAtomCraftAssetRoot(criAtomWindowPrefs.outputAssetsRoot, out errorMsg) == false) {
Debug.LogWarning(errorMsg);
} else {
try {
CopyDirectory(criAtomWindowPrefs.outputAssetsRoot, Application.dataPath);
Debug.Log("[CRIWARE] Assets successfully imported from " + criAtomWindowPrefs.outputAssetsRoot);
} catch (Exception ex) {
Debug.LogError(ex.Message);
Debug.LogError("[CRIWARE] Failed to import assets from " + criAtomWindowPrefs.outputAssetsRoot);
}
AssetDatabase.Refresh();
ReloadAcbInfo();
}
}
GUI.color = Color.white;
EditorGUILayout.HelpBox("Copy \"Assets\" folder (created in CRI Atom Craft) to the \"StreamingAssets\" folder.\nThe folder can be created by building with the \"With Unity Assets\" flag in CRI Atom Craft.", MessageType.Info);
}
GUILayout.EndHorizontal();
EditorGUI.indentLevel--;
}
}
private bool CheckPathIsAtomCraftAssetRoot(string outString, out string errorMsg)
{
errorMsg = "";
try {
if (string.IsNullOrEmpty(outString) == false && Path.GetFileName(outString) == "Assets") {
if (Directory.Exists(outString) == false) {
errorMsg = "[CRIWARE] Path to the assets does not exist: " + outString;
return false;
}
foreach (string dir in Directory.GetDirectories(outString)) {
if (Path.GetFileName(dir) == "Editor") {
errorMsg = "[CRIWARE] Please choose the Assets folder in your <color=yellow>Atom Craft project</color> instead of the one in your Unity project. Import path will not be changed.";
return false;
}
}
return true;
} else {
errorMsg = "[CRIWARE] Unmatched folder name. Please set the right import path (\"Assets\" folder).";
return false;
}
} catch (Exception ex) {
errorMsg = "[CRIWARE] I/O Error: " + ex.Message;
return false;
}
}
private static void CopyDirectory(string sourceDirName, string destDirName)
{
try {
if (Directory.Exists(destDirName) == false) {
Directory.CreateDirectory(destDirName);
File.SetAttributes(destDirName, File.GetAttributes(sourceDirName));
}
foreach (var file in Directory.GetFiles(sourceDirName)) {
string ext = Path.GetExtension(file.Replace("\\", "/"));
if (ext == ".acf" || ext == ".acb" || ext == ".awb") {
string targetPath = Path.Combine(destDirName, Path.GetFileName(file));
Debug.Log(String.Format("[CRIWARE] Copying \"{0}\" to \"{1}\"", file, targetPath));
File.Copy(file, targetPath, true);
}
}
foreach (var dir in Directory.GetDirectories(sourceDirName)) {
/* sub directories */
CopyDirectory(dir, Path.Combine(destDirName, Path.GetFileName(dir)));
}
} catch {
throw;
}
}
private void CreateAtomSourceGameObject(bool createGameObjectFlag)
{
if (Selection.gameObjects.Length == 0) {
createGameObjectFlag = true;
}
var acbInfoList = projInfo.GetAcbInfoList(false, searchPath);
if (acbInfoList.Count > this.selectedCueSheetId) {
GameObject go = null;
if (createGameObjectFlag) {
go = new GameObject(acbInfoList[this.selectedCueSheetId].cueInfoList[this.selectedCueInfoIndex].name + "(CriAtomSource)");
if (Selection.gameObjects.Length > 0) {
go.transform.parent = Selection.gameObjects[0].transform;
}
Undo.RegisterCreatedObjectUndo(go, "Create AtomSource GameObject");
} else {
go = Selection.gameObjects[0];
}
var acbInfo = acbInfoList[this.selectedCueSheetId];
CriAtom atom = GameObject.FindObjectOfType(typeof(CriAtom)) as CriAtom;
if (atom == null) {
var criObject = GameObject.Find("/CRIWARE");
if (criObject == null) {
criObject = new GameObject("CRIWARE");
Undo.RegisterCreatedObjectUndo(criObject, "Add CRIWARE GameObject");
}
atom = Undo.AddComponent<CriAtom>(criObject);
var acfList = projInfo.GetAcfInfoList(false, searchPath);
if (acfList.Count > selectedAcfId) {
atom.acfFile = acfList[selectedAcfId].filePath;
}
}
CriAtomCueSheet cueSheet = atom.GetCueSheetInternal(acbInfo.name);
if (cueSheet == null) {
cueSheet = atom.AddCueSheetInternal(null, acbInfo.acbPath, acbInfo.awbPath, null);
}
CriAtomSource newCriAtomSource = Undo.AddComponent<CriAtomSource>(go);
newCriAtomSource.cueSheet = cueSheet.name;
newCriAtomSource.cueName = acbInfo.cueInfoList[this.selectedCueInfoIndex].name;
Selection.activeObject = go;
}
}
private Vector2 GUILayoutResizeHandler(Rect rect, bool isVertical, ref Vector2 lastMousePos, ref bool isResizing) {
EditorGUIUtility.AddCursorRect(rect, isVertical ? MouseCursor.SplitResizeLeftRight : MouseCursor.SplitResizeUpDown);
if (Event.current.type == EventType.MouseDown && rect.Contains(Event.current.mousePosition)) {
lastMousePos = Event.current.mousePosition;
isResizing = true;
}
if (isResizing) {
var mousePos = Event.current.mousePosition;
GUI.DrawTexture(new Rect(isVertical ? new Vector2(mousePos.x, rect.y) : new Vector2(rect.x, mousePos.y), rect.size), EditorGUIUtility.whiteTexture);
Repaint();
if (new Rect(Vector2.zero, this.position.size).Contains(mousePos) == false) {
isResizing = false;
}
}
if (Event.current.type == EventType.MouseUp) {
if (isResizing) {
isResizing = false;
return Event.current.mousePosition - lastMousePos;
}
isResizing = false;
}
return Vector2.zero;
}
private string Ms2String(long timeMs) {
long hh, mm, ss, ms;
hh = timeMs / 3600000;
mm = (timeMs % 3600000) / 60000;
ss = (timeMs % 60000) / 1000;
ms = timeMs % 1000;
string res = ((hh > 0) ? hh.ToString("00") + ":" : "") + ((mm > 0) ? mm.ToString("00") + ":" : "") + ss.ToString("00") + ":" + ms.ToString("000");
return res;
}
private bool CriFoldout(bool foldout, string content) {
#if UNITY_5_5_OR_NEWER
return EditorGUILayout.Foldout(foldout, content, true);
#else
return EditorGUILayout.Foldout(foldout, content);
#endif
}
#endregion
}
} //namespace CriWare
/* end of file */
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: bacfcb712a3304a40b91990e9f581c6d
timeCreated: 1433816076
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,17 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7dbb5a65a01a1de4ebfe0c4a1352cc1a, type: 3}
m_Name: CriAtomWindowPrefs
m_EditorClassIdentifier:
outputAssetsRoot:
useCommonKey: 1
cuesheetKeyList: []
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 88e77466f0e64194e982232dcf64d4e7
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,401 @@
/****************************************************************************
*
* Copyright (c) 2011 CRI Middleware Co., Ltd.
*
****************************************************************************/
using UnityEngine;
using UnityEditor;
using System;
using System.Collections.Generic;
using System.IO;
namespace CriWare {
[Serializable]
public class CriAtomWindowPrefs : ScriptableObject
{
public string outputAssetsRoot = String.Empty;
/* @cond excludele */
static readonly private string commonCuesheetGuid = "000000000";
public bool useCommonKey = true;
[SerializeField] private List<CueSheetKeyPair> cuesheetKeyList = new List<CueSheetKeyPair>();
private Dictionary<string, ulong> searchableKeyList = new Dictionary<string, ulong>();
/* @endcond */
static string FindInstance() {
var guids = AssetDatabase.FindAssets("t:" + typeof(CriAtomWindowPrefs).Name);
if (guids.Length <= 0)
return null;
if (guids.Length > 1) {
Debug.LogWarning("[CRIWARE] There are multiple preferences file of CriAtomWindow.");
}
return guids[0];
}
/* @cond excludele */
[Serializable]
public class CueSheetKeyPair {
public string cuesheetGuid;
public ulong key;
public CueSheetKeyPair(string cuesheetGuid, ulong key) {
this.cuesheetGuid = cuesheetGuid;
this.key = key;
}
}
/* Slow. Don't run it every frame */
public void SetOrRenewKeyThenSave(string cuesheetGuid, ulong key) {
if (useCommonKey) {
cuesheetGuid = commonCuesheetGuid;
}
if (searchableKeyList.ContainsKey(cuesheetGuid)) {
if (key == 0) {
searchableKeyList.Remove(cuesheetGuid);
} else {
searchableKeyList[cuesheetGuid] = key;
}
} else {
searchableKeyList.Add(cuesheetGuid, key);
}
this.Save();
}
/* Slow. Don't run it every frame */
public ulong GetKey(string cuesheetGuid) {
if (useCommonKey) {
cuesheetGuid = commonCuesheetGuid;
}
return searchableKeyList.ContainsKey(cuesheetGuid) ? searchableKeyList[cuesheetGuid] : 0;
}
public void ClearKeysAndSave() {
searchableKeyList.Clear();
useCommonKey = true;
this.Save();
}
private void SerializeKeyDict() {
this.cuesheetKeyList.Clear();
foreach (var elem in searchableKeyList) {
cuesheetKeyList.Add(new CueSheetKeyPair(elem.Key, elem.Value));
}
}
private void DeserializeKeyDict() {
this.searchableKeyList.Clear();
foreach(var elem in cuesheetKeyList) {
searchableKeyList.Add(elem.cuesheetGuid, elem.key);
}
}
/* @endcond */
public void Save ()
{
/* @cond excludele */
this.SerializeKeyDict();
/* @endcond */
if (string.IsNullOrEmpty(FindInstance())) {
var script = MonoScript.FromScriptableObject(this);
var prefsFilePath = Path.Combine(Path.GetDirectoryName(AssetDatabase.GetAssetPath(script)), "CriAtomWindowPrefs.asset");
AssetDatabase.CreateAsset(this, prefsFilePath);
} else {
EditorUtility.SetDirty(this);
}
AssetDatabase.SaveAssets ();
AssetDatabase.Refresh ();
}
public static CriAtomWindowPrefs Load ()
{
CriAtomWindowPrefs preference;
var guid = FindInstance();
if (string.IsNullOrEmpty(guid)) {
preference = CreateInstance<CriAtomWindowPrefs>();
preference.Save();
} else {
var path = AssetDatabase.GUIDToAssetPath(guid);
preference = AssetDatabase.LoadAssetAtPath<CriAtomWindowPrefs>(path);
}
/* @cond excludele */
preference.DeserializeKeyDict();
/* @endcond */
return preference;
}
}
[Serializable]
public class CriAtomWindowInfo {
#region Serializable Classes
[Serializable]
public class InfoBase {
public string name = "";
public int id = 0;
public string assetGuid = null;
public string comment = "";
}
[Serializable]
public class AcfInfo : InfoBase {
public string filePath = "";
public List<string> dspBusSettingsList = new List<string>();
public AcfInfo(string name, int id, string comment, string filePath) {
this.name = name;
this.id = id;
this.comment = comment;
this.filePath = filePath;
}
}
[Serializable]
public class AcbInfo : InfoBase {
public string acbPath = "";
public string awbPath = "";
public List<CueInfo> cueInfoList;
public List<CueInfo> publicCueInfoList;
private bool sortOrder = true; /* true = incremental */
public AcbInfo(string name, int id, string comment, string acbPath, string awbPath) {
this.name = name;
this.id = id;
this.comment = comment;
this.acbPath = acbPath;
this.awbPath = awbPath;
this.cueInfoList = new List<CueInfo>();
this.publicCueInfoList = new List<CueInfo>();
}
public void SortCueInfo(CueSortType type) {
if (cueInfoList.Count <= 0) {
return;
}
switch (type) {
case CueSortType.Id:
this.cueInfoList.Sort((CueInfo x, CueInfo y) => {
return sortOrder ? (x.id - y.id) : (y.id - x.id);
});
this.publicCueInfoList.Sort((CueInfo x, CueInfo y) => {
return sortOrder ? (x.id - y.id) : (y.id - x.id);
});
break;
case CueSortType.Name:
this.cueInfoList.Sort((CueInfo x, CueInfo y) => {
return sortOrder ? string.Compare(x.name, y.name) : string.Compare(y.name, x.name);
});
this.publicCueInfoList.Sort((CueInfo x, CueInfo y) => {
return sortOrder ? string.Compare(x.name, y.name) : string.Compare(y.name, x.name);
});
break;
default:
break;
}
sortOrder = !sortOrder;
}
}
public void SortCueSheet() {
switch (cuesheetSortType) {
case CueSheetSortType.NameInc:
this.acbInfoList.Sort((AcbInfo x, AcbInfo y) => (
string.Compare(x.name, y.name)
));
cuesheetSortType = CueSheetSortType.NameDec;
break;
case CueSheetSortType.NameDec:
this.acbInfoList.Sort((AcbInfo x, AcbInfo y) => (
string.Compare(y.name, x.name)
));
cuesheetSortType = CueSheetSortType.Id;
break;
case CueSheetSortType.Id:
this.acbInfoList.Sort((AcbInfo x, AcbInfo y) => (
x.id - y.id
));
cuesheetSortType = CueSheetSortType.NameInc;
break;
default:
break;
}
}
private enum CueSheetSortType {
NameInc,
NameDec,
Id
}
private CueSheetSortType cuesheetSortType = CueSheetSortType.NameInc;
public enum CueSortType {
Id,
Name
}
[Serializable]
public class CueInfo : InfoBase {
public long length;
public bool isPublic;
public CueInfo(string name, int id, string comment, long length, bool isPublic) {
this.name = name;
this.id = id;
this.comment = comment;
this.length = length;
this.isPublic = isPublic;
}
} /* end of class */
#endregion
#region Fields
[SerializeField] private List<AcfInfo> acfInfoList = new List<AcfInfo>();
[SerializeField] private List<AcbInfo> acbInfoList = new List<AcbInfo>();
#endregion
public List<AcbInfo> GetAcbInfoList(bool forceReload, string searchPath) {
if (acbInfoList == null || forceReload) {
if (acbInfoList != null) { acbInfoList.Clear(); }
acbInfoList = new List<AcbInfo>();
string[] files = null;
try {
files = Directory.GetFiles(searchPath, "*.acb", SearchOption.AllDirectories);
} catch (Exception ex) {
if (ex is ArgumentException || ex is ArgumentNullException) {
Debug.LogWarning("[CRIWARE] Insufficient search path. Please check the path for file searching.");
} else if (ex is DirectoryNotFoundException) {
Debug.LogWarning("[CRIWARE] Search path not found: " + searchPath);
} else {
Debug.LogError("[CRIWARE] Error getting ACB files. Message: " + ex.Message);
}
}
if (files != null && CriAtomPlugin.IsLibraryInitialized()) {
int acbIndex = 0;
foreach (string file in files) {
string acbFilePath = file.Replace("\\", "/");
AcbInfo acbInfo = new AcbInfo(
Path.GetFileNameWithoutExtension(acbFilePath),
acbIndex++,
"",
TryGetRelFilePath(acbFilePath),
TryGetAwbFile(acbFilePath));
/* 指定したACBファイル名(キューシート名)を指定してキュー情報を取得 */
CriAtomExAcb acb = CriAtomExAcb.LoadAcbFile(null, acbFilePath, "");
if (acb != null) {
acbInfo.assetGuid = AssetDatabase.AssetPathToGUID("Assets" + acbFilePath.Substring(Application.dataPath.Length));
/* キュー名リストの作成 */
CriAtomEx.CueInfo[] cueInfoList = acb.GetCueInfoList();
foreach (CriAtomEx.CueInfo cueInfo in cueInfoList) {
bool found = false;
foreach (var key in acbInfo.cueInfoList) {
if (key.id == cueInfo.id) {
found = true;
break;
}
}
if (found == false) {
var newCueInfo = new CueInfo(cueInfo.name, cueInfo.id, cueInfo.userData, cueInfo.length, Convert.ToBoolean(cueInfo.headerVisibility));
acbInfo.cueInfoList.Add(newCueInfo);
if (newCueInfo.isPublic) {
acbInfo.publicCueInfoList.Add(newCueInfo);
}
} else {
/* inGame時のサブシーケンスの場合あり */
Debug.Log("[CRIWARE] Duplicate cue ID " + cueInfo.id.ToString() + " in cue sheet " + acbInfo.name + ". Last cue name:" + cueInfo.name);
}
}
acb.Dispose();
} else {
Debug.Log("[CRIWARE] Failed to load ACB file: " + file);
}
acbInfoList.Add(acbInfo);
}
}
}
return acbInfoList;
}
public List<AcfInfo> GetAcfInfoList(bool forceReload, string searchPath) {
if (acfInfoList == null || forceReload) {
if (acfInfoList != null) { acfInfoList.Clear(); }
acfInfoList = new List<AcfInfo>();
string[] files = null;
try {
files = System.IO.Directory.GetFiles(searchPath, "*.acf", System.IO.SearchOption.AllDirectories);
} catch (Exception ex) {
if (ex is ArgumentException || ex is ArgumentNullException) {
Debug.LogWarning("[CRIWARE] Insufficient search path. Please check the path for file searching.");
} else if (ex is DirectoryNotFoundException) {
Debug.LogWarning("[CRIWARE] Search path not found: " + searchPath);
} else {
Debug.LogError("[CRIWARE] Error getting ACF files. Message: " + ex.Message);
}
}
if (files != null && CriAtomPlugin.IsLibraryInitialized()) {
int index = 0;
foreach (string file in files) {
string acfFilePath = file.Replace("\\", "/");
var acfInfo = new AcfInfo(
System.IO.Path.GetFileNameWithoutExtension(acfFilePath),
index++,
"",
TryGetRelFilePath(acfFilePath));
acfInfo.assetGuid = AssetDatabase.AssetPathToGUID("Assets" + acfFilePath.Substring(Application.dataPath.Length));
CriAtomEx.RegisterAcf(null, acfFilePath);
CriAtomExAcf.AcfInfo nativeAcfInfo;
CriAtomExAcf.GetAcfInfo(out nativeAcfInfo);
for (ushort i = 0; i < nativeAcfInfo.numDspSettings; ++i) {
acfInfo.dspBusSettingsList.Add(CriAtomExAcf.GetDspSettingNameByIndex(i));
}
CriAtomEx.UnregisterAcf();
acfInfoList.Add(acfInfo);
}
}
}
return acfInfoList;
}
public void ResetInfo() {
this.acfInfoList.Clear();
this.acfInfoList = null;
this.acbInfoList.Clear();
this.acbInfoList = null;
}
private string TryGetRelFilePath(string path) {
Uri streamingAssetsUri = new Uri(CriWare.Common.streamingAssetsPath);
Uri fullPathUri = new Uri(path);
if (fullPathUri.ToString().Contains(streamingAssetsUri.ToString())) {
string[] splitter = { streamingAssetsUri.ToString() + "/" };
var pathChunks = fullPathUri.ToString().Split(splitter, StringSplitOptions.RemoveEmptyEntries);
return pathChunks[pathChunks.Length - 1];
} else {
return path;
}
}
private string TryGetAwbFile(string acbPath) {
string dir = Path.GetDirectoryName(acbPath);
string filenameNoExt = Path.GetFileNameWithoutExtension(acbPath);
string presumedAwbPath = Path.Combine(dir, filenameNoExt + ".awb");
if (File.Exists(presumedAwbPath)) {
return TryGetRelFilePath(presumedAwbPath);
} else {
return "";
}
}
}
} //namespace CriWare
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7dbb5a65a01a1de4ebfe0c4a1352cc1a
timeCreated: 1445602397
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4cbed90d60f1598439f1b8e8ca810b49
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,213 @@
/****************************************************************************
*
* Copyright (c) CRI Middleware Co., Ltd.
*
****************************************************************************/
#if UNITY_2019_3_OR_NEWER && CRIWARE_TIMELINE_1_OR_NEWER
using UnityEditor;
using UnityEngine;
using UnityEditor.Timeline;
using UnityEngine.Events;
using System;
namespace CriWare {
namespace CriTimeline.Atom {
public partial class CriAtomClipWaveformPreviewer {
private class CriAtomClipWaveformCanvas : IDisposable {
private const string SHADER = "CRIWARE/CriAtomClipWaveformRender";
private const int DEFAULT_TEXTURE_WIDTH = 4096;
private static readonly Color backgroundColor = Color.clear;
private static readonly Color waveColorForAll = new Color(1.0f, 0.635f, 0.0f, 1.0f); /* yellow */
private static readonly Color waveColorForMono = new Color(0.332f, 0.661f, 0.991f, 1f); /* blue */
private Texture2D texture;
private Material material;
private int scanPosition = 0;
private ClipBackgroundRegion lastRegion;
private int lastWidth = 0;
private bool lastLoop = false;
private bool isDirty = true;
private bool isDisposed = false;
public UnityAction updated = null;
public bool IsDirty {
get { return isDirty; }
set {
if (isDirty = value) {
scanPosition = 0;
}
}
}
public CriAtomClipWaveformCanvas() {
this.texture = null;
this.material = new Material(Shader.Find(SHADER));
}
~CriAtomClipWaveformCanvas() {
dispose();
}
public void Dispose() {
dispose();
GC.SuppressFinalize(this);
}
public void UpdateTexture(ref CriAtomClipWaveformInfo info, bool loop, ClipBackgroundRegion? region = null, bool renderOnce = false) {
const int BATCH_NUM_PIXEL = 50;
int scanWidth = region.HasValue ? (int)region.Value.position.width : DEFAULT_TEXTURE_WIDTH;
if (texture == null) {
texture = new Texture2D(scanWidth, info.waveformInfo.numChannels, TextureFormat.RG16, false);
texture.wrapMode = TextureWrapMode.Clamp;
texture.filterMode = FilterMode.Bilinear;
} else if (renderOnce == false) {
if (region.HasValue && lastWidth != scanWidth) {
#if UNITY_2021_2_OR_NEWER
texture.Reinitialize(scanWidth, texture.height);
#else
texture.Resize(scanWidth, texture.height);
#endif
this.IsDirty = true;
lastWidth = scanWidth;
}
if (region.HasValue && region.Value != lastRegion) {
this.IsDirty = true;
lastRegion = region.Value;
}
if (loop != lastLoop) {
this.IsDirty = true;
lastLoop = loop;
}
}
if (isDirty) {
if (this.scanPosition >= scanWidth) {
this.IsDirty = false;
return;
}
} else {
return;
}
long startSmpIdx = region.HasValue
? (long)((region.Value.startTime / info.waveDurationSecond) * info.waveformInfo.numSamples)
: 0;
long endSmpIdx = region.HasValue
? (long)((region.Value.endTime / info.waveDurationSecond) * info.waveformInfo.numSamples)
: (info.waveformInfo.numSamples - 1);
long smpLength = endSmpIdx - startSmpIdx + 1;
float samplePerPixel = smpLength / (float)scanWidth;
if (samplePerPixel <= 0) {
samplePerPixel = float.Epsilon;
}
for (int y = 0; y < texture.height; ++y) {
for (int x = scanPosition; x < scanPosition + BATCH_NUM_PIXEL; ++x) {
Int16 maxValue, minValue;
long startPnt = (long)(startSmpIdx + x * samplePerPixel);
if (loop) {
startPnt %= info.waveformInfo.numSamples;
}
long range = (long)Mathf.Ceil(samplePerPixel);
if (startPnt + range > info.waveformInfo.numSamples) {
range = (long)Mathf.Floor(info.waveformInfo.numSamples - startPnt);
}
GetMinMaxPcmArray(info.lpcmBufferByInterleave,
startPnt,
range,
y,
info.waveformInfo.numChannels,
out minValue, out maxValue);
texture.SetPixel(x, y, new Color(
maxValue / (float)Int16.MaxValue,
minValue / (float)Int16.MinValue,
0));
}
}
texture.Apply();
scanPosition += BATCH_NUM_PIXEL;
if (this.updated != null) {
this.updated();
}
}
private static void GetMinMaxPcmArray(Int16[] array, long index, long length, int channel, int numChannels, out Int16 min, out Int16 max) {
Int16 maxValue = 0;
Int16 minValue = 0;
for (long i = 0; i < length; i++) {
var currentIndex = (index + i) * numChannels + channel;
var amplitude = array[currentIndex];
if (maxValue < amplitude) {
maxValue = amplitude;
}
if (minValue > amplitude) {
minValue = amplitude;
}
}
max = maxValue;
min = minValue;
}
public void Draw(Rect rect) {
if (this.texture == null || this.material == null) { return; }
Graphics.DrawTexture(rect, this.texture, this.material);
}
public void SetMatParams(
RenderChannelMode channelMode,
int numChannels,
bool isLooping,
bool isMuted,
float scale,
float offset)
{
this.material.SetTexture("_MainTex", this.texture);
this.material.SetColor("_BacCol", backgroundColor);
this.material.SetColor("_ForCol", channelMode == RenderChannelMode.All ? waveColorForAll : waveColorForMono);
this.material.SetFloat("_Channel", channelMode == RenderChannelMode.All ? numChannels : 1);
this.material.SetFloat("_Scale", scale);
this.material.SetFloat("_Offset", offset);
this.material.SetInt("_IsLoop", isLooping ? 1 : 0);
this.material.SetInt("_IsMute", isMuted ? 1 : 0);
this.material.SetInt("_ForceMono", channelMode == RenderChannelMode.Mono ? 1 : 0);
}
private void dispose() {
if (this.isDisposed) { return; }
if (Application.isPlaying) {
UnityEngine.Object.Destroy(this.texture);
UnityEngine.Object.Destroy(this.material);
} else {
UnityEngine.Object.DestroyImmediate(this.texture);
UnityEngine.Object.DestroyImmediate(this.material);
}
this.texture = null;
this.material = null;
this.isDisposed = true;
}
} //class CriAtomClipWaveformCanvas
} //partial class CriAtomClipWaveformPreviewer
} //namespace CriTimeline.Atom
} //namespace CriWare
#endif
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f0f13bdc836d8464aabbebf21dab6560
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,84 @@
Shader "CRIWARE/CriAtomClipWaveformRender" {
Properties{
_MainTex("Main Texture", 2D) = "white" { }
}
SubShader{
Pass {
Tags { "RenderType" = "Opaque" }
Cull Off
ZWrite Off
ZTest Always
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
uniform sampler2D _MainTex;
uniform float4 _MainTex_ST;
uniform fixed4 _BacCol;
uniform fixed4 _ForCol;
uniform float _Offset;
uniform float _Scale;
uniform int _IsLoop;
uniform int _IsMute;
uniform float _Channel;
uniform int _ForceMono;
struct appdata {
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
};
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
inline float zero_amplitude(v2f v, float volume) {
return floor(volume * 100.0) == 0.0 ? abs(ddy(v.uv.y)) : volume;
}
v2f vert(appdata v) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
o.uv.x *= _Scale;
o.uv.x += _Offset;
return o;
}
fixed4 frag(v2f v) : SV_Target {
float channel_height = (1.0 / (_Channel));
int ch = floor(v.uv.y / (1.0 / _Channel)) + 1;
/* uv.y reads the values in reverse order of texture creation. */
/* but _ForceMono is true, read the first channel at the end. */
float2 ch_vec2 = {frac(v.uv.x), _Channel > 1 ? (ch - 1) * (1.0 / (_Channel - 1)) : 0.0 };
ch_vec2.y = _ForceMono < 1 ? 1.0 - ch_vec2.y : ch_vec2.y;
float volume_max = tex2D(_MainTex, ch_vec2).r * channel_height / 2.0;
volume_max = zero_amplitude(v, volume_max);
volume_max = v.uv.x > 1 && _IsLoop < 1 ? abs(ddy(v.uv.y)) : volume_max;
volume_max = _IsMute >= 1 ? abs(ddy(v.uv.y)) : volume_max;
float volume_min = tex2D(_MainTex, ch_vec2).g * channel_height / 2.0;
volume_min = zero_amplitude(v, volume_min);
volume_min = v.uv.x > 1 && _IsLoop < 1 ? abs(ddy(v.uv.y)) : volume_min;
volume_min = _IsMute >= 1 ? abs(ddy(v.uv.y)) : volume_min;
float uvY = v.uv.y - ((channel_height / 2.0) * ch * 2.0) + channel_height / 2.0;
fixed4 col = lerp(
_BacCol,
_ForCol,
-volume_min <= uvY && uvY <= volume_max
);
clip(col.a - 0.5);
return col;
}
ENDCG
}
}
}
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: f420a9b00c3898a4eb0ed6f645a04081
timeCreated: 1606370626
licenseType: Pro
ShaderImporter:
externalObjects: {}
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,302 @@
/****************************************************************************
*
* Copyright (c) 2019 CRI Middleware Co., Ltd.
*
****************************************************************************/
//#define CRI_TIMELINE_ATOM_VERBOSE_DEBUG
#if UNITY_2018_1_OR_NEWER && CRIWARE_TIMELINE_1_OR_NEWER
using UnityEditor;
using UnityEngine;
using UnityEditor.Timeline;
using UnityEngine.Timeline;
using System.Runtime.InteropServices;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace CriWare {
namespace CriTimeline.Atom {
[CustomPropertyDrawer(typeof(CriAtomBehaviour))]
public class CriAtomTimelineDrawer : PropertyDrawer {
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
SerializedProperty volumeProp = property.FindPropertyRelative("volume");
SerializedProperty pitchProp = property.FindPropertyRelative("pitch");
SerializedProperty aisacProp = property.FindPropertyRelative("AISACValue");
EditorGUILayout.PropertyField(volumeProp);
EditorGUILayout.PropertyField(pitchProp);
EditorGUILayout.PropertyField(aisacProp);
}
}
[CustomEditor(typeof(CriAtomClipBase)), CanEditMultipleObjects]
public class CriAtomClipEditor : UnityEditor.Editor { }
[CustomEditor(typeof(CriAtomTrack))]
public class CriAtomTrackEditor : UnityEditor.Editor {
private CriAtomTrack m_object;
public void OnEnable() {
if (target != null) {
m_object = target as CriAtomTrack;
}
}
public override void OnInspectorGUI() {
if (m_object == null) {
return;
}
serializedObject.Update();
EditorGUI.BeginChangeCheck();
EditorGUILayout.LabelField("Track Settings", EditorStyles.boldLabel);
DrawLine(Color.black);
m_object.m_AisacControls
= EditorGUILayout.TextField("Aisac Control", m_object.m_AisacControls);
m_object.m_StopOnWrapping
= EditorGUILayout.Toggle("Stop On Wrapping", m_object.m_StopOnWrapping);
m_object.m_StopAtGraphEnd
= EditorGUILayout.Toggle("Stop At Graph End", m_object.m_StopAtGraphEnd);
EditorGUILayout.Space();
EditorGUILayout.LabelField("Unity Editor", EditorStyles.boldLabel);
DrawLine(Color.black);
m_object.m_IsRenderMono
= EditorGUILayout.Toggle("Show Mono Waveform", m_object.m_IsRenderMono);
serializedObject.ApplyModifiedProperties();
if (EditorGUI.EndChangeCheck()) {
EditorUtility.SetDirty(m_object);
}
}
private static void DrawLine(Color color, int thickness = 1, int padding = 10) {
Rect rect = EditorGUILayout.GetControlRect(GUILayout.Height(padding + thickness));
rect.height = thickness;
rect.y += padding / 2;
rect.x -= 2;
rect.width += 6;
EditorGUI.DrawRect(rect, color);
}
}
#if UNITY_2019_3_OR_NEWER
[CustomTimelineEditor(typeof(CriAtomClipBase))]
public class CriAtomClipWaveformEditor : UnityEditor.Timeline.ClipEditor {
private Dictionary<CriAtomClipBase, CriAtomClipWaveformPreviewer> atomClipPreviewDirectory
= new Dictionary<CriAtomClipBase, CriAtomClipWaveformPreviewer>();
public override void OnCreate(TimelineClip clip, TrackAsset track, TimelineClip clonedFrom) {
base.OnCreate(clip, track, clonedFrom);
#if CRI_TIMELINE_ATOM_VERBOSE_DEBUG
Debug.Log("[CRIWARE][Timeline] OnCreate");
#endif
atomClipPreviewDirectory.Clear();
CriAtomClipBase atomClip = clip.asset as CriAtomClipBase;
atomClipPreviewDirectory.Add(atomClip, new CriAtomClipWaveformPreviewer(atomClip));
}
public override void OnClipChanged(TimelineClip clip) {
base.OnClipChanged(clip);
#if CRI_TIMELINE_ATOM_VERBOSE_DEBUG
Debug.Log("[CRIWARE][Timeline] OnClipChanged");
#endif
CriAtomClipBase atomClip = clip.asset as CriAtomClipBase;
if (atomClipPreviewDirectory.ContainsKey(atomClip)) {
return;
}
atomClipPreviewDirectory.Add(atomClip, new CriAtomClipWaveformPreviewer(atomClip));
}
public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region) {
base.DrawBackground(clip, region);
#if CRI_TIMELINE_ATOM_VERBOSE_DEBUG
Debug.Log("[CRIWARE][Timeline] DrawBackground");
Debug.Log("region.startTime : " + region.startTime.ToString() + "region.endTime : " + region.endTime.ToString());
#endif
CriAtomClipBase atomClip = clip.asset as CriAtomClipBase;
CriAtomClipWaveformPreviewer atomClipPreviewer;
if (!atomClipPreviewDirectory.TryGetValue(atomClip, out atomClipPreviewer)) {
#if CRI_TIMELINE_ATOM_VERBOSE_DEBUG
Debug.LogError("[CRIWARE][Timeline] not contains key : " + clip.displayName);
#endif
return;
}
if (!atomClipPreviewer.HasDecodeTask()) {
atomClipPreviewDirectory.Remove(atomClip);
atomClipPreviewDirectory.Add(atomClip, new CriAtomClipWaveformPreviewer(atomClip));
}
if (!atomClipPreviewer.HasPreviewData()) {
/* While decoding or decode error. Skip renderring. */
return;
}
atomClipPreviewer.IsLooping = atomClip.loopWithinClip;
atomClipPreviewer.IsMuted = atomClip.muted;
CriAtomTrack atomTrack = clip.parentTrack as CriAtomTrack;
if (atomTrack.m_IsRenderMono) {
atomClipPreviewer.ChannelMode = CriAtomClipWaveformPreviewer.RenderChannelMode.Mono;
} else {
atomClipPreviewer.ChannelMode = CriAtomClipWaveformPreviewer.RenderChannelMode.All;
}
if (Event.current.type == EventType.Repaint) {
atomClipPreviewer.RenderMaterial(region);
}
}
}
public partial class CriAtomClipWaveformPreviewer {
/* Number of drawing channels */
public enum RenderChannelMode {
Mono = 0, /* Mono(Left Channel) */
All /* All Channels */
}
public bool IsLooping = false;
public bool IsMuted = true;
public RenderChannelMode ChannelMode = RenderChannelMode.Mono;
private struct CriAtomClipWaveformInfo {
public CriAtomEx.WaveformInfo waveformInfo;
public double waveDurationSecond;
public Int16[] lpcmBufferByInterleave;
}
private Task decodeTask = null;
private CriAtomClipWaveformInfo atomClipWaveformInfo;
private CriAtomClipWaveformCanvas simpleCanvas;
private CriAtomClipWaveformCanvas regionalCanvas;
public CriAtomClipWaveformPreviewer(CriAtomClipBase criAtomClip) {
if (!CriAtomTimelinePreviewer.IsInitialized || string.IsNullOrEmpty(criAtomClip.AcbPath)) {
return;
}
var acb = CriAtomTimelinePreviewer.Instance.GetAcb(criAtomClip.AcbPath, criAtomClip.AwbPath);
if (acb == null) {
Debug.LogError("[CRIWARE][Timeline] faild to load acb object.");
return;
}
decodeTask = Task.Run(() =>
{
this.atomClipWaveformInfo = new CriAtomClipWaveformInfo();
if (!acb.GetWaveFormInfo(criAtomClip.CueName, out this.atomClipWaveformInfo.waveformInfo)) {
/* without waveform */
return;
}
this.atomClipWaveformInfo.lpcmBufferByInterleave = new Int16[this.atomClipWaveformInfo.waveformInfo.numSamples * this.atomClipWaveformInfo.waveformInfo.numChannels];
if (!LoadWaveform(acb.nativeHandle, criAtomClip.CueName, ref this.atomClipWaveformInfo.lpcmBufferByInterleave)) {
this.atomClipWaveformInfo.lpcmBufferByInterleave = null;
return;
}
this.atomClipWaveformInfo.waveDurationSecond = this.atomClipWaveformInfo.waveformInfo.numSamples / (double)this.atomClipWaveformInfo.waveformInfo.samplingRate;
});
simpleCanvas = new CriAtomClipWaveformCanvas();
simpleCanvas.updated += () => {
TimelineEditor.Refresh(RefreshReason.WindowNeedsRedraw);
};
regionalCanvas = new CriAtomClipWaveformCanvas();
regionalCanvas.updated += () => {
TimelineEditor.Refresh(RefreshReason.WindowNeedsRedraw);
};
}
~CriAtomClipWaveformPreviewer() {
if (decodeTask != null) {
if (!decodeTask.IsCompleted) {
decodeTask.Wait();
}
decodeTask.Dispose();
decodeTask = null;
}
simpleCanvas.Dispose();
simpleCanvas = null;
regionalCanvas.Dispose();
regionalCanvas = null;
}
public bool HasDecodeTask() {
return decodeTask == null ? false : true;
}
public bool HasPreviewData() {
if (decodeTask == null || decodeTask.IsFaulted || decodeTask.IsCanceled || !decodeTask.IsCompleted) {
return false;
}
/* decodeTask.IsCompleted == true and buffer == null is decode error. */
return this.atomClipWaveformInfo.lpcmBufferByInterleave != null;
}
public void RenderMaterial(ClipBackgroundRegion region) {
if (region.position.height <= 0 | region.position.width <= 0) {
/* region.position is invalid. */
return;
}
simpleCanvas.UpdateTexture(ref this.atomClipWaveformInfo, this.IsLooping, renderOnce:true);
regionalCanvas.UpdateTexture(ref this.atomClipWaveformInfo, this.IsLooping, region);
simpleCanvas.SetMatParams(
channelMode: ChannelMode,
numChannels: this.atomClipWaveformInfo.waveformInfo.numChannels,
isLooping: this.IsLooping,
isMuted: this.IsMuted,
scale: (float)((region.endTime - region.startTime) / this.atomClipWaveformInfo.waveDurationSecond),
offset: (float)(region.startTime / this.atomClipWaveformInfo.waveDurationSecond));
regionalCanvas.SetMatParams(
channelMode: ChannelMode,
numChannels: this.atomClipWaveformInfo.waveformInfo.numChannels,
isLooping: this.IsLooping,
isMuted: this.IsMuted,
scale: 1f,
offset: 0);
if (regionalCanvas.IsDirty) {
simpleCanvas.Draw(region.position);
} else {
regionalCanvas.Draw(region.position);
}
}
private static bool LoadWaveform(IntPtr acbHn, string cueName, ref System.Int16[] decodeLpcmBuffer) {
var gcHandle = GCHandle.Alloc(decodeLpcmBuffer, GCHandleType.Pinned);
var result = CRIWAREF2B79675(acbHn, cueName, gcHandle.AddrOfPinnedObject(), decodeLpcmBuffer.LongLength);
gcHandle.Free();
return result;
}
#region DLL Import
#if !CRIWARE_ENABLE_HEADLESS_MODE
[DllImport(CriWare.Common.pluginName, CallingConvention = CriWare.Common.pluginCallingConvention)]
private static extern bool CRIWAREF2B79675(IntPtr acbHn, string cue_name, IntPtr decode_lpcm_buffer, System.Int64 decodeLpcmBufferLength);
#else
private static bool CRIWAREF2B79675(IntPtr acbHn, string cue_name, IntPtr decode_lpcm_buffer, System.Int64 decodeLpcmBufferLength) {return false;}
#endif
#endregion
}
#endif //UNITY_2019_3_OR_NEWER
}
} //namespace CriWare
#endif //UNITY_2018_1_OR_NEWER
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 64709c1c359e022439e2bde0e6afa2d4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: