Пример #1
0
        public IEnumerator CreateSurfaceAssetWithPhysicMaterial_ChangePhysicMaterial_ManagerOnlyKnowsNewMaterial()
        {
            using (var newSurface = new CSGSurfaceAsset())
            {
                var newPhysicsMaterial1 = new PhysicMaterial();
                var newPhysicsMaterial2 = new PhysicMaterial();

                newSurface.PhysicsMaterial = newPhysicsMaterial1;
                yield return(null);

                var foundPhysicsMaterial = CSGSurfaceAssetManager.GetPhysicsMaterialByInstanceID(newPhysicsMaterial2.GetInstanceID(), false);

                Assert.AreNotEqual(newPhysicsMaterial1, newPhysicsMaterial2);
                Assert.AreEqual(newPhysicsMaterial1, CSGSurfaceAssetManager.GetPhysicsMaterialByInstanceID(newPhysicsMaterial1.GetInstanceID(), false));
                Assert.AreEqual(1, CSGSurfaceAssetManager.GetPhysicsMaterialRefCountByInstanceID(newPhysicsMaterial1.GetInstanceID()));
                LogAssert.Expect(LogType.Error, new Regex("Could not find"));
                Assert.IsNull(foundPhysicsMaterial);
                newSurface.PhysicsMaterial = newPhysicsMaterial2;
                yield return(null);

                CSGSurfaceAssetManager.Update();

                LogAssert.Expect(LogType.Error, new Regex("Could not find"));
                Assert.IsNull(CSGSurfaceAssetManager.GetPhysicsMaterialByInstanceID(newPhysicsMaterial1.GetInstanceID(), false));
                Assert.AreEqual(newPhysicsMaterial2, CSGSurfaceAssetManager.GetPhysicsMaterialByInstanceID(newPhysicsMaterial2.GetInstanceID(), false));
                Assert.AreEqual(1, CSGSurfaceAssetManager.GetPhysicsMaterialRefCountByInstanceID(newPhysicsMaterial2.GetInstanceID()));

                UnityEngine.Object.DestroyImmediate(newPhysicsMaterial1);
                UnityEngine.Object.DestroyImmediate(newPhysicsMaterial2);
            }
        }
Пример #2
0
    public override Hashtable EditorDragDrop(object o)
    {
        if (typeof(PhysicMaterial).IsAssignableFrom(o.GetType()))
        {
            PhysicMaterial ac = (PhysicMaterial)o;

            string path = UnityEditor.AssetDatabase.GetAssetPath(ac.GetInstanceID( ));

            int index = path.IndexOf("Resources/");

            if (index > 0)
            {
                path = path.Substring(index + "Resources/".Length);

                int dot = path.LastIndexOf('.');
                if (dot >= 0)
                {
                    path = path.Substring(0, dot);
                }

                Hashtable hashtable = new Hashtable( );
                hashtable["name"] = path;

                return(hashtable);
            }
        }

        return(null);
    }
Пример #3
0
 public bool IsValid()
 {
     if ((!PhysicsMaterial || PhysicsMaterial.GetInstanceID() != 0) &&
         (!RenderMaterial || RenderMaterial.GetInstanceID() != 0))
     {
         if (SharedMesh)
         {
             if (SharedMesh.vertexCount < 0)
             {
                 return(false);
             }
         }
         else
         if (SharedMesh.GetInstanceID() != 0)
         {
             return(false);
         }
         return(true);
     }
     return(false);
 }
Пример #4
0
        public static MeshInstanceKey GenerateKey(RenderSurfaceType renderSurfaceType, Material renderMaterial, PhysicMaterial physicsMaterial)
        {
            var realRenderMaterial = renderMaterial;

            if (renderSurfaceType != RenderSurfaceType.Normal)
            {
                realRenderMaterial = null;
            }

            return(new MeshInstanceKey(renderSurfaceType, (!realRenderMaterial) ? 1 : realRenderMaterial.GetInstanceID(),
                                       (!physicsMaterial) ? 1 : physicsMaterial.GetInstanceID()));
        }
        internal int GetID(PhysicMaterial physicMaterial)
        {
            if (!physicMaterial)
            {
                return(0);
            }
            var instanceID = physicMaterial.GetInstanceID();

            if (physicMaterialToID.TryGetValue(instanceID, out var id))
            {
                return(id);
            }
            id = ToID(physicMaterial);
            physicMaterialToID[instanceID] = id;
            idToPhysicMaterial[id]         = physicMaterial;
            return(id);
        }
        static PhysicsMaterialInstance IncRefCount(PhysicMaterial physicsMaterial)
        {
            if (physicsMaterial == null)
            {
                return(null);
            }
            var instanceID = physicsMaterial.GetInstanceID();

            if (!instanceIdToPhysicsMaterialLookup.TryGetValue(instanceID, out var instance))
            {
                instance = new PhysicsMaterialInstance(physicsMaterial);
                instanceIdToPhysicsMaterialLookup[instanceID] = instance;
                unknownPhysicsMaterialInstanceIDs.Remove(instanceID);
            }
            instance.refCount++;
            return(instance);
        }
Пример #7
0
        public IEnumerator CreateSurfaceAssetWithPhysicMaterial_DestroySurface_ManagerDoesNotKnowMaterial()
        {
            using (var newSurface = new CSGSurfaceAsset())
            {
                var newPhysicsMaterial = new PhysicMaterial();

                newSurface.PhysicsMaterial = newPhysicsMaterial;
                newSurface.Dispose();
                yield return(null);

                CSGSurfaceAssetManager.Update();

                LogAssert.Expect(LogType.Error, new Regex("Could not find"));
                Assert.IsNull(CSGSurfaceAssetManager.GetPhysicsMaterialByInstanceID(newPhysicsMaterial.GetInstanceID(), false));

                UnityEngine.Object.DestroyImmediate(newPhysicsMaterial);
            }
        }
Пример #8
0
        public IEnumerator CreateSurfaceAssetWithPhysicMateriall_RetrieveRenderMaterialWithPhysicsMaterialInstanceID_ReturnsNull()
        {
            using (var newSurface = new CSGSurfaceAsset())
            {
                var newPhysicsMaterial = new PhysicMaterial();

                newSurface.PhysicsMaterial = newPhysicsMaterial;
                yield return(null);

                CSGSurfaceAssetManager.Update();

                Assert.True(CSGSurfaceAssetManager.IsRegistered(newSurface));
                LogAssert.Expect(LogType.Error, new Regex("Trying to use PhysicMaterial with"));
                Assert.IsNull(CSGSurfaceAssetManager.GetRenderMaterialByInstanceID(newPhysicsMaterial.GetInstanceID(), false));

                UnityEngine.Object.DestroyImmediate(newPhysicsMaterial);
            }
        }
        static void DecRefCount(PhysicMaterial physicsMaterial)
        {
            if (!physicsMaterial)
            {
                return;
            }
            var instanceID = physicsMaterial.GetInstanceID();
            PhysicsMaterialInstance instance;

            if (!physicsMaterialLookup.TryGetValue(instanceID, out instance))
            {
                return;
            }
            instance.refCount--;
            if (instance.refCount <= 0)
            {
                removePhysicsMaterials.Add(instanceID);
            }
        }
Пример #10
0
        public IEnumerator CreateTwoBrushMaterialsWithSamePhysicsMaterial_DestroyOneBrushMaterial_ManagerKnowsMaterial()
        {
            using (ChiselBrushMaterial newBrushMaterial1 = new ChiselBrushMaterial(), newBrushMaterial2 = new ChiselBrushMaterial())
            {
                var newPhysicsMaterial = new PhysicMaterial();

                newBrushMaterial1.PhysicsMaterial = newPhysicsMaterial;
                newBrushMaterial2.PhysicsMaterial = newPhysicsMaterial;
                newBrushMaterial1.Dispose();
                yield return(null);

                ChiselBrushMaterialManager.Update();

                Assert.AreEqual(newPhysicsMaterial, ChiselBrushMaterialManager.GetPhysicsMaterialByInstanceID(newPhysicsMaterial.GetInstanceID(), false));
                Assert.AreEqual(1, ChiselBrushMaterialManager.GetPhysicsMaterialRefCountByInstanceID(newPhysicsMaterial.GetInstanceID()));

                UnityEngine.Object.DestroyImmediate(newPhysicsMaterial);
            }
        }
Пример #11
0
        public IEnumerator CreateSurfaceAssetWithPhysicMaterial_ManagerKnowsMaterial()
        {
            using (var newSurface = new CSGSurfaceAsset())
            {
                var newPhysicsMaterial = new PhysicMaterial();

                newSurface.PhysicsMaterial = newPhysicsMaterial;
                yield return(null);

                CSGSurfaceAssetManager.Update();

                Assert.True(CSGSurfaceAssetManager.IsRegistered(newSurface));
                Assert.AreEqual(newPhysicsMaterial, CSGSurfaceAssetManager.GetPhysicsMaterialByInstanceID(newPhysicsMaterial.GetInstanceID(), false));
                Assert.AreEqual(1, CSGSurfaceAssetManager.GetPhysicsMaterialRefCountByInstanceID(newPhysicsMaterial.GetInstanceID()));

                UnityEngine.Object.DestroyImmediate(newPhysicsMaterial);
            }
        }
Пример #12
0
        public IEnumerator CreateTwoSurfaceAssetsWithSamePhysicsMaterial_DestroyOneSurface_ManagerKnowsMaterial()
        {
            using (CSGSurfaceAsset newSurface1 = new CSGSurfaceAsset(), newSurface2 = new CSGSurfaceAsset())
            {
                var newPhysicsMaterial = new PhysicMaterial();

                newSurface1.PhysicsMaterial = newPhysicsMaterial;
                newSurface2.PhysicsMaterial = newPhysicsMaterial;
                newSurface1.Dispose();
                yield return(null);

                CSGSurfaceAssetManager.Update();

                Assert.AreEqual(newPhysicsMaterial, CSGSurfaceAssetManager.GetPhysicsMaterialByInstanceID(newPhysicsMaterial.GetInstanceID(), false));
                Assert.AreEqual(1, CSGSurfaceAssetManager.GetPhysicsMaterialRefCountByInstanceID(newPhysicsMaterial.GetInstanceID()));

                UnityEngine.Object.DestroyImmediate(newPhysicsMaterial);
            }
        }
Пример #13
0
        public IEnumerator RemoveAndAddPhysicsMaterialToAnotherSurface_MaterialStillRegistered()
        {
            using (CSGSurfaceAsset newSurface1 = new CSGSurfaceAsset(), newSurface2 = new CSGSurfaceAsset())
            {
                var newPhysicsMaterial1 = new PhysicMaterial();
                var newPhysicsMaterial2 = new PhysicMaterial();

                newSurface1.PhysicsMaterial = newPhysicsMaterial1;
                newSurface2.PhysicsMaterial = newPhysicsMaterial2;
                yield return(null);

                CSGSurfaceAssetManager.Update();

                Assert.AreEqual(newPhysicsMaterial1, CSGSurfaceAssetManager.GetPhysicsMaterialByInstanceID(newPhysicsMaterial1.GetInstanceID(), false));
                Assert.AreEqual(newPhysicsMaterial2, CSGSurfaceAssetManager.GetPhysicsMaterialByInstanceID(newPhysicsMaterial2.GetInstanceID(), false));
                Assert.AreEqual(1, CSGSurfaceAssetManager.GetPhysicsMaterialRefCountByInstanceID(newPhysicsMaterial1.GetInstanceID()));
                Assert.AreEqual(1, CSGSurfaceAssetManager.GetPhysicsMaterialRefCountByInstanceID(newPhysicsMaterial2.GetInstanceID()));
                newSurface1.PhysicsMaterial = newPhysicsMaterial2;
                newSurface2.PhysicsMaterial = newPhysicsMaterial1;
                yield return(null);

                CSGSurfaceAssetManager.Update();

                Assert.AreEqual(newPhysicsMaterial1, CSGSurfaceAssetManager.GetPhysicsMaterialByInstanceID(newPhysicsMaterial1.GetInstanceID(), false));
                Assert.AreEqual(newPhysicsMaterial2, CSGSurfaceAssetManager.GetPhysicsMaterialByInstanceID(newPhysicsMaterial2.GetInstanceID(), false));
                Assert.AreEqual(1, CSGSurfaceAssetManager.GetPhysicsMaterialRefCountByInstanceID(newPhysicsMaterial1.GetInstanceID()));
                Assert.AreEqual(1, CSGSurfaceAssetManager.GetPhysicsMaterialRefCountByInstanceID(newPhysicsMaterial2.GetInstanceID()));

                UnityEngine.Object.DestroyImmediate(newPhysicsMaterial1);
                UnityEngine.Object.DestroyImmediate(newPhysicsMaterial2);
            }
        }
Пример #14
0
        public IEnumerator CreateTwoBrushMaterialsWithSamePhysicsMaterial_DestroyBothBrushMaterials_ManagerDoesNotKnowMaterial()
        {
            using (ChiselBrushMaterial newBrushMaterial1 = new ChiselBrushMaterial(), newBrushMaterial2 = new ChiselBrushMaterial())
            {
                var newPhysicsMaterial = new PhysicMaterial();

                newBrushMaterial1.PhysicsMaterial = newPhysicsMaterial;
                newBrushMaterial2.PhysicsMaterial = newPhysicsMaterial;
                newBrushMaterial1.Dispose();
                newBrushMaterial2.Dispose();
                yield return(null);

                ChiselBrushMaterialManager.Update();

                LogAssert.Expect(LogType.Error, new Regex("Could not find"));
                Assert.IsNull(ChiselBrushMaterialManager.GetPhysicsMaterialByInstanceID(newPhysicsMaterial.GetInstanceID(), false));

                UnityEngine.Object.DestroyImmediate(newPhysicsMaterial);
            }
        }
Пример #15
0
        public IEnumerator CreateBrushMaterialWithPhysicMaterial_ManagerKnowsMaterial()
        {
            using (var newBrushMaterial = ChiselBrushMaterial.CreateInstance())
            {
                var newPhysicsMaterial = new PhysicMaterial();

                newBrushMaterial.PhysicsMaterial = newPhysicsMaterial;
                yield return(null);

                ChiselBrushMaterialManager.Update();

                Assert.True(ChiselBrushMaterialManager.IsRegistered(newBrushMaterial));
                Assert.AreEqual(newPhysicsMaterial, ChiselBrushMaterialManager.GetPhysicsMaterialByInstanceID(newPhysicsMaterial.GetInstanceID(), false));
                Assert.AreEqual(1, ChiselBrushMaterialManager.GetPhysicsMaterialRefCountByInstanceID(newPhysicsMaterial.GetInstanceID()));

                UnityEngine.Object.DestroyImmediate(newPhysicsMaterial);
            }
        }
Пример #16
0
        public IEnumerator RemoveAndAddPhysicsMaterialToAnotherBrushMaterial_MaterialStillRegistered()
        {
            using (ChiselBrushMaterial newBrushMaterial1 = ChiselBrushMaterial.CreateInstance(), newBrushMaterial2 = ChiselBrushMaterial.CreateInstance())
            {
                var newPhysicsMaterial1 = new PhysicMaterial();
                var newPhysicsMaterial2 = new PhysicMaterial();

                newBrushMaterial1.PhysicsMaterial = newPhysicsMaterial1;
                newBrushMaterial2.PhysicsMaterial = newPhysicsMaterial2;
                yield return(null);

                ChiselBrushMaterialManager.Update();

                Assert.AreEqual(newPhysicsMaterial1, ChiselBrushMaterialManager.GetPhysicsMaterialByInstanceID(newPhysicsMaterial1.GetInstanceID(), false));
                Assert.AreEqual(newPhysicsMaterial2, ChiselBrushMaterialManager.GetPhysicsMaterialByInstanceID(newPhysicsMaterial2.GetInstanceID(), false));
                Assert.AreEqual(1, ChiselBrushMaterialManager.GetPhysicsMaterialRefCountByInstanceID(newPhysicsMaterial1.GetInstanceID()));
                Assert.AreEqual(1, ChiselBrushMaterialManager.GetPhysicsMaterialRefCountByInstanceID(newPhysicsMaterial2.GetInstanceID()));
                newBrushMaterial1.PhysicsMaterial = newPhysicsMaterial2;
                newBrushMaterial2.PhysicsMaterial = newPhysicsMaterial1;
                yield return(null);

                ChiselBrushMaterialManager.Update();

                Assert.AreEqual(newPhysicsMaterial1, ChiselBrushMaterialManager.GetPhysicsMaterialByInstanceID(newPhysicsMaterial1.GetInstanceID(), false));
                Assert.AreEqual(newPhysicsMaterial2, ChiselBrushMaterialManager.GetPhysicsMaterialByInstanceID(newPhysicsMaterial2.GetInstanceID(), false));
                Assert.AreEqual(1, ChiselBrushMaterialManager.GetPhysicsMaterialRefCountByInstanceID(newPhysicsMaterial1.GetInstanceID()));
                Assert.AreEqual(1, ChiselBrushMaterialManager.GetPhysicsMaterialRefCountByInstanceID(newPhysicsMaterial2.GetInstanceID()));

                UnityEngine.Object.DestroyImmediate(newPhysicsMaterial1);
                UnityEngine.Object.DestroyImmediate(newPhysicsMaterial2);
            }
        }
 public WXPhysicsMaterial(PhysicMaterial mat)
 {
     this.material = mat;
     this.path     = wxFileUtil.cleanIllegalChar(AssetDatabase.GetAssetPath(mat.GetInstanceID()), false);
     _fileName     = this.path.Split('.')[0];
 }