-
-
Save lucasvdiepen/18a30720853bbc8562908f430ffacc5a to your computer and use it in GitHub Desktop.
Cosmetics Structure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class CosmeticsApplier : MonoBehaviour | |
| { | |
| public ItemType[] applyPriority; | |
| private void Start() | |
| { | |
| ApplySelectedItems(); | |
| } | |
| private void ApplySelectedItems() | |
| { | |
| List<ItemBase> selectedItems = FindObjectOfType<ItemManager>().GetAllSelectedItems(); | |
| //Apply priority first | |
| foreach(ItemType priorityType in applyPriority) | |
| { | |
| for(int i = 0; i < selectedItems.Count; i++) | |
| { | |
| if(selectedItems[i].itemType == priorityType) | |
| { | |
| selectedItems[i].Apply(gameObject); | |
| selectedItems.RemoveAt(i); | |
| break; | |
| } | |
| } | |
| } | |
| //Apply the rest here | |
| foreach(ItemBase item in selectedItems) | |
| { | |
| item.Apply(gameObject); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public abstract class ItemBase : ScriptableObject | |
| { | |
| public int itemID = -1; | |
| [HideInInspector] public ItemType itemType; | |
| protected ItemBase(ItemType _itemType) | |
| { | |
| itemType = _itemType; | |
| } | |
| public abstract void Apply(GameObject player); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [CreateAssetMenu(fileName = "NewColor", menuName = "Player Items/New Color")] | |
| public class ItemColor : ItemBase | |
| { | |
| public Color color; | |
| public ItemColor() : base(ItemType.Color) { } | |
| public override void Apply(GameObject player) | |
| { | |
| SpriteRenderer spriteRenderer = player.FindComponentInChildWithTag<SpriteRenderer>("Shape"); | |
| spriteRenderer.color = color; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [CreateAssetMenu(fileName = "NewShape", menuName = "Player Items/New Shape")] | |
| public class ItemShape : ItemBase | |
| { | |
| public GameObject shape; | |
| public ItemShape() : base(ItemType.Shape) { } | |
| public override void Apply(GameObject player) | |
| { | |
| Instantiate(shape, player.transform); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment