public static void AddAbilityComponents(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem, AbilitySetup[] abilities) { dstManager.AddComponentData(entity, new AbilityCollection.State()); // Create ability entities var abilityEntities = new List <Entity>(abilities.Length); for (int i = 0; i < abilities.Length; i++) { var e = conversionSystem.GetEntities(abilities[i].ability); e.MoveNext(); var abilityEntity = e.Current; if (abilityEntities.Contains(abilityEntity)) { GameDebug.LogError("Ability " + abilities[i].ability + " registered multiple times in abilities list"); } abilityEntities.Add(abilityEntity); } // Add abilities to ability buffer dstManager.AddBuffer <AbilityCollection.AbilityEntry>(entity); var abilityBuffer = dstManager.GetBuffer <AbilityCollection.AbilityEntry>(entity); for (int i = 0; i < abilities.Length; i++) { var entry = new AbilityCollection.AbilityEntry { entity = abilityEntities[i], abilityType = abilities[i].abilityTypeFlags, canRunWith = abilities[i].canRunWithFlags, canInterrupt = abilities[i].canInterruptFlags, }; if (abilities[i].ActivateButtons.Count > 4) { GameDebug.LogError("A maximum of 4 activate buttons are allowed. Currently specified:" + abilities[i].ActivateButtons.Count); } if (abilities[i].ActivateButtons.Count > 0) { entry.ActivateButton0 = abilities[i].ActivateButtons[0]; } if (abilities[i].ActivateButtons.Count > 1) { entry.ActivateButton1 = abilities[i].ActivateButtons[1]; } if (abilities[i].ActivateButtons.Count > 2) { entry.ActivateButton2 = abilities[i].ActivateButtons[2]; } if (abilities[i].ActivateButtons.Count > 3) { entry.ActivateButton3 = abilities[i].ActivateButtons[3]; } abilityBuffer.Add(entry); } }
private static int GetActiveButtonIndex(UserCommand cmd, ref AbilityCollection.AbilityEntry abilityEntry) { if (cmd.buttons.IsSet(abilityEntry.ActivateButton0)) { return(0); } if (cmd.buttons.IsSet(abilityEntry.ActivateButton1)) { return(1); } if (cmd.buttons.IsSet(abilityEntry.ActivateButton2)) { return(2); } if (cmd.buttons.IsSet(abilityEntry.ActivateButton3)) { return(3); } return(-1); }