/// <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(); }
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 = new GPUSkinningPlayerResources(); int numItems = items.Count; for (int i = 0; i < numItems; ++i) { if (items[i].anim.guid == anim.guid) { item.texture = items[i].texture; break; } } items.Add(item); if (item.anim == null) { item.anim = anim; } if (item.mesh == null) { item.mesh = mesh; } item.InitMaterial(originalMtrl, HideFlags.None); if (item.texture == null) { item.texture = GPUSkinningUtil.CreateTexture2D(textureRawData, anim); } if (!item.players.Contains(player)) { item.players.Add(player); item.AddCullingBounds(); } resources = item; }
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 Init() { if (player != null) { return; } if (anim != null && mesh != null && mtrl != null && boneTexture != null) { GPUSkinningPlayerResources res = null; if (Application.isPlaying) { playerManager.Register(anim, mesh, mtrl, boneTexture, this, out res); } else { res = new GPUSkinningPlayerResources(); res.anim = anim; res.mesh = mesh; res.InitMaterial(mtrl, HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor); res.boneTexture = boneTexture; //GPUSkinningUtil.CreateTexture2D(boneTexture, anim); //res.boneTexture.hideFlags = HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor; } player = new GPUSkinningPlayer(gameObject, res); 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); } } }