Reply To: Unity issues

Home Forums Syphon Syphon Implementations – User Unity issues Reply To: Unity issues

#4506
Brian Chasalow
Participant

SteveElbows: that’s definitely on our radar, the multiple server support thing for Unity as client.

I checked out your demo- those are certainly similar issues to what we’re experiencing. For now, do four things:
1)go to file/build settings/player settings, and check ‘run in background’
2) go to edit/render settings, and drag a global skybox there to where it says ‘skybox’ from your project window.
3) replace the SyphonServerBridge with this script:

using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;

public class SyphonServerBridge : MonoBehaviour {

//1)go to file/build settings/player settings, and check 'run in background'
//2) go to edit/render settings, and drag a global skybox there to where it says 'skybox' from your project window.

private GameObject _RTCameraObject;
private Camera _RTCamera;
private RenderTexture _rTexture = null;
public int desiredWidth = 1024;
public int desiredHeight = 768;
[DllImport ("SyphonUnityPlugin")]
private static extern void syphonServerPublishTexture(int nativeTexture, int width, int height);
[DllImport ("SyphonUnityPlugin")]
private static extern void syphonServerDestroyResources();

// Use this for initialization
void Start ()
{
_rTexture = new RenderTexture(desiredWidth, desiredHeight, 24);
_rTexture.format = RenderTextureFormat.ARGB32;
_rTexture.isPowerOfTwo = false;
_rTexture.isCubemap = false;
_rTexture.Create();
//create a new render texture camera object, parent it to this object
_RTCameraObject = new GameObject();
_RTCameraObject.transform.parent = transform;
_RTCameraObject.name = "RTCamera";
_RTCameraObject.AddComponent("Camera");
_RTCameraObject.AddComponent("makeSyphonServerWork");
//clone the current camera's settings to the RT Camera
_RTCameraObject.camera.CopyFrom(camera);
//add the render texture target to the RTCamera object
_RTCameraObject.camera.targetTexture = _rTexture;
//<edit nov 7 2010 - bc>
RenderTexture.active = _rTexture;
//</edit>
}
public void callFromRTCamera(){
syphonServerPublishTexture(_rTexture.GetNativeTextureID(), _rTexture.width, _rTexture.height);
}
// Also called in the editor when play is stopped
void OnApplicationQuit ()
{
syphonServerDestroyResources();
}

}

4) then create a new file, call it makeSyphonServerWork.cs, and write this to it:


using UnityEngine;
using System.Collections;

public class makeSyphonServerWork : MonoBehaviour {
private SyphonServerBridge myScript;
// Use this for initialization
void Start () {
myScript = transform.parent.GetComponent<SyphonServerBridge>();
}
static Material lineMaterial;
static void CreateLineMaterial() {
if( !lineMaterial ) {
lineMaterial = new Material( "Shader "Lines/Colored Blended" {" +
"SubShader { Pass { " +
" Blend SrcAlpha OneMinusSrcAlpha " +
" ZWrite Off Cull Off Fog { Mode Off } " +
" BindChannels {" +
" Bind "vertex", vertex Bind "color", color }" +
"} } }" );
lineMaterial.hideFlags = HideFlags.HideAndDontSave;
lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave;
}
}
void OnPostRender() {
CreateLineMaterial();
lineMaterial.SetPass( 0 );
}
void OnRenderObject() {
CreateLineMaterial();
lineMaterial.SetPass( 0 );
myScript.callFromRTCamera();

}

}