Unity RPC未被调用 [英] Unity RPC not being called

查看:129
本文介绍了Unity RPC未被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在反对这个RPC调用几个小时,尽管谷歌搜索广泛但我无法弄清楚出了什么问题。



那一刻,我在团结编辑器中进行所有测试,(如果重要的话,播放器设置为在后台运行)。



出于某种原因,我的RPC调用不会通过。



代码中有很多内容,所以唯一重要的一点(我认为)是:



  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);
} // 如果瓷砖结束!= 0
} // end for

Debug.Log( 完成推送瓷砖);
// networkView.RPC(SpawnCharacter,RPCMode.AllBuffered,team1Spawn);
networkView.RPC( SpawnCharacter,RPCMode.All);
// networkView.RPC(Merp,RPCMode.All);
// networkView.RPC(PushTiles,RPCMode.All);
// Debug.Log(Merr?);

} // end generate dungeon

[RPC]
void SpawnCharacter()
{
Debug.Log( 产卵人物:);
// 实例化(字符,位置,Quaternion.identity);
}



目前,这只应称为服务器端。



以下是该剧本的完整代码:





< pre lang =c#> 使用 UnityEngine;
使用 System.Collections;
///
/ // BSP Spawning Script负责从头开始创建一个地牢。
///
公开 BSPSpawningScript:MonoBehaviour {

public int dungeonWidth = 80 ;
public int dungeonHeight = 80 ;
public int numSplits = 4 ;
public GameObject字符;
public float charYOffset;

[] tile;

BSPDungeon dungeon;
CoConvert转换;
bool team1 = false ;
bool team2 = false ;
GameObject lastTile;
Vector3 team1Spawn;

void Start()
{
if (Network.isClient)
{
GameObject.Destroy( this .gameObject);
Debug.Log( 销毁);
}

convert = new CoConvert(dungeonWidth);
dungeon = new BSPDungeon(dungeonWidth,dungeonHeight);
dungeon.treeData.SplitNodes(numSplits);
dungeon.GenerateRooms();
dungeon.GenerateCorridors();
GenerateDungeon();
}

public void 重置()
{
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);
} // 如果瓷砖结束!= 0
} // end for

Debug.Log( 完成推送瓷砖);
// networkView.RPC(SpawnCharacter,RPCMode.AllBuffered,team1Spawn);
networkView.RPC( SpawnCharacter,RPCMode.All);
// networkView.RPC(Merp,RPCMode.All);
// networkView.RPC(PushTiles,RPCMode.All);
// Debug.Log(Merr?);

} // end generate dungeon

[RPC]
void SpawnCharacter()
{
Debug.Log( 产卵人物:);
// 实例化(字符,位置,Quaternion.identity);
}

///
/// Create Tile负责实例化切片。
///
/// 要生成的Tile类型。
/// 生成瓷砖的x坐标。
/// 生成瓷砖的z坐标。
/// 产生图块的轮换内容。
/// 地牢宽度。
/// 地牢高度。
public void CreateTile( int tileType, int x, int z, float rotation, int dungeonWidth, int dungeonHeight)
{
// 因此它在场景的中心正面显示
x - = dungeonWidth / 2;
z - = dungeonHeight / 2;

// 磁贴大小的抵消
x * = < span class =code-digit> 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( 错误)) ;
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
{
// character.transform.position = new Vector3(x,charYOffset,z);
// GameObject.Find
team1Spawn = new Vector3(x,charYOffset,z);
team1 = true ;
sendSpawn = true ;
Debug.Log( SETTING SPAWN);
}
break ;
case int )Enums.TileType.Corridor:
tempObje ct =(GameObject)GameObject.Instantiate(Resources.Load( Corridor));
break ;
默认
tempObject =(GameObject)GameObject.Instantiate(Resources.Load( 错误));
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);

// GameObject.Destroy(tempObject);
}

[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 );
}

///
/// 确定切片应面向哪个方向,作为一个角。
///
/// 目标图块左侧的图块。
/// 目标图块右侧的图块。
/// 目标图块上的图块
/// 目标图块下方的图块
/// 目标图块的x坐标。
/// 目标图块的z坐标。
/// 地牢宽度。
/// 地牢高度。
public void CheckCorners( int leftTile, int rightTile, int topTile, int bottomTile, int x, int z, int dungeonWidth, int dungeonHeight)
{
// 左和顶空= NW
// 左和底空= SW
// 右和顶空= NE
// 右和底空= NW

< span class =code-keyword> if (le ftTile ==( 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,(< span class =code-keyword> 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,(< span class =code-keyword> float )Enums.CornerDirections.SouthEast,dungeonWidth,dungeonHeight);

else
CreateTile(-1,x,z, 0 ,dungeonWidth,dungeonHeight);
}
else
CreateTile(-1,x,z, 0 ,dungeonWidth,dungeonHeight);
}

///
/// 确定图块应面向哪个方向,作为单个墙。
///
/// 目标图块左侧的图块。
/// 目标图块右侧的图块。
/// 目标图块上的图块
/// 目标图块下方的图块
/// 目标图块的x坐标。
/// 目标图块的z坐标。
/// 地牢宽度。
/// 地牢高度。
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,(< span class =code-keyword> float )Enums.DoorwayDirections.South,dungeonWidth,dungeonHeight);

else if (topTile ==( int )Enums.TileType.Corridor)
CreateTile(( int )Enums.TileType.Doorway,x,z,(< span class =code-keyword> float )Enums.DoorwayDirections.North,dungeonWidth,dungeonHeight);

else if (leftTile ==( int )Enums.TileType.Corridor)
CreateTile(( int )Enums.TileType.Doorway,x,z,(< span class =code-keyword> float )Enums.DoorwayDirections.West,dungeonWidth,dungeonHeight);

else if (rightTile ==( int )Enums.TileType.Corridor)
CreateTile(( int )Enums.TileType.Doorway,x,z,(< span class =code-keyword> float )Enums.DoorwayDirections.East,dungeonWidth,dungeonHeight);

else
CreateTile(-1,x,z, 0 ,dungeonWidth,dungeonHeight);
}

///
/// 确定图块应面向哪个方向,作为走廊。
///
/// 目标图块左侧的图块。
/// 目标图块右侧的图块。
/// 目标图块上的图块
/// 目标图块下方的图块
/// 目标图块的x坐标。
/// 目标图块的z坐标。
/// 地牢宽度。
/// 地牢高度。
public void CheckCorridors( int leftTile, int rightTile, int topTile, int bottomTile, int x, int z,int dungeonWidth, int dungeonHeight)
{
//We are a N/S corridor IF our bottom tile is a...
//Doorway, corridor, or a single wall (because sometimes we are checked before walls have become doorways)
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);

//We are a W/E corridor IF our bottom tile is a...
//Doorway, corridor, or a single wall (because sometimes we are checked before walls have become doorways)
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);

\t\telse
\t CreateTile(-1, x,z,0, dungeonWidth, dungeonHeight);
}

///
/// Create Debug Dungeon is responible for creating a flat dungeon underneathe (-2 y) the real dungeon.
/// This is for testing only and should not be included in the final product.
///
/// The x coordinate of the tile to create.
/// The z coordinate of the tile to create.
public void CreateDebugDungeon(int x, int z)
{
//So it displays right-side up in the center of the scene
x -= dungeonWidth/2;
z -= dungeonHeight/2;

//Offsetting for the tile size
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

解决方案

You must be sure to add a nertworkview on the gameobject of your script. You can add

[RequireComponent (typeof (NetworkView))]

at the start of your class to ensure unity add it by itself.


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();

     //Begin looking through every single tile
     for(int i = 0; i < tiles.Length; i++)
     {
         //If our tile is something useful, aka not a void area in the dungeon
         if(tiles[i] != 0){

             //Bogus location
             int x = 0;
             int z = 0;

             //Real World Location
             convert.ConvertIndexToXY(i,ref x,ref z);

             //Wouldn't need if I understood the math, but since I don't being extra careful
             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)];

             //Create a base layer for compairing dungeon
             CreateDebugDungeon(x,z);

             //Determine what we are trying to spawn, and spawn it
             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);
         }//end if tiles != 0
     }//end for

     Debug.Log ("Done pushing tiles");
     //networkView.RPC("SpawnCharacter",RPCMode.AllBuffered, team1Spawn);
     networkView.RPC ("SpawnCharacter",RPCMode.All);
     //networkView.RPC ("Merp",RPCMode.All);
     //networkView.RPC ("PushTiles",RPCMode.All);
     //Debug.Log ("Merr?");

 }//end generate dungeon

 [RPC]
 void SpawnCharacter()
 {
     Debug.Log ("Spawning character at : " );
     //Instantiate(character,position, Quaternion.identity);
 }


At the moment, this should only be called server side.

Here is the full code for the script:


    using UnityEngine;
    using System.Collections;
    /// 
    /// BSP Spawning Script is responsible creating a dungeon from scratch to finished.
    /// 
    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();
    
        //Begin looking through every single tile
        for(int i = 0; i < tiles.Length; i++)
        {	
            //If our tile is something useful, aka not a void area in the dungeon
            if(tiles[i] != 0){
    
            //Bogus location
            int x = 0;
            int z = 0;

            //Real World Location
            convert.ConvertIndexToXY(i,ref x,ref z);

            //Wouldn't need if I understood the math, but since I don't being extra careful
            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)];

            //Create a base layer for compairing dungeon
            CreateDebugDungeon(x,z);

            //Determine what we are trying to spawn, and spawn it
            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);	
            }//end if tiles != 0
		}//end for

        Debug.Log ("Done pushing tiles");
        //networkView.RPC("SpawnCharacter",RPCMode.AllBuffered, team1Spawn);
        networkView.RPC ("SpawnCharacter",RPCMode.All);
        //networkView.RPC ("Merp",RPCMode.All);
        //networkView.RPC ("PushTiles",RPCMode.All);
        //Debug.Log ("Merr?");

    }//end generate dungeon

    [RPC]
    void SpawnCharacter()
    {
        Debug.Log ("Spawning character at : " );
        //Instantiate(character,position, Quaternion.identity);
    }

    /// 
    /// Create Tile is responsible for instantiating tiles.  
    /// 
    /// What Tile type to spawn.
    /// The x coordinate to spawn tile at.
    /// The z coordinate to spawn tile at.
    /// What rotation to spawn the tile at.
    /// Dungeon width.
    /// Dungeon height.
    public void CreateTile(int tileType, int x, int z, float rotation, int dungeonWidth, int dungeonHeight)
    {
        //So it displays right-side up in the center of the scene
        x -= dungeonWidth/2;
        z -= dungeonHeight/2;

        //Offsetting for the tile size
        x *= 8;
        z *= -8;

        //Set up temporary object
        GameObject tempObject;

        //Get it's position
        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)
                {
                    //character.transform.position = new Vector3(x, charYOffset,z);
                    //GameObject.Find"		
                    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;


        //TESTING
        networkView.RPC ("PushTile", RPCMode.AllBuffered, tempObject, tempPos, rotation);

        //GameObject.Destroy (tempObject);
    }

    [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);
    }

    /// 
    /// Determins which direction a tile should face, as a corner.
    /// 
    /// The tile to the left of the target tile.
    /// The tile to the right of the target tile.
    /// The tile ontop of the target tile
    /// The tile below the target tile
    /// The x coordinate of the target tile.
    /// The z coordinate of the target tile.
    /// Dungeon width.
    /// Dungeon height.
    public void CheckCorners (int leftTile, int rightTile, int topTile, int bottomTile, int x, int z, int dungeonWidth, int dungeonHeight)
    {
        //Left And Top Empty = NW
        //Left and Bottom Empty = SW
        //Right and Top Empty = NE
        //Right and Bottom Empty = NW
    
        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);
    }

        /// 
        /// Determins which direction a tile should face, as a single wall.
        /// 
        /// The tile to the left of the target tile.
        /// The tile to the right of the target tile.
        /// The tile ontop of the target tile
        /// The tile below the target tile
        /// The x coordinate of the target tile.
        /// The z coordinate of the target tile.
        /// Dungeon width.
        /// Dungeon height.
        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);
    }

    /// 
    /// Determins which direction a tile should face, as a corridor.
    /// 
    /// The tile to the left of the target tile.
    /// The tile to the right of the target tile.
    /// The tile ontop of the target tile
    /// The tile below the target tile
        /// The x coordinate of the target tile.
    /// The z coordinate of the target tile.
    /// Dungeon width.
    /// Dungeon height.
    public void CheckCorridors(int leftTile, int rightTile, int topTile, int bottomTile, int x, int z, int dungeonWidth, int dungeonHeight)
    {
        //We are a N/S corridor IF our bottom tile is a...
        //Doorway, corridor, or a single wall (because sometimes we are checked before walls have become doorways)
        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);

        //We are a W/E corridor IF our bottom tile is a...
        //Doorway, corridor, or a single wall (because sometimes we are checked before walls have become doorways)
        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);
    }

    /// 
    /// Create Debug Dungeon is responible for creating a flat dungeon underneathe (-2 y) the real dungeon.
    /// This is for testing only and should not be included in the final product.
    /// 
    /// The x coordinate of the tile to create.
    /// The z coordinate of the tile to create.
    public void CreateDebugDungeon(int x, int z)
    {
        //So it displays right-side up in the center of the scene
        x -= dungeonWidth/2;
        z -= dungeonHeight/2;

        //Offsetting for the tile size
        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

解决方案

You must be sure to add a nertworkview on the gameobject of your script. You can add

[RequireComponent (typeof (NetworkView))]

at the start of your class to ensure unity add it by itself.


这篇关于Unity RPC未被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆