public static void EntitySpawn(Entity ent, bool isActive) { //string state = isActive ? "spawned" : "despawned"; //DebugManager.LogToFile("[OnEntitySpawn] Entity " + ent.name + " has " + state); VarHelper.AddEnts(ent, isActive); OnEntitySpawn?.Invoke(ent, isActive); }
private void SpawnEntity() { owner = gameObject; isOnDespawn = false; if (invulnerableSpawn > 0 && !isInvulnerable) { isInvulnerable = true; Invoke("StopInvulnerable", invulnerableSpawn); } if (randomLife) { life = UnityEngine.Random.Range(rndMinLife, rndMaxLife); maxLife = (int)life; } else { life = maxLife; } if (subEntity && parentEntity) { faction = parentEntity.faction; entityType = parentEntity.entityType; } if (entityType != EntityType.NotTraceable) { GameManager.Instance.RegisterEntity(this); } onEntitySpawn.Invoke(); if (spawnEffects.Length > 0) { for (int i = 0; i < spawnEffects.Length; i++) { PoolManager.Spawn(spawnEffects[i], transform.position + spawnEffectOffset, transform.rotation); } } #if UNITY_EDITOR if (faction == null && !subEntity) { //Debug.LogWarning("Faction not assigned on " + gameObject.name,gameObject); } if (subEntity && parentEntity == null) { Debug.LogWarning("Parent entity not assigned on " + gameObject.name, gameObject); } #endif }
public GameObject AddAndInitCustomSystem <T>(GameObject go, out T sysIns) where T : Entity { if (go.AddComponent <T>() is T entity) { OnEntitySpawn?.Invoke(this, new OnEntitySpawn(entity)); entity.Init(); sysIns = entity; return(go); } else { throw new Exception($"添加组件{typeof(T).Name}失败"); } }
/// <summary> /// Called every few milliseconds. This function updates the local cache of known entities. /// </summary> public void Update() { // 8B 34 8A 8B 0D ?? ?? ?? ?? 89 81 ?? ?? ?? ?? 8B 15 ?? ?? ?? ?? // http://i.imgur.com/LIGX6AY.png _currentManager = Game.Read <IntPtr>(Game.Read <int>(0x009BE7E0) + 0x463C, true); _localGUID = Game.Read <ulong>(_currentManager + 0xC8, true); CurrentMap = Game.Read <int>(_currentManager + 0xD4, true); foreach (var oldEntitiy in _entities) { oldEntitiy.Value.BaseAddressUpdated = false; } foreach (var newEntityPtr in Enumerate()) { var updateFieldOffset = Game.Read <IntPtr>(newEntityPtr + 0xC, true); var objectGuid = Game.Read <ObjectGuid>(updateFieldOffset, true); if (_entities.ContainsKey(objectGuid)) { _entities[objectGuid].UpdateBaseAddress(newEntityPtr); OnEntityUpdated?.Invoke(_entities[objectGuid]); } else { switch (Game.Read <ObjectType>(newEntityPtr + 0x14, true)) { default: case ObjectType.Object: _entities[objectGuid] = new CGObject_C(newEntityPtr); break; case ObjectType.Unit: _entities[objectGuid] = new CGUnit_C(newEntityPtr); break; case ObjectType.Player: _entities[objectGuid] = new CGPlayer_C(newEntityPtr); break; case ObjectType.GameObject: _entities[objectGuid] = new CGGameObject_C(newEntityPtr); break; case ObjectType.Container: _entities[objectGuid] = new CGContainer_C(newEntityPtr); break; case ObjectType.Item: _entities[objectGuid] = new CGItem_C(newEntityPtr); break; } OnEntitySpawn?.Invoke(_entities[objectGuid]); _entities[objectGuid].OnSpawn(); } } foreach (var removalKey in _entities.Where(kv => !kv.Value.BaseAddressUpdated).Select(kv => kv.Key).ToList()) { OnEntityDespawn?.Invoke(_entities[removalKey]); _entities[removalKey].OnDespawn(); _entities.Remove(removalKey); } OnWorldUpdate?.Invoke(); }