protected override void OnValidate()
 {
     base.OnValidate();
     uiController = this;
     if (pathSettings == null)
     {
         pathSettings = GetComponent <RootPathSettings>();
     }
 }
Beispiel #2
0
        /// <summary>
        /// Request to load a file asynchronously.
        /// </summary>
        /// <param name="objName"></param>
        /// <param name="filePath"></param>
        /// <param name="parentTransform"></param>
        /// <param name="options"></param>
        public void ImportModelAsync(string objName, string filePath, Transform parentTransform, ModelImportOptions options)
        {
            filePath = filePath.Replace('/', Path.DirectorySeparatorChar);
            RootPathSettings rootPath = GetComponent <RootPathSettings>();

            if (!Path.IsPathRooted(filePath) && rootPath != null)
            {
                filePath = rootPath + filePath;
            }
            if (options != null && options.reuseLoaded)
            {
                useCache = true;
            }
            //useCache = false;
            lastModelCacheKey = CreateModelKey(filePath, options);
            if (useCache && objectCache.ContainsKey(lastModelCacheKey))
            {
                if (objectCache[lastModelCacheKey] == null)
                {
                    objectCache.Remove(lastModelCacheKey);
                }
                else
                {
                    GameObject cachedObj = Instantiate(objectCache[lastModelCacheKey], parentTransform);
                    cachedObj.name = objName;
                    OnImportingStart();
                    OnCreatedModel(cachedObj, filePath);
                    OnImportedModel(cachedObj, filePath);
                    OnImportingComplete();
                    return;
                }
            }

            if (filePath.EndsWith(".obj", true, CultureInfo.InvariantCulture))
            {
                ImportOptions objOptions = new ImportOptions();
                if (options != null)
                {
                    objOptions.buildColliders       = options.buildColliders;
                    objOptions.convertToDoubleSided = options.convertToDoubleSided;
                    objOptions.inheritLayer         = options.inheritLayer;
                    objOptions.litDiffuse           = options.litDiffuse;
                    objOptions.localEulerAngles     = options.localEulerAngles;
                    objOptions.localPosition        = options.localPosition;
                    objOptions.localScale           = options.localScale;
                    objOptions.modelScaling         = options.modelScaling;
                }
                else
                {
                    //TODO: define global default options
                    objOptions.buildColliders       = true;
                    objOptions.convertToDoubleSided = false;
                    objOptions.inheritLayer         = false;
                    objOptions.litDiffuse           = false;
                    objOptions.localEulerAngles     = Vector3.zero;
                    objOptions.localPosition        = Vector3.zero;
                    objOptions.localScale           = Vector3.one;
                    objOptions.modelScaling         = 0.01f;
                }
                objOptions.colliderConvex   = true;
                objOptions.reuseLoaded      = false;
                objOptions.use32bitIndices  = true;
                objOptions.zUp              = options.zUp;
                objOptions.hideWhileLoading = true;

                objLoader.ImportModelAsync(objName, filePath, parentTransform, objOptions);
            }
            else if (filePath.EndsWith(".gltf", true, CultureInfo.InvariantCulture))
            {
                ImportGltfAsync(objName, filePath, parentTransform, options);
            }
        }