public void Awake() { //first thing you do is make sure callbacks are registered. that's what this method does. cacheAssembly(); //if there is an extra instance of Syphon that exists, destroy it. //Syphon is supposed to act like a singleton, so force it to behave like one. if (Syphon.Instance != null && Syphon.Instance != this) { DestroyImmediate(this); return; } //force the instance references to be valid each time you play the game. instance = this; //init the syphon servers. this will effectively call OnServerAnnounce for every client object that exists. Instance.initSyphonServers(); //update the server names to be shown in the gui. this is kinda dumb, but... UpdateServerNames(); //so it's really not correct to call this. // Instance.initSyphonClients(); //print(serverAppNames.Count +" " + Syphon.ServerAppNames.Count); initialized = true; }
public void DestroySyphonClient(){ // UnityEngine.Debug.Log("destroying syphon client" + syphonClientPointer + " " + BoundAppName + " " + boundName); if(attachedTexture != null){ RenderTexture.active = null; attachedTexture.Release(); //RenderTexture.active = null; UnityEngine.Object.DestroyImmediate(attachedTexture); attachedTexture = null; } if(syphonClientPointer != IntPtr.Zero && initialized){ Syphon.QueueToKillTexture(syphonClientPointer); GL.IssuePluginEvent((int)syphonClientPointer); syphonClientPointer = IntPtr.Zero; initialized = false; //let anySyphonClientTextures who's registered for updates know that we've retired. if(RetireClient != null){ RetireClient(this); } } else{ // Debug.Log("syphon client: " + boundAppName + " " + boundName + " was not initialized, so not cleaning up the plugin on exit."); } }
void Start() { //this next line creates a syphon instance if it doesn't already exist Syphon instance = Syphon.Instance; setupTexture(); }
protected int cachedHeight = 0; // current camera texture height #if UNITY_EDITOR //i don't trust that this doesn't crash unity. need more testing. // public SyphonServerTexture(){ // Syphon.syphonScriptCount++; // } // ~SyphonServerTexture(){ // Syphon.syphonScriptCount--; // } #endif public virtual void Start() { //this next line creates a syphon instance if it doesn't already exist Syphon instance = Syphon.Instance; syphonServerTextureInstance = Syphon.CreateServerTexture(gameObject.name); }
public void DestroySyphonClient() { //Debug.Log("destroying syphon client"); if (attachedTexture != null) { attachedTexture.Release(); //RenderTexture.active = null; UnityEngine.Object.DestroyImmediate(attachedTexture); attachedTexture = null; } if (syphonClientPointer != 0 && initialized) { // Debug.Log("DESTROY plugin syphon client destroy method..."); Syphon.KillClientTexture(syphonClientPointer); syphonClientPointer = 0; initialized = false; if (RetireClient != null) { RetireClient(this); } } else { // Debug.Log("syphon client: " + boundAppName + " " + boundName + " was not initialized, so not cleaning up the plugin on exit."); } }
public static void OnRetireServer(string appName, string name, string uuid) { string realAppName = ""; string realName = ""; //if there are any ACTIVE client singleton objects in use, //destroy them immediately. //destroy their texture and destroy the pointer to them, and remove them from the SyphonClients list. SyphonClientObject result = Syphon.GetSyphonClient(uuid); if (result) { //because the Syphon callback may not have a valid appName and name key in the OnServerRetire Syphon callback, //we need to ensure we get the extract those cached names from the uuid/instance. realAppName = result.BoundAppName; realName = result.BoundName; DestroyClient(result); } // //now remove the server name // //if it doesn't contain the appName key, you shouldn't have to do anything. if (Syphon.Servers.ContainsKey(realAppName)) { if (realName == "") { //if the name is UNNAMED_STRING and it contains the unnamed string, remove the server from the list. if (Syphon.Servers[realAppName].ContainsKey(Syphon.UNNAMED_STRING)) { Syphon.Servers[realAppName].Remove(Syphon.UNNAMED_STRING); //if there are no more objects in the dictionary list for that app, remove the associated appName entry if (Syphon.Servers[realAppName].Count == 0) { Syphon.Servers.Remove(realAppName); } } } //if the name is valid and the server's app dictionary contains the name string, remove the server from the list. else if (Syphon.Servers[realAppName].ContainsKey(realName)) { Syphon.Servers[realAppName].Remove(realName); //if there are no more entries in the dictionary list for that app, remove the associated appName entry if (Syphon.Servers[realAppName].Count == 0) { Syphon.Servers.Remove(realAppName); } } //TODO: remove this. Instance.UpdateServerNames(); } if (RetireServer != null) { RetireServer(realAppName, realName); } }
public void cacheTextureValues() { if (storedWidth != 0 && storedHeight != 0 && storedTexID != 0) { Syphon.CacheServerTextureValues(storedTexID, storedWidth, storedHeight, syphonServerTextureInstance); syphonServerTextureInstanceInitialized = true; } }
public void LateUpdate() { Syphon.UpdateTextureSizes(); if (UpdateClientTextures != null) { UpdateClientTextures(); } }
public void drawGUIClientEditor() { foreach (KeyValuePair <string, string[]> kvp in SyphonTarget.clientAppNames) { GUI.changed = false; int selectIndex = 0; //if you're not drawing the one you've selected, the index is 0. if (kvp.Key != clientConfirmKey) { selectIndex = 0; } //otherwise, the index is whatever the selected index is. else { selectIndex = GUIClientSelectionIndex; } selectIndex = EditorGUILayout.Popup(kvp.Key, selectIndex, kvp.Value); if (GUI.changed) { //Debug.Log("Selected: " + kvp.Key + " : " + kvp.Value[GUIClientSelectionIndex] + "!"); GUIClientSelectionIndex = selectIndex; showClientConfirmState = true; clientConfirmKey = kvp.Key; clientConfirmValue = kvp.Value[GUIClientSelectionIndex]; selectedClientObj = Syphon.GetSyphonClient(clientConfirmKey, clientConfirmValue); } } if (showClientConfirmState && selectedClientObj != null) { SyphonClientObject destroyObj = null; GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); GUILayout.Label("App: " + selectedClientObj.AttachedServer.SyphonServerDescriptionAppName + "\nName: " + selectedClientObj.AttachedServer.SyphonServerDescriptionName); if (GUILayout.Button("remove client")) { destroyObj = selectedClientObj; } GUILayout.EndVertical(); GUILayout.Label(new GUIContent("", selectedClientObj.AttachedTexture, "App: " + selectedClientObj.AttachedServer.SyphonServerDescriptionAppName + "\nName: " + selectedClientObj.AttachedServer.SyphonServerDescriptionName), GUILayout.MaxWidth(150), GUILayout.MaxHeight(128)); GUILayout.EndHorizontal(); if (destroyObj != null) { Syphon.DestroyClient(destroyObj); showClientConfirmState = false; GUIClientSelectionIndex = 0; } } }
void Start() { clientObject = Syphon.GetSyphonClient(clientAppName, clientName); //if the client object exists, if (clientObject != null) { //if the texture has been initialized, apply its texture to something. ApplyTexture(); } }
void OnTriggerEnter(Collider other) { if (other.gameObject.tag == "Player" && syphonScript == null) { // add the syphon script to this item if they entered the players trigger syphonScript = gameObject.AddComponent <Syphon>(); syphonScript.player = other.transform; Debug.Log("syphoncreated"); stopBobbing = true; } }
public void OnDestroy() { if (syphonServerTextureInstance != IntPtr.Zero) { Syphon.QueueToKillTexture(syphonServerTextureInstance); GL.IssuePluginEvent((int)syphonServerTextureInstance); } syphonServerTextureInstance = IntPtr.Zero; syphonServerTextureValuesCached = false; cachedTexID = 0; }
public void OnDestroy() { if (syphonServerTextureInstance != 0) { Syphon.KillServerTexture(syphonServerTextureInstance); } syphonServerTextureInstance = 0; syphonServerTextureValuesCached = false; srcTex = null; cachedTexID = 0; }
// // Cache the current texture data to server public void cacheTextureValues(RenderTexture rt) { if (rt.GetNativeTexturePtr() != IntPtr.Zero && rt.width != 0 && rt.height != 0) { Syphon.CacheServerTextureValues((int)rt.GetNativeTexturePtr(), rt.width, rt.height, syphonServerTextureInstance); cachedTexID = (int)rt.GetNativeTexturePtr(); cachedWidth = rt.width; cachedHeight = rt.height; syphonServerTextureValuesCached = true; } }
public void OnRenderObject() { if (!testCameraExists()) { return; } if (renderWidth != _renderWidth || renderHeight != _renderHeight) { if (renderWidth <= 4) { renderWidth = 4; } if (renderHeight <= 4) { renderHeight = 4; } if (renderWidth > 8192) { renderWidth = 8192; } if (renderHeight > 8192) { renderHeight = 8192; } _renderWidth = renderWidth; _renderHeight = renderHeight; createOrResizeRenderTexture(); } // Update texture data on Syphon server if (!syphonServerTextureValuesCached || cachedTexID != cameraInstance.targetTexture.GetNativeTexturePtr() || cameraInstance.targetTexture.width != cachedWidth || cameraInstance.targetTexture.height != cachedHeight) { cacheTextureValues(cameraInstance.targetTexture); } Syphon.SafeMaterial.SetPass(0); // Publish texture to Syphon Server if (syphonServerTextureInstance != IntPtr.Zero && cachedTexID != IntPtr.Zero) { GL.IssuePluginEvent(Syphon.SyphonGetRenderEventFunc(), (int)syphonServerTextureInstance); } if (_renderMe != renderMe) { TestIfShouldRender(); } }
static AutorunSyphon() { //only cache the assembly/update the instance/etc if the syphon instance already exists in the scene if (UnityEngine.Object.FindObjectOfType(typeof(Syphon)) != null) { if (!Syphon.assemblyIsUpdated()) { Syphon.cacheAssembly(); } EditorApplication.update += myUpdate; } }
public void OnDestroy() { if (syphonServerTextureInstance != 0) { Syphon.KillServerTexture(syphonServerTextureInstance); } syphonServerTextureInstance = 0; syphonServerTextureInstanceInitialized = false; tex = null; storedWidth = 0; storedHeight = 0; }
//i don't trust that this doesn't crash unity. need more testing. // public SyphonClientTexture(){ // Syphon.syphonScriptCount++; // } // ~SyphonClientTexture(){ // Syphon.syphonScriptCount--; // } #endif void setupTexture() { //when you initialize the client texture, you should TRY to create the syphon client object. //if it needs to exist because the server is available, it will create it. if the server is offline, //nothing will happen. this basically initializes a singleton for that particular server appName/name. clientObject = Syphon.CreateClient(clientAppName, clientName); // if the client object exists if (clientObject != null) { //only registers it if it doesn't already exist. Syphon.RegisterClientInstance(this, clientObject); } }
// private void InitSyphonClient(){ if(Application.isPlaying && attachedServer.SyphonServerPointer != IntPtr.Zero && !initialized){ //does not allocate GL resources: creates SyphonCacheData object on heap, saves ptr to Unity syphonClientPointer = Syphon.CreateClientTexture(attachedServer.SyphonServerPointer); // int texID = (int)attachedTexture.GetNativeTexturePtr(); // Syphon.CacheClientTextureValues(texID, attachedTexture.width, attachedTexture.height, syphonClientPointer); if(AnnounceClient != null) AnnounceClient(this); //do not mark as 'initialized yet- wait til we get a 'valid' texture ID. //this is because Unity (as of 4.2) no longer immediately returns a texture with a valid color backing on RT creation. //gets marked as initialized in the Render() method further below. } }
public void AnnounceServer(string appName, string name) { if (!initialized && MatchesDescription(appName, name)) { announceServerQueueServer = Syphon.GetSyphonServer(appName, name); if (announceServerQueueServer != null) { announceServerQueue = true; // // DestroySyphonClient(); // DefineSyphonClient(server); // InitSyphonClient(); // Debug.Log("announced app:" + appName + " name: " + name ); } } }
{// static AutorunSyphon() { //only cache the assembly/update the instance/etc if the syphon instance already exists in the scene //but, using registered syphon clients/server scripts instead of 'finding' them in the scene. this is faster. if (UnityEngine.Object.FindObjectOfType(typeof(SyphonServerTexture)) != null || UnityEngine.Object.FindObjectOfType(typeof(SyphonClientTexture)) != null) { // if(Syphon.syphonScriptCount > 0){ if (!Syphon.assemblyIsUpdated()) { Syphon.cacheAssembly(); } EditorApplication.update += myUpdate; } }
////////////////////////////////////////////////////////////// // // GAME LOOP CALLBACKS -- In order they are called // // // OnRenderImage() is called after all rendering is complete to render image, but the GUI is not rendered yet // http://docs.unity3d.com/Documentation/ScriptReference/Camera.OnRenderImage.html public virtual void OnRenderImage(RenderTexture src, RenderTexture dst) { // Update texture data on Syphon server if (!syphonServerTextureValuesCached || cachedTexID != src.GetNativeTexturePtr() || src.width != cachedWidth || src.height != cachedHeight) { cacheTextureValues(src); } // Copy src to dst Syphon.SafeMaterial.SetPass(0); Graphics.Blit(src, dst); // Publish texture to Syphon Server if (syphonServerTextureInstance != IntPtr.Zero && cachedTexID != IntPtr.Zero) { GL.IssuePluginEvent(Syphon.SyphonGetRenderEventFunc(), (int)syphonServerTextureInstance); } }
public void Render(){ if(attachedTexture.GetNativeTextureID() != cachedTexID){ cachedTexID = attachedTexture.GetNativeTextureID(); Syphon.CacheClientTextureValues(attachedTexture.GetNativeTextureID(), attachedTexture.width, attachedTexture.height, syphonClientPointer); initialized = true; } if(syphonClientPointer != IntPtr.Zero && initialized){ //you need to render once per frame for each texture. Syphon.SafeMaterial.SetPass(0); RenderTexture.active = attachedTexture; GL.IssuePluginEvent((int)syphonClientPointer); RenderTexture.active = null; } }
public void Render() { if (attachedTexture.GetNativeTexturePtr() != cachedTexID) { cachedTexID = attachedTexture.GetNativeTexturePtr(); Syphon.CacheClientTextureValues(attachedTexture.GetNativeTexturePtr(), attachedTexture.width, attachedTexture.height, syphonClientPointer); initialized = true; } if (syphonClientPointer != IntPtr.Zero && initialized) { //you need to render once per frame for each texture. Syphon.SafeMaterial.SetPass(0); RenderTexture.active = attachedTexture; // UnityEngine.Debug.Log ("ISSUING EVENT?" + (int)syphonClientPointer) ; GL.IssuePluginEvent(Syphon.SyphonGetRenderEventFunc(), (int)syphonClientPointer); RenderTexture.active = null; } }
public void drawGUIServerEditor() { foreach (KeyValuePair <string, string[]> kvp in SyphonTarget.serverAppNames) { GUI.changed = false; int selectIndex = 0; if (kvp.Key != serverConfirmKey) { selectIndex = 0; } else { selectIndex = GUIServerSelectionIndex; } selectIndex = EditorGUILayout.Popup(kvp.Key, selectIndex, kvp.Value); if (GUI.changed) { //Debug.Log("Selected: " + kvp.Key + " : " + kvp.Value[GUIServerSelectionIndex] + "!"); GUIServerSelectionIndex = selectIndex; showServerConfirmState = true; serverConfirmKey = kvp.Key; serverConfirmValue = kvp.Value[selectIndex]; } } if (showServerConfirmState && SyphonTarget.servers.ContainsKey(serverConfirmKey) && SyphonTarget.servers[serverConfirmKey].ContainsKey(serverConfirmValue)) { GUILayout.BeginHorizontal(); GUILayout.Label("ADD CLIENT:\nAPP: " + serverConfirmKey + "\nNAME: " + serverConfirmValue); if (GUILayout.Button("YES")) { Syphon.CreateClient(serverConfirmKey, serverConfirmValue); showServerConfirmState = false; } else if (GUILayout.Button("NO")) { showServerConfirmState = false; } GUILayout.EndHorizontal(); } }
public void InitSyphonClient() { //call Syphon initialize method here. //if we have a valid syphon server attached, and not initialized yet, if (Application.isPlaying && attachedServer.SyphonServerPointer != 0 && !initialized) { // Debug.Log("EXECUTING syphon client: " + boundAppName + " " + boundName); attachedTexture.Create(); RenderTexture.active = attachedTexture; Graphics.Blit(Syphon.NullTexture, attachedTexture); RenderTexture.active = null; //RenderTexture.active = attachedTexture; syphonClientPointer = Syphon.CreateClientTexture(attachedServer.SyphonServerPointer); Syphon.CacheClientTextureValues(attachedTexture.GetNativeTextureID(), attachedTexture.width, attachedTexture.height, syphonClientPointer); initialized = true; if (AnnounceClient != null) { AnnounceClient(this); } } }
public void Awake() { cacheAssembly(); // DontDestroyOnLoad(this.gameObject); //if there is an extra instance of Syphon that exists, destroy it. //Syphon is supposed to act like a singleton, so force it to behave like one. if (Syphon.Instance != null && Syphon.Instance != this) { DestroyImmediate(this); return; } //force the instance references to be valid each time you play the game. instance = this; Instance.initSyphonServers(); Instance.initSyphonClients(); //print(serverAppNames.Count +" " + Syphon.ServerAppNames.Count); initialized = true; }
private RenderTexture dstTex = null; // reference to the camera render destination (when GUI in ON) void Start() { //Syphon instance = Syphon.Instance; syphonServerTextureInstance = Syphon.CreateServerTexture(gameObject.name); }
void OnDestroy() { Syphon.UnregisterClientInstance(this); }