-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBlenderRuntimeImportFix.cs
More file actions
47 lines (40 loc) · 1.39 KB
/
BlenderRuntimeImportFix.cs
File metadata and controls
47 lines (40 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// CC0, use as you like
// If you work with .blend files directly (also added check for sketchup), and save them during runtime. You notice any meshcollider
// Stops working. This is a band aid for that issue.
// Install the Editor Coroutines package to use. Also do not forget to place this script in a folder that starts with "Editor"
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using Unity.EditorCoroutines.Editor;
public class BlenderRuntimeImportFix : AssetPostprocessor
{
void OnPostprocessModel(GameObject g)
{
if (Application.isPlaying && (assetPath.Contains(".blend") || assetPath.Contains(".skp")))
{
EditorCoroutineUtility.StartCoroutine(RefreshMeshColliders(), this);
}
}
IEnumerator RefreshMeshColliders()
{
var colliders = Object.FindObjectsOfType<MeshCollider>();
int c = colliders.Length;
List<MeshCollider> updateColliders = new List<MeshCollider>();
for (int i = 0; i < c; i++)
{
if (colliders[i].enabled)
{
updateColliders.Add(colliders[i]);
colliders[i].enabled = false;
}
}
// Wait a frame.
yield return null;
c = updateColliders.Count;
for (int i = 0; i < c; i++)
{
updateColliders[i].enabled = true;
}
}
}