Exclude Network View from WebGL Build
I want my to build my current project for WebGL. It was originally made for PC, Mac & Linux Standalone and therefore there were many parts of the programm (mainly about networking stuff) that had to be excluded.
For Scripts there are precompiler directives and for Plugins (.dll) there is the option to choose for which platform they should be included.
Now I'm facing the problem that I have the component NetworkView attached to 2 Prefabs and 1 Gameobject in the scene.
NetworkView is needed for the original platform build but the WebGL build won't work while this component is on any gameobject/prefab.
I tried deactivating them in the Editor. This didn't make any difference. I also wrote a Script that was supposed to remove these components at the start.
void Start ()
{
#if UNITY_WEBGL
Destroy(GetComponent<NetworkView>());
#endif
}
This was the resulting error
Assets/WebGLManager.cs(14,9): error CS0246: The type or namespace name `NetworkView' could not be found. Are you missing a using directive or an assembly reference?
Is there a method to exclude a component in general (or NetworkView in this particular case) from a specific build so that I don't have to delete these components manually everytime I want to do a WebGL build?
Answer by deDarxo · Jun 20, 2016 at 09:03 AM
Right know I'm using this script as a solution. Instead of the component "NetworkView" I just added this script to the respective gameobjects.
But I don't know how reliable it is in the longterm if this component is created at runtime.
using UnityEngine;
using System.Collections;
public class CreateNetworkView : MonoBehaviour {
#if !UNITY_WEBGL
public NetworkStateSynchronization stateSynchronization;
public Transform observed;
public void Awake()
{
AddNetworkView();
}
[RPC]
private void AddNetworkView()
{
gameObject.AddComponent<NetworkView>();
gameObject.GetComponent<NetworkView>().observed = observed;
gameObject.GetComponent<NetworkView>().stateSynchronization = stateSynchronization;
gameObject.GetComponent<NetworkView>().viewID = Network.AllocateViewID();
}
#endif
}