Exemplo n.º 1
0
    static void ProcessRoot(
        List <ReducerTask> reducerTasks,
        MeshCache meshCache,
        SAMeshColliderBuilder meshColliderBuilder,
        GameObject parentGameObject)
    {
        if (reducerTasks == null || meshCache == null || meshColliderBuilder == null || parentGameObject == null)
        {
            Debug.LogError("");
            return;
        }

        SplitMesh resplitMesh = SAMeshColliderEditorCommon.MakeRootSplitMesh(meshCache);

        if (resplitMesh == null)
        {
            return;
        }

        if (meshColliderBuilder.splitMaterialEnabled)
        {
            ProcessMaterial(reducerTasks, meshCache, meshColliderBuilder, parentGameObject);
        }
        else if (meshColliderBuilder.splitPrimitiveEnabled)
        {
            ProcessPrimitive(reducerTasks, meshCache, meshColliderBuilder, parentGameObject, resplitMesh);
        }
        else if (meshColliderBuilder.splitPolygonNormalEnabled)
        {
            SAMeshColliderEditorCommon.MakeSplitMeshTriangles(meshCache, resplitMesh);
            ProcessPolygon(reducerTasks, meshCache, meshColliderBuilder, parentGameObject, resplitMesh);
        }
        else
        {
            SAMeshCollider[] existingMeshColliders = SAMeshColliderEditorCommon.GetChildSAMeshColliders(parentGameObject);
            SAMeshCollider   existingMeshCollider  = SAMeshColliderEditorCommon.FindSAMeshCollider(existingMeshColliders, resplitMesh);
            if (existingMeshCollider != null && existingMeshCollider.modified)
            {
                return;                 // Not overwrite modified SAMeshCollider.
            }

            string         resplitMeshColliderName = SAMeshColliderEditorCommon.GetSAMeshColliderName_Root(parentGameObject);
            SAMeshCollider resplitMeshCollider     = null;
            if (existingMeshCollider != null)
            {
                resplitMeshCollider = existingMeshCollider;
                SAMeshColliderEditorCommon.SetupSAMeshCollider(
                    meshColliderBuilder,
                    resplitMeshCollider,
                    resplitMeshColliderName);
                resplitMesh = resplitMeshCollider.splitMesh;
            }
            else
            {
                resplitMeshCollider = SAMeshColliderEditorCommon.CreateSAMeshCollider(
                    meshColliderBuilder,
                    parentGameObject,
                    resplitMeshColliderName,
                    resplitMesh,
                    SplitMode.None);
            }

            SAMeshColliderEditorCommon.MakeSplitMeshTriangles(meshCache, resplitMesh);
            SAMeshColliderEditorCommon.RegistReducerTask(reducerTasks, resplitMeshCollider);
        }
    }