Beispiel #1
0
    public GameObject CreateSticker(PPPrefabInfo info, Action loadFinish = null)
    {
        if (info == null)
        {
            throw new ArgumentNullException("PPPrefabInfo can't be null!");
        }
        string     matPath   = Path.Combine(AppBlockPath(BlockPath.Sticker_Material_Dir), info.Name);
        var        modelPath = Path.Combine(PrefixPath, info.Model + "/" + info.Model + ".gltf");
        GameObject sticker   = null;

        sticker = PTGLTFLoader.loadGltf(modelPath, () =>
        {
            var stickerRoot = sticker.transform.Find("Root Scene");
            var render      = stickerRoot == null ? null : stickerRoot.GetComponentInChildren <Renderer>(true);
            if (render != null)
            {
                Material mat             = PBMatLoader.LoadTextureMatAsset(matPath, info.Texture, true);
                render.receiveShadows    = false;
                render.shadowCastingMode = ShadowCastingMode.Off;
                render.sharedMaterial    = mat;
            }
            else
            {
                PTDebug.LogError("Sticker:<color=#FF00FF>{0}</color> load failed! Model:<color=#FF00FF>{1}</color>", info.Name, info.Model);
            }
            loadFinish.InvokeGracefully();
        }, OnInitializeGltfObject);
        blockObj.Add(sticker);

        return(sticker);
    }
Beispiel #2
0
    private Material LoadCommonMatAsset(MaterialInfo matInfo)
    {
        //model 工程中 所有的 Material 必须放到 commonres里面,不能放到对应的category里面,所有的material不能重名
        string matPath = Path.Combine(BlockPath.MaterialCommon(), matInfo.name);

        Material mat = null;

        if (blockMats.ContainsKey(matPath))
        {
            mat = blockMats[matPath];
        }
        else
        {
            mat = PBMatLoader.GetMaterial(matInfo);
            blockMats[matPath] = mat;
        }
        return(mat);
    }
Beispiel #3
0
 public void Dispose()
 {
     blockObj.ForEach(t =>
     {
         if (t != null)
         {
             Object.Destroy(t);
         }
     });
     blockObj.Clear();
     PBMatLoader.Dispose();
     foreach (var mat in blockMats)
     {
         if (mat.Value != null)
         {
             Object.Destroy(mat.Value);
         }
     }
     blockMats.Clear();
     blockAbs.Clear();
     PTGLTFLoader.Dispose();
 }
Beispiel #4
0
    public GameObject CreateTexture(PPPrefabTexInfo info, Action loadFinish = null)
    {
        if (info == null)
        {
            throw new ArgumentNullException("PPPrefabInfo can't be null!");
        }
        var    prefabName = info.Name;
        string matPath    = Path.Combine(AppBlockPath(BlockPath.Texture_Material_Dir), prefabName);

        var model     = info.Model;
        var modelPath = Path.Combine(AppBlockPath(BlockPath.Texture_Fbx_Dir), model);

        modelPath = modelPath + "/" + model + ".gltf";

        GameObject texObj = null;

        texObj = PTGLTFLoader.loadGltf(modelPath, () =>
        {
            var texRoot = texObj.transform.Find("Root Scene");
            var render  = texRoot == null ? null : texRoot.GetComponentInChildren <Renderer>(true);
            if (render != null)
            {
                Material mat             = PBMatLoader.LoadTextureMatAsset(matPath, info.Texture, false);
                render.receiveShadows    = false;
                render.shadowCastingMode = ShadowCastingMode.Off;
                render.material          = mat;
            }
            else
            {
                PTDebug.LogError("Texture:<color=#FF00FF>{0}</color> load failed! Model:<color=#FF00FF>{1}</color>", prefabName, model);
            }
            loadFinish.InvokeGracefully();
        }, OnInitializeGltfObject);

        texObj.name = prefabName;
        blockObj.Add(texObj);

        return(texObj);
    }