protected virtual void InitServices() { GameSettings = new GameSettings(this); InputManager = new InputManager(this); CollisionsManager = new CollisionsManager(this); RandomBehavior = new RandomBehavior(this); ScoreManager = new ScoreManager(this); SoundManager = new SoundManager(this); }
// Use this for initialization void Start() { // Get access to the unit we are controlling unit = GetComponent <Unit>(); // Install an on death function to remove all logic from the unit unit.installDeathListener(delegate() { root = new Leaf(delegate() { return(BehaviorReturnCode.Success); }); }); //////////////////////////////////////////////////////////////////// ///////////////////// PATROLLING/IDLE ////////////////////////// //////////////////////////////////////////////////////////////////// Leaf checkIsPatrolling = new Leaf(delegate() { if (unit.patrolling == false) { return(BehaviorReturnCode.Failure); } return(BehaviorReturnCode.Success); }); Leaf patrolPath = new Leaf(delegate() { // Check if we have a patrol path to make use of PatrolPath path = unit.GetComponent <PatrolPath>(); if (path != null) { unit.setDestination(path.patrolPointHolder.transform.GetChild(path.nextPatrolPoint()).position); unit.patrolling = true; return(BehaviorReturnCode.Success); } return(BehaviorReturnCode.Failure); }); Leaf patrolArea = new Leaf(delegate() { // If we have a patrol area use that to find our random position PatrolArea area = unit.GetComponent <PatrolArea>(); if (area == null) { return(BehaviorReturnCode.Failure); } // Generate our patrol position Vector3 newTargetPosition = Vector3.zero; Vector3 patrolPosition = area.patrolAreaObject.transform.position; float patrolRange = area.patrolAreaObject.transform.localScale.x; if (unit.findRandomPointOnNavMesh(patrolPosition, patrolRange, out newTargetPosition)) { // Start moving towards our new random point unit.setDestination(newTargetPosition); unit.patrolling = true; return(BehaviorReturnCode.Success); } return(BehaviorReturnCode.Failure); }); Leaf manualPatrol = new Leaf(delegate() { // Check to see if the unit manually patrols ManualPatrol manualPatrolling = unit.GetComponent <ManualPatrol>(); if (manualPatrolling == null) { return(BehaviorReturnCode.Failure); } // If the unit manually patrols wait for a new patrol position if (manualPatrolling.getPatrolConsumed()) { return(BehaviorReturnCode.Running); } // If we have a new patrol position consume it unit.setDestination(manualPatrolling.getPatrolPosition()); unit.patrolling = true; return(BehaviorReturnCode.Success); }); Leaf patrolFollowLeader = new Leaf(delegate() { // Check to see if the unit has a leader to follow FollowLeader leaderToFollow = unit.GetComponent <FollowLeader>(); if (leaderToFollow == null) { return(BehaviorReturnCode.Failure); } // If the unit has a leader follow it but don't start patrolling. This allows // the unit to continuously follow the leader as it moves. unit.setDestination(leaderToFollow.getFollowPosition()); return(BehaviorReturnCode.Success); }); Leaf patrolRandom = new Leaf(delegate() { // If we don't have a defined path generate a random position Vector3 patrolCenterPosition = transform.position; float patrolRange = unit.patrolSearchRange; Vector3 newTargetPosition = Vector3.zero; // Generate our patrol position if (unit.findRandomPointOnNavMesh(patrolCenterPosition, patrolRange, out newTargetPosition)) { // Start moving towards our new random point unit.setDestination(newTargetPosition); unit.patrolling = true; return(BehaviorReturnCode.Success); } return(BehaviorReturnCode.Failure); }); Selector selectPatrolPath = new Selector(checkIsPatrolling, patrolPath, patrolArea, manualPatrol, patrolFollowLeader, patrolRandom); Leaf sendPatrolToSquad = new Leaf(delegate() { SquadLeader squad = unit.GetComponent <SquadLeader>(); if (squad == null) { return(BehaviorReturnCode.Success); } // If the unit is part of a squad inform the subordinates of a new patrol position squad.issueNewTroopMovement(); return(BehaviorReturnCode.Success); }); Leaf waitToReachDestination = new Leaf(delegate() { if (unit.isMovingNavMesh() && unit.patrolling) { return(BehaviorReturnCode.Running); } // If the unit is a follower then don't bother waiting to reach a destination else if (unit.GetComponent <FollowLeader>() != null) { return(BehaviorReturnCode.Failure); } else { return(BehaviorReturnCode.Success); } }); Leaf stopRunning = new Leaf(delegate() { unit.anim.SetBool("Running", false); unit.agent.isStopped = true; return(BehaviorReturnCode.Success); }); Leaf playIdleAnim = new Leaf(delegate() { unit.anim.SetTrigger("PatrolIdleAnim1Trigger"); return(BehaviorReturnCode.Success); }); RandomBehavior idleRand = new RandomBehavior(.1f, playIdleAnim); Timer playIdleAnimTimer = new Timer(1.0f, idleRand); Leaf stopPatrolling = new Leaf(delegate() { unit.patrolling = false; return(BehaviorReturnCode.Success); }); Timer stopPatrollingTimer = new Timer(unit.patrolWaitTime, stopPatrolling); StateSequence patrolLogic = new StateSequence(selectPatrolPath, sendPatrolToSquad, waitToReachDestination, stopRunning, playIdleAnimTimer, stopPatrollingTimer); //////////////////////////////////////////////////////////////////// ///////////////////// AGGRO/ATTACKING ////////////////////////// //////////////////////////////////////////////////////////////////// Leaf dropTargetLogic = new Leaf(delegate() { // If we don't have a target continue if (unit.target == null) { return(BehaviorReturnCode.Success); } // If our target is dying search for a new one if (unit.target.isUnitDying()) { unit.target = null; } // If our target it outside of our aggro radius clear it if (unit.distanceToTarget() > unit.enemySearchRadius) { unit.target = null; } return(BehaviorReturnCode.Success); }); Leaf acquireTarget = new Leaf(delegate() { // If we already have a living target just return success if (unit.target != null) { return(BehaviorReturnCode.Success); } // Search for the closest enemy IUnit foundTarget = unit.findClosestTarget(); // If we were able to find a target return success, otherwise we failed if (foundTarget != null) { // If we find a new target stop patrolling unit.patrolling = false; unit.target = foundTarget; return(BehaviorReturnCode.Success); } else { return(BehaviorReturnCode.Failure); } }); Leaf checkToAttack = new Leaf(delegate() { // If we are already attacking continue if (unit.attacking) { return(BehaviorReturnCode.Success); } // Check if our target is within the attack radius and isn't already dying if (unit.distanceToTarget() <= unit.attackRadius) { // Face the target Quaternion lookRot = Quaternion.LookRotation(unit.target.getGameObject().transform.position - unit.transform.position); unit.transform.rotation = Quaternion.Euler(0, lookRot.eulerAngles.y, 0); // Stop the navmesh agent unit.agent.isStopped = true; // Stop running unit.anim.SetBool("Running", false); // Play our attack animation unit.anim.SetTrigger("AttackTrigger"); unit.attacking = true; } else { unit.attacking = false; } return(BehaviorReturnCode.Success); }); Leaf moveToTarget = new Leaf(delegate() { // If we're still attacking wait to finish if (unit.attacking == true) { return(BehaviorReturnCode.Success); } // Start moving towards our target unit.setDestination(unit.target.getGameObject().transform.position); return(BehaviorReturnCode.Success); }); Sequence attackSequence = new Sequence(dropTargetLogic, acquireTarget, checkToAttack, moveToTarget); //////////////////////////////////////////////////////////////////// ////////////////////////// ROOT //////////////////////////////// //////////////////////////////////////////////////////////////////// root = new Selector(attackSequence, patrolLogic); }
/// <summary> /// Determines whether the specified Object is equal to the current Object. /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Equals(object obj) { if (obj == null) { return(false); } if (Object.ReferenceEquals(this, obj)) { return(true); } if (this.GetType() != obj.GetType()) { return(false); } var other = (VLLibraryQuestion)obj; //reference types if (!Object.Equals(ValidationField1, other.ValidationField1)) { return(false); } if (!Object.Equals(ValidationField2, other.ValidationField2)) { return(false); } if (!Object.Equals(ValidationField3, other.ValidationField3)) { return(false); } if (!Object.Equals(RegularExpression, other.RegularExpression)) { return(false); } if (!Object.Equals(QuestionText, other.QuestionText)) { return(false); } if (!Object.Equals(Description, other.Description)) { return(false); } if (!Object.Equals(HelpText, other.HelpText)) { return(false); } if (!Object.Equals(FrontLabelText, other.FrontLabelText)) { return(false); } if (!Object.Equals(AfterLabelText, other.AfterLabelText)) { return(false); } if (!Object.Equals(InsideText, other.InsideText)) { return(false); } if (!Object.Equals(RequiredMessage, other.RequiredMessage)) { return(false); } if (!Object.Equals(ValidationMessage, other.ValidationMessage)) { return(false); } if (!Object.Equals(OtherFieldLabel, other.OtherFieldLabel)) { return(false); } //value types if (!QuestionId.Equals(other.QuestionId)) { return(false); } if (!m_category.Equals(other.m_category)) { return(false); } if (!QuestionType.Equals(other.QuestionType)) { return(false); } if (!IsRequired.Equals(other.IsRequired)) { return(false); } if (!RequiredBehavior.Equals(other.RequiredBehavior)) { return(false); } if (!RequiredMinLimit.Equals(other.RequiredMinLimit)) { return(false); } if (!RequiredMaxLimit.Equals(other.RequiredMaxLimit)) { return(false); } if (!AttributeFlags.Equals(other.AttributeFlags)) { return(false); } if (!ValidationBehavior.Equals(other.ValidationBehavior)) { return(false); } if (!RandomBehavior.Equals(other.RandomBehavior)) { return(false); } if (!OtherFieldType.Equals(other.OtherFieldType)) { return(false); } if (!OtherFieldRows.Equals(other.OtherFieldRows)) { return(false); } if (!OtherFieldChars.Equals(other.OtherFieldChars)) { return(false); } if (!OptionsSequence.Equals(other.OptionsSequence)) { return(false); } if (!ColumnsSequence.Equals(other.ColumnsSequence)) { return(false); } if (!RangeStart.Equals(other.RangeStart)) { return(false); } if (!RangeEnd.Equals(other.RangeEnd)) { return(false); } return(true); }