Author Topic: [Solved] Show newly activated children of prefab over network.  (Read 3988 times)

Etarnalazure

  • Guest
Hello everyone!

The very reason I bought this kit was because I thought it might be able to solve one of
the big problems I had been having.

Mainly; Syncing newly activated children of an instantiated prefab

So I'm building an RPG and as in any RPG I have an inventory, the
way it works is that when an item has been equipped it will make
the gameobject that is of the same name go from inactive to active.

Simple enough, the system I've built works on the client side (Meaning
it works on the player equipping an item) but no one else sees the item
being equipped. I've tried many different things but to no avail.

The problem is that when the previously inactive gameobject
becomes active, it does not update the player 'dummy' so
the rest of the players can see the equipment on their screens.

Is there a way to send a message over the network telling
the dummy connected to the player to active the gameobject?

I hope there is a relatively easy way of doing this, because
the other way I had thought out was by sending booleans
back and forth, but with roughly 98 items in the game
it would take ages to make.


Heres the code for one of the item categories:

  1.  
  2. private static GameObject[] _gloveMesh;
  3. public static Item EquipedGloves
  4.         {
  5.                 get{return _equipment[(int)EquipmentSlot.Hands];}
  6.                 set{
  7.                         _equipment[(int)EquipmentSlot.Hands] = value;
  8.                        
  9.                         //HideGloveMeshes();
  10.  
  11.                         if(_equipment[(int)EquipmentSlot.Hands] == null)
  12.                         {
  13.                                 return;
  14.                         }
  15.                        
  16.                         switch (_equipment[(int)EquipmentSlot.Hands].Name) {
  17.                                 case "ElvenArmourGloves":
  18.                                         _gloveMesh[0].SetActive(true);
  19.                                         break;
  20.                                 case "LeatherArmourGloves":
  21.                                         _gloveMesh[1].SetActive(true);
  22.                                         break;
  23.                                 case "RepublicGloves":
  24.                                         _gloveMesh[2].SetActive(true);
  25.                                         break;
  26.                         }
  27.                 }
  28.         }
  29.  
  30. public override void Awake()
  31.         {
  32.                 base.Awake();
  33.                 Transform _gloveMount = gameObject.transform.Find("Armors/Gloves");
  34.  
  35.                 int countGlove = _gloveMount.GetChildCount();
  36.                 _gloveMesh = new GameObject[countGlove];
  37.                 for (int i = 0; i < countGlove; i++) {
  38.                         _gloveMesh[i] = _gloveMount.GetChild(i).gameObject;
  39.                 }
  40.         }
  41.  


Also I should point this out before anyone tries to tell me to just instantiate the item;

The model is a pre-made 3D model, all the items started out
as child objects, and any attempt on my end to take them out
and make them into gameobjects themselves has resulted in
the item looking weird, not animating properly when the
character does different animations. Or simply refusing to be
the right size.


Hopefully someone can help since this very thing is why I bought
this asset.

Thanks in advance.



**EDIT**

This is where I equip items

  1. public void InventoryWindow(int id)
  2.         {
  3.                 int i = 0;
  4.                 for (int y = 0; y < _inventoryRows; y++) {
  5.                         for (int x = 0; x < _inventoryCollumns; x++) {
  6.                                 if(i < PlayerCharacter.Inventory.Count)
  7.                                 {
  8.                                         if(GUI.Button(new Rect(5 + (x * buttonWidth), 20 + (y * buttonHeight), buttonWidth, buttonHeight), new GUIContent(PlayerCharacter.Inventory[i].Icon, PlayerCharacter.Inventory[i].ToolTip())))
  9.                                         {
  10.                                                 if(_doubleClickTimer != 0 && _selectedItem != null)
  11.                                                 {
  12.                                                         if(Time.time - _doubleClickTimer < DOUBLE_CLICK_TIMER_THRESHOLD)
  13.                                                         {
  14.                                                                 //Debug.Log("Double click: " + PlayerCharacter.Inventory[i].Name);
  15.                                                                 if(typeof(Weapon) == PlayerCharacter.Inventory[i].GetType())
  16.                                                                 {
  17.                                                                         if(PlayerCharacter.EquipedWeapon == null)
  18.                                                                         {
  19.                                                                                 PlayerCharacter.EquipedWeapon = PlayerCharacter.Inventory[i];
  20.                                                                                 PlayerCharacter.Inventory.RemoveAt(i);
  21.                                                                         }
  22.                                                                         else
  23.                                                                         {
  24.                                                                                 Item temp = PlayerCharacter.EquipedWeapon;
  25.                                                                                 PlayerCharacter.EquipedWeapon = PlayerCharacter.Inventory[i];
  26.                                                                                 PlayerCharacter.Inventory[i] = temp;
  27.                                                                         }
  28.                                                                 }
  29.                                                                 else if(typeof(Armor) == PlayerCharacter.Inventory[i].GetType())
  30.                                                                 {
  31.                                                                         Armor arm = (Armor)PlayerCharacter.Inventory[i];
  32.                                                                         switch(arm.Slot)
  33.                                                                         {
  34.                                                                        
  35.                                                                                 case EquipmentSlot.Torso:
  36.                                                                                         ShowArmor(i);
  37.                                                                                         tno.Send(1, Target.All, i);
  38.                                                                                         break;
  39.                                                                                
  40.                                                                         }
  41.                                                                 }
  42.                                                                
  43.                                                                
  44.                                                                 _doubleClickTimer = 0;
  45.                                                                 _selectedItem = null;
  46.                                                         }
  47.                                                         else
  48.                                                         {
  49.                                                                 //Debug.Log("Doublle click timer have been reset");
  50.                                                                 _doubleClickTimer = Time.time;
  51.                                                         }
  52.                                                 }
  53.                                                 else
  54.                                                 {
  55.                                                         _doubleClickTimer = Time.time;
  56.                                                         _selectedItem = PlayerCharacter.Inventory[i];
  57.                                                 }
  58.                                         }
  59.                                 }
  60.                                 else
  61.                                 {
  62.                                         GUI.Button(new Rect(5 + (x * buttonWidth), 20 + (y * buttonHeight), buttonWidth, buttonHeight), (x + y *_inventoryCollumns).ToString(), "box");
  63.                                 }
  64.                                 i++;
  65.                         }
  66.                 }
  67.                
  68.                 SetToolTip();
  69.                 GUI.DragWindow();
  70.         }
  71.         private void ShowArmor(int i)
  72.         {
  73.                
  74.                 if(PlayerCharacter.EquipedTorso == null)
  75.                 {
  76.                         Debug.Log("I am a proper player");
  77.                         PlayerCharacter.EquipedTorso = PlayerCharacter.Inventory[i];
  78.                         PlayerCharacter.Inventory.RemoveAt(i);
  79.                 }
  80.                 else
  81.                 {
  82.                         Debug.Log("I am a proper player else");
  83.                         Item temp = PlayerCharacter.EquipedTorso;
  84.                         PlayerCharacter.EquipedTorso = PlayerCharacter.Inventory[i];
  85.                         PlayerCharacter.Inventory[i] = temp;
  86.                 }
  87.         }
  88.         [RFC(1)]
  89.         private void RemoteShowArmor(int i)
  90.         {
  91.                
  92.                 Debug.Log("id: " + i);
  93.                 if(PlayerCharacter.EquipedTorso == null)
  94.                 {
  95.                        
  96.                         PlayerCharacter.EquipedTorso = PlayerCharacter.Inventory[i];
  97.                         PlayerCharacter.Inventory.RemoveAt(i);
  98.                         Debug.Log("put on torse");
  99.                 }
  100.                 else
  101.                 {
  102.                         Item temp = PlayerCharacter.EquipedTorso;
  103.                         PlayerCharacter.EquipedTorso = PlayerCharacter.Inventory[i];
  104.                         PlayerCharacter.Inventory[i] = temp;
  105.                 }
  106.         }
  107.  
« Last Edit: August 02, 2013, 07:31:13 PM by Etarnalazure »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Show newly activated children of prefab over network.
« Reply #1 on: August 01, 2013, 10:27:28 PM »
You are way overcomplicating this.

1. Have a custom script attached to the root of the prefab.
2. Have this script derived from TNBehavior have "public GameObject[] obj;" type references in it that you can drag & drop set in inspector.
3. When you want to activate some object, instead of calling SetActive, do an RFC call instead: tno.Send("SetState", Target.AllSaved, ...), where "..." should be replaced with a boolean array listing the current state of all the objects.
  1. [RFC]
  2. void SetState (bool[] states)
  3. {
  4.     for (int i = 0; i < states.Length; ++i)
  5.         SetActive(obj[i], states[i]);
  6. }

Etarnalazure

  • Guest
Re: Show newly activated children of prefab over network.
« Reply #2 on: August 01, 2013, 10:34:45 PM »
I had a feeling I was overthinking it as per usual, its 5:30 am and I've been up for a good 20 hours working on this.

Thank you very much for the help, I will try and implement it tomorrow after I've gotten som sleep.

Etarnalazure

  • Guest
Re: Show newly activated children of prefab over network.
« Reply #3 on: August 02, 2013, 01:26:40 PM »
Okay. I simply cannot get your code to work mate so I'm hoping you're willing
to help any further.

My problem is that I am unsure how to proceed. I understand
the basics of what you're telling me;

You send the object with its ID and then you send a message
to the object with the ID that it needs to change it's bool
to what ever it is told.

But I cannot get it working, it sends nothing over the network
and I do not understand what you ment by "SetActive"

Is it an inbuilt thing in the library? Or is it a method you made?
Or is it simply pseudo code?

Also, does tno.send not work when its static?

Since all the item slots I have are static so I can easily change them from
another script (Thats not on the player).

I'm going to go out on a limb and post the code involved with the equipment

(If anyone can use my code, they're welcome to use it, I'm not fussed)

First;

The Player character

(I have to warn; Most of the code is the 'same' but with different variables. I did this to make
the code look nicer since one long method with each and every item was very ugly to look at
and this way I've split items up in categories)

  1.  
  2. private static GameObject[] _weaponMesh;
  3.         private static GameObject[] _armMesh;
  4.         private static GameObject[] _bicepMesh;
  5.         private static GameObject[] _bootMesh;
  6.         private static GameObject[] _gloveMesh;
  7.         private static GameObject[] _helmetMesh;
  8.         private static GameObject[] _legMesh;
  9.         private static GameObject[] _shoulderMesh;
  10.         public static GameObject[] _torsoMesh;
  11.         private static GameObject[] _waistMesh;
  12.         private static GameObject[] _wristMesh;
  13.        
  14.         private static System.Collections.Generic.List<Item> _inventory = new System.Collections.Generic.List<Item>();
  15.         public static System.Collections.Generic.List<Item> Inventory
  16.         {
  17.                 get{return _inventory;}
  18.         }
  19.        
  20.         private static Item[] _equipment = new Item[(int)EquipmentSlot.COUNT];
  21.         public static int currentWepEquipped = 3;
  22.         public static Item EquipedWeapon
  23.         {
  24.                 get{return _equipment[(int)EquipmentSlot.MainHand];}
  25.                 set{
  26.                         _equipment[(int)EquipmentSlot.MainHand] = value;
  27.                
  28.                          //HideWeaponMeshes();
  29.                        
  30.                         if(_equipment[(int)EquipmentSlot.MainHand] == null)
  31.                         {
  32.                                 return;
  33.                         }
  34.                         switch (_equipment[(int)EquipmentSlot.MainHand].Name) {
  35.                         case "Curvy Knife":
  36.                                 _weaponMesh[0].SetActive(true);
  37.                                 currentWepEquipped = 0;
  38.                                 break;
  39.                         case "Stiletto Sword":
  40.                                 _weaponMesh[1].SetActive(true);
  41.                                 currentWepEquipped = 1;
  42.                                 break;
  43.                         case "Stone Axe":
  44.                                 _weaponMesh[2].SetActive(true);
  45.                                 currentWepEquipped = 2;
  46.                                 break;
  47.                         default:
  48.                                 Debug.Log("Fist");
  49.                                 currentWepEquipped = 3;
  50.                                 break;
  51.                                
  52.                         }
  53.                 }
  54.         }
  55.         public static Item EquipedGloves
  56.         {
  57.                 get{return _equipment[(int)EquipmentSlot.Hands];}
  58.                 set{
  59.                         _equipment[(int)EquipmentSlot.Hands] = value;
  60.                        
  61.                         //HideGloveMeshes();
  62.  
  63.                         if(_equipment[(int)EquipmentSlot.Hands] == null)
  64.                         {
  65.                                 return;
  66.                         }
  67.                        
  68.                         switch (_equipment[(int)EquipmentSlot.Hands].Name) {
  69.                                 case "ElvenArmourGloves":
  70.                                         _gloveMesh[0].SetActive(true);
  71.                                         break;
  72.                                 case "LeatherArmourGloves":
  73.                                         _gloveMesh[1].SetActive(true);
  74.                                         break;
  75.                                 case "RepublicGloves":
  76.                                         _gloveMesh[2].SetActive(true);
  77.                                         break;
  78.                         }
  79.                 }
  80.         }
  81.         public static Item EquipedArms
  82.         {
  83.                 get{return _equipment[(int)EquipmentSlot.Arms];}
  84.                 set{
  85.                         _equipment[(int)EquipmentSlot.Arms] = value;
  86.                         //HideArmMeshes();
  87.                         if(_equipment[(int)EquipmentSlot.Arms] == null)
  88.                         {
  89.                                 return;
  90.                         }
  91.                        
  92.                         switch (_equipment[(int)EquipmentSlot.Arms].Name) {
  93.                                 case "FarmerArms":
  94.                                         _armMesh[0].SetActive(true);
  95.                                         break;
  96.                                 case "GuildArms1":
  97.                                         _armMesh[1].SetActive(true);
  98.                                         break;
  99.                                 case "LeatherArmourArms":
  100.                                         _armMesh[2].SetActive(true);
  101.                                         break;
  102.                                 case "MercArms":
  103.                                         _armMesh[3].SetActive(true);
  104.                                         break;
  105.                                 case "MinerArms":
  106.                                         _armMesh[4].SetActive(true);
  107.                                         break;
  108.                                 case "NobleArms":
  109.                                         _armMesh[5].SetActive(true);
  110.                                         break;
  111.                                 case "PlateArmourArmArmour":
  112.                                         _armMesh[6].SetActive(true);
  113.                                         break;
  114.                                 case "RepublicArms":
  115.                                         _armMesh[7].SetActive(true);
  116.                                         break;
  117.                                 case "RomGladArms":
  118.                                         _armMesh[8].SetActive(true);
  119.                                         break;
  120.                                 case "TemplarArms":
  121.                                         _armMesh[9].SetActive(true);
  122.                                         break;
  123.                                 default:
  124.                                         Debug.Log("No Arms");
  125.                                         break;
  126.                                
  127.                                
  128.                         }
  129.                 }
  130.         }
  131.         public static Item EquipedWaist
  132.         {
  133.                 get{return _equipment[(int)EquipmentSlot.Waist];}
  134.                 set{
  135.                         _equipment[(int)EquipmentSlot.Waist] = value;
  136.                        
  137.                         //HideWaistMeshes();
  138.  
  139.                         if(_equipment[(int)EquipmentSlot.Waist] == null)
  140.                         {
  141.                                 return;
  142.                         }
  143.                        
  144.                         switch (_equipment[(int)EquipmentSlot.Waist].Name) {
  145.                                 case "MageSash":
  146.                                         _waistMesh[0].SetActive(true);
  147.                                         break;
  148.                                 case "Moustache":
  149.                                         _waistMesh[1].SetActive(true);
  150.                                         break;
  151.                         }
  152.                 }
  153.         }
  154.         public static Item EquipedWrist
  155.         {
  156.                 get{return _equipment[(int)EquipmentSlot.Wrist];}
  157.                 set{
  158.                         _equipment[(int)EquipmentSlot.Wrist] = value;
  159.                        
  160.                         //HideWristMeshes();
  161.  
  162.                         if(_equipment[(int)EquipmentSlot.Wrist] == null)
  163.                         {
  164.                                 return;
  165.                         }
  166.                         switch (_equipment[(int)EquipmentSlot.Wrist].Name) {
  167.                                 case "ElvenArmourWrist":;
  168.                                         _wristMesh[0].SetActive(true);
  169.                                         break;
  170.                                 case "MercWristArmour":
  171.                                         _wristMesh[1].SetActive(true);
  172.                                         break;
  173.                                 case "NordraicWristArmour":
  174.                                         _wristMesh[2].SetActive(true);
  175.                                         break;
  176.                                 case "TemplarWristArmour":
  177.                                         _wristMesh[3].SetActive(true);
  178.                                         break;
  179.                         }
  180.                 }
  181.         }
  182.         public static Item EquipedBicep
  183.         {
  184.                 get{return _equipment[(int)EquipmentSlot.Torso];}
  185.                 set{
  186.                         _equipment[(int)EquipmentSlot.Biceps] = value;
  187.                        
  188.                         //HideBicepMeshes();
  189.  
  190.                         if(_equipment[(int)EquipmentSlot.Biceps] == null)
  191.                         {
  192.                                 return;
  193.                         }
  194.                        
  195.                         switch (_equipment[(int)EquipmentSlot.Biceps].Name) {
  196.                                 case "ElvenArmourBicep":
  197.                                         _bicepMesh[0].SetActive(true);
  198.                                         break;
  199.                                 case "LeatherArmourBicepArmour":
  200.                                         _bicepMesh[1].SetActive(true);
  201.                                         break;
  202.                                 case "MercBicepArmour":
  203.                                         _bicepMesh[2].SetActive(true);
  204.                                         break;
  205.                                 case "TemplarBicepArmour":
  206.                                         _bicepMesh[3].SetActive(true);
  207.                                         break;
  208.                         }
  209.                 }
  210.         }
  211.         public static Item EquipedShoulder
  212.         {
  213.                 get{return _equipment[(int)EquipmentSlot.Shoulders];}
  214.                 set{
  215.                         _equipment[(int)EquipmentSlot.Shoulders] = value;
  216.                        
  217.                         //HideShoulderMeshes();
  218.  
  219.                         if(_equipment[(int)EquipmentSlot.Shoulders] == null)
  220.                         {
  221.                                 return;
  222.                         }
  223.                        
  224.                         switch (_equipment[(int)EquipmentSlot.Shoulders].Name) {
  225.                         case "MercShoulderArmour":
  226.                                
  227.                                 _shoulderMesh[0].SetActive(true);
  228.                                 break; 
  229.                         case "PLateArmourShoulderPads":
  230.                                 _shoulderMesh[1].SetActive(true);
  231.                                 break;
  232.                                
  233.                         }
  234.                 }
  235.         }
  236.         public static Item EquipedTorso
  237.         {
  238.                 get{return _equipment[(int)EquipmentSlot.Torso];}
  239.                 set{
  240.                         _equipment[(int)EquipmentSlot.Torso] = value;
  241.                        
  242.                         //HideTorsoMeshes();
  243.                        
  244.                         if(_equipment[(int)EquipmentSlot.Torso] == null)return;
  245.                         //string temp = GameSettings2.TORSO_ARMOR_MESH_PATH;
  246.                         switch (_equipment[(int)EquipmentSlot.Torso].Name) {
  247.                         case "ElvenArmourTorso":
  248.                                 _torsoMesh[0].SetActive(true);
  249.                                 break;
  250.                         case "FarmerTorso":
  251.                                 _torsoMesh[1].SetActive(true);
  252.                                 break;
  253.                         case "GuildTorso":
  254.                                 _torsoMesh[2].SetActive(true);
  255.                                 break;
  256.                         case "LeatherArmourTorso":
  257.                                 _torsoMesh[3].SetActive(true);
  258.                                 break;
  259.                         case "MageTorso":
  260.                                 _torsoMesh[4].SetActive(true);
  261.                                 break;
  262.                         case "MerchantTorso":
  263.                                 _torsoMesh[5].SetActive(true);
  264.                                 break;
  265.                         case "MercTorso":
  266.                                 _torsoMesh[6].SetActive(true);
  267.                                 break;
  268.                         case "MinerTorso":
  269.                                 _torsoMesh[7].SetActive(true);
  270.                                 break;
  271.                         case "NobleTorso":
  272.                                 _torsoMesh[8].SetActive(true);
  273.                                 break;
  274.                         case "NordraicTorso":
  275.                                 _torsoMesh[9].SetActive(true);
  276.                                 break;
  277.                         case "PlateArmourTorso":
  278.                                 //temp += "PlateArmourTorso";
  279.                                 _torsoMesh[10].SetActive(true);
  280.                                 break;
  281.                         case "RepublicTorso":
  282.                                 _torsoMesh[11].SetActive(true);
  283.                                 break;
  284.                         case "RomanGladTorso":
  285.                                 _torsoMesh[12].SetActive(true);
  286.                                 break;
  287.                         case "SilveralTorso":
  288.                                 _torsoMesh[13].SetActive(true);
  289.                                 break;
  290.                         case "StormLandsTorso":
  291.                                 _torsoMesh[14].SetActive(true);
  292.                                
  293.                                 break;
  294.                         case "TemplarTorso":
  295.                                 Debug.Log("TemplarTorso");
  296.                                 _torsoMesh[15].SetActive(true);
  297.                                 break;
  298.                         case "ThiefTorso":
  299.                                 _torsoMesh[16].SetActive(true);
  300.                                 break;
  301.                         default:
  302.                                 Debug.Log("Naked");
  303.                                 break;
  304.                         }
  305.                 }
  306.         }
  307.        
  308.        
  309.         public override void Awake()
  310.         {
  311.                 base.Awake();
  312.                 //player = GameObject.Find("PlayerPrefab(Clone)");
  313.                 /*Transform _weaponMount = player.transform.Find("Bip01/Bip01_Pelvis/Bip01_Spine/Bip01_Spine1/Bip01_Spine2/Bip01_Neck/Bip01_R_Clavicle/Bip01_R_UpperArm/Bip01_R_Forearm/Bip01_R_Hand/WeaponSlot");
  314.                 Transform _armMount = player.transform.Find("Armors/Arms");
  315.                 Transform _bicepMount = player.transform.Find("Armors/Biceps");
  316.                 Transform _bootMount = player.transform.Find("Armors/Boots");
  317.                 Transform _gloveMount = player.transform.Find("Armors/Gloves");
  318.                 Transform _helmetMount = player.transform.Find("Armors/Helmet");       
  319.                 Transform _legMount = player.transform.Find("Armors/Legs");
  320.                 Transform _shoulderMount = player.transform.Find("Armors/Shoulders");
  321.                 Transform _torsoMount = player.transform.Find("Armors/Torso");
  322.                 Transform _waistMount = player.transform.Find("Armors/Waist");
  323.                 Transform _wristMount = player.transform.Find("Armors/Wrist");*/
  324.                
  325.                 /*Transform _weaponMount = gameObject.transform.Find("Bip01/Bip01_Pelvis/Bip01_Spine/Bip01_Spine1/Bip01_Spine2/Bip01_Neck/Bip01_R_Clavicle/Bip01_R_UpperArm/Bip01_R_Forearm/Bip01_R_Hand/WeaponSlot");
  326.                 Transform _armMount = gameObject.transform.Find("Armors/Arms");
  327.                 Transform _bicepMount = gameObject.transform.Find("Armors/Biceps");
  328.                 Transform _bootMount = gameObject.transform.Find("Armors/Boots");
  329.                 Transform _gloveMount = gameObject.transform.Find("Armors/Gloves");
  330.                 Transform _helmetMount = gameObject.transform.Find("Armors/Helmet");   
  331.                 Transform _legMount = gameObject.transform.Find("Armors/Legs");
  332.                 Transform _shoulderMount = gameObject.transform.Find("Armors/Shoulders");
  333.                 Transform _torsoMount = gameObject.transform.Find("Armors/Torso");
  334.                 Transform _waistMount = gameObject.transform.Find("Armors/Waist");
  335.                 Transform _wristMount = gameObject.transform.Find("Armors/Wrist");*/
  336.  
  337.                 /*int countPlayerTorso = _playerTorsoMount.GetChildCount();
  338.                 _playerTorsoMesh = new GameObject[countPlayerTorso];
  339.                 for (int i = 0; i < countPlayerTorso; i++) {
  340.                         _playerTorsoMesh[i] = _playerTorsoMount.GetChild(i).gameObject;
  341.                 }*/
  342.                
  343.                
  344.                 /*int count = _weaponMount.GetChildCount();
  345.                 _weaponMesh = new GameObject[count];
  346.                 for (int i = 0; i < count; i++) {
  347.                         _weaponMesh[i] = _weaponMount.GetChild(i).gameObject;
  348.                 }
  349.                
  350.                 int countArm = _armMount.GetChildCount();
  351.                 _armMesh = new GameObject[countArm];
  352.                 for (int i = 0; i < countArm; i++) {
  353.                         _armMesh[i] = _armMount.GetChild(i).gameObject;
  354.                 }
  355.                
  356.                 int countBicep = _bicepMount.GetChildCount();
  357.                 _bicepMesh = new GameObject[countBicep];
  358.                 for (int i = 0; i < countBicep; i++) {
  359.                         _bicepMesh[i] = _bicepMount.GetChild(i).gameObject;
  360.                 }
  361.                 int countBoot = _bootMount.GetChildCount();
  362.                 _bootMesh = new GameObject[countBoot];
  363.                 for (int i = 0; i < countBoot; i++) {
  364.                         _bootMesh[i] = _bootMount.GetChild(i).gameObject;
  365.                 }
  366.                
  367.                 int countGlove = _gloveMount.GetChildCount();
  368.                 _gloveMesh = new GameObject[countGlove];
  369.                 for (int i = 0; i < countGlove; i++) {
  370.                         _gloveMesh[i] = _gloveMount.GetChild(i).gameObject;
  371.                 }
  372.                        
  373.                 int countHelmet = _helmetMount.GetChildCount();
  374.                 _helmetMesh = new GameObject[countHelmet];
  375.                 for (int i = 0; i < countHelmet; i++) {
  376.                         _helmetMesh[i] = _helmetMount.GetChild(i).gameObject;
  377.                 }
  378.                
  379.                 int countLeg = _legMount.GetChildCount();
  380.                 _legMesh = new GameObject[countLeg];
  381.                 for (int i = 0; i < countLeg; i++) {
  382.                         _legMesh[i] = _legMount.GetChild(i).gameObject;
  383.                 }
  384.                
  385.                 int countShoulder = _shoulderMount.GetChildCount();
  386.                 _shoulderMesh = new GameObject[countShoulder];
  387.                 for (int i = 0; i < countShoulder; i++) {
  388.                         _shoulderMesh[i] = _shoulderMount.GetChild(i).gameObject;
  389.                 }
  390.                
  391.                 int countTorso = _torsoMount.GetChildCount();
  392.                 _torsoMesh = new GameObject[countTorso];
  393.                 for (int i = 0; i < countTorso; i++) {
  394.                         _torsoMesh[i] = _torsoMount.GetChild(i).gameObject;
  395.                 }
  396.                
  397.                 int countWaist = _waistMount.GetChildCount();
  398.                 _waistMesh = new GameObject[countWaist];
  399.                 for (int i = 0; i < countWaist; i++) {
  400.                         _waistMesh[i] = _gloveMount.GetChild(i).gameObject;
  401.                 }
  402.                
  403.                 int countWrist = _wristMount.GetChildCount();
  404.                 _wristMesh = new GameObject[countWrist];
  405.                 for (int i = 0; i < countWrist; i++) {
  406.                         _wristMesh[i] = _wristMount.GetChild(i).gameObject;
  407.                 }*/
  408.        
  409.                
  410.                
  411.                 /*HideWeaponMeshes();
  412.                 HideArmMeshes();
  413.                 HideBicepMeshes();
  414.                 HideBootMeshes();
  415.                 HideGloveMeshes();
  416.                 HideHelmetMeshes();
  417.                 HideLegsMeshes();
  418.                 HideShoulderMeshes();
  419.                 HideTorsoMeshes();
  420.                 HideWaistMeshes();
  421.                 HideWristMeshes();*/
  422.         }
  423.         void Start()
  424.         {
  425.                 if(tno.isMine)
  426.                 {
  427.                         Transform _torsoMount = TNObject.Find(tno.uid).gameObject.transform.Find("Armors/Torso");
  428.                         Debug.Log("ID of player: " + TNObject.Find(tno.uid).uid);
  429.                         int countTorso = _torsoMount.GetChildCount();
  430.                         _torsoMesh = new GameObject[countTorso];
  431.                         for (int i = 0; i < countTorso; i++) {
  432.                                 _torsoMesh[i] = _torsoMount.GetChild(i).gameObject;
  433.                         }
  434.                 }
  435.         }
  436.        
  437.         void Update()
  438.         {
  439.                 Messenger<int, int>.Broadcast("PlayerHealthUpdate", 80,100, MessengerMode.DONT_REQUIRE_LISTENER);
  440.  
  441.         }
  442.        
  443. #region Hide Meshes    
  444. /*      private static void HideWeaponMeshes()
  445.         {
  446.                 for (int i = 0; i < _weaponMesh.Length; i++) {
  447.                         _weaponMesh[i].SetActive(false);
  448.                 }
  449.         }      
  450.         private static void HideArmMeshes()
  451.         {
  452.                 for (int i = 0; i < _armMesh.Length; i++) {
  453.                         _armMesh[i].SetActive(false);
  454.                 }
  455.         }
  456.         private static void HideBicepMeshes()
  457.         {
  458.                 for (int i = 0; i < _bicepMesh.Length; i++) {
  459.                         _bicepMesh[i].SetActive(false);
  460.                 }
  461.         }
  462.         private static void HideBootMeshes()
  463.         {
  464.                 for (int i = 0; i < _bootMesh.Length; i++) {
  465.                         _bootMesh[i].SetActive(false);
  466.                 }
  467.         }
  468.         private static void HideGloveMeshes()
  469.         {
  470.                 for (int i = 0; i < _gloveMesh.Length; i++) {
  471.                         _gloveMesh[i].SetActive(false);
  472.                 }
  473.         }
  474.         private static void HideHelmetMeshes()
  475.         {
  476.                 for (int i = 0; i < _helmetMesh.Length; i++) {
  477.                         _helmetMesh[i].SetActive(false);
  478.                 }
  479.         }
  480.         private static void HideLegsMeshes()
  481.         {
  482.                
  483.                 for (int i = 0; i < _legMesh.Length; i++) {
  484.                         _legMesh[i].SetActive(false);
  485.                 }
  486.         }
  487.         private static void HideShoulderMeshes()
  488.         {
  489.                 for (int i = 0; i < _shoulderMesh.Length; i++) {
  490.                         _shoulderMesh[i].SetActive(false);
  491.                 }
  492.         }
  493.         private static void HideTorsoMeshes()
  494.         {
  495.                 for (int i = 0; i < _torsoMesh.Length; i++) {
  496.                         _torsoMesh[i].SetActive(false);
  497.                 }
  498.         }
  499.         private static void HideWaistMeshes()
  500.         {
  501.                 for (int i = 0; i < _waistMesh.Length; i++) {
  502.                         _waistMesh[i].SetActive(false);
  503.                 }
  504.         }
  505.         private static void HideWristMeshes()
  506.         {
  507.                 for (int i = 0; i < _wristMesh.Length; i++) {
  508.                         _wristMesh[i].SetActive(false);
  509.                 }
  510.         }*/
  511. #endregion     
  512. }
  513.  
  514. public enum EquipmentSlot
  515. {
  516.         Head,
  517.         Shoulders,
  518.         Chest,
  519.         Torso,
  520.         Legs,
  521.         Hands,
  522.         Feet,
  523.         Back,
  524.         OffHand,
  525.         MainHand,
  526.         Arms,
  527.         Biceps,
  528.         Waist,
  529.         Wrist,
  530.         COUNT
  531. }
  532.  
  533.  

The PlayerCharacter script is on the player, and it works just fine on the client side, it just does not show
gear to the rest of the players.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Show newly activated children of prefab over network.
« Reply #4 on: August 02, 2013, 02:57:42 PM »
You don't know what I mean about SetActive? You're using it:
  1. _weaponMesh[2].SetActive(true);
Instead of doing that, do this:
  1. tno.Send("SetWeapon", Target.AllSaved, 2, true);
Your SetWeapon function will then be:
  1. [RFC] void SetWeapon (int index, bool isActive) { _weaponMesh[index].SetActive(isActive); }

Etarnalazure

  • Guest
Re: Show newly activated children of prefab over network.
« Reply #5 on: August 02, 2013, 03:04:50 PM »
Ah okay, its because you used the name

"SetActive" as the method name.

Seeing as "SetActive" is usually only available if you use it like "gameobject.SetActive(true)"
I figured it might be an inbuilt method that came with TNet.

Thank, I'll try that.