Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*\
- | |
- | Made by Jason Helman © Jason Tech And Games |
- | I do not condone the use of my work without my permission |
- | |
- \*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- using UnityEngine;
- using System;
- using System.Linq;
- using System.Collections.Generic;
- /*[Serializable]
- public class SpriteArray2D
- {
- public Sprite[] sprites;
- }*/
- [Serializable]
- public class CustomKeyValuePair
- {
- public string Key;
- public ParticleSystem Value;
- }
- [Serializable]
- public class Skin
- {
- public SkinName skinName;
- public Sprite sprite;
- }
- [Serializable]
- public class SpecialSkin
- {
- public SpecialSkinName specialSkinName;
- public Sprite[] sprites;
- }
- public enum SkinName
- {
- Circle,
- Square,
- Dodecagon
- };
- public enum SpecialSkinName
- {
- ChristmasTree,
- EasterEgg
- };
- public class PlayerSkinHandler : MonoBehaviour
- {
- public SpriteRenderer player;
- public Skin[] skins;
- // public Sprite[] skins;
- public SpecialSkin[] specialSkins;
- // public SpriteArray2D[] specialSkins;
- // public ParticleSystem[] particleSystems;
- [SerializeField]
- public List<CustomKeyValuePair> particleSystems;
- [NonSerialized]
- public bool useSpecialSkins = true;
- [NonSerialized]
- public int currentPlayerSkin = (int)SpecialSkinName.EasterEgg;
- [NonSerialized]
- public Color skinColor = new Color(0, 0, 255);
- private Dictionary<string, ParticleSystem> particleSystemsDict;
- private MovementController movementController;
- private UnityEngine.Random random;
- private int currentSpritePos = 0;
- private bool firstTime = true;
- private void Awake()
- {
- movementController = GetComponent<MovementController>();
- particleSystemsDict = particleSystems.ToDictionary(k => k.Key, v => v.Value);
- if (!useSpecialSkins)
- {
- player.sprite = skins[currentPlayerSkin].sprite;
- player.color = skinColor;
- }
- }
- void Update()
- {
- if (useSpecialSkins)
- {
- if (firstTime)
- {
- switch ((SpecialSkinName)currentPlayerSkin)
- {
- case SpecialSkinName.ChristmasTree: // christmas tree
- player.sprite = specialSkins[(int)SpecialSkinName.ChristmasTree].sprites[0];// specialSkins[0].sprites[0];
- // eventually do particle system stuff here (instantiate)
- break;
- case SpecialSkinName.EasterEgg: // easter egg
- int startingEgg = UnityEngine.Random.Range(0, 2) * 4; // need 0 for 0 and 4 for 1, etc
- player.sprite = specialSkins[(int)SpecialSkinName.EasterEgg].sprites[startingEgg];
- currentSpritePos = startingEgg;
- break;
- default: // defaults to square
- player.sprite = skins[(int)SkinName.Square].sprite;
- player.color = skinColor;
- useSpecialSkins = false;
- break;
- }
- firstTime = false;
- }
- else
- {
- switch ((SpecialSkinName)currentPlayerSkin)
- {
- case SpecialSkinName.EasterEgg:
- if (movementController.playerPosChanged)
- {
- if (currentSpritePos % 4 == 0)
- {
- currentSpritePos++;
- player.sprite = specialSkins[(int)SpecialSkinName.EasterEgg].sprites[currentSpritePos];
- break;
- }
- // This is temporary, just until I emplement all features for the easter egg
- currentSpritePos = UnityEngine.Random.Range(0, 2) * 4;
- player.sprite = specialSkins[(int)SpecialSkinName.EasterEgg].sprites[currentSpritePos];
- // SPLIT EGG AND MAKE THEM FALL, ALONG WITH SPAWNING NEXT ONE
- // should add a slight force in a random upward direction and let it fade, also make sure
- // that it has gravity
- // also add a little dust particle area burst when it splits
- }
- break;
- default:
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement