I have been bashing my head against this RPC call for a few hours now, and despite extensive googling I cannot figure out what is going wrong.
At the moment, I am doing all testing within unity editor, (player set to run in background if that matters).
For some reason, my RPC call isn't going through.
There is a lot of stuff going on in the code, so the only important bit (I think) is:
public void GenerateDungeon()
{
Debug.Log ("GENERATING DUNGEON");
tiles = dungeon.SetDungeonData();
for(int i = 0; i < tiles.Length; i++)
{
if(tiles[i] != 0){
int x = 0;
int z = 0;
convert.ConvertIndexToXY(i,ref x,ref z);
int leftTile = tiles[convert.ConvertXYToIndex(x-1,z)];
int rightTile = tiles[convert.ConvertXYToIndex(x+1,z)];
int topTile = tiles[convert.ConvertXYToIndex(x,z-1)];
int bottomTile = tiles[convert.ConvertXYToIndex(x,z+1)];
CreateDebugDungeon(x,z);
if(tiles[i] == (short)Enums.TileType.Corner)
CheckCorners(leftTile, rightTile, topTile, bottomTile, x, z, dungeonWidth, dungeonHeight);
if(tiles[i] == (short)Enums.TileType.OneWall)
CheckOneWalls(leftTile, rightTile, topTile, bottomTile, x, z, dungeonWidth, dungeonHeight);
if(tiles[i] == (short)Enums.TileType.FloorAndRoof)
CreateTile((int)Enums.TileType.FloorAndRoof, x,z,0,dungeonWidth,dungeonHeight);
if(tiles[i] == (short)Enums.TileType.Corridor)
CheckCorridors(leftTile, rightTile, topTile, bottomTile, x, z, dungeonWidth, dungeonHeight);
}
}
Debug.Log ("Done pushing tiles");
networkView.RPC ("SpawnCharacter",RPCMode.All);
}
[RPC]
void SpawnCharacter()
{
Debug.Log ("Spawning character at : " );
}
At the moment, this should only be called server side.
Here is the full code for the script:
using UnityEngine;
using System.Collections;
public class BSPSpawningScript : MonoBehaviour{
public int dungeonWidth = 80;
public int dungeonHeight = 80;
public int numSplits = 4;
public GameObject character;
public float charYOffset;
short[] tiles;
BSPDungeon dungeon;
CoConvert convert;
bool team1 = false;
bool team2 = false;
GameObject lastTile;
Vector3 team1Spawn;
void Start()
{
if(Network.isClient)
{
GameObject.Destroy(this.gameObject);
Debug.Log ("Destroying");
}
convert = new CoConvert(dungeonWidth);
dungeon = new BSPDungeon(dungeonWidth, dungeonHeight);
dungeon.treeData.SplitNodes(numSplits);
dungeon.GenerateRooms ();
dungeon.GenerateCorridors();
GenerateDungeon();
}
public void Reset()
{
dungeon.Reset();
dungeon.treeData.SplitNodes(numSplits);
dungeon.GenerateRooms ();
dungeon.GenerateCorridors();
GenerateDungeon();
}
public void GenerateDungeon()
{
Debug.Log ("GENERATING DUNGEON");
tiles = dungeon.SetDungeonData();
for(int i = 0; i < tiles.Length; i++)
{
if(tiles[i] != 0){
int x = 0;
int z = 0;
convert.ConvertIndexToXY(i,ref x,ref z);
int leftTile = tiles[convert.ConvertXYToIndex(x-1,z)];
int rightTile = tiles[convert.ConvertXYToIndex(x+1,z)];
int topTile = tiles[convert.ConvertXYToIndex(x,z-1)];
int bottomTile = tiles[convert.ConvertXYToIndex(x,z+1)];
CreateDebugDungeon(x,z);
if(tiles[i] == (short)Enums.TileType.Corner)
CheckCorners(leftTile, rightTile, topTile, bottomTile, x, z, dungeonWidth, dungeonHeight);
if(tiles[i] == (short)Enums.TileType.OneWall)
CheckOneWalls(leftTile, rightTile, topTile, bottomTile, x, z, dungeonWidth, dungeonHeight);
if(tiles[i] == (short)Enums.TileType.FloorAndRoof)
CreateTile((int)Enums.TileType.FloorAndRoof, x,z,0,dungeonWidth,dungeonHeight);
if(tiles[i] == (short)Enums.TileType.Corridor)
CheckCorridors(leftTile, rightTile, topTile, bottomTile, x, z, dungeonWidth, dungeonHeight);
}
}
Debug.Log ("Done pushing tiles");
networkView.RPC ("SpawnCharacter",RPCMode.All);
}
[RPC]
void SpawnCharacter()
{
Debug.Log ("Spawning character at : " );
}
public void CreateTile(int tileType, int x, int z, float rotation, int dungeonWidth, int dungeonHeight)
{
x -= dungeonWidth/2;
z -= dungeonHeight/2;
x *= 8;
z *= -8;
GameObject tempObject;
Vector3 tempPos = new Vector3(x,0,z);
bool sendSpawn = false;
switch(tileType)
{
case -1:
Debug.Log ("NONE FOUND " + tempPos);
tempObject = (GameObject)GameObject.Instantiate(Resources.Load("Error"));
break;
case (int)Enums.TileType.Corner:
tempObject = (GameObject)GameObject.Instantiate(Resources.Load("Corner"));
break;
case (int)Enums.TileType.OneWall:
tempObject = (GameObject)GameObject.Instantiate(Resources.Load("OneWall"));
break;
case (int)Enums.TileType.Doorway:
tempObject = (GameObject)GameObject.Instantiate(Resources.Load("Doorway"));
break;
case (int)Enums.TileType.FloorAndRoof:
tempObject =(GameObject)GameObject.Instantiate(Resources.Load("FloorAndRoof"));
if(team1 == false)
{
team1Spawn = new Vector3(x, charYOffset, z);
team1 = true;
sendSpawn = true;
Debug.Log ("SETTING SPAWN");
}
break;
case (int)Enums.TileType.Corridor:
tempObject =(GameObject)GameObject.Instantiate(Resources.Load("Corridor"));
break;
default:
tempObject = (GameObject)GameObject.Instantiate(Resources.Load ("Error"));
Debug.Log ("DEFAULT " + tempPos);
break;
}
tempObject.transform.Rotate (new Vector3(0f, rotation, 0f));
tempObject.transform.position = tempPos;
networkView.RPC ("PushTile", RPCMode.AllBuffered, tempObject, tempPos, rotation);
}
[RPC]
void PushTile(GameObject tileObject, Vector3 tilePosition, float rotation)
{
Debug.Log ("Rawr");
GameObject objectCopy = tileObject;
Quaternion newRotation = Quaternion.Euler(0f, rotation, 0f);
Network.Instantiate(objectCopy, tilePosition, newRotation, 0);
}
public void CheckCorners (int leftTile, int rightTile, int topTile, int bottomTile, int x, int z, int dungeonWidth, int dungeonHeight)
{
if(leftTile == (int)Enums.TileType.Empty)
{
if(topTile == (int)Enums.TileType.Empty)
CreateTile((int)Enums.TileType.Corner,x,z,(float)Enums.CornerDirections.NorthWest, dungeonWidth, dungeonHeight);
else if(bottomTile == (int)Enums.TileType.Empty)
CreateTile((int)Enums.TileType.Corner,x,z,(float)Enums.CornerDirections.SouthWest, dungeonWidth, dungeonHeight);
else
CreateTile(-1,x,z,0, dungeonWidth, dungeonHeight);
}
else if(rightTile == (int)Enums.TileType.Empty)
{
if(topTile == (int)Enums.TileType.Empty)
CreateTile((int)Enums.TileType.Corner,x,z,(float)Enums.CornerDirections.NorthEast, dungeonWidth, dungeonHeight);
else if(bottomTile == (int)Enums.TileType.Empty)
CreateTile((int)Enums.TileType.Corner,x,z,(float)Enums.CornerDirections.SouthEast, dungeonWidth, dungeonHeight);
else
CreateTile(-1,x,z,0, dungeonWidth, dungeonHeight);
}
else
CreateTile(-1,x,z,0, dungeonWidth, dungeonHeight);
}
public void CheckOneWalls(int leftTile, int rightTile, int topTile, int bottomTile, int x, int z, int dungeonWidth, int dungeonHeight)
{
if(bottomTile == (int)Enums.TileType.FloorAndRoof && topTile == (int)Enums.TileType.Empty)
CreateTile((int)Enums.TileType.OneWall, x,z,(float)Enums.OneWallDirections.North, dungeonWidth, dungeonHeight);
else if(leftTile == (int)Enums.TileType.FloorAndRoof && rightTile == (int)Enums.TileType.Empty)
CreateTile((int)Enums.TileType.OneWall, x,z,(float)Enums.OneWallDirections.East, dungeonWidth, dungeonHeight);
else if(rightTile == (int)Enums.TileType.FloorAndRoof && leftTile == (int)Enums.TileType.Empty)
CreateTile((int)Enums.TileType.OneWall, x,z,(float)Enums.OneWallDirections.West, dungeonWidth, dungeonHeight);
else if(topTile == (int)Enums.TileType.FloorAndRoof && bottomTile == (int)Enums.TileType.Empty)
CreateTile((int)Enums.TileType.OneWall, x,z,(float)Enums.OneWallDirections.South, dungeonWidth, dungeonHeight);
else if(bottomTile == (int)Enums.TileType.Corridor)
CreateTile((int)Enums.TileType.Doorway, x,z,(float)Enums.DoorwayDirections.South, dungeonWidth, dungeonHeight);
else if(topTile == (int)Enums.TileType.Corridor)
CreateTile((int)Enums.TileType.Doorway, x,z,(float)Enums.DoorwayDirections.North, dungeonWidth, dungeonHeight);
else if(leftTile == (int)Enums.TileType.Corridor)
CreateTile((int)Enums.TileType.Doorway, x,z,(float)Enums.DoorwayDirections.West, dungeonWidth, dungeonHeight);
else if(rightTile == (int)Enums.TileType.Corridor)
CreateTile((int)Enums.TileType.Doorway, x,z,(float)Enums.DoorwayDirections.East, dungeonWidth, dungeonHeight);
else
CreateTile(-1, x,z,0, dungeonWidth, dungeonHeight);
}
public void CheckCorridors(int leftTile, int rightTile, int topTile, int bottomTile, int x, int z, int dungeonWidth, int dungeonHeight)
{
if(bottomTile == (int)Enums.TileType.Doorway || bottomTile == (int)Enums.TileType.Corridor || bottomTile == (int)Enums.TileType.OneWall)
CreateTile((int)Enums.TileType.Corridor, x,z,(float)Enums.CorridorDirections.NorthSouth, dungeonWidth, dungeonHeight);
else if(leftTile == (int)Enums.TileType.Doorway || leftTile == (int)Enums.TileType.Corridor || leftTile == (int)Enums.TileType.OneWall)
CreateTile((int)Enums.TileType.Corridor, x,z,(float)Enums.CorridorDirections.WestEast, dungeonWidth, dungeonHeight);
else
CreateTile(-1, x,z,0, dungeonWidth, dungeonHeight);
}
public void CreateDebugDungeon(int x, int z)
{
x -= dungeonWidth/2;
z -= dungeonHeight/2;
x *= 8;
z *= -8;
GameObject tempObjectDebug = (GameObject)GameObject.Instantiate(Resources.Load("TestSubject"));
tempObjectDebug.transform.position = new Vector3(x, -2, z);
}
}
After all is said and done, the console will print:
GENERATING DUNGEON
SETTING DUNGEON DATA
SETTING SPAWN
Done pushing tiles
The character reference is set up correctly, the tiles are being instantiated correctly, everything seems to be working as intended, with the exception of the RPC call being ignored? There are no errors, no warnings.
I appreciate any help anyone can give,
Tiffany