Esempio n. 1
0
    //获取实例化资源的地方(同步方式加载预设)
    public GameObject RGet(string bundleName, string assetName, ELoadType loadType, GameObject parent = null)
    {
        if (string.IsNullOrEmpty(bundleName))
        {
            return(null);
        }

        string strFullBundleName = BundleLoaderManager.GetBundleName(bundleName, loadType);
        string strFullAssetName  = BundleLoaderManager.GetAssertName(bundleName, assetName, ABPathHelper.PrefabSuffix, loadType);
        //Debug.Log("<color=yellow>资源:bundleName: " + strFullBundleName + " assetName: " + strFullAssetName + "</color>");

        Object source = null;

#if UNITY_EDITOR
        if (GameUtils.ScriptLoad && loadType == ELoadType.UI)
        {
            source = UnityEditor.AssetDatabase.LoadAssetAtPath(strFullAssetName, typeof(UnityEngine.Object));
        }
        else
#endif
        {
            source = BundleLoaderManager.Instance.Load(strFullBundleName, strFullAssetName, loadType);
        }

        if (source is GameObject)
        {
            GameObject go = GameObject.Instantiate(source) as GameObject;
            MaterialUtils.ResetGameObjectMaterials(go);

            if (loadType == ELoadType.UI)
            {
                AutoDestroy autoDestroyCom = go.GetComponent <AutoDestroy>();
                if (autoDestroyCom == null)
                {
                    autoDestroyCom = go.AddComponent <AutoDestroy>();
                }
            }
            go.name = go.name.Replace("(Clone)", "");

            int nBundleId = strFullBundleName.GetHashCode();
            m_AllGameObjects.Add(go, nBundleId);
            if (parent != null)
            {
                go.transform.parent        = parent.transform;
                go.transform.localPosition = Vector3.zero;
                go.transform.localScale    = Vector3.one;
                go.transform.localRotation = Quaternion.identity;
            }
            return(go);
        }
        else
        {
            Debug.Log("<color=red> object is null: " + strFullAssetName + "\n" + "</color>");
        }
        return(null);
    }