| | 1 | | using System.Collections.Generic; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | namespace AvatarSystem |
| | 5 | | { |
| | 6 | | public class Visibility : IVisibility |
| | 7 | | { |
| 1330 | 8 | | internal readonly HashSet<string> globalConstrains = new HashSet<string>(); |
| 1330 | 9 | | internal readonly HashSet<string> combinedRendererConstrains = new HashSet<string>(); |
| 1330 | 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 | | { |
| 115 | 30 | | globalConstrains.Add(key); |
| 115 | 31 | | UpdateCombinedRendererVisibility(); |
| 115 | 32 | | UpdateFacialFeatureVisibility(); |
| 115 | 33 | | } |
| | 34 | |
|
| | 35 | | public void RemoveGlobalConstrain(string key) |
| | 36 | | { |
| 5 | 37 | | globalConstrains.Remove(key); |
| 5 | 38 | | UpdateCombinedRendererVisibility(); |
| 5 | 39 | | UpdateFacialFeatureVisibility(); |
| 5 | 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 | | internal void UpdateCombinedRendererVisibility() |
| | 67 | | { |
| 159 | 68 | | if (combinedRenderer == null) |
| 120 | 69 | | return; |
| | 70 | |
|
| 39 | 71 | | combinedRenderer.enabled = globalConstrains.Count == 0 && combinedRendererConstrains.Count == 0; |
| 39 | 72 | | } |
| | 73 | |
|
| | 74 | | internal void UpdateFacialFeatureVisibility() |
| | 75 | | { |
| 159 | 76 | | if (facialFeatures == null) |
| 120 | 77 | | return; |
| | 78 | |
|
| 39 | 79 | | bool facialFeaturesVisibility = globalConstrains.Count == 0 && facialFeaturesConstrains.Count == 0; |
| 312 | 80 | | for (int i = 0; i < facialFeatures.Count; i++) |
| | 81 | | { |
| 117 | 82 | | facialFeatures[i].enabled = facialFeaturesVisibility; |
| | 83 | | } |
| 39 | 84 | | } |
| | 85 | |
|
| | 86 | | public void Dispose() |
| | 87 | | { |
| 1405 | 88 | | globalConstrains.Clear(); |
| 1405 | 89 | | combinedRendererConstrains.Clear(); |
| 1405 | 90 | | facialFeaturesConstrains.Clear(); |
| | 91 | |
|
| 1405 | 92 | | combinedRenderer = null; |
| 1405 | 93 | | facialFeatures = null; |
| 1405 | 94 | | } |
| | 95 | | } |
| | 96 | | } |