Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
 public static void RegisterEntity(NetworkedEntity e, int id)
 {
     e.SetEntityIndex(id, false);
     ents[id] = e;
 }
Ejemplo n.º 3
0
 public static uint RegisterEntity(NetworkedEntity e)
 {
     ents[nextNormalEnt++] = e;
     e.SetEntityIndex(nextNormalEnt - 1, false);
     return((uint)(nextNormalEnt - 1));
 }