private bool IsEqual(AudioImporter target)
        {
            AudioImporter reference = referenceImporter as AudioImporter;

            UnityEngine.Assertions.Assert.IsNotNull(reference);

            if (!IsEqualAudioSampleSetting(target.defaultSampleSettings, reference.defaultSampleSettings))
            {
                return(false);
            }

            foreach (var g in NodeGUIUtility.SupportedBuildTargetGroups)
            {
                var platformName = BuildTargetUtility.TargetToAssetBundlePlatformName(g,
                                                                                      BuildTargetUtility.PlatformNameType.AudioImporter);

                if (target.ContainsSampleSettingsOverride(platformName) !=
                    reference.ContainsSampleSettingsOverride(platformName))
                {
                    return(false);
                }
                if (target.ContainsSampleSettingsOverride(platformName))
                {
                    var t = target.GetOverrideSampleSettings(platformName);
                    var r = reference.GetOverrideSampleSettings(platformName);
                    if (!IsEqualAudioSampleSetting(t, r))
                    {
                        return(false);
                    }
                }
            }

            if (target.forceToMono != reference.forceToMono)
            {
                return(false);
            }
            // using "!UNITY_5_6_OR_NEWER" instead of "Unity_5_6" because loadInBackground became obsolete after Unity 5.6b3.
#if !UNITY_5_6_OR_NEWER
            if (target.loadInBackground != reference.loadInBackground)
            {
                return(false);
            }
#endif

#if UNITY_2017_1_OR_NEWER
            if (target.ambisonic != reference.ambisonic)
            {
                return(false);
            }
#endif
            if (target.preloadAudioData != reference.preloadAudioData)
            {
                return(false);
            }

            return(true);
        }
        public static bool IsBuildTargetSupported(BuildTarget t)
        {
            var objType = typeof(UnityEditor.BuildPipeline);
            var method  = objType.GetMethod("IsBuildTargetSupported", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);

                        #if UNITY_5_6 || UNITY_5_6_OR_NEWER
            BuildTargetGroup g = BuildTargetUtility.TargetToGroup(t);
            //internal static extern bool IsBuildTargetSupported (BuildTargetGroup buildTargetGroup, BuildTarget target);
            var retval = method.Invoke(null, new object[] {
                System.Enum.ToObject(typeof(BuildTargetGroup), g),
                System.Enum.ToObject(typeof(BuildTarget), t)
            });
                        #else
            //internal static extern bool IsBuildTargetSupported (BuildTarget target);
            var retval = method.Invoke(null, new object[] { System.Enum.ToObject(typeof(BuildTarget), t) });
                        #endif
            return(Convert.ToBoolean(retval));
        }
            public void SetupSupportedBuildTargets()
            {
                if (supportedBuildTargets == null)
                {
                    supportedBuildTargets      = new List <BuildTarget>();
                    supportedBuildTargetGroups = new List <BuildTargetGroup>();

                    try {
                        foreach (BuildTarget target in Enum.GetValues(typeof(BuildTarget)))
                        {
                            if (BuildTargetUtility.IsBuildTargetSupported(target))
                            {
                                if (!supportedBuildTargets.Contains(target))
                                {
                                    supportedBuildTargets.Add(target);
                                }
                                BuildTargetGroup g = BuildTargetUtility.TargetToGroup(target);
                                if (g == BuildTargetGroup.Unknown)
                                {
                                    // skip unknown platform
                                    continue;
                                }
                                if (!supportedBuildTargetGroups.Contains(g))
                                {
                                    supportedBuildTargetGroups.Add(g);
                                }
                            }
                        }

                        supportedBuildTargetNames = new string[supportedBuildTargets.Count];
                        for (int i = 0; i < supportedBuildTargets.Count; ++i)
                        {
                            supportedBuildTargetNames[i] = BuildTargetUtility.TargetToHumaneString(supportedBuildTargets[i]);
                        }
                    } catch (Exception e) {
                        LogUtility.Logger.LogError(LogUtility.kTag, e);
                    }
                }
            }
        private void OverwriteImportNGSettings(AudioImporter importer)
        {
            var reference = referenceImporter as AudioImporter;

            UnityEngine.Assertions.Assert.IsNotNull(reference);

            importer.defaultSampleSettings = reference.defaultSampleSettings;
            importer.forceToMono           = reference.forceToMono;
            importer.preloadAudioData      = reference.preloadAudioData;

            foreach (var g in NodeGUIUtility.SupportedBuildTargetGroups)
            {
                var platformName = BuildTargetUtility.TargetToAssetBundlePlatformName(g,
                                                                                      BuildTargetUtility.PlatformNameType.AudioImporter);

                if (reference.ContainsSampleSettingsOverride(platformName))
                {
                    var setting = reference.GetOverrideSampleSettings(platformName);
                    if (!importer.SetOverrideSampleSettings(platformName, setting))
                    {
                        LogUtility.Logger.LogError("AudioImporter",
                                                   string.Format("Failed to set override setting for {0}: {1}", platformName, importer.assetPath));
                    }
                }
                else
                {
                    importer.ClearSampleSettingOverride(platformName);
                }
            }

            // using "!UNITY_5_6_OR_NEWER" instead of "Unity_5_6" because loadInBackground became obsolete after Unity 5.6b3.
#if !UNITY_5_6_OR_NEWER
            importer.loadInBackground = reference.loadInBackground;
#endif

#if UNITY_2017_1_OR_NEWER
            importer.ambisonic = reference.ambisonic;
#endif
        }
            public void SetupPlatformButtons()
            {
                SetupSupportedBuildTargets();
                var buttons = new List <PlatformButton>();

                Dictionary <BuildTargetGroup, string> icons = new Dictionary <BuildTargetGroup, string> {
                    { BuildTargetGroup.Android, "BuildNGSettings.Android.Small" },
                    { BuildTargetGroup.iOS, "BuildNGSettings.iPhone.Small" },
                    { BuildTargetGroup.PS4, "BuildNGSettings.PS4.Small" },
                    { BuildTargetGroup.PSM, "BuildNGSettings.PSM.Small" },
                    { BuildTargetGroup.PSP2, "BuildNGSettings.PSP2.Small" },
                    { BuildTargetGroup.SamsungTV, "BuildNGSettings.Android.Small" },
                    { BuildTargetGroup.Standalone, "BuildNGSettings.Standalone.Small" },
                    { BuildTargetGroup.Tizen, "BuildNGSettings.Tizen.Small" },
                    { BuildTargetGroup.tvOS, "BuildNGSettings.tvOS.Small" },
                    { BuildTargetGroup.Unknown, "BuildNGSettings.Standalone.Small" },
                    { BuildTargetGroup.WebGL, "BuildNGSettings.WebGL.Small" },
                    { BuildTargetGroup.WiiU, "BuildNGSettings.WiiU.Small" },
                    { BuildTargetGroup.WSA, "BuildNGSettings.WP8.Small" },
                    { BuildTargetGroup.XboxOne, "BuildNGSettings.XboxOne.Small" }
                                        #if !UNITY_5_5_OR_NEWER
                    ,
                    { BuildTargetGroup.XBOX360, "BuildNGSettings.Xbox360.Small" },
                    { BuildTargetGroup.Nintendo3DS, "BuildNGSettings.N3DS.Small" },
                    { BuildTargetGroup.PS3, "BuildNGSettings.PS3.Small" }
                                        #endif
                                        #if UNITY_5_5_OR_NEWER
                    ,
                    { BuildTargetGroup.N3DS, "BuildNGSettings.N3DS.Small" }
                                        #endif
                                        #if UNITY_5_6 || UNITY_5_6_OR_NEWER
                    ,
                    { BuildTargetGroup.Facebook, "BuildNGSettings.Facebook.Small" },
                    { BuildTargetGroup.Switch, "BuildNGSettings.Switch.Small" }
                                        #endif
                };

                buttons.Add(new PlatformButton(new GUIContent("Default", "Default NGSettings"), BuildTargetGroup.Unknown));

                foreach (var g in supportedBuildTargetGroups)
                {
                    buttons.Add(new PlatformButton(new GUIContent(GetPlatformIcon(icons[g]), BuildTargetUtility.GroupToHumaneString(g)), g));
                }

                this.platformButtons = buttons.ToArray();
            }
        private void OverwriteImportNGSettings(TextureImporter importer)
        {
            var reference = referenceImporter as TextureImporter;

            UnityEngine.Assertions.Assert.IsNotNull(reference);

            importer.textureType = reference.textureType;

            TextureImporterSettings NGSettings = new TextureImporterSettings();

            reference.ReadTextureSettings(NGSettings);
            importer.SetTextureSettings(NGSettings);

            // some unity version do not properly copy properties via TextureNGSettings,
            // so also perform manual copy

            importer.anisoLevel         = reference.anisoLevel;
            importer.borderMipmap       = reference.borderMipmap;
            importer.compressionQuality = reference.compressionQuality;
            importer.convertToNormalmap = reference.convertToNormalmap;
            importer.fadeout            = reference.fadeout;
            importer.filterMode         = reference.filterMode;
            importer.generateCubemap    = reference.generateCubemap;
            importer.heightmapScale     = reference.heightmapScale;

            importer.isReadable              = reference.isReadable;
            importer.maxTextureSize          = reference.maxTextureSize;
            importer.mipMapBias              = reference.mipMapBias;
            importer.mipmapEnabled           = reference.mipmapEnabled;
            importer.mipmapFadeDistanceEnd   = reference.mipmapFadeDistanceEnd;
            importer.mipmapFadeDistanceStart = reference.mipmapFadeDistanceStart;
            importer.mipmapFilter            = reference.mipmapFilter;

            importer.normalmapFilter = reference.normalmapFilter;
            importer.npotScale       = reference.npotScale;

            importer.spriteBorder        = reference.spriteBorder;
            importer.spriteImportMode    = reference.spriteImportMode;
            importer.spritePackingTag    = reference.spritePackingTag;
            importer.spritePivot         = reference.spritePivot;
            importer.spritePixelsPerUnit = reference.spritePixelsPerUnit;
            importer.spritesheet         = reference.spritesheet;

            importer.wrapMode = reference.wrapMode;

            /* read only */
            // importer.qualifiesForSpritePacking

#if !UNITY_5_5_OR_NEWER
            // obsolete features
            importer.generateMipsInLinearSpace = reference.generateMipsInLinearSpace;
            importer.grayscaleToAlpha          = reference.grayscaleToAlpha;
            importer.lightmap      = reference.lightmap;
            importer.linearTexture = reference.linearTexture;
            importer.normalmap     = reference.normalmap;
            importer.textureFormat = reference.textureFormat;

            foreach (var g in NodeGUIUtility.SupportedBuildTargetGroups)
            {
                var platformName = BuildTargetUtility.TargetToAssetBundlePlatformName(g, BuildTargetUtility.PlatformNameType.TextureImporter);

                int maxTextureSize;
                TextureImporterFormat format;
                int compressionQuality;

                if (reference.GetPlatformTextureSettings(platformName, out maxTextureSize, out format, out compressionQuality))
                {
                    importer.SetPlatformTextureSettings(platformName, maxTextureSize, format, compressionQuality, false);
                }
                else
                {
                    importer.ClearPlatformTextureSettings(platformName);
                }
            }
#else
            importer.allowAlphaSplitting = reference.allowAlphaSplitting;
            importer.alphaIsTransparency = reference.alphaIsTransparency;
            importer.textureShape        = reference.textureShape;

            importer.alphaSource         = reference.alphaSource;
            importer.sRGBTexture         = reference.sRGBTexture;
            importer.textureCompression  = reference.textureCompression;
            importer.crunchedCompression = reference.crunchedCompression;

            foreach (var g in NodeGUIUtility.SupportedBuildTargetGroups)
            {
                var platformName = BuildTargetUtility.TargetToAssetBundlePlatformName(g, BuildTargetUtility.PlatformNameType.TextureImporter);
                var impSet       = reference.GetPlatformTextureSettings(platformName);
                importer.SetPlatformTextureSettings(impSet);
            }
#endif

#if UNITY_2017_1_OR_NEWER
            importer.alphaTestReferenceValue = reference.alphaTestReferenceValue;
            importer.mipMapsPreserveCoverage = reference.mipMapsPreserveCoverage;
            importer.wrapModeU = reference.wrapModeU;
            importer.wrapModeV = reference.wrapModeV;
            importer.wrapModeW = reference.wrapModeW;
#endif
        }
        private bool IsEqual(TextureImporter target, bool ignorePackingTagDifference)
        {
            TextureImporter reference = referenceImporter as TextureImporter;

            UnityEngine.Assertions.Assert.IsNotNull(reference);

            // UnityEditor.TextureImporter.textureFormat' is obsolete:
            // `textureFormat is not longer accessible at the TextureImporter level
            if (target.textureType != reference.textureType)
            {
                return(false);
            }

            TextureImporterSettings targetSetting    = new TextureImporterSettings();
            TextureImporterSettings referenceSetting = new TextureImporterSettings();

            target.ReadTextureSettings(targetSetting);
            reference.ReadTextureSettings(referenceSetting);

            if (!TextureImporterSettings.Equal(targetSetting, referenceSetting))
            {
                return(false);
            }

            if (target.textureType == TextureImporterType.Sprite)
            {
                if (target.spritePackingTag != reference.spritePackingTag)
                {
                    return(false);
                }

                var s1 = target.spritesheet;
                var s2 = reference.spritesheet;

                if (s1.Length != s2.Length)
                {
                    return(false);
                }

                for (int i = 0; i < s1.Length; ++i)
                {
                    if (s1 [i].alignment != s2 [i].alignment)
                    {
                        return(false);
                    }
                    if (s1 [i].border != s2 [i].border)
                    {
                        return(false);
                    }
                    if (s1 [i].name != s2 [i].name)
                    {
                        return(false);
                    }
                    if (s1 [i].pivot != s2 [i].pivot)
                    {
                        return(false);
                    }
                    if (s1 [i].rect != s2 [i].rect)
                    {
                        return(false);
                    }
                }
            }

            if (target.wrapMode != reference.wrapMode)
            {
                return(false);
            }
            if (target.anisoLevel != reference.anisoLevel)
            {
                return(false);
            }
            if (target.borderMipmap != reference.borderMipmap)
            {
                return(false);
            }
            if (target.compressionQuality != reference.compressionQuality)
            {
                return(false);
            }
            if (target.convertToNormalmap != reference.convertToNormalmap)
            {
                return(false);
            }
            if (target.fadeout != reference.fadeout)
            {
                return(false);
            }
            if (target.filterMode != reference.filterMode)
            {
                return(false);
            }
            if (target.generateCubemap != reference.generateCubemap)
            {
                return(false);
            }
            if (target.heightmapScale != reference.heightmapScale)
            {
                return(false);
            }
            if (target.isReadable != reference.isReadable)
            {
                return(false);
            }
            if (target.maxTextureSize != reference.maxTextureSize)
            {
                return(false);
            }
            if (target.mipMapBias != reference.mipMapBias)
            {
                return(false);
            }
            if (target.mipmapEnabled != reference.mipmapEnabled)
            {
                return(false);
            }
            if (target.mipmapFadeDistanceEnd != reference.mipmapFadeDistanceEnd)
            {
                return(false);
            }
            if (target.mipmapFadeDistanceStart != reference.mipmapFadeDistanceStart)
            {
                return(false);
            }
            if (target.mipmapFilter != reference.mipmapFilter)
            {
                return(false);
            }
            if (target.normalmapFilter != reference.normalmapFilter)
            {
                return(false);
            }
            if (target.npotScale != reference.npotScale)
            {
                return(false);
            }
            if (target.spriteBorder != reference.spriteBorder)
            {
                return(false);
            }
            if (target.spriteImportMode != reference.spriteImportMode)
            {
                return(false);
            }
            if (!ignorePackingTagDifference && target.spritePackingTag != reference.spritePackingTag)
            {
                return(false);
            }
            if (target.spritePivot != reference.spritePivot)
            {
                return(false);
            }
            if (target.spritePixelsPerUnit != reference.spritePixelsPerUnit)
            {
                return(false);
            }

            /* read only properties */
            // target.qualifiesForSpritePacking

#if !UNITY_5_5_OR_NEWER
            // obsolete features
            if (target.normalmap != reference.normalmap)
            {
                return(false);
            }
            if (target.linearTexture != reference.linearTexture)
            {
                return(false);
            }
            if (target.lightmap != reference.lightmap)
            {
                return(false);
            }
            if (target.grayscaleToAlpha != reference.grayscaleToAlpha)
            {
                return(false);
            }
            if (target.generateMipsInLinearSpace != reference.generateMipsInLinearSpace)
            {
                return(false);
            }
            if (target.textureFormat != reference.textureFormat)
            {
                return(false);
            }

            foreach (var g in NodeGUIUtility.SupportedBuildTargetGroups)
            {
                var platformName = BuildTargetUtility.TargetToAssetBundlePlatformName(g, BuildTargetUtility.PlatformNameType.TextureImporter);

                int srcMaxTextureSize;
                TextureImporterFormat srcFormat;
                int srcCompressionQuality;

                int dstMaxTextureSize;
                TextureImporterFormat dstFormat;
                int dstCompressionQuality;

                var srcHasSetting = target.GetPlatformTextureSettings(platformName, out srcMaxTextureSize, out srcFormat, out srcCompressionQuality);
                var dstHasSetting = reference.GetPlatformTextureSettings(platformName, out dstMaxTextureSize, out dstFormat, out dstCompressionQuality);

                if (srcHasSetting != dstHasSetting)
                {
                    return(false);
                }
                if (srcMaxTextureSize != dstMaxTextureSize)
                {
                    return(false);
                }
                if (srcFormat != dstFormat)
                {
                    return(false);
                }
                if (srcCompressionQuality != dstCompressionQuality)
                {
                    return(false);
                }
            }
#else
            if (target.allowAlphaSplitting != reference.allowAlphaSplitting)
            {
                return(false);
            }
            if (target.alphaIsTransparency != reference.alphaIsTransparency)
            {
                return(false);
            }
            if (target.textureShape != reference.textureShape)
            {
                return(false);
            }

            if (target.alphaSource != reference.alphaSource)
            {
                return(false);
            }
            if (target.sRGBTexture != reference.sRGBTexture)
            {
                return(false);
            }
            if (target.textureCompression != reference.textureCompression)
            {
                return(false);
            }
            if (target.crunchedCompression != reference.crunchedCompression)
            {
                return(false);
            }

            foreach (var g in NodeGUIUtility.SupportedBuildTargetGroups)
            {
                var platformName = BuildTargetUtility.TargetToAssetBundlePlatformName(g, BuildTargetUtility.PlatformNameType.TextureImporter);

                var impSet       = reference.GetPlatformTextureSettings(platformName);
                var targetImpSet = target.GetPlatformTextureSettings(platformName);
                if (!CompareImporterPlatformNGSettings(impSet, targetImpSet))
                {
                    return(false);
                }
            }
#endif

#if UNITY_2017_1_OR_NEWER
            if (target.alphaTestReferenceValue != reference.alphaTestReferenceValue)
            {
                return(false);
            }
            if (target.mipMapsPreserveCoverage != reference.mipMapsPreserveCoverage)
            {
                return(false);
            }
            if (target.wrapModeU != reference.wrapModeU)
            {
                return(false);
            }
            if (target.wrapModeV != reference.wrapModeV)
            {
                return(false);
            }
            if (target.wrapModeW != reference.wrapModeW)
            {
                return(false);
            }
#endif
            return(true);
        }
        private void OverwriteImportNGSettings(VideoClipImporter importer)
        {
            var reference = referenceImporter as VideoClipImporter;

            UnityEngine.Assertions.Assert.IsNotNull(reference);

            /*
             * defaultTargetSettings	Default values for the platform-specific import NGSettings.
             * deinterlaceMode			Images are deinterlaced during transcode. This tells the importer how to interpret fields in the source, if any.
             * flipHorizontal			Apply a horizontal flip during import.
             * flipVertical			Apply a vertical flip during import.
             * frameCount				Number of frames in the clip.
             * frameRate				Frame rate of the clip.
             * importAudio				Import audio tracks from source file.
             * isPlayingPreview		Whether the preview is currently playing.
             * keepAlpha				Whether to keep the alpha from the source into the transcoded clip.
             * linearColor				Used in legacy import mode. Same as MovieImport.linearTexture.
             * outputFileSize			Size in bytes of the file once imported.
             * quality					Used in legacy import mode. Same as MovieImport.quality.
             * sourceAudioTrackCount	Number of audio tracks in the source file.
             * sourceFileSize			Size in bytes of the file before importing.
             * sourceHasAlpha			True if the source file has a channel for per-pixel transparency.
             * useLegacyImporter		Whether to import a MovieTexture (legacy) or a VideoClip.
             */

            importer.defaultTargetSettings = reference.defaultTargetSettings;
            importer.deinterlaceMode       = reference.deinterlaceMode;
            importer.flipHorizontal        = reference.flipHorizontal;
            importer.flipVertical          = reference.flipVertical;
            importer.importAudio           = reference.importAudio;
            importer.keepAlpha             = reference.keepAlpha;
            importer.linearColor           = reference.linearColor;
            importer.quality           = reference.quality;
            importer.useLegacyImporter = reference.useLegacyImporter;

#if UNITY2017_2_OR_NEWER
            importer.pixelAspectRatioDenominator = reference.pixelAspectRatioDenominator;
            importer.pixelAspectRatioNumerator   = reference.pixelAspectRatioNumerator;
#endif

            foreach (var g in NodeGUIUtility.SupportedBuildTargetGroups)
            {
                var platformName = BuildTargetUtility.TargetToAssetBundlePlatformName(g,
                                                                                      BuildTargetUtility.PlatformNameType.VideoClipImporter);

                try {
                    var setting = reference.GetTargetSettings(platformName);
                    if (setting != null)
                    {
                        importer.SetTargetSettings(platformName, setting);
                    }
                    else
                    {
                        importer.ClearTargetSettings(platformName);
                    }
                } catch (Exception e) {
                    LogUtility.Logger.LogWarning("VideoClipImporter",
                                                 string.Format("Failed to set override setting for platform {0}: file :{1} \\nreason:{2}",
                                                               platformName, importer.assetPath, e.Message));
                }
            }

            /* read only */

            /*
             * importer.frameCount
             * importer.frameRate
             * importer.isPlayingPreview
             * importer.outputFileSize
             * importer.sourceAudioTrackCount
             * importer.sourceFileSize
             * importer.sourceHasAlpha
             */
        }
        public bool IsEqual(VideoClipImporter target)
        {
            VideoClipImporter reference = referenceImporter as VideoClipImporter;

            UnityEngine.Assertions.Assert.IsNotNull(reference);

            if (!IsEqual(target.defaultTargetSettings, reference.defaultTargetSettings))
            {
                return(false);
            }

            /* read only properties. ImportSettingConfigurator will not use these properties for diff. */

            /*
             * importer.frameCount
             * importer.frameRate
             * importer.isPlayingPreview
             * importer.outputFileSize
             * importer.sourceAudioTrackCount
             * importer.sourceFileSize
             * importer.sourceHasAlpha
             */

            if (target.deinterlaceMode != reference.deinterlaceMode)
            {
                return(false);
            }
            if (target.flipHorizontal != reference.flipHorizontal)
            {
                return(false);
            }
            if (target.flipVertical != reference.flipVertical)
            {
                return(false);
            }
            if (target.importAudio != reference.importAudio)
            {
                return(false);
            }
            if (target.keepAlpha != reference.keepAlpha)
            {
                return(false);
            }
            if (target.linearColor != reference.linearColor)
            {
                return(false);
            }
            if (target.quality != reference.quality)
            {
                return(false);
            }
            if (target.useLegacyImporter != reference.useLegacyImporter)
            {
                return(false);
            }

#if UNITY2017_2_OR_NEWER
            if (target.pixelAspectRatioDenominator != reference.pixelAspectRatioDenominator)
            {
                return(false);
            }
            if (target.pixelAspectRatioNumerator != reference.pixelAspectRatioNumerator)
            {
                return(false);
            }
#endif

            foreach (var g in NodeGUIUtility.SupportedBuildTargetGroups)
            {
                var platformName = BuildTargetUtility.TargetToAssetBundlePlatformName(g,
                                                                                      BuildTargetUtility.PlatformNameType.VideoClipImporter);

                try {
                    var r = reference.GetTargetSettings(platformName);
                    var t = target.GetTargetSettings(platformName);

                    if (!IsEqual(r, t))
                    {
                        return(false);
                    }
                } catch (Exception e) {
                    LogUtility.Logger.LogWarning("VideoClipImporter",
                                                 string.Format("Failed to set override setting for platform {0}: file :{1} \\nreason:{2}",
                                                               platformName, target.assetPath, e.Message));
                }
            }

            return(true);
        }