// // Copyright (c) 2017 Anthony Marmont. All rights reserved. // Licensed for use under the Unity Asset Store EULA. See https://unity3d.com/legal/as_terms for full license information. // #if UNITY_EDITOR #pragma warning disable using System; using System.Collections.Generic; using UnityEngine; namespace AssetIcons.Editors { /// /// A camera setup used in to render a Prefab. /// /// /// [Serializable] public struct AssetIconsCameraSetup : IEquatable { /// /// A set of default settings to render a Prefab with. /// public static AssetIconsCameraSetup Default { get { return new AssetIconsCameraSetup() { Padding = 0.0f, TransparentBackground = false, BackgroundColor = new Color(0.2f, 0.2f, 0.2f, 1.0f), Orthographic = false, PreviewDirection = new Vector3(-1.0f, -1.0f, -1.0f) }; } } [Header("Positioning")] [SerializeField] private float padding; [SerializeField] private Vector3 previewDirection; [Header("Camera Settings")] [SerializeField] private bool transparentBackground; [SerializeField] private Color backgroundColor; [SerializeField] private bool orthographic; /// /// Indicates whether the background should be rendered as transparent. /// public bool TransparentBackground { get { return transparentBackground; } set { transparentBackground = value; } } /// /// The vector direction to render a Prefab from. /// public Vector3 PreviewDirection { get { return previewDirection; } set { previewDirection = value; } } /// /// Padding around the edges of a rendered Prefab. /// public float Padding { get { return padding; } set { padding = value; } } /// /// The background color of the rendered graphic. /// public Color BackgroundColor { get { return backgroundColor; } set { backgroundColor = value; } } /// /// Indicates whether projection should be orthographic. /// public bool Orthographic { get { return orthographic; } set { orthographic = value; } } /// /// Applies this to a Unity . /// /// The Unity to be modified. public void ApplyToCamera(Camera camera) { camera.orthographic = Orthographic; camera.backgroundColor = BackgroundColor; camera.clearFlags = TransparentBackground ? CameraClearFlags.Depth : CameraClearFlags.Color; } /// /// Evaluates whether this is equal to an . /// /// The other to compare against. /// /// true if the is a s and is equal to this; otherwise false. /// public override bool Equals(object obj) { return obj is AssetIconsCameraSetup && Equals((AssetIconsCameraSetup)obj); } /// /// Evaluates whether this is equal to another . /// /// The other to compare against. /// /// true if the s are equal; otherwise false. /// public bool Equals(AssetIconsCameraSetup other) { return Padding == other.Padding && PreviewDirection == other.PreviewDirection && TransparentBackground == other.TransparentBackground && BackgroundColor == other.BackgroundColor && Orthographic == other.Orthographic; } /// /// Returns a unique hash for this of . /// /// /// An that represents a unique has of this instance. /// public override int GetHashCode() { int hashCode = -1977805934; hashCode = hashCode * -1521134295 + Padding.GetHashCode(); hashCode = hashCode * -1521134295 + PreviewDirection.GetHashCode(); hashCode = hashCode * -1521134295 + TransparentBackground.GetHashCode(); hashCode = hashCode * -1521134295 + BackgroundColor.GetHashCode(); hashCode = hashCode * -1521134295 + Orthographic.GetHashCode(); return hashCode; } /// /// Evaluates whether a is equal to another . /// /// The other to compare against. /// /// true if the s are equal; otherwise false. /// public static bool operator ==(AssetIconsCameraSetup left, AssetIconsCameraSetup right) { return left.Equals(right); } /// /// Evaluates whether a is not equal to another . /// /// The other to compare against. /// /// true if the s are not equal; otherwise false. /// public static bool operator !=(AssetIconsCameraSetup left, AssetIconsCameraSetup right) { return !(left == right); } } } #pragma warning restore #endif