Inheritance: MonoBehaviour
Ejemplo n.º 1
0
    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;
    }
Ejemplo n.º 2
0
	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.");
		}			
	}
Ejemplo n.º 3
0
    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.");
        }
    }
Ejemplo n.º 6
0
    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);
        }
    }
Ejemplo n.º 7
0
 public void cacheTextureValues()
 {
     if (storedWidth != 0 && storedHeight != 0 && storedTexID != 0)
     {
         Syphon.CacheServerTextureValues(storedTexID, storedWidth, storedHeight, syphonServerTextureInstance);
         syphonServerTextureInstanceInitialized = true;
     }
 }
Ejemplo n.º 8
0
    public void LateUpdate()
    {
        Syphon.UpdateTextureSizes();

        if (UpdateClientTextures != null)
        {
            UpdateClientTextures();
        }
    }
Ejemplo n.º 9
0
    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;
            }
        }
    }
Ejemplo n.º 10
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();
     }
 }
Ejemplo n.º 11
0
 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;
 }
Ejemplo n.º 13
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;
     }
 }
Ejemplo n.º 15
0
    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();
        }
    }
Ejemplo n.º 16
0
    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;
        }
    }
Ejemplo n.º 17
0
    public void OnDestroy()
    {
        if (syphonServerTextureInstance != 0)
        {
            Syphon.KillServerTexture(syphonServerTextureInstance);
        }

        syphonServerTextureInstance            = 0;
        syphonServerTextureInstanceInitialized = false;
        tex          = null;
        storedWidth  = 0;
        storedHeight = 0;
    }
Ejemplo n.º 18
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);
        }
    }
Ejemplo n.º 19
0
	//
	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;
        }
    }
Ejemplo n.º 22
0
    //////////////////////////////////////////////////////////////
    //
    // 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);
        }
    }
Ejemplo n.º 23
0
	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;
		}
	}
Ejemplo n.º 24
0
    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;
        }
    }
Ejemplo n.º 25
0
    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);
            }
        }
    }
Ejemplo n.º 27
0
    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);
    }
Ejemplo n.º 29
0
 void OnDestroy()
 {
     Syphon.UnregisterClientInstance(this);
 }
Ejemplo n.º 30
0
    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;
    }
Ejemplo n.º 31
0
    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;
    }