Ejemplo n.º 1
0
    public static GameObject LoadRes(Transform parent, string path)
    {
        if (CheckResInDic(path))
        {
            if (GetResInDic(path) != null)
            {
                return(GetResInDic(path));
            }
            else
            {
                LoadResDic.Remove(path);
            }
        }

        GameObject objLoad = null;

        //加载资源
        ResourceItem objUnit = ResourcesManager.Instance.loadImmediate(path, ResourceType.PREFAB);

        if (objUnit == null || objUnit.Asset == null)
        {
            Debug.LogError("load unit failed" + path);
            return(null);
        }
        objLoad = GameObject.Instantiate(objUnit.Asset) as GameObject;
        objLoad.transform.parent        = parent;
        objLoad.transform.localScale    = Vector3.one;
        objLoad.transform.localPosition = Vector3.zero;
        LoadResDic.Add(path, objLoad);
        return(objLoad);
    }
Ejemplo n.º 2
0
    public static GameObject LoadRes(Transform parent, string path, bool cache = true)
    {
        if (cache == true && CheckResInDic(path))
        {
            if (GetResInDic(path) != null)
            {
                return(GetResInDic(path));
            }
            else
            {
                LoadResDic.Remove(path);
            }
        }

        GameObject objLoad = null;

        GameObject asset = (GameObject)Resources.Load(path);

        if (asset == null)
        {
            Debug.LogError("load unit failed " + path);
            return(null);
        }
        objLoad = GameObject.Instantiate(asset) as GameObject;
        objLoad.transform.localScale    = Vector3.one;
        objLoad.transform.localPosition = Vector3.zero;

        //Vector3 anchorPos = Vector3.zero;
        //Vector2 sizeDel = Vector2.zero;
        //Vector3 scale = Vector3.one;
        //RectTransform rect = objLoad.GetComponent<RectTransform>();
        //if(rect != null)
        //{
        //    anchorPos = rect.anchoredPosition;
        //    sizeDel = rect.sizeDelta;
        //    scale = rect.localScale;
        //}

        objLoad.transform.SetParent(parent, false);
        //if (rect != null)
        //{
        //    rect.anchoredPosition = anchorPos;
        //    rect.sizeDelta = sizeDel;
        //    rect.localScale = scale;
        //}
        if (cache)
        {
            LoadResDic.Add(path, objLoad);
        }
        return(objLoad);
    }