Advertisement
CassataGames

Untitled

Sep 17th, 2014
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.87 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ComponentList : MonoBehaviour {
  5.  
  6.     // Step 1 - Add to Components Enum.
  7.     // Step 2 - Add LevelComponent Instance. (In Unity)
  8.  
  9.     public EditorGlobals GlobalAccess;
  10.     void Start()
  11.     {
  12.         // Required to have GlobalAccess
  13.         GlobalAccess = GameObject.Find("EditorGlobals").GetComponent<EditorGlobals>();
  14.     }
  15.  
  16.     public enum Components // Step 1
  17.     {
  18.         Diamond,
  19.         SpikedDiamond,
  20.         SolidBrick,
  21.         GlassBrick,
  22.         ColorSwitchBrick,
  23.         ColorSwitchGate,
  24.         ColorHazardBrick,
  25.         ColorHazardGate,
  26.         Fuse,
  27.         HomingFuse,
  28.         ClingingBombs,
  29.         ClingingBrick,
  30.         ElementalFire,
  31.         ElementalLightning,
  32.         ElementalFreeze,
  33.         ColoredForceField,
  34.         FieldSwitch,
  35.         Generator,
  36.         Wire,
  37.         ElectricForceField
  38.     }
  39.    
  40.     public string ComponentRealName(Components receiveComponent) // Step 2
  41.     {
  42.  
  43.         return GlobalAccess.Components.RequestName(receiveComponent);
  44.  
  45.     }
  46.  
  47. }
  48. [System.Serializable]
  49. public class LevelComponents // Be sure not to remove or edit any of these or their values will be lost in Unity.
  50. {
  51.     public LevelComponent[] List; // Step 2 (In Unity)
  52.     public EditorGlobals GlobalAccess;
  53.     public GameObject ReturnObject;
  54.  
  55.     // Provides various information about requested component to UPDATE EditorGlobals.
  56.     public void UpdateEditorGlobals(ComponentList.Components ComponentName)
  57.     {
  58.         foreach (LevelComponent LevelComponent in List)
  59.         {
  60.             if (LevelComponent.AttachedComponent == ComponentName)
  61.             {
  62.                 GlobalAccess.OneSize = LevelComponent.OneSize;
  63.                 GlobalAccess.IsColored = LevelComponent.Colored;
  64.             }
  65.         }
  66.     }
  67.  
  68.     // Returns the string name of requested component.
  69.     public string RequestName(ComponentList.Components ComponentName)
  70.     {
  71.         string name = "No Matching Components";
  72.         foreach (LevelComponent LevelComponent in List)
  73.         {
  74.             if (LevelComponent.AttachedComponent == ComponentName)
  75.             {
  76.                 name = LevelComponent.Name;
  77.                 break;
  78.             }
  79.         }
  80.         return name;
  81.     }
  82.    
  83.     // Returns the GameObject of the requested component.
  84.     public GameObject RequestGameObject(ComponentList.Components ComponentName)
  85.     {
  86.         foreach (LevelComponent LevelComponent in List)
  87.         {
  88.             if (LevelComponent.AttachedComponent == ComponentName)
  89.             {
  90.                 if (LevelComponent.OneSize)
  91.                 {
  92.                     if (!LevelComponent.Colored)
  93.                     {
  94.                         ReturnObject = LevelComponent.AttachedBase;
  95.                     }
  96.                     else
  97.                     {
  98.                         ReturnObject = RequestColor(LevelComponent, GlobalAccess.ColorSelected);
  99.                     }
  100.                     break;
  101.                 }
  102.                 else
  103.                 {
  104.                     ReturnObject = RequestSize(LevelComponent, GlobalAccess.SizeSelected);
  105.                 }
  106.             }
  107.         }
  108.         return ReturnObject;
  109.  
  110.     }
  111.     GameObject RequestColor(LevelComponent LevelComponent, EditorGlobals.EditorColor ColorRequest)
  112.     {
  113.         switch (ColorRequest)
  114.         {
  115.             case EditorGlobals.EditorColor.Red:
  116.                 return LevelComponent.AttachedColor.Red;
  117.             case EditorGlobals.EditorColor.Yellow:
  118.                 return LevelComponent.AttachedColor.Yellow;
  119.             case EditorGlobals.EditorColor.Green:
  120.                 return LevelComponent.AttachedColor.Green;
  121.             case EditorGlobals.EditorColor.Blue:
  122.                 return LevelComponent.AttachedColor.Blue;
  123.             case EditorGlobals.EditorColor.Purple:
  124.                 return LevelComponent.AttachedColor.Purple;
  125.             case EditorGlobals.EditorColor.Black:
  126.                 return LevelComponent.AttachedColor.Black;
  127.             case EditorGlobals.EditorColor.White:
  128.                 return LevelComponent.AttachedColor.White;
  129.             default:
  130.                 return new GameObject();
  131.         }
  132.     }
  133.     GameObject RequestSize(LevelComponent LevelComponent, int SizeRequest)
  134.     {
  135.         switch (SizeRequest)
  136.         {
  137.             case 1:
  138.                 return LevelComponent.AttachedSize.x1;
  139.             case 2:
  140.                 return LevelComponent.AttachedSize.x2;
  141.             case 3:
  142.                 return LevelComponent.AttachedSize.x3;
  143.             case 4:
  144.                 return LevelComponent.AttachedSize.x4;
  145.             case 5:
  146.                 return LevelComponent.AttachedSize.x5;
  147.             default:
  148.                 Debug.Log("Invalid SizeRequest.");
  149.                 return new GameObject();
  150.         }
  151.     }
  152.     GameObject RequestSizeColor(LevelComponent LevelComponent, EditorGlobals.EditorColor ColorRequest, int SizeRequest)
  153.     {
  154.         switch (SizeRequest)
  155.         {
  156.             default:
  157.                 Debug.Log("Invalid SizeRequest.");
  158.                 return new GameObject();
  159.  
  160.             case 1:
  161.                 return ColorSwitch(ColorRequest, LevelComponent.AttachedSizeColor.x1);
  162.             case 2:
  163.                 return ColorSwitch(ColorRequest, LevelComponent.AttachedSizeColor.x2);
  164.             case 3:
  165.                 return ColorSwitch(ColorRequest, LevelComponent.AttachedSizeColor.x3);
  166.             case 4:
  167.                 return ColorSwitch(ColorRequest, LevelComponent.AttachedSizeColor.x4);
  168.             case 5:
  169.                 return ColorSwitch(ColorRequest, LevelComponent.AttachedSizeColor.x5);
  170.         }
  171.     }
  172.     GameObject ColorSwitch(EditorGlobals.EditorColor ColorRequest, LevelComponent.ColorComponent SizePassthrough) // THIS IS ONLY USED BY: RequestSizeColor()
  173.     {
  174.         switch (ColorRequest)
  175.         {
  176.             default:
  177.                 Debug.Log("Invalid ColorRequest.");
  178.                 return new GameObject();
  179.  
  180.             case EditorGlobals.EditorColor.Red:
  181.                 return SizePassthrough.Red;
  182.             case EditorGlobals.EditorColor.Yellow:
  183.                 return SizePassthrough.Yellow;
  184.             case EditorGlobals.EditorColor.Green:
  185.                 return SizePassthrough.Green;
  186.             case EditorGlobals.EditorColor.Blue:
  187.                 return SizePassthrough.Blue;
  188.             case EditorGlobals.EditorColor.Purple:
  189.                 return SizePassthrough.Purple;
  190.             case EditorGlobals.EditorColor.Black:
  191.                 return SizePassthrough.Black;
  192.             case EditorGlobals.EditorColor.White:
  193.                 return SizePassthrough.White;
  194.         }
  195.     }
  196.  
  197. }
  198. [System.Serializable]
  199. public class LevelComponent // Be sure not to remove or edit any of these or their values will be lost in Unity.
  200. {
  201.     public string Name;
  202.     public ComponentList.Components AttachedComponent;
  203.     public bool OneSize;
  204.     public bool Colored;
  205.     public GameObject AttachedBase;
  206.     public ColorComponent AttachedColor;
  207.     public SizeComponent AttachedSize;
  208.     public ColoredSizeComponent AttachedSizeColor;
  209.     [System.Serializable]
  210.     public class ColorComponent
  211.     {
  212.         public GameObject Red;
  213.         public GameObject Yellow;
  214.         public GameObject Green;
  215.         public GameObject Blue;
  216.         public GameObject Purple;
  217.         public GameObject Black;
  218.         public GameObject White;
  219.     }
  220.     [System.Serializable]
  221.     public class SizeComponent
  222.     {
  223.         public GameObject x1;
  224.         public GameObject x2;
  225.         public GameObject x3;
  226.         public GameObject x4;
  227.         public GameObject x5;
  228.     }
  229.     [System.Serializable]
  230.     public class ColoredSizeComponent
  231.     {
  232.         public ColorComponent x1;
  233.         public ColorComponent x2;
  234.         public ColorComponent x3;
  235.         public ColorComponent x4;
  236.         public ColorComponent x5;
  237.     }
  238. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement