Hovering Usernames

Post here all your questions related with SmartFoxServer .Net/Unity3D API

Moderators: Lapo, Bax

User avatar
docremix
Posts: 4
Joined: 12 Jun 2010, 14:56

Hovering Usernames

Postby docremix » 12 Jun 2010, 15:07

Greetings!

I am new to unity and smartfox :( ,
though ive managed to set up a networking chat with the help of tutorials and the islanddemo.., I can't get the smartfox usernames hovering above my players :(

I understand they have to be dynamically generated in a GUIText?
And I see they are already there in the bubblepopup script? I simply am not experienced enough to understand how to get them from there :((

Can someone plse help this noob out ..., lol a short piece of code would be appreciated a lot!!!

Thanks in advance

ps: i found this script to hover an object label
I simply want it to say the username from smartfox login
http://www.unifycommunity.com/wiki/index.php?title=ObjectLabel
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 14 Jun 2010, 19:57

I would definitely post this question over on the Unity forums. It would get way more responses than here, where its not really SmartFoxServer related.

Best
Thomas
User avatar
docremix
Posts: 4
Joined: 12 Jun 2010, 14:56

thanks Thomas

Postby docremix » 09 Jul 2010, 10:23

thanks Thomas! but the post there didnt do the trick lol

so I'm simplifying the question....

How do I retrieve the usernames from smartfox?

I have this:

Code: Select all

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;

using SmartFoxClientAPI;
using SmartFoxClientAPI.Data;

public class NewBehaviourScript : MonoBehaviour {
   
   
    public class User
   {
      private int id;
      private string name;
      private Hashtable variables;
      private bool isSpec;
      private bool isMod;
      private int pId;


      public User(int id, string name)
      {
         this.id = id;
         this.name = name;
         this.variables = new Hashtable();
         this.isSpec = false;
         this.isMod = false;
      }   
     

}

   // Use this for initialization
   void Start () {
   }
   
   // Update is called once per frame
   void Update () {
        Debug.Log=(user.GetName());
   }

   
}


But it gives me errors on the debug part :S
I really dont know where to go from here,
as I tried to understand all tuts and tricks
without results.

Can someone help me out I just want the username (from smartfox)
to display in a GUIText attached to the remotePlayer.

I managed to retrieve my own username btw that was easier but not what I wanted...

Boohoo my players have no Identity :cry:

Thank you so much in advance,

RemiX
1
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 17 Jul 2010, 12:39

Once you have the User object that the remote user avatar model represents, its as simple as to do a GetName() on that.

So you could e.g. query the API for the current rooms user list.

Something along the lines of

Hashtable users = room.GetUserList();

foreach (User u in users.Values)
Trace.WriteLine(u.GetName());

Now - the trick is then to figure out which avatar in the world is what User. You will need to keep track of the users Id - and correlate that with the info from the SFS API.

Once you got that - its as simple as to have a 3d text object attached to each model that moves with it - that you can then set to the name. Or maybe you can use a 2d text projected into the 2d screen space instead of the world.

Hope that helps you along

/Thomas
User avatar
docremix
Posts: 4
Joined: 12 Jun 2010, 14:56

Postby docremix » 18 Jul 2010, 08:08

Aaargh! I dont really get it

I started looking in the Network Controller script in the demo,
because ive seen that the username is used in there...

So I added a guitext to the remotePlayer prefab named unameit
and hooked into the OnPublicMessage lines.
So if there is something said the username should appear in the guitext ("atleast thats what i thought loool)

Code: Select all

   public void OnPublicMessage(string message, User fromUser, int roomId)
   {
      int userId = fromUser.GetId();
      
      
       if (userId!=smartFoxClient.myUserId) {  // If it's not myself
          string mes = fromUser.GetName()+": "+message;

                   // here is what i tried
         GameObject hovertje = GameObject.Find("remote_"+userId+"/unameit");
         hovertje.guiText.text = (fromUser.GetName());
         
         // Send chat message to the Chat Controller         
         SendMessage("AddChatMessage", mes);
         

         
         //Find user object with such Id
         GameObject user = GameObject.Find("remote_"+userId);
         //If found - send him bubble message
         if (user) {
            user.SendMessage("ShowBubble", mes);

         }


Nothing shows, I just cant figure it out.., noob as I am in CS and JS and SFS

Am I going in the right direction here?

Thanks docremix

ps: If you want to take a look....

http://kingdub.com/228616
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 18 Jul 2010, 09:38

Without having tried it, it seems sane enough. Nothing obvious to spot. Put in some debug messaging though to see if you really get anything. E.g. if you have the wrong id, then your lookup fails and nothing will show.

So pepper the code with Debug.Log() and check everything on the console.
User avatar
docremix
Posts: 4
Joined: 12 Jun 2010, 14:56

I give UP!

Postby docremix » 18 Jul 2010, 10:25

Thanks for your time Thomas, but I really can't get it to work :twisted:

debug gives me nothing and all stutters as if there is something missing

and if it should work its only when something is said

why cant i just add a script to the remoteplayer prefab GuiText saying something like... here u get your smartfox client username?

I think its not of my programming level.., I quit.., give up... no identity for me avies :(

thanks a million anyways

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 17 guests