private void OnCharacterSelected(long entityId) { selectedCharacter = characters.FirstOrDefault(a => a.EntityId == entityId); if (selectedCharacter == null) { Debug.LogErrorFormat("Missing character '{0}'.", entityId); return; } UpdateChannels(selectedCharacter.Server); SelChannel.interactable = true; var server = selectedCharacter.Server; var name = selectedCharacter.Name; var color = MabiMath.GetNameColor(name).ToString("X6"); TxtSelectedChar.text = string.Format("<size=20>{0}</size>\n<color=#{2}>{1}</color>", server, name, color); Connection.SelectedCharacter = selectedCharacter; }
public void AddMessage(string name, string message) { var color = MabiMath.GetNameColor(name); AddMessage(color, name, message); }
void Update() { // Go through all entities foreach (Transform entityTransform in EntityList) { // Get entity info component, ignore empty names var entityInfo = entityTransform.GetComponent <EntityInfo>(); if (string.IsNullOrEmpty(entityInfo.Name)) { continue; } // Get information for placement var nameTarget = entityTransform.FindChild("NameTarget"); var pos = mainCamera.WorldToScreenPoint(nameTarget.transform.position); // Create new name object if new entity Transform nameTransform; if (!nameTransforms.TryGetValue(entityTransform, out nameTransform)) { // Get creature Entity creature; Connection.Entities.TryGetValue(entityInfo.Id, out creature); // Create object in list var newNameObj = (GameObject)GameObject.Instantiate(reference, pos, Quaternion.identity); nameTransform = newNameObj.transform; nameTransform.SetParent(me); // Set colored name var color = MabiMath.GetNameColor(entityInfo.Name); var text = nameTransform.GetComponent <Text>(); var name = entityInfo.Name; var displayName = string.Format("<color=#{0:X6}>{1}</color>", color, name); // NPC prefix if (entityInfo.IsConversationNpc) { displayName = "<size=8>NPC</size> " + displayName; } text.text = displayName; // Save for automatic removal nameTransforms.Add(entityTransform, nameTransform); } var nameObject = nameTransform.gameObject; // If entity is visible, activate name object and move it into // position. if (pos.z > 0) { nameTransform.position = pos; if (!nameObject.activeSelf) { nameObject.SetActive(true); } } // If entity is not visible deactivate the name. else if (nameObject.activeSelf) { nameObject.SetActive(false); } } // Check for removed entities var toRemove = new List <Transform>(); foreach (var nameTransformX in nameTransforms) { // Remove name if entity transform became null (destroyed) var entityTransform = nameTransformX.Key; if (entityTransform == null) { var nameTransform = nameTransformX.Value; GameObject.Destroy(nameTransform.gameObject); toRemove.Add(entityTransform); } } // Remove destroyed entity's names from the list if (toRemove.Count != 0) { foreach (var key in toRemove) { nameTransforms.Remove(key); } } }