Exemple #1
0
    static void Process(SABoneCollider boneCollider)
    {
        if (boneCollider == null || boneCollider.colliderProperty == null)
        {
            Debug.LogError("");
            return;
        }

        GameObject rootGameObject = SABoneColliderEditorCommon.GetSABoneColliderRootGameObject(boneCollider);

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

        string collidersPath = null;

        if (boneCollider.colliderProperty.isCreateAsset)
        {
            collidersPath = SABoneColliderEditorCommon.GetCollidersPath(rootGameObject);

            if (string.IsNullOrEmpty(collidersPath))
            {
                Debug.LogWarning("Not found collidersPath. Can't create asset.");
            }
        }

        HashSet <Transform> boneHashSet = SABoneColliderEditorCommon.GetBoneHashSet(rootGameObject);

        BoneMeshCache boneMeshCache = new BoneMeshCache();

        boneMeshCache.Process(rootGameObject);

        List <ReducerTask> reducerTasks = new List <ReducerTask>();

        SABoneColliderEditorCommon.CleanupSABoneCollider(boneCollider);
        SABoneColliderEditorCommon.RegistReducerTask(reducerTasks, boneCollider, boneMeshCache);

        SABoneColliderEditorCommon.MarkManualProcessingToParent(boneCollider);

        if (boneCollider.recursivery)
        {
            foreach (Transform childTransform in boneCollider.gameObject.transform)
            {
                if (SAColliderBuilderEditorCommon.IsRootTransform(childTransform))
                {
                    // Nothing.
                }
                else
                {
                    _ProcessTransform(childTransform, reducerTasks, boneCollider, boneHashSet, boneMeshCache);
                }
            }
        }

        SABoneColliderEditorCommon.Reduce(reducerTasks, collidersPath, boneCollider.isDebug);
    }
    static void _ProcessTransform(
        Transform transform,
        List <ReducerTask> reducerTasks,
        SABoneColliderBuilder boneColliderBuilder,
        HashSet <Transform> boneHashSet,
        SABoneColliderEditorCommon.BoneMeshCache boneMeshCache)
    {
        if (transform == null || reducerTasks == null || boneColliderBuilder == null ||
            boneHashSet == null || boneMeshCache == null)
        {
            return;
        }

        if (boneHashSet.Contains(transform))
        {
            SABoneCollider boneCollider = transform.gameObject.GetComponent <SABoneCollider>();

            if (boneCollider != null)
            {
                if (boneColliderBuilder.cleanupModified || !boneCollider.modified)
                {
                    SABoneColliderEditorCommon.DestroySABoneCollider(boneCollider);
                    boneCollider = null;
                }

                if (boneCollider != null && boneCollider.recursivery)
                {
                    return;                     // Skip modified children.
                }
            }

            if (boneCollider == null)                 // Don't overwrite modified.
            {
                boneCollider = SABoneColliderEditorCommon.CreateSABoneCollider(transform.gameObject, boneColliderBuilder);
                SABoneColliderEditorCommon.RegistReducerTask(reducerTasks, boneCollider, boneMeshCache);
            }
        }

        foreach (Transform childTransform in transform)
        {
            if (SAColliderBuilderEditorCommon.IsRootTransform(childTransform))
            {
                // Nothing.
            }
            else
            {
                _ProcessTransform(childTransform, reducerTasks, boneColliderBuilder, boneHashSet, boneMeshCache);
            }
        }
    }