コード例 #1
0
 // called on children getting merged by their parent
 void OnGettingMerged()
 {
     Object.Destroy(obj.mf.mesh);
     SplitManager.ReturnObject(obj);
     if (col != null)
     {
         SplitManager.ReturnCollider(col);
         col = null;
     }
     dead = true;
 }
コード例 #2
0
    public void Update()
    {
        if (hasChildren)
        {
            if (ShouldMerge())
            {
                Merge();
            }
            else
            {
                for (int i = 0; i < 8; i++)
                {
                    children[i].Update();
                }
            }
        }
        else if (!splitting && ShouldSplit())
        {
            //SplitManager.AddToSplitList(this);
            SplitCompute();
        }
        else if (splitting && childMeshCount >= 8)
        {
            SplitResolveCompute();
        }
        else
        {
            // if at max depth, have valid mesh, and close to cam then should have a collider
            if (depth == MAX_DEPTH && !emptyMesh && obj.mf.sharedMesh && GetSqrDistToCamFromCenter() < colliderGenDistance * colliderGenDistance)
            {
                if (col == null)       // if collider is null then spawn one
                {
                    col = SplitManager.GetCollider();
                    col.go.transform.SetParent(obj.go.transform, false);
                    col.go.transform.localPosition = Vector3.zero;
                    col.go.transform.localRotation = Quaternion.identity;
                    col.mc.sharedMesh = obj.mf.sharedMesh;
                }
            }
            else if (col != null)       // otherwise if have collider then return it
            {
                SplitManager.ReturnCollider(col);
                col = null;
            }
        }

        SetGeomorph();
    }