public static void DestroyProfile(PostProcessProfile profile, bool destroyEffects)
 {
     if (destroyEffects)
     {
         foreach (PostProcessEffectSettings setting in profile.settings)
         {
             Destroy(setting);
         }
     }
     Destroy(profile);
 }
Esempio n. 2
0
        public static void DestroyProfile(PostProcessProfile profile, bool destroyEffects)
        {
            if (destroyEffects)
            {
                foreach (var effect in profile.settings)
                {
                    Destroy(effect);
                }
            }

            Destroy(profile);
        }
Esempio n. 3
0
        private VolumeProfile ConvertVolumeProfileAsset(BIRPRendering.PostProcessProfile oldProfile,
                                                        StringBuilder errorString, ref bool success)
        {
            // Don't convert if it appears to already have been converted.
            if (!oldProfile)
            {
                return(null);
            }

            var oldPath      = AssetDatabase.GetAssetPath(oldProfile);
            var oldDirectory = Path.GetDirectoryName(oldPath);
            var oldName      = Path.GetFileNameWithoutExtension(oldPath);
            var newPath      = Path.Combine(oldDirectory, $"{oldName}(URP).asset");

            if (File.Exists(newPath))
            {
                return(AssetDatabase.LoadAssetAtPath <VolumeProfile>(newPath));
            }

            var newProfile = ScriptableObject.CreateInstance <VolumeProfile>();

            try
            {
                AssetDatabase.CreateAsset(newProfile, newPath);
            }
            catch (Exception e)
            {
                errorString.AppendLine($"PPv2 PostProcessLayer failed to be converted with exception:\n{e}");
                success = false;

                if (!newProfile)
                {
                    return(null);
                }
            }

            foreach (var oldSettings in oldProfile.settings)
            {
                foreach (var effectConverter in effectConverters)
                {
                    effectConverter.AddConvertedProfileSettingsToProfile(oldSettings, newProfile);
                }
            }

            EditorUtility.SetDirty(newProfile);

            return(newProfile);
        }
Esempio n. 4
0
        //Create a global post processing volume and assign the correct layer and default profile
        public static void SetupGlobalVolume()
        {
            GameObject volumeObject = new GameObject("Global Post-process Volume");

#if PPS
            UnityEngine.Rendering.PostProcessing.PostProcessVolume volume = volumeObject.AddComponent<UnityEngine.Rendering.PostProcessing.PostProcessVolume>();
            volumeObject.layer = SCPE.GetLayerID();
            volume.isGlobal = true;
#endif

#if URP
            Volume volume = volumeObject.AddComponent<Volume>();
            volume.isGlobal = true;
#endif

            string type = "PostProcessProfile";
#if URP
            type = "VolumeProfile";
#endif
            //Find default profile
            string[] assets = AssetDatabase.FindAssets("SC Default Profile t: " + type);

            if (assets.Length > 0)
            {
                string assetPath = AssetDatabase.GUIDToAssetPath(assets[0]);
#if PPS
                UnityEngine.Rendering.PostProcessing.PostProcessProfile defaultProfile = (UnityEngine.Rendering.PostProcessing.PostProcessProfile)AssetDatabase.LoadAssetAtPath(assetPath, typeof(UnityEngine.Rendering.PostProcessing.PostProcessProfile));
                volume.sharedProfile = defaultProfile;
#endif
#if URP
                UnityEngine.Rendering.VolumeProfile defaultProfile = (UnityEngine.Rendering.VolumeProfile)AssetDatabase.LoadAssetAtPath(assetPath, typeof(UnityEngine.Rendering.VolumeProfile));
                volume.sharedProfile = defaultProfile;
#endif
            }
            else
            {
                Debug.Log("The default \"SC Post Effects\" profile could not be found. Add a new profile to the volume to get started.");
            }

            Selection.objects = new[] { volumeObject };
            EditorUtility.SetDirty(volumeObject);
        }
        public PostProcessVolume QuickVolume(int layer, float priority, params PostProcessEffectSettings[] settings)
        {
            GameObject gameObject = new GameObject();

            gameObject.name      = "Quick Volume";
            gameObject.layer     = layer;
            gameObject.hideFlags = HideFlags.HideAndDontSave;
            GameObject        gameObject2       = gameObject;
            PostProcessVolume postProcessVolume = gameObject2.AddComponent <PostProcessVolume>();

            postProcessVolume.priority = priority;
            postProcessVolume.isGlobal = true;
            PostProcessProfile profile = postProcessVolume.profile;

            foreach (PostProcessEffectSettings effect in settings)
            {
                profile.AddSettings(effect);
            }
            return(postProcessVolume);
        }
Esempio n. 6
0
        private void ConvertProfile(BIRPRendering.PostProcessProfile oldProfile, ref bool succeeded,
                                    StringBuilder errorString)
        {
            if (!succeeded)
            {
                return;
            }

            if (!oldProfile)
            {
                errorString.AppendLine(
                    "PPv2 PostProcessProfile failed to be converted because the original asset reference was lost during conversion.");
                return;
            }

            ConvertVolumeProfileAsset(oldProfile, errorString, ref succeeded);

            // TODO:
            // - Perhaps old Profiles should only be deleted if they actually no longer have references,
            // just in case some some Volume conversions are skipped and still need references for future conversion.
            // - Alternatively, leave deletion of Profiles entirely to the user. (I think this is preferred)
        }