Exemple #1
0
 private void OnDestroy()
 {
     if (_instance == this)
     {
         _instance = null;
     }
 }
Exemple #2
0
        protected AsyncFractureResult Fracture(FractureDetails details, bool hideAfterFracture)
        {
            if (NumGenerations == 0 || _processingFracture)
            {
                return(null);
            }

            if (FractureTemplate == null || FractureTemplate.GetComponent <MeshFilter>() == null)
            {
                Debug.LogError("DinoFracture: A fracture template with a MeshFilter component is required.");
            }

            _processingFracture = true;

            if (details.Mesh == null)
            {
                MeshFilter          meshFilter      = GetComponent <MeshFilter>();
                SkinnedMeshRenderer skinnedRenderer = GetComponent <SkinnedMeshRenderer>();

                if (meshFilter == null && skinnedRenderer == null)
                {
                    Debug.LogError("DinoFracture: A mesh filter required if a mesh is not supplied.");
                    return(null);
                }

                Mesh mesh;
                if (meshFilter != null)
                {
                    mesh = meshFilter.sharedMesh;
                }
                else
                {
                    mesh = new Mesh();
                    skinnedRenderer.BakeMesh(mesh);
                }

                details.Mesh = mesh;
            }

            if (details.MeshScale == Vector3.zero)
            {
                details.MeshScale = transform.localScale;
            }

            // Unassigned transforms aren't actually assigned to null by Unity, so we need check for it here.
            Transform piecesParent = (PiecesParent == null) ? null : PiecesParent;

            return(FractureEngine.StartFracture(details, this, piecesParent, DistributeMass, hideAfterFracture));
        }