Пример #1
0
        private bool ConvertVolumeComponent(BIRPRendering.PostProcessVolume oldVolume, StringBuilder errorString)
        {
            // Don't convert if it appears to already have been converted.
            if (oldVolume.GetComponent <Volume>())
            {
                return(true);
            }

            var gameObject = oldVolume.gameObject;
            var newVolume  = gameObject.AddComponent <Volume>();

            newVolume.priority      = oldVolume.priority;
            newVolume.weight        = oldVolume.weight;
            newVolume.blendDistance = oldVolume.blendDistance;
            newVolume.isGlobal      = oldVolume.isGlobal;
            newVolume.enabled       = oldVolume.enabled;

            var success = true;

            newVolume.sharedProfile = ConvertVolumeProfileAsset(oldVolume.sharedProfile, errorString, ref success);

            if (PrefabUtility.IsPartOfPrefabAsset(oldVolume))
            {
                postConversionDestroyables.Add(oldVolume);
            }
            else
            {
                Object.DestroyImmediate(oldVolume, allowDestroyingAssets: true);
            }

            EditorUtility.SetDirty(gameObject);

            return(success);
        }
Пример #2
0
        private void ConvertVolume(BIRPRendering.PostProcessVolume oldVolume, ref bool succeeded,
                                   StringBuilder errorString)
        {
            if (!succeeded)
            {
                return;
            }

            if (!oldVolume)
            {
                // TODO: unless there's good way to tell the if the object is just missing because it was already
                //       converted as part of an earlier conversion object, then these two lines should be commented
                //       out or removed.  It should still return though.
                // succeeded = false;
                // errorString.AppendLine("PPv2 PostProcessVolume failed to be converted because the original asset reference was lost during conversion.");
                return;
            }

            if (PrefabUtility.IsPartOfPrefabInstance(oldVolume) &&
                !PrefabUtility.IsAddedComponentOverride(oldVolume))
            {
                // This is a property override on an instance of the component,
                // so override the component instance with the modifications.
                succeeded = ConvertVolumeInstance(oldVolume, errorString);
            }
            else
            {
                // The entire component is unique, so just convert it
                succeeded = ConvertVolumeComponent(oldVolume, errorString);
            }
        }
Пример #3
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);
        }
Пример #4
0
        internal void Unregister(PostProcessVolume volume)
        {
            int layer = volume.gameObject.layer;

            Unregister(volume, layer);
        }
Пример #5
0
 internal void UpdateVolumeLayer(PostProcessVolume volume, int prevLayer, int newLayer)
 {
     Assert.IsTrue(prevLayer >= 0 && prevLayer <= k_MaxLayerCount, "Invalid layer bit");
     Unregister(volume, prevLayer);
     Register(volume, newLayer);
 }
Пример #6
0
 internal void Unregister(PostProcessVolume volume)
 {
     Unregister(volume, volume.previousLayer);
     Unregister(volume, volume.gameObject.layer);
 }
Пример #7
0
 // Use this for initialization
 void Start()
 {
     vol = GetComponent <UnityEngine.Rendering.PostProcessing.PostProcessVolume>();
     StartCoroutine("Routine");
 }
Пример #8
0
        private bool ConvertVolumeInstance(BIRPRendering.PostProcessVolume oldVolume, StringBuilder errorString)
        {
            // First get a reference to the local instance of the converted component
            // which may require immediately converting it at its origin location first.
            var newVolumeInstance = oldVolume.GetComponent <Volume>();

            if (!newVolumeInstance)
            {
                var oldVolumeOrigin = PrefabUtility.GetCorrespondingObjectFromSource(oldVolume);

                if (!ConvertVolumeComponent(oldVolumeOrigin, errorString))
                {
                    return(false);
                }

                PrefabUtility.SavePrefabAsset(oldVolumeOrigin.gameObject);

                newVolumeInstance = oldVolume.GetComponent <Volume>();

                if (!newVolumeInstance)
                {
                    errorString.AppendLine(
                        "PPv2 PostProcessVolume failed to be converted because the instance object did not inherit the converted Prefab source.");
                    return(false);
                }
            }

            bool success          = true;
            var  oldModifications = PrefabUtility.GetPropertyModifications(oldVolume);

            foreach (var oldModification in oldModifications)
            {
                if (oldModification.target is BIRPRendering.PostProcessVolume)
                {
                    if (oldModification.propertyPath.EndsWith("priority", StringComparison.InvariantCultureIgnoreCase))
                    {
                        newVolumeInstance.priority = oldVolume.priority;
                    }
                    else if (oldModification.propertyPath.EndsWith("weight",
                                                                   StringComparison.InvariantCultureIgnoreCase))
                    {
                        newVolumeInstance.weight = oldVolume.weight;
                    }
                    else if (oldModification.propertyPath.EndsWith("blendDistance",
                                                                   StringComparison.InvariantCultureIgnoreCase))
                    {
                        newVolumeInstance.blendDistance = oldVolume.blendDistance;
                    }
                    else if (oldModification.propertyPath.EndsWith("isGlobal",
                                                                   StringComparison.InvariantCultureIgnoreCase))
                    {
                        newVolumeInstance.isGlobal = oldVolume.isGlobal;
                    }
                    else if (oldModification.propertyPath.EndsWith("enabled",
                                                                   StringComparison.InvariantCultureIgnoreCase))
                    {
                        newVolumeInstance.enabled = oldVolume.enabled;
                    }
                    else if (oldModification.propertyPath.EndsWith("sharedProfile",
                                                                   StringComparison.InvariantCultureIgnoreCase))
                    {
                        newVolumeInstance.sharedProfile =
                            ConvertVolumeProfileAsset(oldVolume.sharedProfile, errorString, ref success);
                    }

                    EditorUtility.SetDirty(newVolumeInstance);
                }
            }

            return(success);
        }
 private static bool IsVolumeRenderedByCamera(PostProcessVolume volume, Camera camera)
 {
     return(true);
 }
 internal void UpdateVolumeLayer(PostProcessVolume volume, int prevLayer, int newLayer)
 {
     Unregister(volume, prevLayer);
     Register(volume, newLayer);
 }