private void InvokeUnitAction(UnitActionType actionType, IUnit unit) { var methodInfos = GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); var unitActionMethods = methodInfos.Where(m => m.GetCustomAttributes <UnitActionAttribute>().Any()); var unitAttackMethods = unitActionMethods.Where( m => m.GetCustomAttribute <UnitActionAttribute>().UnitActionType.HasAnyFlag(actionType)) .ToDictionary(m => m.Name); if (unitAttackMethods != null && unitAttackMethods.Count > 0) { var keys = unitAttackMethods.Keys.ToList(); var keyIndex = new Random().Next(0, keys.Count); var method = unitAttackMethods[keys[keyIndex]]; method.Invoke(this, new object[] { unit }); } }
public UnitActionAttribute() { _actionType = UnitActionType.Attack; }
public UnitActionAttribute(UnitActionType type) { _actionType = type; }
void setActionNet(int action) { this.myAction = (UnitActionType)action; }
void initUnitNet(int unitTypeID, NetworkViewID locationTileID, NetworkViewID villageID) { //Getting all the parameters UnitType unitType = (UnitType)unitTypeID; Tile location = NetworkView.Find (locationTileID).gameObject.GetComponent<Tile>(); Village v = NetworkView.Find (villageID).gameObject.GetComponent<Village>(); //CreateComponent Tile toplace = null; foreach (Tile a in location.getNeighbours()) { if(a.prefab == null && a.getOccupyingUnit() == null && a.getColor() == location.getColor()) { toplace = a; } } if(toplace == null) { toplace = location; } //BE CAREFUL!!! If the order of Tiles in neighbors are not the same, the position of the new unit will be different!! gameObject.transform.position = new Vector3(toplace.point.x, 0.15f, toplace.point.y); locatedAt = toplace; myType = unitType; myVillage = v; myAction = UnitActionType.ReadyForOrders; locatedAt.setOccupyingUnit (this); }