| | 1 | | using System.Collections.Generic; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | namespace AvatarSystem |
| | 5 | | { |
| | 6 | | public class Visibility : IVisibility |
| | 7 | | { |
| 1068 | 8 | | internal readonly HashSet<string> globalConstrains = new HashSet<string>(); |
| 1068 | 9 | | internal readonly HashSet<string> combinedRendererConstrains = new HashSet<string>(); |
| 1068 | 10 | | internal readonly HashSet<string> facialFeaturesConstrains = new HashSet<string>(); |
| | 11 | |
|
| | 12 | | private Renderer combinedRenderer = null; |
| | 13 | | private List<Renderer> facialFeatures = null; |
| | 14 | |
|
| | 15 | | /// <summary> |
| | 16 | | /// Bind a set of renderers, previous renderers enabled wont be modified |
| | 17 | | /// </summary> |
| | 18 | | /// <param name="combinedRenderer"></param> |
| | 19 | | /// <param name="facialFeatures"></param> |
| | 20 | | public void Bind(Renderer combinedRenderer, List<Renderer> facialFeatures) |
| | 21 | | { |
| 26 | 22 | | this.combinedRenderer = combinedRenderer; |
| 26 | 23 | | this.facialFeatures = facialFeatures; |
| 26 | 24 | | UpdateCombinedRendererVisibility(); |
| 26 | 25 | | UpdateFacialFeatureVisibility(); |
| 26 | 26 | | } |
| | 27 | |
|
| | 28 | | public void AddGlobalConstrain(string key) |
| | 29 | | { |
| 6 | 30 | | globalConstrains.Add(key); |
| 6 | 31 | | UpdateCombinedRendererVisibility(); |
| 6 | 32 | | UpdateFacialFeatureVisibility(); |
| 6 | 33 | | } |
| | 34 | |
|
| | 35 | | public void RemoveGlobalConstrain(string key) |
| | 36 | | { |
| 1 | 37 | | globalConstrains.Remove(key); |
| 1 | 38 | | UpdateCombinedRendererVisibility(); |
| 1 | 39 | | UpdateFacialFeatureVisibility(); |
| 1 | 40 | | } |
| | 41 | |
|
| | 42 | | public void AddCombinedRendererConstrain(string key) |
| | 43 | | { |
| 0 | 44 | | combinedRendererConstrains.Add(key); |
| 0 | 45 | | UpdateCombinedRendererVisibility(); |
| 0 | 46 | | } |
| | 47 | |
|
| | 48 | | public void RemoveCombinedRendererConstrain(string key) |
| | 49 | | { |
| 0 | 50 | | combinedRendererConstrains.Remove(key); |
| 0 | 51 | | UpdateCombinedRendererVisibility(); |
| 0 | 52 | | } |
| | 53 | |
|
| | 54 | | public void AddFacialFeaturesConstrain(string key) |
| | 55 | | { |
| 0 | 56 | | facialFeaturesConstrains.Add(key); |
| 0 | 57 | | UpdateFacialFeatureVisibility(); |
| 0 | 58 | | } |
| | 59 | |
|
| | 60 | | public void RemoveFacialFeaturesConstrain(string key) |
| | 61 | | { |
| 0 | 62 | | facialFeaturesConstrains.Remove(key); |
| 0 | 63 | | UpdateFacialFeatureVisibility(); |
| 0 | 64 | | } |
| | 65 | |
|
| | 66 | | public bool IsGloballyVisible() |
| | 67 | | { |
| 0 | 68 | | return AreFacialFeaturesVisible() && IsMainRenderVisible(); |
| | 69 | | } |
| | 70 | |
|
| | 71 | | public bool AreFacialFeaturesVisible() |
| | 72 | | { |
| 0 | 73 | | return globalConstrains.Count == 0 && facialFeaturesConstrains.Count == 0; |
| | 74 | | } |
| | 75 | |
|
| | 76 | | public bool IsMainRenderVisible() |
| | 77 | | { |
| 0 | 78 | | return globalConstrains.Count == 0 && combinedRendererConstrains.Count == 0; |
| | 79 | | } |
| | 80 | |
|
| | 81 | | internal void UpdateCombinedRendererVisibility() |
| | 82 | | { |
| 46 | 83 | | if (combinedRenderer == null) |
| 7 | 84 | | return; |
| | 85 | |
|
| 39 | 86 | | combinedRenderer.enabled = globalConstrains.Count == 0 && combinedRendererConstrains.Count == 0; |
| 39 | 87 | | } |
| | 88 | |
|
| | 89 | | internal void UpdateFacialFeatureVisibility() |
| | 90 | | { |
| 46 | 91 | | if (facialFeatures == null) |
| 7 | 92 | | return; |
| | 93 | |
|
| 39 | 94 | | bool facialFeaturesVisibility = globalConstrains.Count == 0 && facialFeaturesConstrains.Count == 0; |
| 312 | 95 | | for (int i = 0; i < facialFeatures.Count; i++) |
| | 96 | | { |
| 117 | 97 | | facialFeatures[i].enabled = facialFeaturesVisibility; |
| | 98 | | } |
| 39 | 99 | | } |
| | 100 | |
|
| | 101 | | public void Dispose() |
| | 102 | | { |
| 1054 | 103 | | globalConstrains.Clear(); |
| 1054 | 104 | | combinedRendererConstrains.Clear(); |
| 1054 | 105 | | facialFeaturesConstrains.Clear(); |
| | 106 | |
|
| 1054 | 107 | | combinedRenderer = null; |
| 1054 | 108 | | facialFeatures = null; |
| 1054 | 109 | | } |
| | 110 | | } |
| | 111 | | } |