示例#1
0
    static void ProcessPrimitive(
        List <ReducerTask> reducerTasks,
        MeshCache meshCache,
        SAMeshColliderBuilder meshColliderBuilder,
        GameObject parentGameObject,
        SplitMesh parentSplitMesh)
    {
        if (reducerTasks == null || meshCache == null || meshColliderBuilder == null || parentGameObject == null || parentSplitMesh == null)
        {
            Debug.LogError("");
            return;
        }

        SplitMesh[] resplitMeshes = SAMeshColliderEditorCommon.MakeSplitMeshesByPrimitive(meshCache, parentSplitMesh);
        if (resplitMeshes == null || resplitMeshes.Length == 0)
        {
            return;
        }

        SAMeshCollider[] existingMeshColliders = SAMeshColliderEditorCommon.GetChildSAMeshColliders(parentGameObject);

        for (int i = 0; i < resplitMeshes.Length; ++i)
        {
            SplitMesh      resplitMesh          = resplitMeshes[i];
            SAMeshCollider existingMeshCollider = SAMeshColliderEditorCommon.FindSAMeshCollider(existingMeshColliders, resplitMesh);
            if (existingMeshCollider != null && existingMeshCollider.modified)
            {
                continue;                 // Not overwrite modified SAMeshCollider.
            }

            string         resplitMeshColliderName = SAMeshColliderEditorCommon.GetSAMeshColliderName_Primitive(i);
            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.Primitive);
            }

            if (resplitMeshCollider.splitPolygonNormalEnabled)
            {
                SAMeshColliderEditorCommon.MakeSplitMeshTriangles(meshCache, resplitMesh);
                ProcessPolygon(reducerTasks, meshCache, meshColliderBuilder, resplitMeshCollider.gameObject, resplitMeshCollider.splitMesh);
            }
            else
            {
                SAMeshColliderEditorCommon.MakeSplitMeshTriangles(meshCache, resplitMesh);
                SAMeshColliderEditorCommon.RegistReducerTask(reducerTasks, resplitMeshCollider);
            }
        }
    }