| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Linq; |
| | 4 | | using DCL.Models; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.Assertions; |
| | 7 | |
|
| | 8 | | namespace DCL |
| | 9 | | { |
| | 10 | | public static class DataStore_WorldObjects_Extensions |
| | 11 | | { |
| 1 | 12 | | private static bool VERBOSE = false; |
| 1 | 13 | | private static ILogger logger = new Logger(Debug.unityLogger.logHandler) { filterLogType = VERBOSE ? LogType.Log |
| | 14 | |
|
| | 15 | | public static void AddScene( this DataStore_WorldObjects self, string sceneId ) |
| | 16 | | { |
| 537 | 17 | | if (!self.sceneData.ContainsKey(sceneId)) |
| 532 | 18 | | self.sceneData.Add(sceneId, new DataStore_WorldObjects.SceneData()); |
| 537 | 19 | | } |
| | 20 | |
|
| | 21 | | public static void RemoveScene( this DataStore_WorldObjects self, string sceneId ) |
| | 22 | | { |
| 447 | 23 | | if (self.sceneData.ContainsKey(sceneId)) |
| 42 | 24 | | self.sceneData.Remove(sceneId); |
| 447 | 25 | | } |
| | 26 | |
|
| | 27 | | /// <summary> |
| | 28 | | /// Add owner to the excluded owners list. |
| | 29 | | /// </summary> |
| | 30 | | /// <param name="self"></param> |
| | 31 | | /// <param name="sceneId"></param> |
| | 32 | | /// <param name="ownerId"></param> |
| | 33 | | [Obsolete("This feature is only used by the SmartItem component and will have to be deprecated on the future. Pl |
| | 34 | | public static void AddExcludedOwner(this DataStore_WorldObjects self, string sceneId, long ownerId) |
| | 35 | | { |
| 9 | 36 | | if (!self.sceneData.ContainsKey(sceneId)) |
| 0 | 37 | | return; |
| | 38 | |
|
| 9 | 39 | | self.sceneData[sceneId].ignoredOwners.Add(ownerId); |
| 9 | 40 | | self.sceneData[sceneId].owners.Remove(ownerId); |
| 9 | 41 | | } |
| | 42 | |
|
| | 43 | | [Obsolete("This feature is only used by the SmartItem component and will have to be deprecated on the future. Pl |
| | 44 | | public static void RemoveExcludedOwner(this DataStore_WorldObjects self, string sceneId, long ownerId) |
| | 45 | | { |
| 8 | 46 | | if (!self.sceneData.ContainsKey(sceneId)) |
| 3 | 47 | | return; |
| | 48 | |
|
| 5 | 49 | | self.sceneData[sceneId].ignoredOwners.Remove(ownerId); |
| 5 | 50 | | } |
| | 51 | |
|
| | 52 | | public static void AddTexture(this DataStore_WorldObjects self, string sceneId, long ownerId, Texture texture) |
| | 53 | | { |
| 59 | 54 | | var r = new Rendereable(); |
| 59 | 55 | | r.textures.Add(texture); |
| 59 | 56 | | r.ownerId = ownerId; |
| 59 | 57 | | AddRendereable(self, sceneId, r); |
| 59 | 58 | | } |
| | 59 | |
|
| | 60 | | public static void RemoveTexture(this DataStore_WorldObjects self, string sceneId, long ownerId, Texture texture |
| | 61 | | { |
| 33 | 62 | | var r = new Rendereable(); |
| 33 | 63 | | r.textures.Add(texture); |
| 33 | 64 | | r.ownerId = ownerId; |
| 33 | 65 | | RemoveRendereable(self, sceneId, r); |
| 33 | 66 | | } |
| | 67 | |
|
| | 68 | | public static void AddMaterial(this DataStore_WorldObjects self, string sceneId, long ownerId, |
| | 69 | | Material material) |
| | 70 | | { |
| 58 | 71 | | var r = new Rendereable(); |
| 58 | 72 | | r.materials.Add(material); |
| 58 | 73 | | r.ownerId = ownerId; |
| 58 | 74 | | AddRendereable(self, sceneId, r); |
| 58 | 75 | | } |
| | 76 | |
|
| | 77 | | public static void RemoveMaterial(this DataStore_WorldObjects self, string sceneId, long ownerId, |
| | 78 | | Material material) |
| | 79 | | { |
| 109 | 80 | | var r = new Rendereable(); |
| 109 | 81 | | r.materials.Add(material); |
| 109 | 82 | | r.ownerId = ownerId; |
| 109 | 83 | | RemoveRendereable(self, sceneId, r); |
| 109 | 84 | | } |
| | 85 | |
|
| | 86 | | public static void AddAudioClip(this DataStore_WorldObjects self, string sceneId, AudioClip clip) |
| | 87 | | { |
| 20 | 88 | | if (!self.sceneData.ContainsKey(sceneId)) |
| 1 | 89 | | return; |
| | 90 | |
|
| | 91 | | // NOTE(Brian): entityId is not used here, so audio clips do not work with the ignoreOwners |
| | 92 | | // feature. This is done on purpose as ignoreOwners is only used by the smart item component |
| | 93 | | // and should be deprecated. Also, supporting this would complicate the tracking logic and |
| | 94 | | // has a high maintenance cost. |
| | 95 | |
|
| 19 | 96 | | var sceneData = self.sceneData[sceneId]; |
| 19 | 97 | | sceneData.audioClips.Add(clip); |
| 19 | 98 | | } |
| | 99 | |
|
| | 100 | | public static void RemoveAudioClip(this DataStore_WorldObjects self, string sceneId, AudioClip clip) |
| | 101 | | { |
| 3 | 102 | | if (!self.sceneData.ContainsKey(sceneId)) |
| 0 | 103 | | return; |
| | 104 | |
|
| 3 | 105 | | var sceneData = self.sceneData[sceneId]; |
| 3 | 106 | | sceneData.audioClips.Remove(clip); |
| 3 | 107 | | } |
| | 108 | |
|
| | 109 | | public static void AddRendereable( this DataStore_WorldObjects self, string sceneId, Rendereable rendereable ) |
| | 110 | | { |
| 494 | 111 | | if (!self.sceneData.ContainsKey(sceneId)) |
| 0 | 112 | | return; |
| | 113 | |
|
| 494 | 114 | | if (rendereable == null) |
| | 115 | | { |
| 0 | 116 | | logger.Log( $"Trying to add null rendereable! (id: {sceneId})"); |
| 0 | 117 | | return; |
| | 118 | | } |
| | 119 | |
|
| 494 | 120 | | if (string.IsNullOrEmpty(sceneId) || !self.sceneData.ContainsKey(sceneId)) |
| | 121 | | { |
| 0 | 122 | | logger.Log($"AddRendereable", $"invalid sceneId! (id: {sceneId})"); |
| 0 | 123 | | return; |
| | 124 | | } |
| | 125 | |
|
| 494 | 126 | | var sceneData = self.sceneData[sceneId]; |
| | 127 | |
|
| 494 | 128 | | if ( sceneData.ignoredOwners.Contains(rendereable.ownerId)) |
| 6 | 129 | | return; |
| | 130 | |
|
| 488 | 131 | | sceneData.materials.AddRefCount(rendereable.materials); |
| 488 | 132 | | sceneData.meshes.AddRefCount(rendereable.meshes); |
| 488 | 133 | | sceneData.textures.AddRefCount(rendereable.textures); |
| 488 | 134 | | sceneData.renderers.Add(rendereable.renderers); |
| 488 | 135 | | sceneData.owners.Add(rendereable.ownerId); |
| 488 | 136 | | sceneData.animationClips.AddRefCount(rendereable.animationClips); |
| 488 | 137 | | sceneData.triangles.Set( sceneData.triangles.Get() + rendereable.totalTriangleCount); |
| 488 | 138 | | sceneData.animationClipSize.Set(sceneData.animationClipSize.Get() + rendereable.animationClipSize); |
| 488 | 139 | | sceneData.meshDataSize.Set(sceneData.meshDataSize.Get() + rendereable.meshDataSize); |
| 488 | 140 | | } |
| | 141 | |
|
| | 142 | | public static void RemoveRendereable( this DataStore_WorldObjects self, string sceneId, Rendereable rendereable |
| | 143 | | { |
| 447 | 144 | | if (!self.sceneData.ContainsKey(sceneId)) |
| 158 | 145 | | return; |
| | 146 | |
|
| 289 | 147 | | if ( rendereable == null ) |
| | 148 | | { |
| 0 | 149 | | logger.Log( $"Trying to remove null rendereable! (id: {sceneId})"); |
| 0 | 150 | | return; |
| | 151 | | } |
| | 152 | |
|
| 289 | 153 | | if ( string.IsNullOrEmpty(sceneId) || !self.sceneData.ContainsKey(sceneId) ) |
| | 154 | | { |
| 0 | 155 | | logger.Log($"RemoveRendereable", $"invalid sceneId! (id: {sceneId})"); |
| 0 | 156 | | return; |
| | 157 | | } |
| | 158 | |
|
| 289 | 159 | | var sceneData = self.sceneData[sceneId]; |
| | 160 | |
|
| 289 | 161 | | if ( sceneData.ignoredOwners.Contains(rendereable.ownerId)) |
| 6 | 162 | | return; |
| | 163 | |
|
| 283 | 164 | | sceneData.materials.RemoveRefCount(rendereable.materials); |
| 283 | 165 | | sceneData.meshes.RemoveRefCount(rendereable.meshes); |
| 283 | 166 | | sceneData.textures.RemoveRefCount(rendereable.textures); |
| 283 | 167 | | sceneData.renderers.Remove(rendereable.renderers); |
| 283 | 168 | | sceneData.owners.Remove(rendereable.ownerId); |
| 283 | 169 | | sceneData.animationClips.RemoveRefCount(rendereable.animationClips); |
| 283 | 170 | | sceneData.triangles.Set( sceneData.triangles.Get() - rendereable.totalTriangleCount); |
| 283 | 171 | | sceneData.animationClipSize.Set(sceneData.animationClipSize.Get() - rendereable.animationClipSize); |
| 283 | 172 | | sceneData.meshDataSize.Set(sceneData.meshDataSize.Get() - rendereable.meshDataSize); |
| 283 | 173 | | } |
| | 174 | | } |
| | 175 | | } |