private static void JoinOn(PrefabBaker prefab, LightmapData newData)
        {
            var hashCode = prefab.GetLightMapHashCode();

            if (string.IsNullOrEmpty(hashCode))
            {
                return;
            }
            if (!prefabToLightmap.TryGetValue(hashCode, out LightMapPrefabStorage storage))
            {
                storage = new LightMapPrefabStorage
                {
                    lightData = new List <LightmapData>(4)
                };
            }
            bool addedNew            = true;
            var  hashCodeOfLightData = GetHashCodeCustom(newData);

            foreach (var item in storage.HashCodes)
            {
                if (item == hashCodeOfLightData)
                {
                    addedNew = false;
                    break;
                }
            }
            if (addedNew)
            {
                storage.lightData.Add(newData);
                storage.HashCodes.Add(hashCodeOfLightData);
                prefabToLightmap[hashCode] = storage;
            }
        }
        public static void RemoveInstanceRef(PrefabBaker prefab)
        {
            var hashCode = prefab.GetLightMapHashCode();

            if (prefabToLightmap.TryGetValue(hashCode, out LightMapPrefabStorage storage))
            {
                storage.referenceCount--;
                if (storage.referenceCount <= 0)
                {
                    storage.referenceCount = 0;
                }
            }
        }
Exemple #3
0
        public static void RemoveInstance(PrefabBaker instance)
        {
            if (!AddOrRemove.TryGetValue(instance, out _))
            {
                AddOrRemove.TryAdd(instance, false);
            }
            AddOrRemove[instance] = false;
            var lightMapHasCode = instance.GetLightMapHashCode();

            if (!AddOrRemoveToCheck.TryGetValue(lightMapHasCode, out _))
            {
                AddOrRemoveToCheck.TryAdd(lightMapHasCode, instance.name);
            }
            RunCoroutine();
        }
        public static bool CheckInstance(PrefabBaker prefab)
        {
            bool fullyCleaned = false;
            var  hashCode     = prefab.GetLightMapHashCode();

            if (prefabToLightmap.TryGetValue(hashCode, out LightMapPrefabStorage storage))
            {
                if (storage.referenceCount <= 0)
                {
                    storage.referenceCount = 0;
                    fullyCleaned           = true;
                    RemoveEmpty(prefab, storage);
                    prefabToLightmap.Remove(hashCode);
                }
            }
            return(fullyCleaned);
        }
        public static void AddInstanceRef(PrefabBaker prefab)
        {
            var hashCode = prefab.GetLightMapHashCode();

            if (!prefabToLightmap.TryGetValue(hashCode, out _))
            {
                if (!prefab.BakeApplied)
                {
                    int max = Mathf.Max(prefab.texturesColor.Length, prefab.texturesDir.Length);
                    max = Mathf.Max(max, prefab.texturesShadow.Length);
                    for (int i = 0; i < max; i++)
                    {
                        var newLightmapData = new LightmapData
                        {
                            lightmapColor = GetElement(prefab.texturesColor, i),
                            lightmapDir   = GetElement(prefab.texturesDir, i),
                            shadowMask    = GetElement(prefab.texturesShadow, i)
                        };
                        JoinOn(prefab, newLightmapData);
                    }
                }
            }
            prefabToLightmap[hashCode].referenceCount++;
        }