public override bool checkProceduralPrecondition(GameObject agent) { // retreive objects if (blocks == null) { blocks = FindObjectsOfType(typeof(ChoppingBlockComponent)) as ChoppingBlockComponent[]; } // find closest if (closest == null) { // linq 'OrderBy extension method for collections' finds nearest closest = blocks.OrderBy(t => Vector3.Distance(transform.position, t.transform.position)).FirstOrDefault(); } // ensure we have a value to set if (closest != null) { // set GoapAction target target = closest.gameObject; } // return our success return(closest != null); }
public override bool checkProceduralPrecondition (GameObject agent) { // find the nearest chopping block that we can chop our wood at ChoppingBlockComponent[] blocks = (ChoppingBlockComponent[]) UnityEngine.GameObject.FindObjectsOfType ( typeof(ChoppingBlockComponent) ); ChoppingBlockComponent closest = null; float closestDist = 0; foreach (ChoppingBlockComponent block in blocks) { if (closest == null) { // first one, so choose it for now closest = block; closestDist = (block.gameObject.transform.position - agent.transform.position).magnitude; } else { // is this one closer than the last? float dist = (block.gameObject.transform.position - agent.transform.position).magnitude; if (dist < closestDist) { // we found a closer one, use it closest = block; closestDist = dist; } } } if (closest == null) return false; targetChoppingBlock = closest; target = targetChoppingBlock.gameObject; return closest != null; }
public override bool checkProceduralPrecondition(GameObject agent) { // find the nearest chopping block that we can chop our wood at ChoppingBlockComponent[] blocks = (ChoppingBlockComponent[])UnityEngine.GameObject.FindObjectsOfType(typeof(ChoppingBlockComponent)); ChoppingBlockComponent closest = null; float closestDist = 0; foreach (ChoppingBlockComponent block in blocks) { if (closest == null) { // first one, so choose it for now closest = block; closestDist = (block.gameObject.transform.position - agent.transform.position).magnitude; } else { // is this one closer than the last? float dist = (block.gameObject.transform.position - agent.transform.position).magnitude; if (dist < closestDist) { // we found a closer one, use it closest = block; closestDist = dist; } } } if (closest == null) { return(false); } targetChoppingBlock = closest; target = targetChoppingBlock.gameObject; return(closest != null); }
public override void reset() { chopped = false; targetChoppingBlock = null; startTime = 0; }
/// <summary> /// Resets the action to its default values, so it can be used again. /// </summary> public override void Reset() { _chopped = false; _targetChoppingBlock = null; StartTime = 0; }
public override void reset () { chopped = false; targetChoppingBlock = null; startTime = 0; }