Exemple #1
0
    protected override GameObject Create()
    {
        IPlacementArea targetArea  = (IPlacementArea)args[0];
        IntVector2     destination = (IntVector2)args[1];


        long       id    = currentTargetLevelData.monster.Id;
        GameObject agent = Instantiate(Resources.Load <GameObject>("Prefab/Monster/" + id), transform);

        Animator          animator          = agent.GetComponent <Animator>();
        CharacterAnimator characterAnimator = GetComponentInParent <CharacterAnimator>();
        AIBehaviors       ai = GetComponent <AIBehaviors>();
        AIAnimationStates animationStates = GetComponentInParent <AIAnimationStates>();

        characterAnimator.anim = animator;


        PatrolState patrolState = ai.GetState <PatrolState>();

        Transform[] transforms = new Transform[2];
        transforms[0] = targetArea.transform;
        transforms[1] = targetArea.transform;
        patrolState.SetPatrolPoints(transforms);
        patrolState.GetTrigger <WithinDistanceTrigger>().center = transform;
        //IdleState ldleState = ai.GetState<IdleState>();
        //ldleState.currentNode = targetArea.transform;
        //ldleState.GetTrigger<WithinDistanceTrigger>().center = targetArea.transform;

        AttackState attackState = ai.GetState <AttackState>();

        attackState.GetTrigger <BeyondDistanceTrigger>().center = targetArea.transform;

        //AI
        //BaseState baseState = ComponentHelper.AddComponentByName(ai.transform.Find("States").gameObject, "GotHitState") as BaseState;
        //baseState.name = "GotHitState";
        //GotHitState gotHitState = baseState as GotHitState;
        //gotHitState.hitStateDuration = 0;
        //gotHitState.returnToPreviousState = true;
        //gotHitState.animationStates[0] = animationStates.GetStateWithName("Hit");
        //ai.AddSubTrigger(gotHitState);

        //初始化
        UnityEngine.Object alignment = Resources.Load("Data/Alignment/TowerAlignment");

        if (this.configuration.alignment == null)
        {
            this.configuration.alignment = new SerializableIAlignmentProvider();
            this.configuration.alignment.unityObjectReference = alignment;
        }
        else
        {
            this.configuration.alignment.unityObjectReference = alignment;
        }

        ai.Initialize();
        //放置
        UpdateTargetPos(targetArea, destination);
        return(agent);
    }