Example #1
0
    public void Init()
    {
        if (player != null)
        {
            return;
        }

        if (anim != null && mesh != null && mtrl != null && textureRawData != null)
        {
            GPUSkinningPlayerResources res = null;

            if (Application.isPlaying)
            {
                playerManager.Register(anim, mesh, mtrl, textureRawData, this, out res);
            }
            else
            {
                res                   = new GPUSkinningPlayerResources();
                res.anim              = anim;
                res.mesh              = mesh;
                res.mtrl              = new Material(mtrl);
                res.texture           = GPUSkinningUtil.CreateTexture2D(textureRawData, anim);
                res.mtrl.hideFlags    = HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor;
                res.texture.hideFlags = HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor;
            }

            player = new GPUSkinningPlayer(gameObject, res);
            player.RootMotionEnabled = Application.isPlaying ? rootMotionEnabled : false;

            if (anim != null && anim.clips != null && anim.clips.Length > 0)
            {
                player.Play(anim.clips[Mathf.Clamp(defaultPlayingClipIndex, 0, anim.clips.Length)].name);
            }
        }
    }
Example #2
0
    public void Register(GPUSkinningAnimation anim, Mesh mesh, Material originalMtrl, TextAsset textureRawData, GPUSkinningPlayerMono player, out GPUSkinningPlayerResources resources)
    {
        resources = null;

        if (anim == null || originalMtrl == null || textureRawData == null || player == null)
        {
            return;
        }

        GPUSkinningPlayerResources item = null;

        int numItems = items.Count;

        for (int i = 0; i < numItems; ++i)
        {
            if (items[i].anim.guid == anim.guid)
            {
                item = items[i];
                break;
            }
        }

        if (item == null)
        {
            item = new GPUSkinningPlayerResources();
            items.Add(item);
        }

        if (item.anim == null)
        {
            item.anim = anim;
        }

        if (item.mesh == null)
        {
            item.mesh = mesh;
        }

        if (item.mtrl == null)
        {
            item.mtrl = new Material(originalMtrl);
        }

        if (item.texture == null)
        {
            item.texture = GPUSkinningUtil.CreateTexture2D(textureRawData, anim);
        }

        if (!item.players.Contains(player))
        {
            item.players.Add(player);
        }

        resources = item;
    }
    /// <summary>
    /// 初始化PlayerMono设置:
    /// 创建/查询对应的GPUSkinningPlayerResources,通过GPUSkinningPlayerManager管理
    /// fzy remark:初始化存在潜在的开销问题,在首次生成PlayerMono时,Creating CullingBounds会产生较大的开销
    /// </summary>
    public void Init()
    {
        //player != null 表示已经初始化,return结束执行
        if (player != null)
        {
            return;
        }

        GPUSkinningPlayerResources res = null;

        //所有属性设置完毕,开始初始化
        if (anim != null && mesh != null && mtrl != null && textureRawData != null)
        {
            //运行时,注册蒙皮网格、动画、材质等数据
            if (Application.isPlaying)
            {
                playerManager.Register(anim, mesh, mtrl, textureRawData, this, out res);
            }
            else
            {
                //编辑时,创建蒙皮网格资源实例,保存数据
                res                   = new GPUSkinningPlayerResources();
                res.anim              = anim;
                res.mesh              = mesh;
                res.texture           = GPUSkinningUtil.CreateTexture2D(textureRawData, anim);
                res.texture.hideFlags = HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor;
                //初始化Material(一共有6种Material)
                //创建的Material和Texture不保存(游戏运行时在Project视图无法找到索引,游戏运行后销毁)
                res.InitMaterial(mtrl, HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor);
            }

            player = new GPUSkinningPlayer(gameObject, res);
            // 非运行状态设置为false(preview)
            player.RootMotionEnabled = Application.isPlaying ? rootMotionEnabled : false;
            player.LODEnabled        = Application.isPlaying ? lodEnabled : false;
            // 动画片段播放的设置
            player.CullingMode = cullingMode;

            if (anim != null && anim.clips != null && anim.clips.Length > 0)
            {
                player.Play(anim.clips[Mathf.Clamp(defaultPlayingClipIndex, 0, anim.clips.Length)].name);
            }
        }

        // fzy add:
        myRes         = res;
        mf            = GetComponent <MeshFilter>();
        mf.sharedMesh = mesh;
        mr            = GetComponent <MeshRenderer>();
        SetMaterial(GPUSkinningPlayerResources.MaterialState.RootOff_BlendOff);
        mpb = new MaterialPropertyBlock();
    }
Example #4
0
    public void Init()
    {
        if (player != null)
        {
            return;
        }
        if (anim != null && mesh != null && mtrl != null && textureRawData != null)
        {
            GPUSkinningPlayerResources res = null;

            if (Application.isPlaying)
            {
                //if (EZ.Global.gApp.CurScene != null && EZ.Global.gApp.CurScene.GetPlayerMgr() != null)
                if (EZ.Global.gApp.CurScene != null)
                {
                    m_PlayerMonoManager.Register(anim, mesh, mtrl, textureRawData, this, out res);
                }
                else
                {
                    return;
                }
            }
            else
            {
                res      = new GPUSkinningPlayerResources();
                res.anim = anim;
                res.mesh = mesh;
                res.InitMaterial(mtrl, HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor);
                res.texture           = GPUSkinningUtil.CreateTexture2D(textureRawData, anim);
                res.texture.hideFlags = HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor;
            }

            player = new GPUSkinningPlayer(gameObject, res);
            //player.RootMotionEnabled = Application.isPlaying ? rootMotionEnabled : false;
            player.RootMotionEnabled = false;
            //player.LODEnabled = Application.isPlaying ? lodEnabled : false;
            player.LODEnabled  = false;
            player.CullingMode = cullingMode;

            if (anim != null && anim.clips != null && anim.clips.Length > 0)
            {
                player.Play(anim.clips[Mathf.Clamp(defaultPlayingClipIndex, 0, anim.clips.Length)].name);
            }
        }
    }
    //注册需要渲染的模型种类
    public void Register(GPUSkinningAnimation anim, Mesh mesh, Material originalMtrl, TextAsset textureRawData, GPUSkinningPlayerMono player, out GPUSkinningPlayerResources resources)
    {
        resources = null;

        if (anim == null || originalMtrl == null || textureRawData == null || player == null)
        {
            return;
        }

        // item完成初始化后赋值给resources
        GPUSkinningPlayerResources item = null;

        int numItems = items.Count;

        //查询该anim是否已注册,根据guid(唯一标识符)判断
        for (int i = 0; i < numItems; ++i)
        {
            if (items[i].anim.guid == anim.guid)
            {
                //找到已注册的Resources,赋值给item
                item = items[i];
                break;
            }
        }

        #region 未找到,初始化赋值
        if (item == null)
        {
            item = new GPUSkinningPlayerResources();
            //Debug.Log("new");
            items.Add(item);
        }

        if (item.anim == null)
        {
            item.anim = anim;
        }

        if (item.mesh == null)
        {
            item.mesh = mesh;
        }

        if (item.texture == null)
        {
            item.texture = GPUSkinningUtil.CreateTexture2D(textureRawData, anim);
        }

        item.InitMaterial(originalMtrl, HideFlags.None);

        #endregion

        //为player设置CullingBounds(在CullingGroup中)
        if (!item.players.Contains(player))
        {
            item.players.Add(player);
            // fzy delete:culling
            //item.AddCullingBounds();
        }

        resources = item;
    }