Пример #1
0
    public void OnSpawn(CharacterModel model, GameObject skinnedRigPrefabInstance, int spawnAnimationIndex, bool playSpawnEffect)
    {
        // For EnemyControllers, when Awake is called the child prefab containing the animator hasn't been set
        // So we need this special method here to initialize the reference to the animator once the full
        // initialization has been done
        _animator = skinnedRigPrefabInstance.GetComponent <Animator>();
        if (_animator == null)
        {
#if DEBUG
            DebugSystem.Log("Failed to find animator on rigged prefab: searching for animator in children", "CharacterComponent", LogType.Warning);
#endif
            _animator = skinnedRigPrefabInstance.GetComponentInChildren <Animator>();
        }

        //_animationController.Initialize(_animator, typeof(eCharacterAnimationState), typeof(eCharacterAnimationParameter));
        //_animationController.onAnimationEventBegin += OnAnimationEventBegin;

        _moveController.Initialize(_animator);

        _conditionComponent.SetAnimator(_animator);

        _characterModel = model;

        if (_combatController != null)
        {
            _combatController.SetAutoAttack(_characterModel.autoAttack);
        }

        if (_characterModel.team == eTeamId.Interactable)
        {
            if (GetComponent <InteractableComponent>() == null)
            {
                gameObject.AddComponent <InteractableComponent>();
            }
        }
        else if (_characterModel.team == eTeamId.Interactable)
        {
            gameObject.layer = LayerMask.NameToLayer("Enemy");
        }

        //GetComponent<Collider>().enabled = true;

        if (_locomotionComponent != null)
        {
            _locomotionComponent.MaxSpeed = model.speed;
            _locomotionComponent.Enabled  = true;
        }

        RVOController rvoController = GetComponent <RVOController>();
        if (rvoController != null)
        {
            rvoController.radius = model.rvoRadius;
        }

        //EventManager.instance.Raise(new OnSpawnEvent(gameObject));

        if (playSpawnEffect)        // && _characterModel.characterClass.onSpawnEffect != null)
        {
            //EffectContext newContext = EffectContext.Create();
            //newContext.Initialize(gameObject, gameObject);
            //_characterModel.characterClass.onSpawnEffect.CreateAndCast(gameObject, gameObject, newContext);
        }

        //如果没有寻路目标,才需初始化转换动作状态ChangeState
        if (State == eCampaignCharacterState.Idle)
        {
            ChangeState(eCampaignCharacterState.Idle);
        }


        if (GetComponent <Collider>() != null && GetComponent <Collider>() is BoxCollider)
        {
            BoxCollider box = GetComponent <Collider>() as BoxCollider;
            //box.size = new Vector3(1.75f, 1.75f, 1.75f) * _characterModel.CharacterRadiusNormalized + new Vector3(0, _characterModel.heightOffset, 0);
            //这里暂时把box的大小设置为定值, 因为_characterModel.CharacterRadiusNormalized 目前�?  为了人物之间没有碰撞  后期可以改动为另一个变量来设置合体大小
            //lzt-2015-7-21
            if (GetComponent <PlayerController>() != null)
            {
                box.size = new Vector3(1.5f, 1.5f, 1.5f) + new Vector3(0, _characterModel.heightOffset, 0);
            }
            else if (GetComponent <EnemyController>() != null)
            {
                box.size = new Vector3(2f, 2f, 2f) + new Vector3(0, _characterModel.heightOffset, 0);
            }
            box.center = new Vector3(0, box.size.y / 2.0f, 0);
        }
    }