public static void Move(NPCUnit unit, Vector3 point) { NavMeshPath p = new NavMeshPath(); unit.nav.CalculatePath(point, p); unit.nav.SetPath(p); }
void Start() { agent = GetComponent <NavMeshAgent>(); unit = GetComponent <NPCUnit>(); wanderTime = Random.Range(1.5f, 3.5f); GotoNextPoint(); }
private void OnHostileFound(NPCUnit ally) { if (_unit.TargetManager.CurrentTarget == null) { _unit.TargetManager.OverrideCurrentTarget(ally.TargetManager.CurrentTarget); } }
/** * public void NpcCanBeCarried(int index) * { * NPCEvents[index].gameObject.GetComponent<NPCUnit>().canBeCarried = true; * } **/ public void NPCCanFollowPlayer(int index) { NPCUnit unit = NPCEvents[index].gameObject.GetComponent <NPCUnit>(); unit.canFollowPlayer = true; unit.isFloat = false; unit.floatCube.SetActive(false); playerController.allowThrowCube = false; }
public void InterpetMessage(NPCUnit ally, UnitMessage message) { switch (message) { case UnitMessage.HostileFound: OnHostileFound(ally); break; // add more cases as necessary } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // Makes a rectangle that is used to tell the Camera how much of the game // it is supposed to show at any given time. var screenRectangle = new Rectangle(0, 0, this.graphics.PreferredBackBufferHeight, this.graphics.PreferredBackBufferWidth); // Loads the texture for Fog of War and Valid Move, which are used during the game. // Instead of saving it in the tilemap, it is saved with the Engine, as both of them // are tilesets consisting of only one tile. No point in saving them as a full tileset in the map. Engine.FoWTexture = this.Content.Load <Texture2D>(@"Textures\TileSets\fow_of_war"); Engine.ValidMoveTexture = this.Content.Load <Texture2D>(@"Textures\TileSets\move_range"); Font = this.Content.Load <SpriteFont>(@"Fonts\OwnFont"); var tempMap = this.mapLoader.LoadTmxFile("Test_1.tmx", this); tempMap.FowEnabled = true; tempMap.PersistentFoW = true; var tempPlayerUnits = new List <Unit>(); var tempNPCUnits = new List <Unit>(); // Makes an AnimatedSprite from a spritesheet, makes a PlayerUnit from it and // adds it to the playerUnits list. var sprite = this.MakeSprite("Ally", "Lin28px", 28, 28); var playerUnit = new PlayerUnit(Unit.GenerateUniqueID(tempPlayerUnits), "Akai", new Vector(5, 3), sprite, new BladesmasterClass()); tempPlayerUnits.Add(playerUnit); sprite = this.MakeSprite("Ally", "FemaleAssassin28px", 28, 28); playerUnit = new PlayerUnit(Unit.GenerateUniqueID(tempPlayerUnits), "Kitai", new Vector(5, 2), sprite, new AssassinClass()); tempPlayerUnits.Add(playerUnit); sprite = this.MakeSprite("Ally", "FlyingUnit32px", 32, 32); playerUnit = new PlayerUnit(Unit.GenerateUniqueID(tempPlayerUnits), "Flyer", new Vector(9, 10), sprite, new FlyingUnitClass()); tempPlayerUnits.Add(playerUnit); sprite = this.MakeSprite("Enemy", "FlyingUnit32px", 32, 32); var enemyUnit = new NPCUnit(Unit.GenerateUniqueID(tempNPCUnits), "Flyer", new Vector(10, 10), sprite, new FlyingUnitClass()); tempNPCUnits.Add(enemyUnit); tempMap.LoadUnits(new List <Unit>(tempPlayerUnits)); tempMap.LoadUnits(new List <Unit>(tempNPCUnits)); this.CurrentLevel = new Level( new Camera(screenRectangle), tempMap); this.CurrentLevel.AddPlayer(new PlayerHuman(tempPlayerUnits)); this.CurrentLevel.AddPlayer(new PlayerNPC(tempNPCUnits)); }
public static NPCUnit newInstance(ushort npcID, ushort serialNumber) { //NPCUnit instance = null; //GameObject obj = new GameObject(string.Format("NPC_{0:0000}_{1:000}", npcID, serialNumber)); //instance = obj.AddComponent<NPCUnit>(); //instance._NPCID = npcID; //instance._serialNumber = serialNumber; NPCUnit instance = new NPCUnit(npcID, serialNumber); instance._gameObject = new GameObject(string.Format("NPC_{0:0000}_{1:000}", npcID, serialNumber)); return instance; }
public void Initialize(PooledObjectInitializationData initializationData) { NPCUIDisplayInitializationData initData = initializationData as NPCUIDisplayInitializationData; if (initData == null) { return; } _unit = initData.Unit; _unit.Damageable.OnCurrentHealthChanged += OnCurrentHealthChanged; _unit.Damageable.OnMaxHealthChanged += OnMaxHealthChanged; }
// process certain unit messages in order to message other units in the "alliance" private void OnUnitMessageReceived(NPCUnit ally, UnitMessage message) { switch (message) { case UnitMessage.HostileFound: case UnitMessage.PlayerObjectiveInProgress: case UnitMessage.PlayerObjectiveCompleted: OnAllianceMessageSent?.Invoke(ally, message); break; default: break; } }
public void NpcDisappear(int index) { NPCUnit unit = NPCEvents[index].gameObject.GetComponent <NPCUnit>(); playerController.allowThrowCube = true; unit.floatCube.SetActive(true); // NPCEvents[index].gameObject.SetActive(false); Destroy(NPCEvents[index].gameObject, 1); if (TransitionBGAnim != null) { TransitionBGAppear(); Invoke("TransitionBGDisappear", 1); } }
private void OnAllianceMessageReceived(NPCUnit ally, UnitMessage message) { // don't override state if this was the sender if (ally == _unit) { return; } // retrieve the appropriate state if (!_messageOverrideStates.TryGetValue(message, out AIState nextState)) { return; } _messageInterpeter.InterpetMessage(ally, message); OnReadyToTransitionState(nextState); }
private void OnEnemySpawned(NPCUnit enemy) { if (!PooledObjectManager.Instance.UsePooledObject(NPCUIDisplayPrefabId, out PooledObject obj)) { CustomLogger.Error(nameof(NPCUIDisplayManager), $"Could not get NPC info display object with id {NPCUIDisplayPrefabId}!"); return; } NPCUIDisplay npcUIDisplay = obj as NPCUIDisplay; if (npcUIDisplay == null) { CustomLogger.Error(nameof(NPCUIDisplayManager), $"Did not receive a {nameof(NPCUIDisplay)} object!"); return; } NPCUIDisplayInitializationData initData = new NPCUIDisplayInitializationData() { Unit = enemy }; npcUIDisplay.Initialize(initData); npcUIDisplay.Spawn(); enemy.OnUnitDefeated += OnUnitDefeated; _registeredUnits.Add(enemy, npcUIDisplay); }
public NPCMessageInterpreter(NPCUnit unit) { _unit = unit; }
public AIStateEngageHostileInitData(NPCUnit unit) { }
public static void Stop(NPCUnit unit) { unit.nav.ResetPath(); }
protected virtual void OnAllianceMessageSent(NPCUnit unit, UnitMessage message) { OnUnitMessageReceived?.Invoke(unit, message); }
public void Dispose() { _unit = null; }