Exemplo n.º 1
0
 public static void OnEntityAwake(NetworkedEntity e)
 {
     //if(!Networking.isConnected)
     //{
     registeredPreplacedEnts[e.GetComponent <UniqueId>().uniqueId] = e;
     //}
     //ents[nextTempIndex--] = e;
 }
Exemplo n.º 2
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);
        }