Advertisement
JJCUBER

Untitled

Apr 21st, 2019
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.88 KB | None | 0 0
  1. /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*\
  2. |                                                               |
  3. |          Made by Jason Helman © Jason Tech And Games          |
  4. |   I do not condone the use of my work without my permission   |
  5. |                                                               |
  6. \*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
  7.  
  8. using UnityEngine;
  9. using System;
  10. using System.Linq;
  11. using System.Collections.Generic;
  12.  
  13. /*[Serializable]
  14. public class SpriteArray2D
  15. {
  16.     public Sprite[] sprites;
  17. }*/
  18.  
  19. [Serializable]
  20. public class CustomKeyValuePair
  21. {
  22.     public string Key;
  23.     public ParticleSystem Value;
  24. }
  25.  
  26. [Serializable]
  27. public class Skin
  28. {
  29.     public SkinName skinName;
  30.     public Sprite sprite;
  31. }
  32. [Serializable]
  33. public class SpecialSkin
  34. {
  35.     public SpecialSkinName specialSkinName;
  36.     public Sprite[] sprites;
  37. }
  38. public enum SkinName
  39. {
  40.     Circle,
  41.     Square,
  42.     Dodecagon
  43. };
  44. public enum SpecialSkinName
  45. {
  46.     ChristmasTree,
  47.     EasterEgg
  48. };
  49.  
  50.  
  51. public class PlayerSkinHandler : MonoBehaviour
  52. {
  53.     public SpriteRenderer player;
  54.  
  55.     public Skin[] skins;
  56.     // public Sprite[] skins;
  57.     public SpecialSkin[] specialSkins;
  58.     // public SpriteArray2D[] specialSkins;
  59.  
  60.     // public ParticleSystem[] particleSystems;
  61.     [SerializeField]
  62.     public List<CustomKeyValuePair> particleSystems;
  63.     [NonSerialized]
  64.     public bool useSpecialSkins = true;
  65.     [NonSerialized]
  66.     public int currentPlayerSkin = (int)SpecialSkinName.EasterEgg;
  67.     [NonSerialized]
  68.     public Color skinColor = new Color(0, 0, 255);
  69.  
  70.     private Dictionary<string, ParticleSystem> particleSystemsDict;
  71.     private MovementController movementController;
  72.     private UnityEngine.Random random;
  73.     private int currentSpritePos = 0;
  74.     private bool firstTime = true;
  75.  
  76.     private void Awake()
  77.     {
  78.         movementController = GetComponent<MovementController>();
  79.  
  80.         particleSystemsDict = particleSystems.ToDictionary(k => k.Key, v => v.Value);
  81.        
  82.         if (!useSpecialSkins)
  83.         {
  84.             player.sprite = skins[currentPlayerSkin].sprite;
  85.             player.color = skinColor;
  86.         }
  87.     }
  88.    
  89.     void Update()
  90.     {
  91.         if (useSpecialSkins)
  92.         {
  93.             if (firstTime)
  94.             {
  95.                 switch ((SpecialSkinName)currentPlayerSkin)
  96.                 {
  97.                     case SpecialSkinName.ChristmasTree: // christmas tree
  98.                         player.sprite = specialSkins[(int)SpecialSkinName.ChristmasTree].sprites[0];// specialSkins[0].sprites[0];
  99.                         // eventually do particle system stuff here (instantiate)
  100.                         break;
  101.                     case SpecialSkinName.EasterEgg: // easter egg
  102.                         int startingEgg = UnityEngine.Random.Range(0, 2) * 4; // need 0 for 0 and 4 for 1, etc
  103.                         player.sprite = specialSkins[(int)SpecialSkinName.EasterEgg].sprites[startingEgg];
  104.                         currentSpritePos = startingEgg;
  105.                         break;
  106.                     default: // defaults to square
  107.                         player.sprite = skins[(int)SkinName.Square].sprite;
  108.                         player.color = skinColor;
  109.                         useSpecialSkins = false;
  110.                         break;
  111.                 }
  112.                 firstTime = false;
  113.             }
  114.             else
  115.             {
  116.                 switch ((SpecialSkinName)currentPlayerSkin)
  117.                 {
  118.                     case SpecialSkinName.EasterEgg:
  119.                         if (movementController.playerPosChanged)
  120.                         {
  121.                             if (currentSpritePos % 4 == 0)
  122.                             {
  123.                                 currentSpritePos++;
  124.                                 player.sprite = specialSkins[(int)SpecialSkinName.EasterEgg].sprites[currentSpritePos];
  125.                                 break;
  126.                             }
  127.                            
  128.                             // This is temporary, just until I emplement all features for the easter egg
  129.                             currentSpritePos = UnityEngine.Random.Range(0, 2) * 4;
  130.                             player.sprite = specialSkins[(int)SpecialSkinName.EasterEgg].sprites[currentSpritePos];
  131.  
  132.                             // SPLIT EGG AND MAKE THEM FALL, ALONG WITH SPAWNING NEXT ONE
  133.                             // should add a slight force in a random upward direction and let it fade, also make sure
  134.                             // that it has gravity
  135.                             // also add a little dust particle area burst when it splits
  136.                            
  137.                         }
  138.                         break;
  139.                     default:
  140.                         break;
  141.                 }
  142.             }
  143.            
  144.  
  145.  
  146.         }
  147.            
  148.     }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement