Exemplo n.º 1
0
        public static CSGSurfaceAsset CreateInstance(LayerUsageFlags layerUsage = LayerUsageFlags.None)
        {
            var newSurface = new CSGSurfaceAsset();//ScriptableObject.CreateInstance<CSGSurfaceAsset>();

            //newSurface.name				= "Surface";
            newSurface.LayerUsage = layerUsage;
            return(newSurface);
        }
 public static bool IsRegistered(CSGSurfaceAsset surfaceAsset)
 {
     if (surfaceAsset == null)
     {
         return(false);
     }
     return(registeredLookup.Contains(surfaceAsset));
 }
Exemplo n.º 3
0
        public static CSGSurfaceAsset CreateInstance(PhysicMaterial physicsMaterial, LayerUsageFlags layerUsage = LayerUsageFlags.Collidable)
        {
            var newSurface = new CSGSurfaceAsset();//ScriptableObject.CreateInstance<CSGSurfaceAsset>();

            //newSurface.name				= "Surface";
            newSurface.LayerUsage      = layerUsage;
            newSurface.PhysicsMaterial = physicsMaterial;
            return(newSurface);
        }
Exemplo n.º 4
0
        public static CSGSurfaceAsset CreateInstance(Material renderMaterial, LayerUsageFlags layerUsage = LayerUsageFlags.RenderReceiveCastShadows)
        {
            var newSurface = new CSGSurfaceAsset();//ScriptableObject.CreateInstance<CSGSurfaceAsset>();

            //newSurface.name				= "Surface " + renderMaterial.name;
            newSurface.LayerUsage     = layerUsage;
            newSurface.RenderMaterial = renderMaterial;
            return(newSurface);
        }
Exemplo n.º 5
0
        public static CSGSurfaceAsset CreateInstance(CSGSurfaceAsset other)
        {
            var newSurface = new CSGSurfaceAsset();//ScriptableObject.CreateInstance<CSGSurfaceAsset>();

            //newSurface.name				= "Copy of " + other.name;
            newSurface.LayerUsage      = other.layerUsage;
            newSurface.RenderMaterial  = other.renderMaterial;
            newSurface.PhysicsMaterial = other.physicsMaterial;
            return(newSurface);
        }
        public static void OnLayerUsageFlagsChanged(CSGSurfaceAsset surfaceAsset, LayerUsageFlags prevValue, LayerUsageFlags value)
        {
            if (!registeredLookup.Contains(surfaceAsset) || (prevValue == value))
            {
                return;
            }

            if (OnSurfaceAssetChanged != null)
            {
                OnSurfaceAssetChanged(surfaceAsset);
            }
        }
        public static void OnPhysicsMaterialChanged(CSGSurfaceAsset surfaceAsset, PhysicMaterial prevValue, PhysicMaterial value)
        {
            if (!registeredLookup.Contains(surfaceAsset) || (prevValue == value))
            {
                return;
            }

            DecRefCount(prevValue);
            IncRefCount(value);

            if (OnSurfaceAssetChanged != null)
            {
                OnSurfaceAssetChanged(surfaceAsset);
            }
        }
        public static void Register(CSGSurfaceAsset surfaceAsset)
        {
            if (surfaceAsset == null || !registeredLookup.Add(surfaceAsset))
            {
                return;
            }

            surfaceRenderMaterialLookup [surfaceAsset] = IncRefCount(surfaceAsset.RenderMaterial);
            surfacePhysicsMaterialLookup[surfaceAsset] = IncRefCount(surfaceAsset.PhysicsMaterial);

            if (OnSurfaceAssetAdded != null)
            {
                OnSurfaceAssetAdded(surfaceAsset);
            }
        }
        public static void Unregister(CSGSurfaceAsset surfaceAsset)
        {
            if (!registeredLookup.Remove(surfaceAsset))
            {
                return;
            }

            surfaceRenderMaterialLookup.Remove(surfaceAsset);
            surfacePhysicsMaterialLookup.Remove(surfaceAsset);

            DecRefCount(surfaceAsset.RenderMaterial);
            DecRefCount(surfaceAsset.PhysicsMaterial);

            if (OnSurfaceAssetRemoved != null)
            {
                OnSurfaceAssetRemoved(surfaceAsset);
            }
        }
        public static void NotifyContentsModified(CSGSurfaceAsset surfaceAsset)
        {
            if (surfaceAsset == null || !registeredLookup.Contains(surfaceAsset))
            {
                return;
            }

            RenderMaterialInstance renderMaterialInstance;

            if (surfaceRenderMaterialLookup.TryGetValue(surfaceAsset, out renderMaterialInstance))
            {
                if ((renderMaterialInstance == null && surfaceAsset.RenderMaterial) ||
                    (renderMaterialInstance != null && renderMaterialInstance.renderMaterial != surfaceAsset.RenderMaterial))
                {
                    if (renderMaterialInstance != null)
                    {
                        DecRefCount(renderMaterialInstance.renderMaterial);
                    }
                    surfaceRenderMaterialLookup[surfaceAsset] = IncRefCount(surfaceAsset.RenderMaterial);
                }
            }
            PhysicsMaterialInstance physicsMaterialInstance;

            if (surfacePhysicsMaterialLookup.TryGetValue(surfaceAsset, out physicsMaterialInstance))
            {
                if ((physicsMaterialInstance == null && surfaceAsset.PhysicsMaterial) ||
                    (physicsMaterialInstance != null && physicsMaterialInstance.physicsMaterial != surfaceAsset.PhysicsMaterial))
                {
                    if (physicsMaterialInstance != null)
                    {
                        DecRefCount(physicsMaterialInstance.physicsMaterial);
                    }
                    surfacePhysicsMaterialLookup[surfaceAsset] = IncRefCount(surfaceAsset.PhysicsMaterial);
                }
            }

            if (OnSurfaceAssetChanged != null)
            {
                OnSurfaceAssetChanged(surfaceAsset);
            }
        }
        static void OnSurfaceAssetRemoved(CSGSurfaceAsset surfaceAsset)
        {
            HashSet <CSGBrushMeshAsset> brushMeshAssets;

            if (surfaceBrushMeshes.TryGetValue(surfaceAsset, out brushMeshAssets))
            {
                foreach (var brushMeshAsset in brushMeshAssets)
                {
                    HashSet <CSGSurfaceAsset> uniqueSurfaces;
                    if (brushMeshSurfaces.TryGetValue(brushMeshAsset, out uniqueSurfaces))
                    {
                        uniqueSurfaces.Remove(surfaceAsset);
                        if (brushMeshAsset)
                        {
                            updateQueue.Add(brushMeshAsset);
                        }
                    }
                }
            }
            surfaceBrushMeshes.Remove(surfaceAsset);
        }
        static void OnSurfaceAssetChanged(CSGSurfaceAsset surfaceAsset)
        {
            if (surfaceAsset == null)
            {
                return;
            }

            HashSet <CSGBrushMeshAsset> brushMeshAssets;

            if (!surfaceBrushMeshes.TryGetValue(surfaceAsset, out brushMeshAssets))
            {
                return;
            }

            foreach (var brushMeshAsset in brushMeshAssets)
            {
                if (brushMeshAsset)
                {
                    updateQueue.Add(brushMeshAsset);
                }
            }
        }