using GLTFast; using UnityEngine; /// /// 场景模型导入 /// public class SceneImport : MonoBehaviour { public string[] colliers; public virtual async void Start() { var url = $"{Application.streamingAssetsPath}/Buildings/Scene/Scene.gltf"; var gltf = new GltfImport(); var impoerSetting = new ImportSettings { generateMipMaps = true }; var success = await gltf.Load(url, impoerSetting); if (success) { gltf.InstantiateMainScene(transform); Transform[] grandFa = gameObject.GetComponentsInChildren(true); foreach (Transform child in grandFa) { if (child.GetComponent()) child.gameObject.AddComponent(); } for(int i=0;i< colliers.Length; i++) { var data= transform.Find("Scene/" + colliers[i]).gameObject.AddComponent(); data.floorId = 0; data.Equipment = true; data.Power = true; } } else { Debug.LogError("Loading glTF failed!"); } } }