Exemplo n.º 1
0
    static void Cleanup(SAMeshColliderBuilder meshColliderBuilder)
    {
        if (meshColliderBuilder == null)
        {
            Debug.LogError("");
            return;
        }

        MeshFilter[]          meshFilters          = SAColliderBuilderEditorCommon.GetMeshFilters(meshColliderBuilder.gameObject);
        SkinnedMeshRenderer[] skinnedMeshRenderers = SAColliderBuilderEditorCommon.GetSkinnedMeshRenderers(meshColliderBuilder.gameObject);

        if ((meshFilters == null || meshFilters.Length == 0) && (skinnedMeshRenderers == null || skinnedMeshRenderers.Length == 0))
        {
            Debug.LogError("Nothing MeshFilter/SkinnedMeshRenderer. Skip Cleanuping.");
            return;
        }

        if (meshFilters != null)
        {
            foreach (MeshFilter meshFilter in meshFilters)
            {
                SAMeshColliderEditorCommon.CleanupChildSAMeshColliders(meshFilter.gameObject, meshColliderBuilder.cleanupModified);
            }
        }

        if (skinnedMeshRenderers != null)
        {
            foreach (SkinnedMeshRenderer skinnedMeshRenderer in skinnedMeshRenderers)
            {
                SAMeshColliderEditorCommon.CleanupChildSAMeshColliders(skinnedMeshRenderer.gameObject, meshColliderBuilder.cleanupModified);
            }
        }
    }
Exemplo n.º 2
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);
            }
        }
    }
Exemplo n.º 4
0
    static void Process(SAMeshColliderBuilder meshColliderBuilder)
    {
        if (meshColliderBuilder == null)
        {
            Debug.LogError("");
            return;
        }

        MeshFilter[]          meshFilters          = SAColliderBuilderEditorCommon.GetMeshFilters(meshColliderBuilder.gameObject);
        SkinnedMeshRenderer[] skinnedMeshRenderers = SAColliderBuilderEditorCommon.GetSkinnedMeshRenderers(meshColliderBuilder.gameObject);

        if ((meshFilters == null || meshFilters.Length == 0) && (skinnedMeshRenderers == null || skinnedMeshRenderers.Length == 0))
        {
            Debug.LogError("Nothing MeshFilter/SkinnedMeshRenderer. Skip Processing.");
            return;
        }

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

        if (meshFilters != null)
        {
            foreach (MeshFilter meshFilter in meshFilters)
            {
                Mesh       mesh      = SAColliderBuilderEditorCommon.GetMesh(meshFilter);
                Material[] materials = SAColliderBuilderEditorCommon.GetMaterials(meshFilter);
                MeshCache  meshCahce = new MeshCache(mesh, materials);
                SAMeshColliderEditorCommon.CleanupChildSAMeshColliders(meshFilter.gameObject, meshColliderBuilder.cleanupModified);
                ProcessRoot(reducerTasks, meshCahce, meshColliderBuilder, meshFilter.gameObject);
            }
        }

        if (skinnedMeshRenderers != null)
        {
            foreach (SkinnedMeshRenderer skinnedMeshRenderer in skinnedMeshRenderers)
            {
                Mesh       mesh      = SAColliderBuilderEditorCommon.GetMesh(skinnedMeshRenderer);
                Material[] materials = SAColliderBuilderEditorCommon.GetMaterials(skinnedMeshRenderer);
                MeshCache  meshCahce = new MeshCache(mesh, materials);
                SAMeshColliderEditorCommon.CleanupChildSAMeshColliders(skinnedMeshRenderer.gameObject, meshColliderBuilder.cleanupModified);
                ProcessRoot(reducerTasks, meshCahce, meshColliderBuilder, skinnedMeshRenderer.gameObject);
            }
        }

        SAMeshColliderEditorCommon.Reduce(reducerTasks, meshColliderBuilder.isDebug);
    }
    static void _CleanupTransform(
        Transform transform,
        SABoneColliderBuilder boneColliderBuilder,
        HashSet <Transform> boneHashSet)
    {
        if (transform == null || boneColliderBuilder == null || boneHashSet == 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;
                }
            }
        }

        foreach (Transform childTransform in transform)
        {
            if (SAColliderBuilderEditorCommon.IsRootTransform(childTransform))
            {
                // Nothing.
            }
            else
            {
                _CleanupTransform(childTransform, boneColliderBuilder, boneHashSet);
            }
        }
    }
    static void Process(SABoneColliderBuilder boneColliderBuilder)
    {
        if (boneColliderBuilder == null || boneColliderBuilder.colliderProperty == null)
        {
            Debug.LogError("");
            return;
        }

        string collidersPath = null;

        if (boneColliderBuilder.colliderProperty.isCreateAsset)
        {
            collidersPath = SABoneColliderEditorCommon.GetCollidersPath(boneColliderBuilder.gameObject);

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

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

        SABoneColliderEditorCommon.BoneMeshCache boneMeshCache = new SABoneColliderEditorCommon.BoneMeshCache();
        boneMeshCache.Process(boneColliderBuilder.transform.gameObject);

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

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

        SABoneColliderEditorCommon.Reduce(reducerTasks, collidersPath, boneColliderBuilder.isDebug);
    }
    static void Cleanup(SABoneColliderBuilder boneColliderBuilder)
    {
        if (boneColliderBuilder == null)
        {
            Debug.LogError("");
            return;
        }

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

        foreach (Transform transform in boneColliderBuilder.transform)
        {
            if (SAColliderBuilderEditorCommon.IsRootTransform(transform))
            {
                // Nothing.
            }
            else
            {
                _CleanupTransform(transform, boneColliderBuilder, boneHashSet);
            }
        }
    }
    static void Cleanup(SABoneCollider boneCollider)
    {
        if (boneCollider == null)
        {
            Debug.LogError("");
            return;
        }

        GameObject rootGameObject = SABoneColliderEditorCommon.GetSABoneColliderRootGameObject(boneCollider);

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

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

        bool cleanupModified = boneCollider.cleanupModified;

        SABoneColliderEditorCommon.CleanupSABoneCollider(boneCollider);

        SABoneColliderEditorCommon.MarkManualProcessingToParent(boneCollider);

        if (boneCollider.recursivery)
        {
            foreach (Transform childTransform in boneCollider.gameObject.transform)
            {
                if (SAColliderBuilderEditorCommon.IsRootTransform(childTransform))
                {
                    // Nothing.
                }
                else
                {
                    _CleanupTransform(childTransform, cleanupModified, boneHashSet);
                }
            }
        }
    }
Exemplo n.º 9
0
    public override void OnInspectorGUI()
    {
        SAMeshColliderBuilder meshColliderBuilder = (SAMeshColliderBuilder)target;

        if (meshColliderBuilder.edittingMeshColliderBuilderProperty == null)
        {
            if (meshColliderBuilder.meshColliderBuilderProperty != null)
            {
                meshColliderBuilder.edittingMeshColliderBuilderProperty = meshColliderBuilder.meshColliderBuilderProperty.Copy();
            }
        }
        SAMeshColliderBuilderProperty meshColliderBuilderProperty = meshColliderBuilder.edittingMeshColliderBuilderProperty;

        if (meshColliderBuilderProperty != null)
        {
            SplitProperty splitProperty = meshColliderBuilderProperty.splitProperty;
            if (splitProperty != null)
            {
                GUILayout.Label("Split", EditorStyles.boldLabel);
                // Split Material
                splitProperty.splitMaterialEnabled = EditorGUILayout.Toggle("Split Material", splitProperty.splitMaterialEnabled);
                // Split Primitive
                splitProperty.splitPrimitiveEnabled = EditorGUILayout.Toggle("Split Primitive", splitProperty.splitPrimitiveEnabled);
                // Split Polygon Normal
                EditorGUILayout.BeginHorizontal();
                splitProperty.splitPolygonNormalEnabled = EditorGUILayout.Toggle("Split Polygon Normal", splitProperty.splitPolygonNormalEnabled);
                GUI.enabled = splitProperty.splitPolygonNormalEnabled;
                splitProperty.splitPolygonNormalAngle = EditorGUILayout.Slider(splitProperty.splitPolygonNormalAngle, 0.0f, 180.0f);
                GUI.enabled = true;
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.Separator();
            GUILayout.Label("Reducer", EditorStyles.boldLabel);
            SAColliderBuilderEditorCommon.ReducerInspectorGUI(meshColliderBuilderProperty.reducerProperty, ReducerOption.None);

            GUI.enabled = meshColliderBuilderProperty.reducerProperty.shapeType != ShapeType.None;
            EditorGUILayout.Separator();
            GUILayout.Label("Collider", EditorStyles.boldLabel);
            SAColliderBuilderEditorCommon.ColliderInspectorGUI(meshColliderBuilderProperty.colliderProperty, ColliderOption.None);
            EditorGUILayout.Separator();
            GUILayout.Label("Rigidbody", EditorStyles.boldLabel);
            SAColliderBuilderEditorCommon.RigidbodyInspectorGUI(meshColliderBuilderProperty.rigidbodyProperty);
            GUI.enabled = true;
        }

        EditorGUILayout.Separator();
        if (meshColliderBuilderProperty != null)
        {
            meshColliderBuilderProperty.modifyNameEnabled = EditorGUILayout.Toggle("Modify Name", meshColliderBuilderProperty.modifyNameEnabled);
        }
        meshColliderBuilder.cleanupModified = EditorGUILayout.Toggle("Cleanup Modified", meshColliderBuilder.cleanupModified);
        meshColliderBuilder.isDebug         = EditorGUILayout.Toggle("Is Debug", meshColliderBuilder.isDebug);

        EditorGUILayout.Separator();

        EditorGUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        if (GUILayout.Button("Revert"))
        {
            meshColliderBuilder.edittingMeshColliderBuilderProperty = null;
        }
        if (GUILayout.Button("Cleanup"))
        {
            if (meshColliderBuilder.edittingMeshColliderBuilderProperty != null)
            {
                meshColliderBuilder.meshColliderBuilderProperty         = meshColliderBuilder.edittingMeshColliderBuilderProperty;
                meshColliderBuilder.edittingMeshColliderBuilderProperty = null;
                Cleanup(meshColliderBuilder);
                meshColliderBuilder.cleanupModified = false;
                meshColliderBuilder.isDebug         = false;
                Debug.Log("Cleanuped.");
            }
        }
        if (GUILayout.Button("Process"))
        {
            if (meshColliderBuilder.edittingMeshColliderBuilderProperty != null)
            {
                meshColliderBuilder.meshColliderBuilderProperty         = meshColliderBuilder.edittingMeshColliderBuilderProperty;
                meshColliderBuilder.edittingMeshColliderBuilderProperty = null;
                float beginTime = Time.realtimeSinceStartup;
                Process(meshColliderBuilder);
                meshColliderBuilder.cleanupModified = false;
                meshColliderBuilder.isDebug         = false;
                float endTime = Time.realtimeSinceStartup;
                Debug.Log("Processed.[" + (endTime - beginTime) + " sec]");
            }
        }
        EditorGUILayout.EndHorizontal();
    }
    public override void OnInspectorGUI()
    {
        SABoneColliderBuilder boneColliderBuilder = (SABoneColliderBuilder)target;

        if (boneColliderBuilder.edittingBoneColliderBuilderProperty == null)
        {
            if (boneColliderBuilder.boneColliderBuilderProperty != null)
            {
                boneColliderBuilder.edittingBoneColliderBuilderProperty = boneColliderBuilder.boneColliderBuilderProperty.Copy();
            }
        }

        SABoneColliderBuilderProperty boneColliderBuilderProperty = boneColliderBuilder.edittingBoneColliderBuilderProperty;

        if (boneColliderBuilderProperty != null)
        {
            SplitProperty splitProperty = boneColliderBuilderProperty.splitProperty;

            if (splitProperty != null)
            {
                GUILayout.Label("Split", EditorStyles.boldLabel);
                SABoneColliderEditorCommon.SplitInspectorGUI(splitProperty);
            }

            EditorGUILayout.Separator();
            GUILayout.Label("Reducer", EditorStyles.boldLabel);
            SAColliderBuilderEditorCommon.ReducerInspectorGUI(boneColliderBuilderProperty.reducerProperty,
                                                              ReducerOption.ColliderToChild);

            GUI.enabled = boneColliderBuilderProperty.reducerProperty.shapeType != ShapeType.None;
            EditorGUILayout.Separator();
            GUILayout.Label("Collider", EditorStyles.boldLabel);
            SAColliderBuilderEditorCommon.ColliderInspectorGUI(boneColliderBuilderProperty.colliderProperty, ColliderOption.CreateAsset);
            EditorGUILayout.Separator();
            GUILayout.Label("Rigidbody", EditorStyles.boldLabel);
            SAColliderBuilderEditorCommon.RigidbodyInspectorGUI(boneColliderBuilderProperty.rigidbodyProperty);
            GUI.enabled = true;
        }

        EditorGUILayout.Separator();

        if (boneColliderBuilderProperty != null)
        {
            boneColliderBuilderProperty.modifyNameEnabled = EditorGUILayout.Toggle("Modify Name", boneColliderBuilderProperty.modifyNameEnabled);
        }

        boneColliderBuilder.cleanupModified = EditorGUILayout.Toggle("Cleanup Modified", boneColliderBuilder.cleanupModified);
        boneColliderBuilder.isDebug         = EditorGUILayout.Toggle("Is Debug", boneColliderBuilder.isDebug);

        EditorGUILayout.Separator();

        EditorGUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();

        if (GUILayout.Button("Revert"))
        {
            boneColliderBuilder.edittingBoneColliderBuilderProperty = null;
        }

        if (GUILayout.Button("Cleanup"))
        {
            if (boneColliderBuilder.edittingBoneColliderBuilderProperty != null)
            {
                boneColliderBuilder.boneColliderBuilderProperty         = boneColliderBuilder.edittingBoneColliderBuilderProperty;
                boneColliderBuilder.edittingBoneColliderBuilderProperty = null;
                Cleanup(boneColliderBuilder);
                boneColliderBuilder.cleanupModified = false;
                boneColliderBuilder.isDebug         = false;
                Debug.Log("Cleanuped.");
            }
        }

        if (GUILayout.Button("Process"))
        {
            if (boneColliderBuilder.edittingBoneColliderBuilderProperty != null)
            {
                boneColliderBuilder.boneColliderBuilderProperty         = boneColliderBuilder.edittingBoneColliderBuilderProperty;
                boneColliderBuilder.edittingBoneColliderBuilderProperty = null;
                float beginTime = Time.realtimeSinceStartup;
                Process(boneColliderBuilder);
                boneColliderBuilder.cleanupModified = false;
                boneColliderBuilder.isDebug         = false;
                float endTime = Time.realtimeSinceStartup;
                Debug.Log("Processed.[" + (endTime - beginTime) + " sec]");
            }
        }

        EditorGUILayout.EndHorizontal();
    }