/* * doMethodsForSplitting method will call all the methods for splitting the the polygons with an object\ * Parameter: (AIObjects) objectToSplitWith is the object that the polygons need to be split by * (ref int) polygonToSplitCount is the number of polygons that need to be split */ void doMethodsForSplitting(AIObjects objectToSplitWith, ref int polygonToSplitCount) { int[] indicesWithObject = markPolygonsThatSplitWithObject(ref polygonToSplitCount, objectToSplitWith); AIPolygon[] splitingPolygons = getPolygonsThatWillBeSplit(indicesWithObject, polygonToSplitCount); AIPolygon[] tempArray = splitPolygons(splitingPolygons, objectToSplitWith); if (tempArray == null) { return; } AIPolygon[] newArray = new AIPolygon[tempArray.Length + polygonArray.Length - polygonToSplitCount]; int newArrayCount = 0; for (int count = 0; count < polygonArray.Length; count++) { if (indicesWithObject[count] != 1) { newArray[newArrayCount] = new AIPolygon(polygonArray[count].getVertices(), newArrayCount); newArrayCount++; } } for (int count = 0; count < tempArray.Length; count++) { newArray[newArrayCount] = new AIPolygon(tempArray[count].getVertices(), newArrayCount); newArrayCount++; } setNewArray(newArray); }
// Method for putting random values in AI groups. void RandomizeGroups() { for (int i = 0; i < AIObject.Count(); i++) { if (AIObject[i].randomizeStats) { AIObject[i] = new AIObjects(AIObject[i].AIGroupName, AIObject[i].objectPrefab, Random.Range(1, 30), Random.Range(1, 20), Random.Range(1, 10), AIObject[i].randomizeStats); } } }
void RandomiseGroups() { for (int i = 0; i < AIObject.Count(); i++) { if (AIObject[i].randomizeStats) { //AIObjects[i].maxAI = Random.Range(1, 30); AIObject[i] = new AIObjects(AIObject[i].AIGroupName, AIObject[i].objectPrefab, Random.Range(1, 30), Random.Range(1, 20), Random.Range(1, 10), AIObject[i].randomizeStats); AIObject[i].setValues(Random.Range(1, 30), Random.Range(1, 20), Random.Range(1, 10)); } } }
private void OnTriggerStay(Collider other) { if (other.tag == "Enemy") { AIObjects ai = other.GetComponent <AIObjects>(); if (ai != null) { if (ai.Heading() == PositiveDirection) { ai.Jump(); } } } }
/* * markPolygonsThatSplitWithObject method make an array that consist of the indices for all the polygons that need to be * split by an object * Parameter: (ref int)polygonToSplitCount is the current list of the polygons that need to be split * (AIObject) objectToSplitWith is the object that needs to be split * Return: (int[]) * an array of indices that are the polygons that need to be split */ int[] markPolygonsThatSplitWithObject(ref int polygonToSplitCount, AIObjects objectToSplitWith) { int[] indicesWithObject = new int[polygonArray.Length]; polygonToSplitCount = 0; for (int count2 = 0; count2 < polygonArray.Length; count2++) { indicesWithObject [count2] = 0; if (polygonArray [count2].getObjctsThatWillSplit(objectToSplitWith) == true) { indicesWithObject [count2] = 1; polygonToSplitCount++; } } return(indicesWithObject); }
private void OnTriggerEnter(Collider other) { Debug.Log(other.name); if (other.tag == "Enemy") { AIObjects ai = other.GetComponent <AIObjects>(); if (ai != null) { if (ai.heading() == PositiveDirection) { ai.jump(); } } } }
/* getObjectsArray gets all the triangle polygons that compose all objects in a Unity map, * and loads them into the triangleArray. Then creates new AIObjects from those triangles and loads * them into objectsArray to be used for nav mesh construction. * Parameters: none * Return: none */ void getObjectsArray() { Vector3[] WorldPositionArray = new Vector3[3]; for (int count = 0; count < staticObjects.Length; count++) { staticObjectMesh [count] = staticObjects [count].GetComponent <MeshFilter> ().mesh; vectorArray = staticObjectMesh[count].vertices; triangleArray = staticObjectMesh[count].GetTriangles(0); objectsArray[count] = new AIObjects(triangleArray.Length / 3, staticObjects[count]); for (int count1 = 0, count2 = 1, count3 = 2; count1 < triangleArray.Length; count1 += 3, count2 += 3, count3 += 3) { WorldPositionArray [0] = staticObjects [count].transform.TransformPoint(vectorArray [triangleArray [count1]]); WorldPositionArray [1] = staticObjects [count].transform.TransformPoint(vectorArray [triangleArray [count2]]); WorldPositionArray [2] = staticObjects [count].transform.TransformPoint(vectorArray [triangleArray [count3]]); objectsArray[count].addPolygon(WorldPositionArray); } } }
/* * splitPolygons method will split the polygons that was collected to be split * Parameter: (AIPolygon[]) splitingPolygons is an array containing the polygons that need to be split * (AIObject) objectsToSplitWith is the object that the polygons will be split by */ AIPolygon[] splitPolygons(AIPolygon[] splitingPolygons, AIObjects objectToSplitWith) { AIPolygon[] tempArray = null; for (int count = 0; count < splitingPolygons.Length; count++) { AIPolygonQueue tempQueue = splitingPolygons [count].splitThisPolygon(objectToSplitWith); if (tempQueue != null) { tempArray = makeNewArray(count, tempQueue, AINavigationMeshAgent.agentDiameter, tempArray); } } int counter = 0; if (tempArray == null) { return(tempArray); } for (int count = 0; count < tempArray.Length; count++) { if (tempArray[count] != null) { counter++; } } AIPolygon[] temp2Array = new AIPolygon[counter]; for (int count = 0, tempCount = 0; count < tempArray.Length; count++) { if (tempArray[count] != null) { temp2Array[tempCount] = new AIPolygon(tempArray[count].getVertices(), tempCount); tempCount++; } } return(temp2Array); }