Audio importer lets you modify AudioClip import settings from editor scripts.

Inheritance: AssetImporter
Esempio n. 1
0
        public static void SetAudioImporterThreeD(UnityEditor.AudioImporter importer, bool p)
        {
#if UNITY_4_6_OR_EARLIER
            //3Dサウンドをオフに
            importer.threeD = false;
#else
#endif
        }
    public GLexSound(AudioClip pClip, float pVolume, bool pLooping)
        : base()
    {
        mComponent = pClip;
        mImporter = (AudioImporter)AssetImporter.GetAtPath(OriginalURL);

        _volume = pVolume;
        _loops = pLooping;

        _dataBytes = File.ReadAllBytes(AssetDatabase.GetAssetPath(mComponent));
        _dataBinaryId = NamesUtil.GenerateBinaryId(_dataBytes, GLex.Instance.UserName);
    }
        // public void OnPostprocessAudio (AudioClip clip) {}
        public static bool IsSameAudioSetting(AudioImporter target, AudioImporter compareBase)
        {
            // defaultSampleSettings
            if (target.defaultSampleSettings.compressionFormat != compareBase.defaultSampleSettings.compressionFormat) return false;
            if (target.defaultSampleSettings.loadType != compareBase.defaultSampleSettings.loadType) return false;
            if (target.defaultSampleSettings.quality != compareBase.defaultSampleSettings.quality) return false;
            if (target.defaultSampleSettings.sampleRateOverride != compareBase.defaultSampleSettings.sampleRateOverride) return false;
            if (target.defaultSampleSettings.sampleRateSetting != compareBase.defaultSampleSettings.sampleRateSetting) return false;

            if (target.forceToMono != compareBase.forceToMono) return false;
            if (target.loadInBackground != compareBase.loadInBackground) return false;
            if (target.preloadAudioData != compareBase.preloadAudioData) return false;

            return true;
        }
Esempio n. 4
0
        public override Texture2D RenderStaticPreview(string assetPath, Object[] subAssets, int width, int height)
        {
            AssetImporter atPath    = AssetImporter.GetAtPath(assetPath);
            AudioImporter importer2 = atPath as AudioImporter;

            if (importer2 == null)
            {
                return(null);
            }
            AudioClip target = this.target as AudioClip;

            Texture2D[] waveForms = new Texture2D[target.channels];
            for (int i = 0; i < target.channels; i++)
            {
                waveForms[i] = AudioUtil.GetWaveForm(target, atPath, i, (float)width, (float)(height / target.channels));
            }
            return(CombineWaveForms(waveForms));
        }
        public override Texture2D RenderStaticPreview(string assetPath, UnityEngine.Object[] subAssets, int width, int height)
        {
            AudioClip     clip          = this.target as AudioClip;
            AssetImporter atPath        = AssetImporter.GetAtPath(assetPath);
            AudioImporter audioImporter = atPath as AudioImporter;

            if (audioImporter == null || !ShaderUtil.hardwareSupportsRectRenderTexture)
            {
                return(null);
            }
            if (this.m_PreviewUtility == null)
            {
                this.m_PreviewUtility = new PreviewRenderUtility();
            }
            this.m_PreviewUtility.BeginStaticPreview(new Rect(0f, 0f, (float)width, (float)height));
            this.DoRenderPreview(clip, audioImporter, new Rect(0.05f * (float)width * EditorGUIUtility.pixelsPerPoint, 0.05f * (float)width * EditorGUIUtility.pixelsPerPoint, 1.9f * (float)width * EditorGUIUtility.pixelsPerPoint, 1.9f * (float)height * EditorGUIUtility.pixelsPerPoint), 1f);
            return(this.m_PreviewUtility.EndStaticPreview());
        }
Esempio n. 6
0
        private static void ChangeAudios(bool mono)
        {
            AudioClip[] selections = Selection.GetFiltered <AudioClip>(SelectionMode.Assets);
            if (selections == null || selections.Length == 0)
            {
                Debug.Log("Please select some assets first");
                return;
            }

            foreach (var asset in selections)
            {
                string path = AssetDatabase.GetAssetPath(asset);
                UnityEditor.AudioImporter clip = global::UnityEditor.AudioImporter.GetAtPath(path) as UnityEditor.AudioImporter;
                clip.forceToMono = mono;

                AssetDatabase.ImportAsset(path);
                Debug.Log($"AudioImporter  {path}");
            }
        }
Esempio n. 7
0
        public static float[] GetMinMaxData(AudioImporter importer)
        {
            Assembly   unityEditorAssembly = typeof(AudioImporter).Assembly;
            Type       audioUtilClass      = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
            MethodInfo method = audioUtilClass.GetMethod(
                "GetMinMaxData",
                BindingFlags.Static | BindingFlags.Public,
                null,
                new System.Type[] {
                typeof(AudioImporter)
            },
                null
                );

            return((float[])method.Invoke(
                       null,
                       new object[] {
                importer
            }
                       ));
        }
Esempio n. 8
0
        // Passing in clip and importer separately as we're not completely done with the asset setup at the time we're asked to generate the preview.
        private void DoRenderPreview(AudioClip clip, AudioImporter audioImporter, Rect wantedRect, float scaleFactor)
        {
            scaleFactor *= 0.95f; // Reduce amplitude slightly to make highly compressed signals fit.
            float[] minMaxData  = (audioImporter == null) ? null : AudioUtil.GetMinMaxData(audioImporter);
            int     numChannels = clip.channels;
            int     numSamples  = (minMaxData == null) ? 0 : (minMaxData.Length / (2 * numChannels));
            float   h           = (float)wantedRect.height / (float)numChannels;

            for (int channel = 0; channel < numChannels; channel++)
            {
                Rect  channelRect = new Rect(wantedRect.x, wantedRect.y + h * channel, wantedRect.width, h);
                Color curveColor  = new Color(1.0f, 140.0f / 255.0f, 0.0f, 1.0f);

                AudioCurveRendering.DrawMinMaxFilledCurve(
                    channelRect,
                    delegate(float x, out Color col, out float minValue, out float maxValue)
                {
                    col = curveColor;
                    if (numSamples <= 0)
                    {
                        minValue = 0.0f;
                        maxValue = 0.0f;
                    }
                    else
                    {
                        float p     = Mathf.Clamp(x * (numSamples - 2), 0.0f, numSamples - 2);
                        int i       = (int)Mathf.Floor(p);
                        int offset1 = (i * numChannels + channel) * 2;
                        int offset2 = offset1 + numChannels * 2;
                        minValue    = Mathf.Min(minMaxData[offset1 + 1], minMaxData[offset2 + 1]) * scaleFactor;
                        maxValue    = Mathf.Max(minMaxData[offset1 + 0], minMaxData[offset2 + 0]) * scaleFactor;
                        if (minValue > maxValue)
                        {
                            float tmp = minValue; minValue = maxValue; maxValue = tmp;
                        }
                    }
                }
                    );
            }
        }
        private void ResetSettingsFromBackend()
        {
            if (GetAllAudioImporterTargets().Any())
            {
                AudioImporter firstImporter = GetAllAudioImporterTargets().First();
                //Just load the settings from the first importer for the default settings
                m_DefaultSampleSettings.settings = firstImporter.defaultSampleSettings;
                m_DefaultSampleSettings.ClearChangedFlags();

                m_SampleSettingOverrides = new Dictionary <BuildTargetGroup, SampleSettingProperties>();
                List <BuildPlatform> validPlatforms = BuildPlatforms.instance.GetValidPlatforms();
                foreach (BuildPlatform platform in validPlatforms)
                {
                    BuildTargetGroup platformGroup = platform.targetGroup;
                    foreach (AudioImporter importer in GetAllAudioImporterTargets())
                    {
                        if (importer.Internal_ContainsSampleSettingsOverride(platformGroup))
                        {
                            SampleSettingProperties newProperties = new SampleSettingProperties();
                            newProperties.settings = importer.Internal_GetOverrideSampleSettings(platformGroup);

                            m_SampleSettingOverrides[platformGroup] = newProperties;

                            //Just grab the first settings we find from any of the importers.
                            //This will be sorted later by checking if there are any differences between importers.
                            break;
                        }
                    }

                    //If we failed to find a valid override setting, just create a default one for use later.
                    if (!m_SampleSettingOverrides.ContainsKey(platformGroup))
                    {
                        SampleSettingProperties newProperties = new SampleSettingProperties();
                        newProperties.settings = firstImporter.Internal_GetOverrideSampleSettings(platformGroup);

                        m_SampleSettingOverrides[platformGroup] = newProperties;
                    }
                }
            }
        }
        private void DoRenderPreview(AudioClip clip, AudioImporter audioImporter, Rect wantedRect, float scaleFactor)
        {
            scaleFactor *= 0.95f;
            float[] minMaxData  = (!(audioImporter == null)) ? AudioUtil.GetMinMaxData(audioImporter) : null;
            int     numChannels = clip.channels;
            int     numSamples  = (minMaxData != null) ? (minMaxData.Length / (2 * numChannels)) : 0;
            float   num         = wantedRect.height / (float)numChannels;
            int     channel;

            for (channel = 0; channel < numChannels; channel++)
            {
                Rect  r          = new Rect(wantedRect.x, wantedRect.y + num * (float)channel, wantedRect.width, num);
                Color curveColor = new Color(1f, 0.549019635f, 0f, 1f);
                AudioCurveRendering.DrawMinMaxFilledCurve(r, delegate(float x, out Color col, out float minValue, out float maxValue)
                {
                    col = curveColor;
                    if (numSamples <= 0)
                    {
                        minValue = 0f;
                        maxValue = 0f;
                    }
                    else
                    {
                        float f  = Mathf.Clamp(x * (float)(numSamples - 2), 0f, (float)(numSamples - 2));
                        int num2 = (int)Mathf.Floor(f);
                        int num3 = (num2 * numChannels + channel) * 2;
                        int num4 = num3 + numChannels * 2;
                        minValue = Mathf.Min(minMaxData[num3 + 1], minMaxData[num4 + 1]) * scaleFactor;
                        maxValue = Mathf.Max(minMaxData[num3], minMaxData[num4]) * scaleFactor;
                        if (minValue > maxValue)
                        {
                            float num5 = minValue;
                            minValue   = maxValue;
                            maxValue   = num5;
                        }
                    }
                });
            }
        }
Esempio n. 11
0
    public void OnPreprocessAudio()
    {
        UnityEditor.AudioImporter   importer = (UnityEditor.AudioImporter)assetImporter;
        AudioImporterSampleSettings settings = new AudioImporterSampleSettings();

        if (assetPath.ToLower().Contains("bgm"))
        {
            importer.preloadAudioData  = false;
            importer.loadInBackground  = false;
            settings.compressionFormat = AudioCompressionFormat.Vorbis;
            settings.quality           = 1;
            //settings.loadType = AudioClipLoadType.Streaming;
        }
        else if (assetPath.ToLower().Contains("sfx"))
        {
            importer.preloadAudioData  = true;
            importer.loadInBackground  = true;
            settings.compressionFormat = AudioCompressionFormat.PCM;
            settings.loadType          = AudioClipLoadType.DecompressOnLoad;
        }

        importer.defaultSampleSettings = settings;
    }
 private bool ResetSettingsFromBackend()
 {
     if (this.GetAllAudioImporterTargets().Any <AudioImporter>())
     {
         AudioImporter audioImporter = this.GetAllAudioImporterTargets().First <AudioImporter>();
         this.m_DefaultSampleSettings.settings = audioImporter.defaultSampleSettings;
         this.m_DefaultSampleSettings.ClearChangedFlags();
         this.m_SampleSettingOverrides = new Dictionary <BuildTargetGroup, AudioImporterInspector.SampleSettingProperties>();
         using (List <BuildPlayerWindow.BuildPlatform> .Enumerator enumerator = BuildPlayerWindow.GetValidPlatforms().GetEnumerator())
         {
             while (enumerator.MoveNext())
             {
                 BuildTargetGroup targetGroup = enumerator.Current.targetGroup;
                 foreach (AudioImporter audioImporterTarget in this.GetAllAudioImporterTargets())
                 {
                     if (audioImporterTarget.Internal_ContainsSampleSettingsOverride(targetGroup))
                     {
                         this.m_SampleSettingOverrides[targetGroup] = new AudioImporterInspector.SampleSettingProperties()
                         {
                             settings = audioImporterTarget.Internal_GetOverrideSampleSettings(targetGroup)
                         };
                         break;
                     }
                 }
                 if (!this.m_SampleSettingOverrides.ContainsKey(targetGroup))
                 {
                     this.m_SampleSettingOverrides[targetGroup] = new AudioImporterInspector.SampleSettingProperties()
                     {
                         settings = audioImporter.Internal_GetOverrideSampleSettings(targetGroup)
                     }
                 }
                 ;
             }
         }
     }
     return(true);
 }
        private OverrideStatus GetOverrideStatus(BuildTargetGroup platform)
        {
            bool mixedOverrides   = false;
            bool containsOverride = false;

            if (GetAllAudioImporterTargets().Any())
            {
                AudioImporter firstImporter = GetAllAudioImporterTargets().First();

                containsOverride = firstImporter.Internal_ContainsSampleSettingsOverride(platform);
                foreach (AudioImporter importer in GetAllAudioImporterTargets().Except(new[] { firstImporter }))
                {
                    bool overrideState = importer.Internal_ContainsSampleSettingsOverride(platform);

                    if (overrideState != containsOverride)
                    {
                        mixedOverrides |= true;
                    }

                    containsOverride |= overrideState;
                }
            }

            if (!containsOverride)
            {
                return(OverrideStatus.NoOverrides);
            }
            else if (mixedOverrides)
            {
                return(OverrideStatus.MixedOverrides);
            }
            else
            {
                return(OverrideStatus.AllOverrides);
            }
        }
Esempio n. 14
0
		public TreeItem(AudioImporter importer, string path, string name)
		{
			this.importer = importer;
			this.path = path;
			this.Name = name;
		}
Esempio n. 15
0
 public static extern float[] GetMinMaxData(AudioImporter importer);
 private AudioImporterInspector.OverrideStatus GetOverrideStatus(BuildTargetGroup platform)
 {
   bool flag1 = false;
   bool flag2 = false;
   if (this.GetAllAudioImporterTargets().Any<AudioImporter>())
   {
     AudioImporter audioImporter1 = this.GetAllAudioImporterTargets().First<AudioImporter>();
     flag2 = audioImporter1.Internal_ContainsSampleSettingsOverride(platform);
     IEnumerable<AudioImporter> audioImporterTargets = this.GetAllAudioImporterTargets();
     AudioImporter[] audioImporterArray = new AudioImporter[1]{ audioImporter1 };
     foreach (AudioImporter audioImporter2 in audioImporterTargets.Except<AudioImporter>((IEnumerable<AudioImporter>) audioImporterArray))
     {
       bool flag3 = audioImporter2.Internal_ContainsSampleSettingsOverride(platform);
       if (flag3 != flag2)
         flag1 = ((flag1 ? 1 : 0) | 1) != 0;
       flag2 |= flag3;
     }
   }
   if (!flag2)
     return AudioImporterInspector.OverrideStatus.NoOverrides;
   return flag1 ? AudioImporterInspector.OverrideStatus.MixedOverrides : AudioImporterInspector.OverrideStatus.AllOverrides;
 }
 private AudioImporterInspector.MultiValueStatus GetMultiValueStatus(BuildTargetGroup platform)
 {
   AudioImporterInspector.MultiValueStatus multiValueStatus;
   multiValueStatus.multiLoadType = false;
   multiValueStatus.multiSampleRateSetting = false;
   multiValueStatus.multiSampleRateOverride = false;
   multiValueStatus.multiCompressionFormat = false;
   multiValueStatus.multiQuality = false;
   multiValueStatus.multiConversionMode = false;
   if (this.GetAllAudioImporterTargets().Any<AudioImporter>())
   {
     AudioImporter audioImporter1 = this.GetAllAudioImporterTargets().First<AudioImporter>();
     AudioImporterSampleSettings importerSampleSettings1 = platform != BuildTargetGroup.Unknown ? audioImporter1.Internal_GetOverrideSampleSettings(platform) : audioImporter1.defaultSampleSettings;
     IEnumerable<AudioImporter> audioImporterTargets = this.GetAllAudioImporterTargets();
     AudioImporter[] audioImporterArray = new AudioImporter[1]{ audioImporter1 };
     foreach (AudioImporter audioImporter2 in audioImporterTargets.Except<AudioImporter>((IEnumerable<AudioImporter>) audioImporterArray))
     {
       AudioImporterSampleSettings importerSampleSettings2 = platform != BuildTargetGroup.Unknown ? audioImporter2.Internal_GetOverrideSampleSettings(platform) : audioImporter2.defaultSampleSettings;
       multiValueStatus.multiLoadType |= importerSampleSettings1.loadType != importerSampleSettings2.loadType;
       multiValueStatus.multiSampleRateSetting |= importerSampleSettings1.sampleRateSetting != importerSampleSettings2.sampleRateSetting;
       multiValueStatus.multiSampleRateOverride |= (int) importerSampleSettings1.sampleRateOverride != (int) importerSampleSettings2.sampleRateOverride;
       multiValueStatus.multiCompressionFormat |= importerSampleSettings1.compressionFormat != importerSampleSettings2.compressionFormat;
       multiValueStatus.multiQuality |= (double) importerSampleSettings1.quality != (double) importerSampleSettings2.quality;
       multiValueStatus.multiConversionMode |= importerSampleSettings1.conversionMode != importerSampleSettings2.conversionMode;
     }
   }
   return multiValueStatus;
 }
Esempio n. 18
0
        public ImportInfo( AudioClip clip )
        {
            Clip			= clip;
            Path 			= AssetDatabase.GetAssetPath( clip.GetInstanceID() );
            GUID			= AssetDatabase.AssetPathToGUID( Path );
            Importer		= AssetImporter.GetAtPath( Path ) as AudioImporter;

            if( GATEditorUtilities.IsInResources( Path ) )
            {
                PathInResources = GATEditorUtilities.PathInResources( Path );

            }
            else if( GATEditorUtilities.IsInStreamingAssets( Path ) )
            {
                PathInResources = GATEditorUtilities.PathInStreamingAssets( Path );
                System.IO.Path.ChangeExtension( PathInResources, System.IO.Path.GetExtension( Importer.assetPath ) );
                IsStreamingAsset = true;
            }
        }
        private bool IsEqual(AudioImporter target)
        {
            AudioImporter reference = referenceImporter as AudioImporter;
            UnityEngine.Assertions.Assert.IsNotNull(reference);

            // defaultSampleSettings
            if (target.defaultSampleSettings.compressionFormat != reference.defaultSampleSettings.compressionFormat) return false;
            if (target.defaultSampleSettings.loadType != reference.defaultSampleSettings.loadType) return false;
            if (target.defaultSampleSettings.quality != reference.defaultSampleSettings.quality) return false;
            if (target.defaultSampleSettings.sampleRateOverride != reference.defaultSampleSettings.sampleRateOverride) return false;
            if (target.defaultSampleSettings.sampleRateSetting != reference.defaultSampleSettings.sampleRateSetting) return false;

            if (target.forceToMono != reference.forceToMono) return false;
            if (target.loadInBackground != reference.loadInBackground) return false;
            if (target.preloadAudioData != reference.preloadAudioData) return false;

            return true;
        }
        public void ForceOnPreprocessAudio(AudioImporter importer)
        {
            if (importerSourceObj == null) return;
            var importerSource = importerSourceObj as AudioImporter;

            importer.defaultSampleSettings = importerSource.defaultSampleSettings;
            importer.forceToMono = importerSource.forceToMono;
            importer.loadInBackground = importerSource.loadInBackground;
            importer.preloadAudioData = importerSource.preloadAudioData;
        }
 private void DoRenderPreview(AudioClip clip, AudioImporter audioImporter, Rect wantedRect, float scaleFactor)
 {
Esempio n. 22
0
 public static extern float[] GetMinMaxData(AudioImporter importer);
        private void OverwriteImportSettings(AudioImporter importer)
        {
            var reference = referenceImporter as AudioImporter;
            UnityEngine.Assertions.Assert.IsNotNull(reference);

            importer.defaultSampleSettings = reference.defaultSampleSettings;
            importer.forceToMono = reference.forceToMono;
            importer.loadInBackground = reference.loadInBackground;
            importer.preloadAudioData = reference.preloadAudioData;
        }
 private void DoRenderPreview(AudioClip clip, AudioImporter audioImporter, Rect wantedRect, float scaleFactor)
 {
   // ISSUE: object of a compiler-generated type is created
   // ISSUE: variable of a compiler-generated type
   AudioClipInspector.\u003CDoRenderPreview\u003Ec__AnonStorey84 previewCAnonStorey84 = new AudioClipInspector.\u003CDoRenderPreview\u003Ec__AnonStorey84();
   // ISSUE: reference to a compiler-generated field
   previewCAnonStorey84.scaleFactor = scaleFactor;
   // ISSUE: reference to a compiler-generated field
   // ISSUE: reference to a compiler-generated field
   previewCAnonStorey84.scaleFactor = previewCAnonStorey84.scaleFactor * 0.95f;
   // ISSUE: reference to a compiler-generated field
   previewCAnonStorey84.minMaxData = !((UnityEngine.Object) audioImporter == (UnityEngine.Object) null) ? AudioUtil.GetMinMaxData(audioImporter) : (float[]) null;
   // ISSUE: reference to a compiler-generated field
   previewCAnonStorey84.numChannels = clip.channels;
   // ISSUE: reference to a compiler-generated field
   // ISSUE: reference to a compiler-generated field
   // ISSUE: reference to a compiler-generated field
   // ISSUE: reference to a compiler-generated field
   previewCAnonStorey84.numSamples = previewCAnonStorey84.minMaxData != null ? previewCAnonStorey84.minMaxData.Length / (2 * previewCAnonStorey84.numChannels) : 0;
   // ISSUE: reference to a compiler-generated field
   float height = wantedRect.height / (float) previewCAnonStorey84.numChannels;
   // ISSUE: object of a compiler-generated type is created
   // ISSUE: variable of a compiler-generated type
   AudioClipInspector.\u003CDoRenderPreview\u003Ec__AnonStorey85 previewCAnonStorey85 = new AudioClipInspector.\u003CDoRenderPreview\u003Ec__AnonStorey85();
   // ISSUE: reference to a compiler-generated field
   // ISSUE: reference to a compiler-generated field
   // ISSUE: reference to a compiler-generated field
   // ISSUE: reference to a compiler-generated field
   // ISSUE: reference to a compiler-generated field
   for (previewCAnonStorey85.channel = 0; previewCAnonStorey85.channel < previewCAnonStorey84.numChannels; previewCAnonStorey85.channel = previewCAnonStorey85.channel + 1)
   {
     // ISSUE: object of a compiler-generated type is created
     // ISSUE: variable of a compiler-generated type
     AudioClipInspector.\u003CDoRenderPreview\u003Ec__AnonStorey83 previewCAnonStorey83 = new AudioClipInspector.\u003CDoRenderPreview\u003Ec__AnonStorey83();
     // ISSUE: reference to a compiler-generated field
     previewCAnonStorey83.\u003C\u003Ef__ref\u0024132 = previewCAnonStorey84;
     // ISSUE: reference to a compiler-generated field
     previewCAnonStorey83.\u003C\u003Ef__ref\u0024133 = previewCAnonStorey85;
     // ISSUE: reference to a compiler-generated field
     Rect r = new Rect(wantedRect.x, wantedRect.y + height * (float) previewCAnonStorey85.channel, wantedRect.width, height);
     // ISSUE: reference to a compiler-generated field
     previewCAnonStorey83.curveColor = new Color(1f, 0.5490196f, 0.0f, 1f);
     // ISSUE: reference to a compiler-generated method
     AudioCurveRendering.DrawMinMaxFilledCurve(r, new AudioCurveRendering.AudioMinMaxCurveAndColorEvaluator(previewCAnonStorey83.\u003C\u003Em__143));
   }
 }