Exemple #1
0
        private MoveController InitModel(GameObject variantObj)
        {
            CharacterVariant variant = variantObj.GetComponent <CharacterVariant>();

            variant.InstantiateCharacter();
            UnityEngine.GameObject character = variant.CharacterInstance;
            character.transform.SetParent(variant.transform);
            character.transform.localScale    = UnityEngine.Vector3.one * 0.2f;
            character.transform.localRotation = UnityEngine.Quaternion.Euler(0, 90, -40);
            character.transform.localPosition = Vector3.zero;
            SetObjLayer(variantObj, GameEngine.Instance.ui3dLayer);
            MoveController mc = character.GetComponent <MoveController>();

            return(mc);
        }
Exemple #2
0
        private void InitModel(GameObject variantObj)
        {
            variantObj.transform.SetParent(mDMono.transform, false);
            variantObj.transform.localScale    = Vector3.one;
            variantObj.transform.localRotation = Quaternion.identity;
            CharacterVariant variant = variantObj.GetComponent <CharacterVariant>();

            variant.InstantiateCharacter();

            GameObject character = variant.CharacterInstance;

            character.transform.parent        = variant.transform;
            character.transform.localScale    = ModelScale;
            character.transform.localRotation = Quaternion.Euler(ModelRotation);
            character.transform.localPosition = ModelPosition;

            MoveController mc = character.GetComponent <MoveController>();

            if (mc != null)
            {
                mc.enabled = false;
                mc.enabled = true;
                System.Action fn = () => {
                    mc.TransitionTo(MoveController.CombatantMoveState.kEntry);
                    needToTransitionToIdle = true;
                };
                if (!mc.IsInitialized)
                {
                    mc.RegisterInitSuccCallBack(fn);
                }
                else
                {
                    fn();
                }
            }
            StartCoroutine(SetParticleOrder(character));
            SetObjLayer(variantObj, 28);
        }
Exemple #3
0
        private void OnSpawnFun(int spawnAnimationIndex = -1, bool playEffect = false, System.Action callback = null)
        {
            enemyController.SpawnLocation = mDMono.transform.position;
            EB.Assets.LoadAsync(enemyController.CharacterModel.ResourcePrefabNameMain, typeof(GameObject), (obj) =>
            {
                GameObject variantObj       = GameObject.Instantiate(obj, mDMono.transform.position, Quaternion.identity) as GameObject;
                variantObj.transform.parent = mDMono.transform;
                CharacterVariant variant    = variantObj.GetComponent <CharacterVariant>();
                variant.InstantiateCharacter();
                enemyController.SkinnedRigPrefab                         = variant.CharacterInstance;
                enemyController.SkinnedRigPrefab.name                    = enemyController.CharacterModel.ResourcePrefabNameMain + "_Character";
                enemyController.SkinnedRigPrefab.tag                     = "CharacterMesh";
                enemyController.SkinnedRigPrefab.transform.parent        = mDMono.transform;
                enemyController.SkinnedRigPrefab.transform.localRotation = Quaternion.identity;
                enemyController.SkinnedRigPrefab.transform.localPosition = Vector3.zero;
                _renderer = enemyController.SkinnedRigPrefab.GetComponentInChildren <Renderer>();

                // Create our death material just once
                if (enemyController.CharacterModel.resourceDirectory == eResourceDirectory.Enemies)
                {
                    if (!_renderer.sharedMaterial.shader.name.EndsWith("-Alpha"))
                    {
                        string alphaShaderName = _renderer.sharedMaterial.shader.name + "-Alpha";
                        Shader alphaShader     = Shader.Find(alphaShaderName);
                        if (alphaShader != null)
                        {
                            // Cache the original, unmodified material
                            _originalMaterial = _renderer.sharedMaterial;

                            // Cache a material copy (this will make a new instance of the shader material)
                            _deathMaterial = _renderer.material;

                            _renderer.material = _originalMaterial;

                            // Set the new shader and keywords on the material copy
                            _deathMaterial.shader         = alphaShader;
                            _deathMaterial.shaderKeywords = new string[] { "ALPHA_ON" };
                            _deathMaterial.shaderKeywords = new string[] { "DEATH_ON" };
                        }
                    }
                    else
                    {
                        DebugSystem.Log("Material's shader is set to -Alpha version.\nMaterial's shader may not be set correctly in source or not set back to original value from pool.{0}EnemyController{1}", enemyController.CharacterModel.prefabName, LogType.Warning);
                    }
                }

                CombatController combatController = mDMono.GetComponent <CombatController>();
                combatController.Initialize(enemyController.SkinnedRigPrefab.transform, enemyController.CharacterModel, 1 << LayerMask.NameToLayer("Player"));
                enemyController.CharacterComponent.OnSpawn(enemyController.CharacterModel, enemyController.SkinnedRigPrefab, spawnAnimationIndex, playEffect);

                //回收后再打开组件检测
                if (enemyController.SkinnedRigPrefab != null)
                {
                    monoArray = enemyController.SkinnedRigPrefab.GetComponents <MonoBehaviour>();
                    for (int i = 0; i < monoArray.Length; i++)
                    {
                        if (monoArray[i] != null && !monoArray[i].enabled)
                        {
                            monoArray[i].enabled = true;
                        }
                    }
                    Animator mAnimator = enemyController.SkinnedRigPrefab.GetComponent <Animator>();
                    if (mAnimator != null && !mAnimator.enabled)
                    {
                        mAnimator.enabled = true;
                    }
                }

                //NPC名字
                _HeadBar = enemyController.SkinnedRigPrefab.GetMonoILRComponent <HeadBars2D>(false);
                if (_HeadBar == null && enemyController.SkinnedRigPrefab.transform.parent.name.CompareTo("EnemySpawns_11") != 0) //主城的世界Boss不需要创建
                {
                    _HeadBar = enemyController.SkinnedRigPrefab.AddMonoILRComponent <HeadBars2D>("Hotfix_LT.UI.HeadBars2D");
                }
//                if (_fsm != null)
//                {
//                    _fsm.Fsm.Stop();
//                    _fsm.Reset();
//                    _fsm.SetFsmTemplate(enemyController.CharacterModel.AITrigger);
//                    _fsm.Fsm.Start();
//                }

                _bestTarget = null;

                if (enemyController.CharacterModel.team == eTeamId.Interactable)
                {
                    enemyController.CharacterComponent.UseAdvancedLocomotionAnimation = true;
                }
                else
                {
                    enemyController.CharacterComponent.UseAdvancedLocomotionAnimation = false;
                }

                callback?.Invoke();
            });
        }
Exemple #4
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);
        }
Exemple #5
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());
            }
        }
Exemple #6
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());
            }
        }