Ejemplo n.º 1
0
        private IEnumerator CreateModelCoroutine(string modelName)
        {
            yield return(new WaitForSeconds(0.3f * Index));

            FxObj.SetActive(false);
            FusionAudio.PostEvent("SFX/General/CharacterSpawn", true);
            FxObj.SetActive(true);
            if (modelName == ModelName && ModelGO != null)
            {
                InitModel(ModelGO);
            }
            if (string.IsNullOrEmpty(modelName) || modelName == ModelName)
            {
                yield break;
            }
            if (!string.IsNullOrEmpty(ModelName))
            {
                PoolModel.DestroyModel(ModelGO);
            }
            ModelName = modelName;
            string prefab_path = "Bundles/Player/Variants/" + modelName + "-I";

            string variant_name = modelName;

            GameObject variantObj = null;
            var        listener   = this;

            Coroutine coroutine = PoolModel.GetModelAsync(prefab_path, Vector3.zero, Quaternion.identity, delegate(Object obj, object param)
            {
                variantObj = obj as GameObject;
                ModelGO    = variantObj;
                if (variantObj == null)
                {
                    return;
                }

                if (listener == null)
                {
                    EB.Debug.LogError("listener == null");
                    PoolModel.DestroyModel(variantObj);
                    return;
                }

                if (variant_name != ModelName)
                {
                    EB.Debug.LogError("variant_name != ModelName");
                    PoolModel.DestroyModel(variantObj);
                    return;
                }

                InitModel((GameObject)obj);
            }, null);

            yield return(coroutine);

            if (variantObj != null)
            {
                SetObjLayer(variantObj, 28);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 加载指定的部件资源
 /// </summary>
 /// <param name="onAssetLoaded">资源加载完成回调</param>
 /// <param name="target">挂载的父级对象</param>
 public void LoadAsset(PartitionAssetLoaded onAssetLoaded, GameObject target)
 {
     if (string.IsNullOrEmpty(_assetName))
     {
         EB.Debug.LogError("[PartitionObject]Asset name is empty or null!");
         return;
     }
     _onAssetLoaded = onAssetLoaded;
     _target        = target;
     PoolModel.GetModelAsync(_assetName, Vector3.zero, Quaternion.identity, (obj, prm) =>
     {
         OnOTALoaded(_assetName, obj as GameObject, true);
     }, null);
 }
Ejemplo n.º 3
0
        //加载模型
        public void LoadModel(Transform root, Vector3 beginPos, Vector3 endPos)
        {
            _beginPos   = beginPos;
            _endPos     = endPos;
            _maxMoveDis = endPos - beginPos;
            string prefab_path = $"Bundles/Player/Variants/{pd.ModelName}";

            PoolModel.GetModelAsync(prefab_path, UnityEngine.Vector3.zero, UnityEngine.Quaternion.identity, delegate(UnityEngine.Object obj, object param)
            {
                var variantObj   = obj as UnityEngine.GameObject;
                var variantTrans = variantObj.transform;
                if (variantObj == null)
                {
                    EB.Debug.LogError("[Racing]Failed to create model!!!");
                    return;
                }
                variantTrans.parent        = root.transform;
                variantTrans.localPosition = new Vector3(beginPos.x, beginPos.y, -50);
                _transform      = variantTrans;
                _moveController = InitModel(variantObj);
            }, null);
        }
Ejemplo n.º 4
0
        //载入选手
        private void LoadPlayerInfo(Player player)
        {
            //create model
            string prefab_path = $"Bundles/Player/Variants/{player.pd.ModelName}-I";

            PoolModel.GetModelAsync(prefab_path, UnityEngine.Vector3.zero, UnityEngine.Quaternion.identity, delegate(UnityEngine.Object obj, object param)
            {
                var variantObj = obj as UnityEngine.GameObject;
                if (variantObj == null)
                {
                    EB.Debug.LogError("[Racing]Failed to create model!!!");
                    return;
                }
                variantObj.transform.parent        = player.Node_Model.transform;
                variantObj.transform.localPosition = new Vector3(0, 0, -500);
                player.Model   = variantObj;
                player.ModelMC = InitModel(variantObj);

                if (currentView.Equals("bet"))
                {
                    playerLoadCnt += 1;
                    if (playerLoadCnt == 3)
                    {
                        var gd           = LTActivityRacingManager.Instance.GetGroupData(currentGroup);
                        int curBetPlayer = gd.CurBetPlayerNum;
                        if (curBetPlayer > 0)
                        {
                            RefreshModelLight(curBetPlayer);
                        }
                    }
                }
            }, null);

            //选手号码和名字刷新
            player.Label_Num.text  = EB.Localizer.Format("ID_RACING_BET_NUM", player.pd.Num.ToString());
            player.Label_Name.text = player.pd.Name;
        }
Ejemplo n.º 5
0
        private void CreatCharacterAsync()
        {
            if (character != null || m_Loading)
            {
                if (m_VariantName == CharacterVariantTemplate)
                {
                    EB.Debug.Log("already loaded variant {0}", CharacterVariantTemplate);
                    return;
                }
                else
                {
                    EB.Debug.Log("destroy last instance {0}", m_VariantName);
                    DestroyCharacter();
                }
            }

            if (string.IsNullOrEmpty(CharacterVariantTemplate))
            {
                return;
            }

            m_Loading     = true;
            m_VariantName = CharacterVariantTemplate;

            var    listener     = this;
            string variant_name = m_VariantName;
            string prefab_path  = variantPath;

            PoolModel.GetModelAsync(prefab_path, Vector3.zero, Quaternion.identity, delegate(Object obj, object param)
            {
                GameObject variantObj = obj as GameObject;
                if (variantObj == null)
                {
                    EB.Debug.LogError("UIBuddy3DModelCreater.CreatCharacter: No Resources for {0}", prefab_path);
                    return;
                }

                if (listener == null)
                {
                    EB.Debug.LogWarning("UIBuddy3DModelCreater.CreatCharacter: creator already destroyed");
                    PoolModel.DestroyModel(variantObj);
                    return;
                }

                if (variant_name != m_VariantName)
                {
                    EB.Debug.LogWarning("UIBuddy3DModelCreater.CreatCharacter: resource not match");
                    PoolModel.DestroyModel(variantObj);
                    return;
                }

                if (m_Character != null)
                {
                    EB.Debug.LogWarning("UIBuddy3DModelCreater.CreatCharacter: character set");
                    PoolModel.DestroyModel(variantObj);
                    return;
                }

                if (!m_Loading)
                {
                    EB.Debug.LogWarning("UIBuddy3DModelCreater.CreatCharacter: load canceled");
                    PoolModel.DestroyModel(variantObj);
                    return;
                }

                // everything is ok
                m_Loading = false;

                variantObj.transform.SetParent(m_CharacterContainer.transform);
                CharacterVariant variant = variantObj.GetComponent <CharacterVariant>();

                if (variant != null)
                {
                    variant.SyncLoad = true;

                    if (m_Partitions == null)
                    {
                        variant.InstantiateCharacter();
                    }
                    else
                    {
                        variant.InstantiateCharacter(m_Partitions);
                    }

                    m_Character = variant.CharacterInstance;
                }

                if (m_Character != null)
                {
                    m_Character.transform.SetParent(m_CharacterContainer.transform);
                    m_Character.transform.localScale    = modelScale;
                    m_Character.transform.localRotation = Quaternion.identity;
                    m_Character.transform.localPosition = Vector3.zero;
                    SetObjLayer(m_Character, m_CharacterContainer.gameObject.layer);
                    //StartCoroutine(SetParticleScaleMode(m_Character));
                    m_Avatar = m_Character.GetComponent <AvatarComponent>();
                    SetNeedToTransitionToIdle(m_Character, true);
                    //StartCoroutine(ScaleOutLine(m_Avatar)); //by pj 异步 开启协程判断
                }

                ShouldSetMipMapBias = true;

                if (mDMono.gameObject.activeInHierarchy)// && HuDState.IsLTLegionFBHudOpen)
                {
                    if (m_Coroutine != null)
                    {
                        StopCoroutine(m_Coroutine);
                        m_Coroutine = null;
                    }
                    m_Coroutine = StartCoroutine(SetMaterial());
                }
            }, null);
        }
Ejemplo n.º 6
0
        public void ChangeModel(string modelName, bool firstCreate, float scale = 1)
        {
            if (playerController == null)
            {
                EB.Debug.LogWarning("playerController is null");
                return;
            }

            if (playerController.CharacterModel != null && playerController.CharacterModel.ResourcePrefabNameMain.IndexOf(modelName) >= 0)
            {
                EB.Debug.LogWarning("ChangeModel: Aready Exist model={0}", modelName);
                return;
            }

            if (_HeadBar != null)
            {
                _HeadBar.ClearBars();
                _HeadBar = null;
            }

            try
            {
                CharacterVariant    CV = mDMono.transform.GetComponentInChildren <CharacterVariant>();
                MoveEditor.FXHelper FH = mDMono.transform.GetComponentInChildren <MoveEditor.FXHelper>();

                if (FH != null)
                {
                    FH.StopAll(true);
                }

                if (CV != null && GameEngine.Instance != null)
                {
                    SetObjLayer(CV.CharacterInstance, GameEngine.Instance.defaultLayer);
                    CV.Recycle();
                    PoolModel.DestroyModel(CV.gameObject);
                }

                if (playerController.SkinnedRigPrefab != null)
                {
                    PoolModel.DestroyModel(playerController.SkinnedRigPrefab);
                }
                ///
                playerController.Gender         = eGender.Male;
                playerController.CharacterModel = CharacterCatalog.Instance.GetModel(modelName);
                string prefabName = playerController.CharacterModel.PrefabNameFromGenderMain(playerController.Gender);
                PoolModel.GetModelAsync(prefabName, mDMono.transform.position, Quaternion.identity, (o, prm) =>
                {
                    var variantObj = o as GameObject;
                    variantObj.transform.SetParent(mDMono.transform);
                    variantObj.transform.localPosition = Vector3.zero;

                    CharacterVariant variant = variantObj.GetComponent <CharacterVariant>();
                    variant.SyncLoad         = true;
                    IDictionary partions     = GetPartitionsData(LoginManager.Instance.LocalUserId.Value);
                    variant.InstantiateCharacter(partions);
                    InitDataLookupSet();

                    playerController.SkinnedRigPrefab      = variant.CharacterInstance;
                    playerController.SkinnedRigPrefab.name = prefabName + "_Character";
                    playerController.SkinnedRigPrefab.tag  = "CharacterMesh";
                    playerController.SkinnedRigPrefab.transform.SetParent(mDMono.transform);
                    playerController.SkinnedRigPrefab.transform.localRotation = Quaternion.identity;
                    playerController.SkinnedRigPrefab.transform.localScale    = new Vector3(scale, scale, scale);
                    _combatController = mDMono.GetComponent <CombatController>();
                    _combatController.Initialize(playerController.SkinnedRigPrefab.transform, playerController.CharacterModel, 1 << LayerMask.NameToLayer("Enemy"));

                    playerController.CharacterComponent = mDMono.GetComponent <CharacterComponent>();
                    playerController.CharacterComponent.OnSpawn(playerController.CharacterModel, playerController.SkinnedRigPrefab, -1, false);

                    _HeadBar = playerController.SkinnedRigPrefab.GetMonoILRComponent <HeadBars2D>(false);
                    if (_HeadBar == null)
                    {
                        _HeadBar = playerController.SkinnedRigPrefab.AddMonoILRComponent <HeadBars2D>("Hotfix_LT.UI.HeadBars2D");
                    }

                    if (mDMono.GetComponent <Collider>() != null && mDMono.GetComponent <Collider>() is BoxCollider)
                    {
                        BoxCollider box = mDMono.GetComponent <Collider>() as BoxCollider;
                        box.size        = new Vector3(1.5f, 1.5f, 1.5f) + new Vector3(0, playerController.CharacterModel.heightOffset, 0);
                        box.center      = new Vector3(0, box.size.y / 2.0f, 0);
                    }

                    _muzzle = GameUtils.SearchHierarchyForBone(playerController.SkinnedRigPrefab.transform, "muzzle");
                    if (null == _muzzle)
                    {
                        _muzzle = mDMono.transform;
                    }

                    if (firstCreate)
                    {
                        LevelOwnerComponent.AssignLevelOwner(mDMono.gameObject); // this must be called after PlayerManager.RegisterPlayerController(this);
                    }
                    _avatar             = playerController.SkinnedRigPrefab.GetComponent <AvatarComponent>();
                    _shouldSetHideColor = !PerformanceManager.Instance.CurrentEnvironmentInfo.slowDevice;

                    if (!firstCreate)
                    {
                        PlayerDataLookupSet PDLS = playerController.SkinnedRigPrefab.transform.GetDataLookupILRComponent <PlayerDataLookupSet>();
                        if (PDLS != null)
                        {
                            PDLS.UserId = playerController.playerUid;
                        }
                    }

                    MoveController mc = playerController.SkinnedRigPrefab.GetComponent <MoveController>();
                    if (mDMono != null && mDMono.GetComponent <CharacterComponent>().State != eCampaignCharacterState.Idle)
                    {
                        mc.TransitionTo(MoveController.CombatantMoveState.kLocomotion);
                    }
                }, null);
            }
            catch (System.NullReferenceException e)
            {
                EB.Debug.LogError(e.ToString());
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// ATTENTION: 已改为异步,待观察是否有问题
        /// </summary>
        /// <param name="characterClass"></param>
        /// <param name="userid"></param>
        /// <param name="size"></param>
        public void CreateOtherPlayer(string characterClass, long userid, float size)
        {
            try
            {
                playerController.Gender         = eGender.Male;
                playerController.CharacterModel = CharacterCatalog.Instance.GetModel(characterClass);
                string      prefabName = playerController.CharacterModel.PrefabNameFromGenderMain(playerController.Gender);
                IDictionary partions   = GetPartitionsData(userid);
                PoolModel.GetModelAsync(prefabName, mDMono.transform.position, Quaternion.identity, (o, prm) =>
                {
                    var variantObj = o as GameObject;
                    variantObj.transform.SetParent(mDMono.transform);
                    variantObj.transform.localPosition = Vector3.zero;

                    CharacterVariant variant = variantObj.GetComponent <CharacterVariant>();
                    variant.InstantiateCharacter(partions);

                    playerController.SkinnedRigPrefab = variant.CharacterInstance;
                    if (playerController.SkinnedRigPrefab == null)
                    {
                        EB.Debug.LogError("SkinnedRigPrefab is NULL");
                        return;
                    }

                    #region 其他玩家的一些设置After Create
                    //SkinnedRigPrefab = PoolModel.GetNext(prefabName, transform.position, Quaternion.identity) as GameObject;
                    //_skinnedRigPrefabInstance = Instantiate(EB.Assets.Load(prefabName), transform.position, Quaternion.identity) as GameObject;
                    playerController.SkinnedRigPrefab.name = prefabName + "_Character";
                    playerController.SkinnedRigPrefab.tag  = "CharacterMesh";
                    playerController.SkinnedRigPrefab.transform.SetParent(mDMono.transform);
                    playerController.SkinnedRigPrefab.transform.localRotation = Quaternion.identity;
                    playerController.SkinnedRigPrefab.transform.localScale    = new Vector3(size, size, size);

                    // only enable once we have our skinned rig prefab instance resolved
                    _combatController = mDMono.GetComponent <CombatController>();
                    _combatController.Initialize(playerController.SkinnedRigPrefab.transform, playerController.CharacterModel, 1 << LayerMask.NameToLayer("Enemy"));

                    playerController.CharacterComponent = mDMono.GetComponent <CharacterComponent>();
                    playerController.CharacterComponent.OnSpawn(playerController.CharacterModel, playerController.SkinnedRigPrefab, -1, false);
                    //bool isUseCharacterRecord = (_viewRPC == null || _viewRPC.isMine);
                    //CharacterRecord characterRecord = null;
                    //NPC名字
                    _HeadBar = playerController.SkinnedRigPrefab.GetMonoILRComponent <HeadBars2D>(false);
                    if (_HeadBar == null)
                    {
                        _HeadBar = playerController.SkinnedRigPrefab.AddMonoILRComponent <HeadBars2D>("Hotfix_LT.UI.HeadBars2D");
                    }
                    if (mDMono.GetComponent <Collider>() != null && mDMono.GetComponent <Collider>() is BoxCollider)
                    {
                        BoxCollider box = mDMono.GetComponent <Collider>() as BoxCollider;
                        box.size        = new Vector3(1.5f, 1.5f, 1.5f) + new Vector3(0, playerController.CharacterModel.heightOffset, 0);
                        box.center      = new Vector3(0, box.size.y / 2.0f, 0);
                    }
                    //if (isUseCharacterRecord)
                    //{
                    //	characterRecord = CharacterManager.Instance.CurrentCharacter;
                    //}
                    _muzzle = GameUtils.SearchHierarchyForBone(playerController.SkinnedRigPrefab.transform, "muzzle");
                    if (null == _muzzle)
                    {
                        _muzzle = mDMono.transform;
                    }

                    //ToDo:看起来无用,暂时屏蔽
                    //PlayMakerGlobals.Instance.Variables.FindFsmGameObject("Player" + (_initialPlayerIndex + 1)).Value =mDMono . gameObject;
                    #endregion
                }, null);
            }
            catch (System.NullReferenceException e)
            {
                EB.Debug.LogError(e.ToString());
            }
        }