Пример #1
0
    private void Start()
    {
        player = GetComponent <GPUSkinningPlayerMono>().Player;
        player.Play("Idle");

        actionTime = Random.Range(5, 30);
    }
Пример #2
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);
            }
        }
    }
    private void Start()
    {
        thisTransform = transform;
        camTransform  = Camera.main.transform;

        camOffsetPos = camTransform.position - thisTransform.position;

        player = GetComponent <GPUSkinningPlayerMono>().Player;
        player.Play("Idle");
    }
    private void Start()
    {
        QualitySettings.shadows = ShadowQuality.Disable;

        thisTransform = transform;
        camTransform  = Camera.main.transform;

        camOffsetPos = camTransform.position - thisTransform.position;

        player = GetComponent <GPUSkinningPlayerMono>().Player;
        player.Play("Idle");
    }
    /// <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();
    }
Пример #6
0
    private void OnDestroy()
    {
        player         = null;
        anim           = null;
        mesh           = null;
        mtrl           = null;
        textureRawData = null;
        m_PlayerMonoManager.Unregister(this);

#if UNITY_EDITOR
        if (!Application.isPlaying)
        {
            Resources.UnloadUnusedAssets();
            UnityEditor.EditorUtility.UnloadUnusedAssetsImmediate();
        }
#endif
    }
Пример #7
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);
            }
        }
    }
    private void SetLODMeshByDistanceIndex(int index, GPUSkinningPlayer player)
    {
        Mesh lodMesh = null;

        if (index == 0)
        {
            lodMesh = this.mesh;
        }
        else
        {
            Mesh[] lodMeshes = anim.lodMeshes;
            lodMesh = lodMeshes == null || lodMeshes.Length == 0 ? this.mesh : lodMeshes[Mathf.Min(index - 1, lodMeshes.Length - 1)];
            if (lodMesh == null)
            {
                lodMesh = this.mesh;
            }
        }
        player.SetLODMesh(lodMesh);
    }
 public void LODSettingChanged(GPUSkinningPlayer player)
 {
     if (player.LODEnabled)
     {
         int numPlayers = players.Count;
         for (int i = 0; i < numPlayers; ++i)
         {
             if (players[i].Player == player)
             {
                 int distanceIndex = cullingGroup.GetDistance(i);
                 SetLODMeshByDistanceIndex(distanceIndex, players[i].Player);
                 break;
             }
         }
     }
     else
     {
         player.SetLODMesh(null);
     }
 }
Пример #10
0
    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);
            }
        }
    }
Пример #11
0
 public void DeletePlayer()
 {
     player = null;
 }