protected virtual void AddToCache(ISightTarget target, Transform meshParent, Mesh mesh, SkinnedMeshRenderer skinnedMeshRenderer) { int instanceID = target.gameObject.GetInstanceID(); //int sampleCount = config.sampleCount; int sampleCount = Mathf.Clamp(20, 0, mesh.vertexCount); // TODO: FIX -- When a sight viewer with 1 sample indexes first, one with a higher sample count won't re-index... var randomIndices = new int[sampleCount]; for (int i = 0; i < sampleCount; i++) { int index = UnityEngine.Random.Range(0, mesh.vertexCount); randomIndices[i] = index; } if (vertexCache.ContainsKey(instanceID) == false) { if (config.debug) { // Debug.Log("Added new object (" + target.name + ") to cache", target.gameObject); } vertexCache.Add(instanceID, new SightCacheLookup(target, meshParent, mesh, randomIndices, skinnedMeshRenderer)); return; } if (config.debug) { Debug.Log("Re-building cache for " + target.name, target.gameObject); } vertexCache[instanceID] = new SightCacheLookup(target, meshParent, mesh, randomIndices, skinnedMeshRenderer); }
public void GetFromCache(ISightTarget target, out SightCacheLookup cacheLookup) { if (vertexCache.ContainsKey(target.gameObject.GetInstanceID())) { cacheLookup = vertexCache[target.gameObject.GetInstanceID()]; return; } throw new InvalidOperationException("Given object is not in cache, check if an object is in cache first by calling Contains"); }