//decrement the enemy count in a room public void DecrementEnemyCount(IslandRoom room) { if (m_RoomList.Contains(room)) { room.DecrementEnemyCount(); } }
private void RPCFindAIandIslandRoomThenInit(string roomName, string aiName) { GameObject roomGO = GameObject.Find(roomName); AI[] aiInGame = Resources.FindObjectsOfTypeAll <AI>(); IslandRoom room = roomGO.GetComponent <IslandRoom>(); AI ai = null; foreach (AI individualAI in aiInGame) { if (individualAI.name == aiName) { ai = individualAI; break; } } if (!PhotonNetwork.isMasterClient) { if (room != null && ai != null) { AddEnemyToRoom(ai, room); } } ai.Init(); ai.enabled = false; }
//adds a room to our list of rooms in the scene public void AddRoomToList(IslandRoom room) { if (!m_RoomList.Contains(room)) { m_RoomList.Add(room); } }
//This method will create the spawn room private void CreateSpawnRoom() { //the current room that is being built from, since this while loop may loop many times IslandRoom currentRoom = m_CurrentRoomToBuildFrom.GetComponent <IslandRoom>(); while (true) { //generate a random number to be used for determinning what portal in the room to use int randomPortal = 0; if (currentRoom.PortalsInRoom.Count > 1) { randomPortal = m_RandomNumberGenerator.RandomRange(0, m_CurrentRoomToBuildFrom.GetComponent <IslandRoom>().PortalsInRoom.Count - 1); } //if the portal that might be used isn't connected to another portal then that means it can be built from. if (currentRoom.PortalsInRoom[randomPortal].ConnectedPortal == null) { CreateNewRoom(currentRoom.PortalsInRoom[randomPortal], SpawnRoom); m_IsSpawnRoomSpawned = true; //return in order to escape this method return; } } }
//Used to disable every none in use portal in the IslandRoom that is passed in private void FinishWithRoom(IslandRoom room) { //iterate through the portals in the room foreach (Portal portal in room.PortalsInRoom) { //if the connected portal is null that means no portal has been attached and this portal must be DESTROYED. IE disable the gameobject if (portal.ConnectedPortal == null) { Destroy(portal.gameObject); } } }
//This will pick a new room to build from randomly from the list of rooms that can be built from private void PickNewRoomToBuildFromRandomly() { //if there are no more rooms to choose from randomly then don't try to pick a new one to spawn objects from if (m_RoomsToBuildFrom.Count < 1) { return; } //create a bool to determine whether or not a new room has been chosen to build from bool roomChosen = false; //while a room hasn't been chosen this logic will continue while (roomChosen == false) { //create a random number using the marsenne twister int randomNumber = 0; if (m_RoomsToBuildFrom.Count > 1) { randomNumber = m_RandomNumberGenerator.RandomRange(0, (m_RoomsToBuildFrom.Count - 1)); } //get the IslandRoom component which will be used to check if the useable portals number is equal to the currently used portal count. IslandRoom room = m_RoomsToBuildFrom[randomNumber].GetComponent <IslandRoom>(); //double check to see how many 2 door rooms have been spawned in a row bool canBuildRoom = true; if (m_TwoPortalRoomsInARow >= 1) { //if 2 or more 2 portal rooms have been spawned and this room only has 2 useable portals then don't let this room spawn if (room.PortalsInRoom.Count == 2) { canBuildRoom = false; } } if (canBuildRoom) { //if the values aren't the same then the room can built from. if (room.UsablePortals != room.CurrentlyUsedPortalsCount) { m_CurrentRoomToBuildFrom = m_RoomsToBuildFrom[randomNumber]; roomChosen = true; m_TwoPortalRoomsInARow = (room.PortalsInRoom.Count == 2 ? (m_TwoPortalRoomsInARow + 1) : 0); } //if the values are the same then that room cannot be built from and should be removed from the list else { FinishWithRoom(room); m_RoomsToBuildFrom.RemoveAt(randomNumber); } } } }
public void AddEnemyToRoom(AI ai, IslandRoom room) { //set ai name over network if (ai.name.Contains("(Clone)")) { string dynamicName = ai.name; dynamicName = dynamicName.Replace("(Clone)", ""); ai.SetName(dynamicName + DynamicEnemyName.ToString()); DynamicEnemyName++; } //add the enemy to the room and set the AI's room room.EnemiesInRoom.Add(ai); room.EnemiesInRoomCount = room.EnemiesInRoom.Count; ai.MyIslandRoom = room; ai.gameObject.SetActive(false); ai.enabled = false; }
public void SwapLODs(IslandRoom roomBeingEntered) { List <IslandRoom> connectedRooms = new List <IslandRoom>(); connectedRooms.Add(roomBeingEntered); for (int i = 0; i < roomBeingEntered.PortalsInRoom.Count; i++) { if (roomBeingEntered.PortalsInRoom[i] != null) { connectedRooms.Add(roomBeingEntered.PortalsInRoom[i].ConnectedRoom); } } foreach (IslandRoom room in m_RoomList) { //if the room in the room list contains the room being iterated through then that means we need to use the high poly version because the player will have direct contact with this portal if (connectedRooms.Contains(room)) { if (room.LODMesh.activeInHierarchy == true) { room.LODMesh.SetActive(false); } if (room.DetailedMesh.activeInHierarchy == false) { room.DetailedMesh.SetActive(true); } } //otherwise this mesh can get the LOD version else { if (room.LODMesh.activeInHierarchy == false) { room.LODMesh.SetActive(true); } if (room.DetailedMesh.activeInHierarchy == true) { room.DetailedMesh.SetActive(false); } } } }
private void OnPostprocessModel(GameObject obj) { //if the obj name doesn't contain the word room, then it's not a room so we can ignore it string lowerCastPath = assetPath.ToLower(); bool isInRoomDirectory = lowerCastPath.IndexOf("/rooms/") != -1; string lowerCaseName = obj.name.ToLower(); if (!isInRoomDirectory) { return; } //add a room component onto the top gameobject that gets passed in obj.tag = "Room"; obj.layer = LayerMask.NameToLayer("Room"); //set room values IslandRoom room = obj.AddComponent <IslandRoom>(); room.EnemiesInRoomCount = 100; //next we need to apply the wall layer and tag to every gameobject in it's children that aren't stairs or doors ApplyLayersToSubObjects(obj, obj); if (m_NumberOfSpawnPoints < 1) { Debug.LogError("The number of spawn points in room " + obj.name + " is currently zero, please fix this and re-import"); Editor.DestroyImmediate(obj); return; } if (m_MeshColliderCount > 100) { Debug.LogError("The number of mesh colliders in room " + obj.name + " is currently " + m_MeshColliderCount + " this is more then the allowed amount. Please change this and reimport"); Editor.DestroyImmediate(obj); return; } Debug.Log("The number of mesh colliders in the object know as " + obj.name + " is " + m_MeshColliderCount); Debug.Log("The number of spawn points in the object know as " + obj.name + " is " + m_NumberOfSpawnPoints); }
public static void SwapToNewCamera(IslandRoom oldRoom, IslandRoom newRoom) { if (oldRoom != null) { foreach (Portal portal in oldRoom.PortalsInRoom) { //disable all of the portal camera's of the room being exited portal.PortalCamera.enabled = false; //disable all of the portals that where connected to the previous room's portals portal.ConnectedPortal.PortalCamera.enabled = false; } } if (newRoom != null) { foreach (Portal portal in newRoom.PortalsInRoom) { //disable all of the portal camera's in the room that I'm entering portal.PortalCamera.enabled = false; //turn the portal camera for the connected portal to be on portal.ConnectedPortal.PortalCamera.enabled = true; } } }
//this method will be the beginning of a unique room being created private void UniqueSpawnRoomRule() { //get the current room to build from. IslandRoom room = m_CurrentRoomToBuildFrom.GetComponent <IslandRoom>(); while (true) { //choose a random room from the unique rooms and compare it against the unique rooms that are already built in the m_BuiltUniqueRooms dictionary int randomUniqueRoomIndex = 0; if (UniqueRooms.Count > 1) { randomUniqueRoomIndex = m_RandomNumberGenerator.RandomRange(0, UniqueRooms.Count - 1); } if (!m_BuiltUniqueRooms.Contains(randomUniqueRoomIndex)) { //instead of finding a random portal to build from we're just going to find the first one as to not have nested while loops foreach (Portal portal in room.PortalsInRoom) { if (portal.ConnectedPortal == null) { //now we build the room CreateNewRoom(portal, UniqueRooms[randomUniqueRoomIndex]); //before we end this build we need to do a few things: //1. the unique room and index need to be added to the list m_BuiltUniqueRooms.Add(randomUniqueRoomIndex); //2. we need to rest the amount of rooms since unique room was built value to zero m_RoomsSinceLastUniqueRoomCreation = 0; //finally we can return return; } } } } }
//passes in the main FBX's gameobject as well as the current gameobject that needs to be edited private void ApplyLayersToSubObjects(GameObject fbxGameObject, GameObject currentObject) { //save the imported FBX's obj transform into a var for use later Transform objTransform = currentObject.transform; //loop through all of the children in the transform we we're passed for (int i = 0; i < objTransform.childCount; i++) { //get the current child Transform child = objTransform.GetChild(i); if (child == null) { continue; } string lowerCaseName = child.name.ToLower(); if (lowerCaseName.Contains("highpoly") || lowerCaseName.Contains("lod_mesh")) { continue; } //if this object has any children then we need to tag and layer those properly too if (child.childCount > 0) { ApplyLayersToSubObjects(fbxGameObject, child.gameObject); } //if the object contains the tag obstacle that means we need to tag and layer it oppropriatly if (lowerCaseName.Contains("obstacle")) { child.tag = "MapGeometry"; child.gameObject.layer = LayerMask.NameToLayer("MapGeometry"); } if (lowerCaseName.Contains("portal")) { Portal portal = child.gameObject.AddComponent <Portal>(); GameObject obj = new GameObject(); obj.transform.parent = portal.transform; obj.AddComponent <Camera>(); } if (lowerCaseName.Contains("spawnpoint")) { //check if it's a player spawn point if (lowerCaseName.Contains("player")) { child.gameObject.AddComponent <PlayerSpawnPoint>(); } //check if it's an enemy spawn point else if (lowerCaseName.Contains("enemy")) { m_NumberOfSpawnPoints++; EnemySpawnPoint spawnPoint = child.gameObject.AddComponent <EnemySpawnPoint>(); IslandRoom r = fbxGameObject.GetComponent <IslandRoom>(); if (r.RoomSpawnPoints == null) { r.RoomSpawnPoints = new System.Collections.Generic.List <EnemySpawnPoint>(); } r.RoomSpawnPoints.Add(spawnPoint); } //check if it's an item spawn point else if (lowerCaseName.Contains("item")) { child.gameObject.AddComponent <ItemSpawnPoint>(); } } //next we check for "dimentions" via the name. If it's a box throw on a box collider if (lowerCaseName.Contains("box")) { child.gameObject.AddComponent <BoxCollider>(); } //if it's a circle or a sphere then we need to add a sphere collider to it else if (lowerCaseName.Contains("sphere") || lowerCaseName.Contains("circle")) { child.gameObject.AddComponent <SphereCollider>(); } //if it's a capsule then add a capsule collider else if (lowerCaseName.Contains("capsule")) { child.gameObject.AddComponent <CapsuleCollider>(); } //if it's a mesh collider then we begrudingly add a mesh collider to it else if (lowerCaseName.Contains("mesh") && !lowerCaseName.Contains("highpoly")) { m_MeshColliderCount++; child.gameObject.AddComponent <MeshCollider>(); Transform findHighPoly = fbxGameObject.transform; for (int j = 0; j < findHighPoly.childCount; j++) { if (findHighPoly.GetChild(j).name.Contains("highpoly") && findHighPoly.GetChild(j).name.Contains(lowerCaseName)) { child.GetComponent <MeshFilter>().mesh = findHighPoly.GetComponent <MeshFilter>().mesh; Editor.DestroyImmediate(findHighPoly.gameObject); break; } } } else if (lowerCaseName.Contains("castpoint")) { child.gameObject.AddComponent <CastPoints>(); } if ((lowerCaseName.Contains("traverse") || lowerCaseName.Contains("traversable")) == false) { UnityEngine.AI.NavMeshObstacle obstacle = child.gameObject.AddComponent <UnityEngine.AI.NavMeshObstacle>(); obstacle.carving = true; if (child.GetComponent <Collider>() != null) { child.GetComponent <Collider>().material = Resources.Load <PhysicMaterial>("PhysicsMaterials/WallMaterial"); } } if (lowerCaseName.Contains("invisablewall")) { child.gameObject.GetComponent <MeshFilter>().mesh = null; } } }
private void OnCollisionEnter(Collision collision) { if (collision.gameObject.tag == "Reflector" || m_IsBeingReflected) { m_IsBeingReflected = false; return; } gameObject.SetActive(false); if (!PhotonNetwork.isMasterClient) { return; } if (((1 << collision.gameObject.layer) & m_LayerMask) != 0) //if the collided gameobject is on the layer provided f**k bitshifts { IslandRoom room = null; transform.localScale = m_OriginalScale; if (collision.gameObject.tag == "Player") { Player playerRef = collision.gameObject.GetComponent <Player>(); int calcedDamage = (int)(m_Damage * (1 + m_ElapsedTime / 2)); playerRef.photonView.RPC("TakeDamage", PhotonTargets.All, calcedDamage > MaxScaledDamage ? MaxScaledDamage : calcedDamage, transform.position, m_StatusEffects); //if not the improved version, return as we don't spawn enemies from the player on the normal projectile if (!isImproved) { return; } room = playerRef.MyIslandRoom; } GameObject summonedObject = ObjectPoolManager.Instance.GetObjectFromNetworkPool(m_ShadowDemonPool); if (summonedObject != null) { //get the room area component from the root parent of the wall or floor if we didnt hit a player if (room == null) { room = collision.transform.root.gameObject.GetComponent <IslandRoom>(); } WorshipperAI ownerRef = null; //loop through the enemies in the room to get the enemy which matches with the number we were given if (m_ProjectileOwnerName != string.Empty) { for (int i = 0; i < room.EnemiesInRoom.Count; i++) { if (room.EnemiesInRoom[i] != null) { if (m_ProjectileOwnerName == room.EnemiesInRoom[i].name) { ownerRef = (WorshipperAI)room.EnemiesInRoom[i].gameObject.GetComponent <AI>(); break; } } } } if (ownerRef.NumberOfShadowDemonsSpawned >= ownerRef.ShadowDemonSpawnLimit) { return; } float offset = 3.0f; //distance away from the hit surface to spawn from Vector3 dir = collision.contacts[0].normal; //direction to offset away from Vector3 spawnLocation = collision.contacts[0].point + dir * offset; //calculated location to spawn shadow demon //if owner is found, summon the shadow demon and set it to active if (ownerRef != null) { ShadowDemonAI ai = summonedObject.GetComponent <ShadowDemonAI>(); ai.enabled = true; ai.Init(); ai.Health.ResetHealth(); ai.MyIslandRoom = room; ai.MasterRef = ownerRef; ai.SetActive(true, spawnLocation, dir); ownerRef.NumberOfShadowDemonsSpawned++; } } } }