コード例 #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);
    }
コード例 #2
0
    public GameObject CreateBlock(PPPrefabInfo info, Action loadFinish = null)
    {
        if (info == null)
        {
            throw new ArgumentNullException("PPPrefabInfo can't be null!");
        }
        var prefabName = info.Name;

        if (info.IsSticker)
        {
            return(CreateSticker(info, loadFinish));
        }

        var model     = info.Model;
        var modelPath = Path.Combine(PrefixPath, model + "/" + model + ".gltf");

        //load gltf
        GameObject block = null;

        block = PTGLTFLoader.loadGltf(modelPath, () =>
        {
            var blockRoot = block.transform.Find("Root Scene");
            if (blockRoot.GetComponentInChildren <Renderer>(true) != null)
            {
                AssignMaterials(blockRoot.gameObject, info.Material, info.MaterialInfos);
            }
            else
            {
                PTDebug.LogError("Block:<color=#FF00FF>{0}</color> load failed! Model:<color=#FF00FF>{1}</color>", prefabName, model);
            }
            loadFinish.InvokeGracefully();
        }, OnInitializeGltfObject);
        blockObj.Add(block);

        block.name = model;

        Animator animator = block.GetComponent <Animator>();

        if (animator != null)
        {
            GameObject.DestroyImmediate(animator);
        }
        return(block);
    }
コード例 #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();
 }
コード例 #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);
    }