質問編集履歴
1
assetBundleはシングルトンクラスだったのでその旨を明記。呼び出し方法を修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,9 +8,9 @@
|
|
8
8
|
|
9
9
|
// ここまでは最初に実行するシーンでのみ行う
|
10
10
|
|
11
|
+
// 2019/05/27 修正(シングルトンからのロードでした。お詫びして訂正します)
|
11
12
|
|
12
|
-
|
13
|
-
GameObject EV = assetBundle.LoadAsset<GameObject>(パス);
|
13
|
+
GameObject EV = AssetBundleManager.Instance.assetBundle.LoadAsset<GameObject>(パス);
|
14
14
|
|
15
15
|
```
|
16
16
|
|
@@ -18,4 +18,82 @@
|
|
18
18
|
|
19
19
|
ところが、最初の1回は正常に読まれるのですが、シーンを再度読み直してLoadAssetを実行するとEVがNullになってしまいます
|
20
20
|
|
21
|
+
また、呼び出し時のassetBundleはデバッガで見ると「AssetBundleManager.Instance.assetBundle = "object (UnityEngine.AssetBundle)"」となっておりNullではありませんでした
|
22
|
+
|
21
23
|
このような現象を回避するためにはどのようにすればよいでしょうか?
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
<追記>
|
28
|
+
|
29
|
+
AssetBundleは以下のコードによるシングルトンです。このクラスをインポートした空オブジェクトを最初に起動されるシーンに配置しています。
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
```ここに言語を入力
|
34
|
+
|
35
|
+
using System.Collections;
|
36
|
+
|
37
|
+
using System.Collections.Generic;
|
38
|
+
|
39
|
+
using UnityEngine;
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
public class AssetBundleManager : SingletonMonoBehaviour<AssetBundleManager>
|
44
|
+
|
45
|
+
{
|
46
|
+
|
47
|
+
/// <summary>
|
48
|
+
|
49
|
+
/// アセットバンドルのインスタンス
|
50
|
+
|
51
|
+
/// </summary>
|
52
|
+
|
53
|
+
public AssetBundle assetBundle;
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
public void Awake()
|
58
|
+
|
59
|
+
{
|
60
|
+
|
61
|
+
if (this != Instance)
|
62
|
+
|
63
|
+
{
|
64
|
+
|
65
|
+
Destroy(this);
|
66
|
+
|
67
|
+
return;
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
DontDestroyOnLoad(this.gameObject);
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
/// <summary>
|
80
|
+
|
81
|
+
/// 初回起動時にアセットバンドルを読ませる
|
82
|
+
|
83
|
+
/// </summary>
|
84
|
+
|
85
|
+
public void Start()
|
86
|
+
|
87
|
+
{
|
88
|
+
|
89
|
+
string assetBundlePath = Application.streamingAssetsPath + "/object";
|
90
|
+
|
91
|
+
assetBundle = AssetBundle.LoadFromFile(assetBundlePath);
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
```
|