Esempio n. 1
0
 public static void OnEntityAwake(NetworkedEntity e)
 {
     //if(!Networking.isConnected)
     //{
     registeredPreplacedEnts[e.GetComponent <UniqueId>().uniqueId] = e;
     //}
     //ents[nextTempIndex--] = e;
 }
Esempio n. 2
0
        // Sorry this function is a bit weird
        // It takes a connection ID on the server,
        // a player ID on client
        public static void OnPlayerDisconnect(int connectionId)
        {
            if (Networking.isServer)
            {
                int             playerId = connectionToPlayer[connectionId];
                NetworkedEntity e        = EntityManager.ents[playerId];
                GameObject.Destroy(e.gameObject);
                EntityManager.ents.Remove(playerId);

                connectedClients.Remove(connectionId);
            }
            else
            {
                int             playerId = connectionId;
                NetworkedEntity e        = EntityManager.ents[playerId];
                GameObject.Destroy(e.gameObject);
                EntityManager.ents.Remove(playerId);

                connectedClients.Remove(connectionId);
            }
        }
Esempio n. 3
0
        public static NetworkedEntity RegenerateEntity(int id, long prefab, int authority, Vector3 pos, long uniqueId = 0)
        {
            // TODO: Separate preplaced entities from dynamically created ents
            Debug.Log("Has regen");
            if (uniqueId != 0)
            {
                Debug.Log("Has UniqueId " + uniqueId);
                if (registeredPreplacedEnts.ContainsKey(uniqueId))
                {
                    Debug.Log("Has PreplacedEnt");
                    NetworkedEntity e = registeredPreplacedEnts[uniqueId];

                    e.SetEntityIndex(id);
                    e.GetComponent <NetworkAuthority>()?.SetAuthority(authority);

                    registeredPreplacedEnts.Remove(uniqueId);

                    return(e);
                }
            }

            if (registeredPrefabs.ContainsKey(prefab))
            {
                GameObject newObject = MonoBehaviour.Instantiate(registeredPrefabs[prefab], pos, Quaternion.identity);

                newObject.GetComponent <NetworkedEntity>().SetEntityIndex(id);
                newObject.GetComponent <NetworkAuthority>()?.SetAuthority(authority);

                return(newObject.GetComponent <NetworkedEntity>());
            }
            else
            {
                Debug.LogError("Entity manager does not have prefab " + prefab);
            }
            return(null);
        }
Esempio n. 4
0
 public static void RegisterEntity(NetworkedEntity e, int id)
 {
     e.SetEntityIndex(id, false);
     ents[id] = e;
 }
Esempio n. 5
0
 public static uint RegisterEntity(NetworkedEntity e)
 {
     ents[nextNormalEnt++] = e;
     e.SetEntityIndex(nextNormalEnt - 1, false);
     return((uint)(nextNormalEnt - 1));
 }