Esempio n. 1
0
    static void ProcessPolygon(
        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;
        }

        if (!meshColliderBuilder.splitPolygonNormalEnabled)
        {
            return;
        }

        SplitMesh[] resplitMeshes = SAMeshColliderEditorCommon.MakeSplitMeshesByPolygon(meshCache, parentSplitMesh, meshColliderBuilder.splitPolygonNormalAngle);
        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_Polygon(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.Polygon);
            }

            SAMeshColliderEditorCommon.SalvageMeshByPolygon(resplitMesh);
            SAMeshColliderEditorCommon.RegistReducerTask(reducerTasks, resplitMeshCollider);
        }
    }
    static void SplitPolygon(List <ReducerTask> reducerTasks, MeshCache meshCache, SAMeshCollider parentMeshCollider, SAMeshCollider rootMeshCollider)
    {
        if (reducerTasks == null || meshCache == null || parentMeshCollider == null || rootMeshCollider == null)
        {
            Debug.LogError("");
            return;
        }

        SplitMesh parentSplitMesh = parentMeshCollider.splitMesh;

        if (parentSplitMesh == null)
        {
            Debug.LogError("");
            return;
        }

        SAMeshColliderEditorCommon.CleanupSelfSAMeshCollider(parentMeshCollider);

        SAMeshCollider[] existingMeshColliders = SAMeshColliderEditorCommon.GetChildSAMeshColliders(parentMeshCollider.gameObject);

        SplitMesh[] resplitMeshes = SAMeshColliderEditorCommon.MakeSplitMeshesByPolygon(meshCache, parentSplitMesh, rootMeshCollider.splitPolygonNormalAngle);

        if (resplitMeshes == null || resplitMeshes.Length == 0)
        {
            return;
        }

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

            string         resplitMeshColliderName = SAMeshColliderEditorCommon.GetSAMeshColliderName_Polygon(i);
            SAMeshCollider resplitMeshCollider     = null;
            if (existingMeshCollider != null)
            {
                resplitMeshCollider = existingMeshCollider;
                SAMeshColliderEditorCommon.SetupSAMeshCollider(
                    parentMeshCollider,
                    resplitMeshCollider,
                    resplitMeshColliderName);
                resplitMesh = resplitMeshCollider.splitMesh;
            }
            else
            {
                resplitMeshCollider = SAMeshColliderEditorCommon.CreateSAMeshCollider(
                    parentMeshCollider,
                    resplitMeshColliderName,
                    resplitMesh,
                    SplitMode.Polygon);
            }

            SAMeshColliderEditorCommon.SalvageMeshByPolygon(resplitMesh);
            SAMeshColliderEditorCommon.RegistReducerTask(reducerTasks, resplitMeshCollider);
        }
    }