public static WidgetManager GetInstance() { if (instance == null) { instance = new GameObject(typeof(WidgetManager).Name).AddComponent <WidgetManager>(); DontDestroyOnLoad(GetInstance().gameObject); } return(instance); }
public void Update() { switch (state) { case State.Loading: if (_request.isDone) { if (_request.error != null) { state = State.Destroyed; } else { gameObject = GameObject.Instantiate(_request.asset as GameObject); state = State.Loaded; if (Onloaded != null) { Onloaded(this); } } } break; case State.Loaded: break; case State.Destroyed: if (gameObject != null) { GameObject.Destroy(gameObject); gameObject = null; } foreach (var item in assets) { item.Value.Release(); } _request.Release(); _request = null; assets.Clear(); WidgetManager.Remove(this); break; default: break; } }
public Widget(string assetPath) { _request = Assets.LoadAssetAsync(assetPath, typeof(GameObject)); state = State.Loading; WidgetManager.Add(this); }