//同期ロード処理(Resourcesから) void LoadResource(string loadPath, Action onComplete, Action onFailed) { loadPath = FilePathUtil.GetPathWithoutExtension(loadPath); UnityEngine.Object asset = Resources.Load(loadPath, GetResourceType()); LoadAsset(asset, onComplete, onFailed); }
//以下、自作のファイルマネージャーから、オブジェクトの参照を行う void InitFromCustomFileManager() { //Resources.Loadの部分を、自作のファイルマネージャーからのオブジェクト参照に切り替える string path = FilePathUtil.GetPathWithoutExtension(FileInfo.FileName); switch (FileType) { case AssetFileType.Text: //テキスト Text = Resources.Load <TextAsset>(path); break; case AssetFileType.Texture: //テクスチャ Texture = Resources.Load <Texture2D>(path); break; case AssetFileType.Sound: //サウンド Sound = Resources.Load <AudioClip>(path); break; case AssetFileType.UnityObject: //Unityオブジェクト(プレハブとか) this.UnityObject = Resources.Load(path); break; default: break; } }
//非同期ロード(Resourcesから) IEnumerator LoadResourceAsync(string loadPath, Action onComplete, Action onFailed) { loadPath = FilePathUtil.GetPathWithoutExtension(loadPath); ResourceRequest request = Resources.LoadAsync(loadPath, GetResourceType()); while (!request.isDone) { yield return(null); } LoadAsset(request.asset, onComplete, onFailed); }
IEnumerator CoPlayMovieFromResources(string path, bool isLoop) { path = FilePathUtil.GetPathWithoutExtension(path); MovieTexture movieTexture = Resources.Load <MovieTexture>(path); if (movieTexture == null) { Debug.LogError("Movie canot load from " + path); yield break; } yield return(StartCoroutine(CoPlayMovieTexture(movieTexture, isLoop))); }
internal TextureInfo(Texture2D texture, DicingTextures target) { if (target.OverrideTextureImporter) { string path = AssetDatabase.GetAssetPath(texture); OverrideTextureImportSetting(path, target); } this.texture = texture; this.name = FilePathUtil.RemoveDirectory(AssetDatabase.GetAssetPath(texture), AssetDatabase.GetAssetPath(target.InputDir)); this.name = FilePathUtil.GetPathWithoutExtension(this.name); MakeCells(target); }
//ロード処理(Resourcesから) void LoadResource(string loadPath) { loadPath = FilePathUtil.GetPathWithoutExtension(loadPath); TextAsset textAsset; switch (FileType) { case AssetFileType.Text: //テキスト textAsset = Resources.Load(loadPath, typeof(TextAsset)) as TextAsset; if (null != textAsset) { text = textAsset.text; Resources.UnloadAsset(textAsset); } else { SetLoadError("LoadResource Error"); } break; case AssetFileType.Bytes: //バイナリ textAsset = Resources.Load(loadPath, typeof(TextAsset)) as TextAsset; if (null != textAsset) { bytes = textAsset.bytes; Resources.UnloadAsset(textAsset); } else { SetLoadError("LoadResource Error"); } break; case AssetFileType.Texture: //テクスチャ texture = Resources.Load(loadPath, typeof(Texture2D)) as Texture2D; if (null == texture) { SetLoadError("LoadResource Error"); } break; case AssetFileType.Sound: //サウンド sound = Resources.Load(loadPath, typeof(AudioClip)) as AudioClip; if (null == sound) { SetLoadError("LoadResource Error"); } break; case AssetFileType.Csv: //CSV textAsset = Resources.Load(loadPath, typeof(TextAsset)) as TextAsset; if (null != textAsset) { csv = new StringGrid(loadPath, FileInfo.IsTsv ? CsvType.Tsv : CsvType.Csv, textAsset.text); Resources.UnloadAsset(textAsset); } else { SetLoadError("LoadResource Error"); } break; case AssetFileType.UnityObject: //Unityオブジェクト(プレハブとか) unityObject = Resources.Load(loadPath); if (null == unityObject) { SetLoadError("LoadResource Error"); } break; default: break; } }