void HandleDuplication()
        {
#if UNITY_EDITOR
            {
                var currentInstanceID = this.GetInstanceID();
                if (instanceID == 0)
                {
                    instanceID = currentInstanceID; genGuidHashCode = Guid.NewGuid().GetHashCode();
                }
                else if (instanceID != currentInstanceID)
                {
                    var prevObject = UnityEditor.EditorUtility.InstanceIDToObject(instanceID) as ChiselGeneratorComponent;
                    // if our stored instanceID is the same as an existing generator and has the same guid,
                    // we can assume we've been duplicated
                    if (prevObject && prevObject.genGuidHashCode == genGuidHashCode)
                    {
                        if (prevObject.brushContainerAsset == brushContainerAsset)
                        {
                            brushContainerAsset = Instantiate(brushContainerAsset);
                        }
                        genGuidHashCode = Guid.NewGuid().GetHashCode();
                    }
                    instanceID = currentInstanceID;
                }
            }
#endif
        }
 public static void RegisterAllSurfaces(ChiselBrushContainerAsset brushContainerAsset)
 {
     if (!brushContainerAsset || brushContainerAsset.SubMeshCount == 0)
     {
         return;
     }
     foreach (var brushMesh in brushContainerAsset.BrushMeshes)
     {
         if (brushMesh.polygons == null)
         {
             continue;
         }
         foreach (var polygon in brushMesh.polygons)
         {
             if (polygon.surface == null)
             {
                 continue;
             }
             if (polygon.surface.brushMaterial == null)
             {
                 polygon.surface.brushMaterial = ChiselBrushMaterial.CreateInstance();
                 if (polygon.surface.brushMaterial != null)
                 {
                     polygon.surface.brushMaterial.LayerUsage      = polygon.surface.brushMaterial.LayerUsage;
                     polygon.surface.brushMaterial.PhysicsMaterial = polygon.surface.brushMaterial.PhysicsMaterial;
                     polygon.surface.brushMaterial.RenderMaterial  = polygon.surface.brushMaterial.RenderMaterial;
                 }
             }
             ChiselBrushMaterialManager.Register(polygon.surface.brushMaterial);
         }
     }
 }
Beispiel #3
0
 public static bool IsDirty(ChiselBrushContainerAsset brushContainerAsset)
 {
     if (!brushContainerAsset)
     {
         return(false);
     }
     return(updateQueueLookup.Contains(brushContainerAsset));
 }
Beispiel #4
0
 public static bool IsRegistered(ChiselBrushContainerAsset brushContainerAsset)
 {
     if (!brushContainerAsset)
     {
         return(false);
     }
     return(registeredLookup.Contains(brushContainerAsset));
 }
 public SurfaceReference(ChiselNode node, ChiselBrushContainerAsset brushContainerAsset, int subNodeIndex, int subMeshIndex, int surfaceIndex, int surfaceID)
 {
     this.node = node;
     this.brushContainerAsset = brushContainerAsset;
     this.subNodeIndex        = subNodeIndex;
     this.subMeshIndex        = subMeshIndex;
     this.surfaceIndex        = surfaceIndex;
     this.surfaceID           = surfaceID;
 }
Beispiel #6
0
        public static void NotifyContentsModified(ChiselBrushContainerAsset brushContainerAsset)
        {
            if (!brushContainerAsset || !registeredLookup.Contains(brushContainerAsset))
            {
                return;
            }

            updateQueue.Add(brushContainerAsset);
        }
        public virtual void UpdateGenerator()
        {
            // BrushMeshes of generators must always be unique
            if (!brushContainerAsset ||
                !ChiselBrushContainerAssetManager.IsBrushMeshUnique(brushContainerAsset))
            {
                brushContainerAsset = ChiselBrushContainerAsset.Create("Generated " + NodeTypeName);
            }

            UpdateGeneratorInternal();

            UpdateBrushMeshInstances();
        }
Beispiel #8
0
        public static bool IsBrushMeshUnique(ChiselBrushContainerAsset currentBrushMesh)
        {
#if UNITY_EDITOR
            var path = UnityEditor.AssetDatabase.GetAssetPath(currentBrushMesh.GetInstanceID());
            if (!string.IsNullOrEmpty(path))
            {
                return(false);
            }
#endif
            // TODO: implement

            return(true);
        }
Beispiel #9
0
        public static bool SetDirty(ChiselBrushContainerAsset brushContainerAsset)
        {
            if (!registeredLookup.Contains(brushContainerAsset) ||
                unregisterQueueLookup.Contains(brushContainerAsset))
            {
                return(false);
            }

            if (updateQueueLookup.Add(brushContainerAsset))
            {
                updateQueue.Add(brushContainerAsset);
            }
            return(true);
        }
        public virtual void UpdateGenerator()
        {
            // BrushMeshes of generators must always be unique
            if (!brushContainerAsset ||
                !ChiselBrushContainerAssetManager.IsBrushMeshUnique(brushContainerAsset))
            {
                brushContainerAsset      = UnityEngine.ScriptableObject.CreateInstance <ChiselBrushContainerAsset>();
                brushContainerAsset.name = "Generated " + NodeTypeName;
            }

            UpdateGeneratorInternal();

            UpdateBrushMeshInstances();
        }
Beispiel #11
0
        public static void Unregister(ChiselBrushContainerAsset brushContainerAsset)
        {
            if (!registeredLookup.Remove(brushContainerAsset))
            {
                return;
            }

            if (updateQueueLookup.Remove(brushContainerAsset))
            {
                updateQueue.Remove(brushContainerAsset);
            }
            if (unregisterQueueLookup.Add(brushContainerAsset))
            {
                unregisterQueue.Add(brushContainerAsset);
            }
        }
Beispiel #12
0
        // TODO: shouldn't be public
        public static void UpdateSurfaces(ChiselBrushContainerAsset brushContainerAsset)
        {
            var brushMeshes = brushContainerAsset.BrushMeshes;

            if (brushMeshes == null)
            {
                return;
            }

            for (int m = 0; m < brushMeshes.Length; m++)
            {
                ref var brushMesh = ref brushMeshes[m];
                if (brushMesh == null)
                {
                    continue;
                }
                UpdateSurfaces(ref brushMesh, brushContainerAsset);
            }
        //**Temporary hack to ensure that a BrushContainerAsset remains unique when duplicated so that we can control when we share a BrushContainerAsset**//
        #region HandleDuplication
        void HandleDuplication()
        {
#if UNITY_EDITOR
            {
                if (brushContainerAsset == null)
                {
                    return;
                }
                if (brushContainerAsset.owner == null)
                {
                    brushContainerAsset.owner = this;
                }
                else
                if (brushContainerAsset.owner != this)
                {
                    brushContainerAsset       = Instantiate(brushContainerAsset);
                    brushContainerAsset.owner = this;
                }
            }
#endif
        }
Beispiel #14
0
 public static void UnregisterAllSurfaces(ChiselBrushContainerAsset brushContainerAsset)
 {
     if (!brushContainerAsset || brushContainerAsset.SubMeshCount == 0)
     {
         return;
     }
     foreach (var brushMesh in brushContainerAsset.BrushMeshes)
     {
         if (brushMesh.polygons == null)
         {
             continue;
         }
         foreach (var polygon in brushMesh.polygons)
         {
             if (polygon.surface == null ||
                 polygon.surface.brushMaterial == null)
             {
                 continue;
             }
             ChiselBrushMaterialManager.Unregister(polygon.surface.brushMaterial);
         }
     }
 }
        public virtual void UpdateGenerator()
        {
            // BrushMeshes of generators must always be unique
            Profiler.BeginSample("ChiselBrushContainerAsset.Create");
            try
            {
                if (!brushContainerAsset ||
                    !ChiselBrushContainerAssetManager.IsBrushMeshUnique(brushContainerAsset))
                {
                    brushContainerAsset = ChiselBrushContainerAsset.Create("Generated " + NodeTypeName);
                }
            }
            finally { Profiler.EndSample(); }

            Profiler.BeginSample("UpdateGeneratorInternal");
            try { UpdateGeneratorInternal(); }
            finally { Profiler.EndSample(); }

            brushContainerAsset.SetDirty();

            Profiler.BeginSample("UpdateBrushMeshInstances");
            try { UpdateBrushMeshInstances(); }
            finally { Profiler.EndSample(); }
        }