public void SpawnPin(byte id, string name, bool enabled, Vector3 position)
 {
     if (Pins.ContainsKey(id))
     {
         Destroy(Pins[id]);
         Pins.Remove(id);
     }
     Pins.Add(id, ClientPin.CreatePin(name, enabled, position));
 }
Ejemplo n.º 2
0
        public static ClientPin CreatePin(string username, bool enabled, Vector3 position)
        {
            MultiplayerClient.Instance.Log("Pin " + (GameManager.instance.gameMap == null) + (SessionManager.Instance.pinPrefab == null));
            GameObject gameObject = Instantiate(
                SessionManager.Instance.pinPrefab,
                GameManager.instance.gameMap.transform);

            MultiplayerClient.Instance.Log("1");

            gameObject.transform.localPosition = position;
            gameObject.name += username;

            MultiplayerClient.Instance.Log("2");

            /*GameObject nameObj = UnityEngine.Object.Instantiate(
             *  new GameObject("Username" + gameObject.name),
             *  GameManager.instance.gameMap.transform);*/

            // copied and edited from https://github.com/SFGrenade/AdditionalMaps/blob/master/AdditionalMaps.cs
            var nameObj = GameObject.Instantiate(GameManager.instance.gameMap.GetComponent <GameMap>().areaCliffs.transform.GetChild(6).GetChild(0).gameObject, gameObject.transform);

            //nameObj.transform.localPosition = new Vector3(7f, -1.5f, nameObj.transform.localPosition.z);
            nameObj.transform.localPosition = new Vector3(position.x, position.y, nameObj.transform.localPosition.z);
            nameObj.GetComponent <SetTextMeshProGameText>().convName = "Player_Name_" + username;
            var rectT = nameObj.GetComponent <RectTransform>();

            rectT.sizeDelta = new Vector2(rectT.sizeDelta.x + 1, rectT.sizeDelta.y);

            MultiplayerClient.Instance.Log("3");

            GameObject.DontDestroyOnLoad(gameObject);
            GameObject.DontDestroyOnLoad(nameObj);
            //nameObj.transform.localPosition = position + Vector3.up;

            MultiplayerClient.Instance.Log("4");

            /*TextMeshPro nameText = nameObj.AddComponent<TextMeshPro>();
             * nameText.text = username;
             * nameText.alignment = TextAlignmentOptions.Center;
             * nameText.fontSize = 10;
             * nameText.color = Color.blue;*/

            MultiplayerClient.Instance.Log("5");
            MultiplayerClient.Instance.Log("enabled = " + enabled + MapOn + SessionManager.Instance.RecievePins + (enabled && MapOn && SessionManager.Instance.RecievePins));

            nameObj.SetActive(enabled && MapOn && SessionManager.Instance.RecievePins);
            gameObject.SetActive(enabled && MapOn && SessionManager.Instance.RecievePins);

            MultiplayerClient.Instance.Log("6");

            ClientPin pin = gameObject.AddComponent <ClientPin>();

            pin.isEnabled = enabled;
            pin.Position  = position;
            pin.username  = nameObj;

            MultiplayerClient.Instance.Log("7");

            On.GameMap.SetupMapMarkers += pin.EnableMarker;
            On.GameMap.DisableMarkers  += pin.DisableMarker;

            MultiplayerClient.Instance.Log("8");

            return(pin);
        }