예제 #1
0
    private IEnumerator CreationQueueCoroutine()
    {
        while (true)
        {
            yield return(new WaitForSeconds(0.5f));

            lock (WorldManager.UPDATE_OBJECT_LOCK)
            {
                foreach (KeyValuePair <long, CharacterDataHolder> entry in _characterCreationQueue)
                {
                    // Object does not exist. Instantiate.
                    GameObject newObj = CreateCharacter(entry.Value).gameObject;

                    // Assign object id and name.
                    WorldObject worldObject = newObj.AddComponent <WorldObject>();
                    worldObject.SetObjectId(entry.Key);
                    worldObject.SetCharacterData(entry.Value);
                    WorldObjectText worldObjectText = newObj.AddComponent <WorldObjectText>();
                    worldObjectText.SetWorldObjectName(entry.Value.GetName());
                    worldObjectText.SetAttachedObject(newObj);
                    worldObjectText.SetWorldObject(worldObject);

                    ((IDictionary <long, GameObject>)WorldManager.Instance.GetGameObjects()).Remove(entry.Key);
                    WorldManager.Instance.GetGameObjects().TryAdd(entry.Key, newObj);

                    ((IDictionary <long, CharacterDataHolder>)_characterCreationQueue).Remove(entry.Key);
                }
            }
        }
    }
예제 #2
0
    private void Start()
    {
        if (Instance != null)
        {
            return;
        }
        Instance = this;

        _gameObjects          = new ConcurrentDictionary <long, GameObject>();
        _moveQueue            = new ConcurrentDictionary <long, MovementHolder>();
        _animationQueue       = new ConcurrentDictionary <long, AnimationHolder>();
        _characterUpdateQueue = new ConcurrentDictionary <long, CharacterDataHolder>();
        _deleteQueue          = new List <long>();

        if (MainManager.Instance.GetSelectedCharacterData() != null)
        {
            // Create player character.
            _activeCharacter = CharacterManager.Instance.CreateCharacter(MainManager.Instance.GetSelectedCharacterData());
            // Tempfix.
            // TODO: Find why character initializes at 0, 0.
            // TODO: Try initialize with delay?
            Destroy(_activeCharacter.gameObject);
            _activeCharacter = CharacterManager.Instance.CreateCharacter(MainManager.Instance.GetSelectedCharacterData());

            // Animations.
            _activeCharacter.gameObject.AddComponent <AnimationController>();

            // Movement.
            _activeCharacter.gameObject.AddComponent <MovementController>();

            // Add name text.
            WorldObjectText worldObjectText = _activeCharacter.gameObject.AddComponent <WorldObjectText>();
            worldObjectText.SetWorldObjectName(""); // MainManager.Instance.selectedCharacterData.GetName();
            worldObjectText.SetAttachedObject(_activeCharacter.gameObject);

            // Update status information.
            StatusInformationManager.Instance.UpdatePlayerInformation();

            // Send enter world to Network.
            NetworkManager.ChannelSend(new EnterWorldRequest(MainManager.Instance.GetSelectedCharacterData().GetName()));
        }
    }