예제 #1
0
    void Awake()
    {
        AIBehaviors ai    = GetComponent <AIBehaviors>();
        PatrolState state = ai.GetState <PatrolState>();

        state.SetPatrolPoints(patrolPoints);
    }
예제 #2
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);
    }
예제 #3
0
    protected override GameObject Create()
    {
        long       id    = currentTargetLevelData.monster.Id;
        GameObject agent = Instantiate(Resources.Load <GameObject>("Prefab/Monster/" + id), transform);

        LootDrop          lootDrop          = GetComponentInParent <LootDrop>();
        DamageTaker       damageTaker       = GetComponentInParent <DamageTaker>();
        UnitInfo          unitInfo          = GetComponentInParent <UnitInfo>();
        AIBehaviors       ai                = GetComponentInParent <AIBehaviors>();
        CharacterAnimator characterAnimator = GetComponentInParent <CharacterAnimator>();

        Node node = (Node)args[0];
        //OffensiveState offensiveState = ai.GetState<OffensiveState>();
        //offensiveState.currentNode = node;
        //offensiveState.GetTrigger<WithinDistanceTrigger>().center = transform;


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

        patrolState.SetPatrolPoints(node.transform.parent);
        patrolState.GetTrigger <WithinDistanceTrigger>().center = transform;

        //AttackState attackState = ai.GetState<AttackState>();
        //attackState.GetTrigger<BeyondDistanceTrigger>().center = transform;
        //动画
        Animator animator = agent.GetComponent <Animator>();
        RuntimeAnimatorController runtimeAnimatorController = Resources.Load <RuntimeAnimatorController>("Model/" + id + "/Animation/Controller");

        if (runtimeAnimatorController != null)
        {
            animator.runtimeAnimatorController = runtimeAnimatorController;
        }
        characterAnimator.anim = animator;

        damageTaker.healthBar = agent.transform.Find("HealthBar");
        damageTaker.sprite    = GetComponentInChildren <SpriteRenderer>();


        //信息
        unitInfo.unitName      = currentTargetLevelData.monster.Name;
        unitInfo.primaryText   = currentTargetLevelData.monster.LootDropped.ToString();
        unitInfo.secondaryText = currentTargetLevelData.monster.PhyAttackMin + "-" + currentTargetLevelData.monster.PhyAttackMax;

        //属性
        lootDrop.lootDropped = currentTargetLevelData.monster.LootDropped;
        UnityEngine.Object alignment = Resources.Load("Data/Alignment/EnemyAlignment");

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

        //总开关
        damageTaker.Initialize();
        ai.Initialize();
        this.gameObject.name = id.ToString();
        return(agent);
    }