Ejemplo n.º 1
0
        public async Task <T> InstantiateAssetAsync <T>(string name, bool isKeep, bool isAssetBundle, Transform parent, params string[] types) where T : Component
        {
            AssetData assetData = await LoadAssetDataAsync <GameObject>(name, ".prefab", isKeep, isAssetBundle, types);

            if (assetData == null)
            {
                return(null);
            }
            GameObject gameObject = (GameObject)Object.Instantiate(assetData.asset);

            gameObject.name = name;
            gameObject.transform.SetParent(parent);
            gameObject.transform.localPosition = Vector3.zero;
            gameObject.transform.localRotation = Quaternion.identity;
            gameObject.transform.localScale    = Vector3.one;
            T component = gameObject.AddComponent <T>();

            return(component);
        }
Ejemplo n.º 2
0
        public void UnloadAssets()
        {
            string assetNames = string.Empty;

            foreach (string item in assetDict.Keys)
            {
                if (!assetDict[item].isKeep)
                {
                    assetNames = $"{assetNames}{item},";
                }
            }
            foreach (string item in assetNames.Split(','))
            {
                if (string.IsNullOrEmpty(item))
                {
                    continue;
                }
                AssetData assetData = assetDict[item];
                UnloadAsset(assetData);
                assetDict.Remove(item);
            }
        }