venerdì 27 dicembre 2013

End of the year post

Hi guys, long time no see. I usually don't make this kind of posts since this is more a "programming spot for nerds" than an actual blog about me. Anyway, I wanted to write something about myself for once, this year is about to end and it brought some major changes in my life. I opened this blog because I was bored and I wanted to dedicate some of my time by helping other with the only thing useful I can bring to the web: my passion for programming, videogame and whatever. However in the process of studying and working I've lost all my interest in the things that made me happy. This and realizing a bunch of things about myself made me become sad and insecure, I've lost the concept of who I am. Hopefully things will change, I've never made things like resolution list, but I want to make one, not only because of the new year crap, but also for helping me out becoming the person I wanted to be to begin with. So, here we go with the new year resolution:

  1. Dedicate more time to my passions (including making music, playing videogames, drawing).
  2. Start thinking and making new apps and games, even if they sound stupid or awful.
  3. Stop passive working and studying, try to find the fun thing for both of the things.
  4. Improve myself as a programmer. I've still a lot of things I want to learn about it in general, I'll find the time to experiment with php, javascript, jquery, tomcat, other.
  5. Be more open with friends and myself.
  6. Generally post some useful or fun thing on the blog.
  7. Start worrying less about money, I'll manage financial problems one step at a time.
  8. Be happy.
An empty smile can't be warm as a real one. I'll try my best.


domenica 1 dicembre 2013

Comunicazione tra Script > Unity3d

Esclusivamente per i miei fellow amici italici riporterò di seguito parte della mia tesi che discute in maniera breve ma concisa uno dei concetti fondamentali di Unity3d. Si parlerà di comunicazione tra i vari script presenti nella scena associati ai vari gameObjects. Un qualsiasi script “attaccato” ad un oggetto nella scena, viene trattato come un componente, quando si crea un nuovo script questo diventa immediatamente un nuovo “tipo” identificato dal nome dato allo stesso. Possiamo accedere a funzioni e proprietà pubbliche del component di un determinato oggetto semplicemente richiamando GetComponent. Per evitare di passare dal componente è possibile utilizzare la funzione SendMessage derivabile dal gameobject, questa si occupa di cercare ed eseguire la funzione il cui nome gli viene passato in input (appartenente a qualsiasi script attaccato a quell’oggetto). Nell’esempio vediamo come è possibile trovare da codice un oggetto nella scena e richiamarne a seguito una sua funzione.
function Start()
{
    var controlCenter : GameObject; //dichiaro una variabile di tipo GameObject
    controlCenter = GameObject.Find("ControlCenter"); //restituisce l'oggetto ControlCenter della scena
    controlCenter.GetComponent(MusicCenter).toogle_music = true; //modifico una proprietà dello script
    
    controlCenter.SendMessage("set_music", true); 
    //richiamo la funzione set_music da qualsiasi script del controlCenter
    //set_music prende in input un booleano, lo passo come secondo parametro di SendMessage
}

Tramite le funzioni Find e FindGameObjectsWithTag della classe GameObject è possibile ottenere i riferimenti agli oggetti presenti nella scena. Ogni proprietà a cui accediamo tramite GetComponent deve essere public o internal.