From 0b0a16220228fcaa9e5f032885a3f9ba2b4e907b Mon Sep 17 00:00:00 2001 From: mackysoft Date: Tue, 16 Mar 2021 21:28:05 +0900 Subject: [PATCH] Update Documentation - Removed the constructor of CullingGroupKeyDefinition. - Renamed from CameraSourceMode to CameraReferenceMode. - Updated some documents. --- .../Editor/Utilities/CameraReferenceDrawer.cs | 6 +-- .../Runtime/CullingGroupKey.cs | 19 ++++---- .../Runtime/CullingGroupProxy.cs | 22 +++++++++- .../Runtime/CullingTargetBehaviour.cs | 11 +++++ .../Runtime/ICullingTarget.cs | 12 +++++- .../Runtime/Utilities/CameraReference.cs | 43 ++++++++++++------- .../CullingGroupTargetCameraSetter.cs | 38 ++++++++++++++-- .../Utilities/CullingTargetRenderers.cs | 3 ++ .../Runtime/VisionSettings.cs | 24 ++++++++++- Documentation/docfx.json | 5 ++- 10 files changed, 148 insertions(+), 35 deletions(-) diff --git a/Assets/MackySoft/MackySoft.Vision/Editor/Utilities/CameraReferenceDrawer.cs b/Assets/MackySoft/MackySoft.Vision/Editor/Utilities/CameraReferenceDrawer.cs index c51e0ab..58911d1 100644 --- a/Assets/MackySoft/MackySoft.Vision/Editor/Utilities/CameraReferenceDrawer.cs +++ b/Assets/MackySoft/MackySoft.Vision/Editor/Utilities/CameraReferenceDrawer.cs @@ -14,8 +14,8 @@ public override void OnGUI (Rect position,SerializedProperty property,GUIContent SerializedProperty mode = property.FindPropertyRelative("m_Mode"); if (!mode.hasMultipleDifferentValues) { - switch ((CameraSourceMode)mode.enumValueIndex) { - case CameraSourceMode.TaggedCamera: + switch ((CameraReferenceMode)mode.enumValueIndex) { + case CameraReferenceMode.TaggedCamera: position.width *= 0.5f; EditorGUI.PropertyField(new Rect(position.xMin,position.yMin,position.width,position.height),mode,GUIContent.none); SerializedProperty tag = property.FindPropertyRelative("m_Tag"); @@ -24,7 +24,7 @@ public override void OnGUI (Rect position,SerializedProperty property,GUIContent tag.stringValue = EditorGUI.TagField(new Rect(position.xMin + position.width,position.yMin,position.width,position.height),GUIContent.none,tag.stringValue); EditorGUI.showMixedValue = false; break; - case CameraSourceMode.Custom: + case CameraReferenceMode.Custom: position.width *= 0.5f; EditorGUI.PropertyField(new Rect(position.xMin,position.yMin,position.width,position.height),mode,GUIContent.none); SerializedProperty customCamera = property.FindPropertyRelative("m_CustomCamera"); diff --git a/Assets/MackySoft/MackySoft.Vision/Runtime/CullingGroupKey.cs b/Assets/MackySoft/MackySoft.Vision/Runtime/CullingGroupKey.cs index 3ccbf8a..d9f56ea 100644 --- a/Assets/MackySoft/MackySoft.Vision/Runtime/CullingGroupKey.cs +++ b/Assets/MackySoft/MackySoft.Vision/Runtime/CullingGroupKey.cs @@ -5,6 +5,10 @@ namespace MackySoft.Vision { + /// + /// Definition of . It can be defined in . + /// Basically, it is not used directly by the user. + /// [Serializable] public class CullingGroupKeyDefinition { @@ -13,19 +17,18 @@ public class CullingGroupKeyDefinition { public string Name { get => m_Name; set => m_Name = value; } - public CullingGroupKeyDefinition () : this(string.Empty) { - - } - - public CullingGroupKeyDefinition (string name) { - m_Name = name; - } - } + /// + /// Key to find the . The essence of a key is an index. + /// The keys are defined in . + /// [Serializable] public struct CullingGroupKey : IEquatable { + /// + /// Key with index -1. + /// public static readonly CullingGroupKey None = new CullingGroupKey(-1); [SerializeField] diff --git a/Assets/MackySoft/MackySoft.Vision/Runtime/CullingGroupProxy.cs b/Assets/MackySoft/MackySoft.Vision/Runtime/CullingGroupProxy.cs index efee643..dafbc5c 100644 --- a/Assets/MackySoft/MackySoft.Vision/Runtime/CullingGroupProxy.cs +++ b/Assets/MackySoft/MackySoft.Vision/Runtime/CullingGroupProxy.cs @@ -117,8 +117,14 @@ public float[] BoundingDistances { } } + /// + /// All culling targets. + /// public IReadOnlyList Targets => m_Targets; + /// + /// BoundingSphere of all culling targets. + /// public IReadOnlyList BoundingSpheres => m_BoundingSpheres; #endregion @@ -331,16 +337,30 @@ public void UpdateDynamicBoundingSphereTransforms () { } } } - + + /// + /// Get the enabled CullingGroupProxy with key. + /// + /// Key to get the CullingGroupProxy. + /// Returns a CullingGroupProxy with the same key as the specified key. public static CullingGroupProxy GetGroup (CullingGroupKey key) { return (key >= 0) ? m_Groups[key] : null; } + /// + /// Try to get the enabled CullingGroupProxy with key. + /// + /// Key to get the CullingGroupProxy. + /// The CullingGroupProxy with the same key as the specified key. + /// True if the CullingGroupProxy could be got, False otherwise. public static bool TryGetGroup (CullingGroupKey key,out CullingGroupProxy result) { result = GetGroup(key); return result != null; } + /// + /// Call the method of all CullingGroupProxy's. + /// public static void UpdateAllGroupTargets () { for (int i = 0;m_Groups.Length > i;i++) { CullingGroupProxy group = m_Groups[i]; diff --git a/Assets/MackySoft/MackySoft.Vision/Runtime/CullingTargetBehaviour.cs b/Assets/MackySoft/MackySoft.Vision/Runtime/CullingTargetBehaviour.cs index 437ad49..501449e 100644 --- a/Assets/MackySoft/MackySoft.Vision/Runtime/CullingTargetBehaviour.cs +++ b/Assets/MackySoft/MackySoft.Vision/Runtime/CullingTargetBehaviour.cs @@ -78,6 +78,9 @@ public TransformUpdateMode BoundingSphereUpdateMode { #region Events + /// + /// Sets the callback that will be called when a sphere visibility and/or distance state has changed. + /// public CullingGroup.StateChanged OnStateChanged { get; set; } #endregion @@ -115,10 +118,18 @@ void OnDisable () { #endregion + /// + /// Returns true if the bounding sphere is currently visible from any of the contributing cameras. + /// + /// True if the bounding sphere is visible, false if it is invisible. public bool IsVisible () { return (m_Group == null) || m_Group.IsVisible(this); } + /// + /// Get the current distance band index of the bounding sphere. + /// + /// The sphere current distance band index. public int GetDistance () { return (m_Group != null) ? m_Group.GetDistance(this) : -1; } diff --git a/Assets/MackySoft/MackySoft.Vision/Runtime/ICullingTarget.cs b/Assets/MackySoft/MackySoft.Vision/Runtime/ICullingTarget.cs index 530e891..92ec847 100644 --- a/Assets/MackySoft/MackySoft.Vision/Runtime/ICullingTarget.cs +++ b/Assets/MackySoft/MackySoft.Vision/Runtime/ICullingTarget.cs @@ -2,13 +2,23 @@ namespace MackySoft.Vision { + /// + /// When to update the transform. + /// public enum TransformUpdateMode { + /// + /// Transform an always updated. + /// Dynamic = 0, + + /// + /// Transform is updated by the first update or by explicitly calling the update method. + /// Static = 1 } public interface ICullingTarget { - + /// /// When to update the bounding sphere transform. /// diff --git a/Assets/MackySoft/MackySoft.Vision/Runtime/Utilities/CameraReference.cs b/Assets/MackySoft/MackySoft.Vision/Runtime/Utilities/CameraReference.cs index ccb01ff..d26106f 100644 --- a/Assets/MackySoft/MackySoft.Vision/Runtime/Utilities/CameraReference.cs +++ b/Assets/MackySoft/MackySoft.Vision/Runtime/Utilities/CameraReference.cs @@ -5,18 +5,22 @@ namespace MackySoft.Vision.Utilities { - public enum CameraSourceMode { + public enum CameraReferenceMode { CurrentCamera = 0, MainCamera = 1, TaggedCamera = 2, Custom = 3 } + /// + /// Advanced camera reference. + /// Useful when referencing camera from multiple scenes and prefabs. + /// [Serializable] public class CameraReference { [SerializeField] - CameraSourceMode m_Mode = CameraSourceMode.MainCamera; + CameraReferenceMode m_Mode = CameraReferenceMode.MainCamera; [SerializeField] string m_Tag = "Untagged"; @@ -26,7 +30,10 @@ public class CameraReference { Camera m_CachedCamera; - public CameraSourceMode Mode { + /// + /// Method of referring to the camera. + /// + public CameraReferenceMode Mode { get => m_Mode; set { if (m_Mode != value) { @@ -36,20 +43,26 @@ public CameraSourceMode Mode { } } + /// + /// A tag for referencing a camera when is . + /// public string Tag { get => m_Tag; set { - if (m_Mode == CameraSourceMode.TaggedCamera) { + if (m_Mode == CameraReferenceMode.TaggedCamera) { ClearCache(); } m_Tag = value; } } + /// + /// Reference to the camera when is . + /// public Camera CustomCamera { get => m_CustomCamera; set { - if (m_Mode == CameraSourceMode.Custom) { + if (m_Mode == CameraReferenceMode.Custom) { ClearCache(); } m_CustomCamera = value; @@ -57,7 +70,7 @@ public Camera CustomCamera { } /// - /// Returns a camera based on the . + /// Returns a camera based on the . /// The retrieved camera will be cached. /// public Camera Camera { @@ -66,11 +79,11 @@ public Camera Camera { return m_CachedCamera; } switch (m_Mode) { - case CameraSourceMode.CurrentCamera: + case CameraReferenceMode.CurrentCamera: return m_CachedCamera = Camera.current; - case CameraSourceMode.MainCamera: + case CameraReferenceMode.MainCamera: return m_CachedCamera = Camera.main; - case CameraSourceMode.TaggedCamera: + case CameraReferenceMode.TaggedCamera: Camera[] allCameras = Camera.allCameras; for (int i = 0;allCameras.Length > i;i++) { Camera camera = allCameras[i]; @@ -79,7 +92,7 @@ public Camera Camera { } } return m_CachedCamera = null; - case CameraSourceMode.Custom: + case CameraReferenceMode.Custom: return m_CachedCamera = m_CustomCamera; default: throw new NotImplementedException(); @@ -87,21 +100,21 @@ public Camera Camera { } } - public CameraReference () : this(CameraSourceMode.MainCamera) { + public CameraReference () : this(CameraReferenceMode.MainCamera) { } - public CameraReference (CameraSourceMode source) { - m_Mode = source; + public CameraReference (CameraReferenceMode mode) { + m_Mode = mode; } public CameraReference (Camera customCamera) { - m_Mode = CameraSourceMode.Custom; + m_Mode = CameraReferenceMode.Custom; m_CustomCamera = customCamera; } public CameraReference (string tag) { - m_Mode = CameraSourceMode.TaggedCamera; + m_Mode = CameraReferenceMode.TaggedCamera; m_Tag = tag; } diff --git a/Assets/MackySoft/MackySoft.Vision/Runtime/Utilities/CullingGroupTargetCameraSetter.cs b/Assets/MackySoft/MackySoft.Vision/Runtime/Utilities/CullingGroupTargetCameraSetter.cs index 8072044..a140464 100644 --- a/Assets/MackySoft/MackySoft.Vision/Runtime/Utilities/CullingGroupTargetCameraSetter.cs +++ b/Assets/MackySoft/MackySoft.Vision/Runtime/Utilities/CullingGroupTargetCameraSetter.cs @@ -2,29 +2,61 @@ namespace MackySoft.Vision.Utilities { + /// + /// A useful component for linking and camera that exist in separate scenes. + /// [AddComponentMenu("MackySoft/Vision/Culling Group Target Camera Setter")] [HelpURL("https://github.com/mackysoft/Vision")] public class CullingGroupTargetCameraSetter : MonoBehaviour { + [Tooltip("Key to reference the CullingGroupProxy")] [SerializeField] CullingGroupKey m_GroupKey = CullingGroupKey.None; + [Tooltip("A reference to the camera you want to set to CullingGroupProxy.TargetCamera")] [SerializeField] - CameraReference m_TargetCamera = new CameraReference(CameraSourceMode.MainCamera); + CameraReference m_TargetCamera = new CameraReference(CameraReferenceMode.MainCamera); - void Start () { + [SerializeField] + bool m_LinkOnEnableOrStart = true; + + /// + /// Key to reference the . + /// + public CullingGroupKey GroupKey { get => m_GroupKey; set => m_GroupKey = value; } + + /// + /// A reference to the camera you want to set to . + /// + public CameraReference TargetCamera { get => m_TargetCamera; set => m_TargetCamera = value; } + + public bool LinkOnEnableOrStart { get => m_LinkOnEnableOrStart; set => m_LinkOnEnableOrStart = value; } + + /// + /// Set the specified camera to the of the specified . + /// See: , + /// + public void Link () { if ((m_TargetCamera.Camera != null) && CullingGroupProxy.TryGetGroup(m_GroupKey,out CullingGroupProxy group)) { group.TargetCamera = m_TargetCamera; } } + void OnEnable () { + Link(); + } + + void Start () { + Link(); + } + #if UNITY_EDITOR void Reset () { if (TryGetComponent(out CullingGroupProxy group)) { m_GroupKey = group.Key; } if (TryGetComponent(out Camera camera)) { - m_TargetCamera.Mode = CameraSourceMode.Custom; + m_TargetCamera.Mode = CameraReferenceMode.Custom; m_TargetCamera.CustomCamera = camera; } } diff --git a/Assets/MackySoft/MackySoft.Vision/Runtime/Utilities/CullingTargetRenderers.cs b/Assets/MackySoft/MackySoft.Vision/Runtime/Utilities/CullingTargetRenderers.cs index f1dc537..349fa7f 100644 --- a/Assets/MackySoft/MackySoft.Vision/Runtime/Utilities/CullingTargetRenderers.cs +++ b/Assets/MackySoft/MackySoft.Vision/Runtime/Utilities/CullingTargetRenderers.cs @@ -17,6 +17,9 @@ public class CullingTargetRenderers : MonoBehaviour { ICullingTarget m_CullingTarget; + /// + /// A renderer's to enable/disable. + /// public Renderer[] Renderers { get => m_Renderers; set => m_Renderers = value; diff --git a/Assets/MackySoft/MackySoft.Vision/Runtime/VisionSettings.cs b/Assets/MackySoft/MackySoft.Vision/Runtime/VisionSettings.cs index 89b959c..91cbb11 100644 --- a/Assets/MackySoft/MackySoft.Vision/Runtime/VisionSettings.cs +++ b/Assets/MackySoft/MackySoft.Vision/Runtime/VisionSettings.cs @@ -3,11 +3,21 @@ namespace MackySoft.Vision { - [CreateAssetMenu(fileName = nameof(VisionSettings),menuName = "MackySoft/Vision/Vision Settings")] + /// + /// VisionSettings is where you can configure settings related to Vision. + /// It can be opened from the "Tools/Vision/Open Settings" menu. + /// + // NOTE: VisionSettings will be created automatically. + // [CreateAssetMenu(fileName = nameof(VisionSettings),menuName = "MackySoft/Vision/Vision Settings")] + [HelpURL("https://github.com/mackysoft/Vision")] public class VisionSettings : ScriptableObject { static VisionSettings m_Instance; + /// + /// A singleton of VisionSettings. + /// This instance will be loaded from "Resources/VisionSettings". + /// public static VisionSettings Instance { get { if (m_Instance == null) { @@ -17,9 +27,19 @@ public static VisionSettings Instance { } } + [Tooltip( + "Definition list of culling group key.\n" + + "Used to display the CullingGroupKey as a popup in the inspector." + )] [SerializeField] - List m_GroupKeyDefinitions = new List(); + List m_GroupKeyDefinitions = new List { + new CullingGroupKeyDefinition { Name = "Main" } + }; + /// + /// Definition list of culling group key. + /// Used to display the as a popup in the inspector. + /// public IReadOnlyList GroupKeyDefinitions => m_GroupKeyDefinitions; } diff --git a/Documentation/docfx.json b/Documentation/docfx.json index e3d0de1..88359e5 100644 --- a/Documentation/docfx.json +++ b/Documentation/docfx.json @@ -20,8 +20,9 @@ "build": { "globalMetadata": { "_appTitle": "Vision", - "_appFooter": "Vision", - "_enableSearch": true + "_appFooter": "Vision - CullingGroup for everyone", + "_enableSearch": true, + "_enableNewTab": true }, "content": [ {