Inheritable RPC Calls for Unity
If you use RPC calls in Unity you sometimes want to be able to call an RPC defined on a base class and not overridden in a derived class. This isn’t normally possible and leads to some complicated workarounds, so I’ve written an extension that allows you do do it generically.
Having installed the package you will be able to do networkView.RPCEx(…) and such calls will be routed to base class members. The only requirements are:
- The game object that is to receive these calls needs to have an InheritableRPC script attached to it
- You cannot pass NetworkPlayer and NetworkViewID by these calls
You can however use this RPCEx method to pass parameters that are of any serializable class type – you are not limited to the usual list of simple parameters offered by Unity’s standard RPC methods.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
using System.Linq;
using Serialization;
public class SomeBaseClass : MonoBehaviour
{
[RPC]
protected void PrintThis(string text)
{
Debug.Log(text);
}
}
[AddComponentMenu("Tests/Inherited")]
public class Inherited : SomeBaseClass
{
}
Using normal RPC you couldn’t call PrintThis on something that had the Inherited script attached, with RPCEx you can
From Unity Script you would need to call the RPCEx like this:
InhertiableRPCExtensions.RPCEx(networkView, routineName, mode /* e.g. RPCMode.All */, parameter1 /* Any number of parameters */, parameter2);
