using System; using System.Diagnostics; using System.Collections.Generic; namespace UnityEngine.Rendering.HighDefinition { /// /// This attribute is used to associate a unique ID to a cloud class. /// This is needed to be able to automatically register cloud classes and avoid collisions and refactoring class names causing data compatibility issues. /// [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public sealed class CloudUniqueID : Attribute { internal readonly int uniqueID; /// /// Attribute CloudUniqueID constructor. /// /// Cloud unique ID. Needs to be different from all other registered unique IDs. public CloudUniqueID(int uniqueID) { this.uniqueID = uniqueID; } } /// /// Base class for custom Cloud Settings. /// public abstract class CloudSettings : VolumeComponent { static Dictionary cloudUniqueIDs = new Dictionary(); /// /// Returns the hash code of the cloud parameters. /// /// The camera we want to use to compute the hash of the cloud. /// The hash code of the cloud parameters. virtual public int GetHashCode(Camera camera) { // By default we don't need to consider the camera position. return GetHashCode(); } /// /// Returns the cloud type unique ID. /// Use this to override the cloudType in the Visual Environment volume component. /// /// Type of clouds. /// The unique ID for the requested cloud type. public static int GetUniqueID() { return GetUniqueID(typeof(T)); } /// /// Returns the cloud type unique ID. /// Use this to override the cloudType in the Visual Environment volume component. /// /// Type of clouds. /// The unique ID for the requested cloud type. public static int GetUniqueID(Type type) { int uniqueID; if (!cloudUniqueIDs.TryGetValue(type, out uniqueID)) { var uniqueIDs = type.GetCustomAttributes(typeof(CloudUniqueID), false); uniqueID = (uniqueIDs.Length == 0) ? -1 : ((CloudUniqueID)uniqueIDs[0]).uniqueID; cloudUniqueIDs[type] = uniqueID; } return uniqueID; } /// /// Returns the class type of the CloudRenderer associated with this Cloud Settings. /// /// The class type of the CloudRenderer associated with this Cloud Settings. public abstract Type GetCloudRendererType(); } }