Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class ComponentList : MonoBehaviour {
- // Step 1 - Add to Components Enum.
- // Step 2 - Add LevelComponent Instance. (In Unity)
- public EditorGlobals GlobalAccess;
- void Start()
- {
- // Required to have GlobalAccess
- GlobalAccess = GameObject.Find("EditorGlobals").GetComponent<EditorGlobals>();
- }
- public enum Components // Step 1
- {
- Diamond,
- SpikedDiamond,
- SolidBrick,
- GlassBrick,
- ColorSwitchBrick,
- ColorSwitchGate,
- ColorHazardBrick,
- ColorHazardGate,
- Fuse,
- HomingFuse,
- ClingingBombs,
- ClingingBrick,
- ElementalFire,
- ElementalLightning,
- ElementalFreeze,
- ColoredForceField,
- FieldSwitch,
- Generator,
- Wire,
- ElectricForceField
- }
- public string ComponentRealName(Components receiveComponent) // Step 2
- {
- return GlobalAccess.Components.RequestName(receiveComponent);
- }
- }
- [System.Serializable]
- public class LevelComponents // Be sure not to remove or edit any of these or their values will be lost in Unity.
- {
- public LevelComponent[] List; // Step 2 (In Unity)
- public EditorGlobals GlobalAccess;
- public GameObject ReturnObject;
- // Provides various information about requested component to UPDATE EditorGlobals.
- public void UpdateEditorGlobals(ComponentList.Components ComponentName)
- {
- foreach (LevelComponent LevelComponent in List)
- {
- if (LevelComponent.AttachedComponent == ComponentName)
- {
- GlobalAccess.OneSize = LevelComponent.OneSize;
- GlobalAccess.IsColored = LevelComponent.Colored;
- }
- }
- }
- // Returns the string name of requested component.
- public string RequestName(ComponentList.Components ComponentName)
- {
- string name = "No Matching Components";
- foreach (LevelComponent LevelComponent in List)
- {
- if (LevelComponent.AttachedComponent == ComponentName)
- {
- name = LevelComponent.Name;
- break;
- }
- }
- return name;
- }
- // Returns the GameObject of the requested component.
- public GameObject RequestGameObject(ComponentList.Components ComponentName)
- {
- foreach (LevelComponent LevelComponent in List)
- {
- if (LevelComponent.AttachedComponent == ComponentName)
- {
- if (LevelComponent.OneSize)
- {
- if (!LevelComponent.Colored)
- {
- ReturnObject = LevelComponent.AttachedBase;
- }
- else
- {
- ReturnObject = RequestColor(LevelComponent, GlobalAccess.ColorSelected);
- }
- break;
- }
- else
- {
- ReturnObject = RequestSize(LevelComponent, GlobalAccess.SizeSelected);
- }
- }
- }
- return ReturnObject;
- }
- GameObject RequestColor(LevelComponent LevelComponent, EditorGlobals.EditorColor ColorRequest)
- {
- switch (ColorRequest)
- {
- case EditorGlobals.EditorColor.Red:
- return LevelComponent.AttachedColor.Red;
- case EditorGlobals.EditorColor.Yellow:
- return LevelComponent.AttachedColor.Yellow;
- case EditorGlobals.EditorColor.Green:
- return LevelComponent.AttachedColor.Green;
- case EditorGlobals.EditorColor.Blue:
- return LevelComponent.AttachedColor.Blue;
- case EditorGlobals.EditorColor.Purple:
- return LevelComponent.AttachedColor.Purple;
- case EditorGlobals.EditorColor.Black:
- return LevelComponent.AttachedColor.Black;
- case EditorGlobals.EditorColor.White:
- return LevelComponent.AttachedColor.White;
- default:
- return new GameObject();
- }
- }
- GameObject RequestSize(LevelComponent LevelComponent, int SizeRequest)
- {
- switch (SizeRequest)
- {
- case 1:
- return LevelComponent.AttachedSize.x1;
- case 2:
- return LevelComponent.AttachedSize.x2;
- case 3:
- return LevelComponent.AttachedSize.x3;
- case 4:
- return LevelComponent.AttachedSize.x4;
- case 5:
- return LevelComponent.AttachedSize.x5;
- default:
- Debug.Log("Invalid SizeRequest.");
- return new GameObject();
- }
- }
- GameObject RequestSizeColor(LevelComponent LevelComponent, EditorGlobals.EditorColor ColorRequest, int SizeRequest)
- {
- switch (SizeRequest)
- {
- default:
- Debug.Log("Invalid SizeRequest.");
- return new GameObject();
- case 1:
- return ColorSwitch(ColorRequest, LevelComponent.AttachedSizeColor.x1);
- case 2:
- return ColorSwitch(ColorRequest, LevelComponent.AttachedSizeColor.x2);
- case 3:
- return ColorSwitch(ColorRequest, LevelComponent.AttachedSizeColor.x3);
- case 4:
- return ColorSwitch(ColorRequest, LevelComponent.AttachedSizeColor.x4);
- case 5:
- return ColorSwitch(ColorRequest, LevelComponent.AttachedSizeColor.x5);
- }
- }
- GameObject ColorSwitch(EditorGlobals.EditorColor ColorRequest, LevelComponent.ColorComponent SizePassthrough) // THIS IS ONLY USED BY: RequestSizeColor()
- {
- switch (ColorRequest)
- {
- default:
- Debug.Log("Invalid ColorRequest.");
- return new GameObject();
- case EditorGlobals.EditorColor.Red:
- return SizePassthrough.Red;
- case EditorGlobals.EditorColor.Yellow:
- return SizePassthrough.Yellow;
- case EditorGlobals.EditorColor.Green:
- return SizePassthrough.Green;
- case EditorGlobals.EditorColor.Blue:
- return SizePassthrough.Blue;
- case EditorGlobals.EditorColor.Purple:
- return SizePassthrough.Purple;
- case EditorGlobals.EditorColor.Black:
- return SizePassthrough.Black;
- case EditorGlobals.EditorColor.White:
- return SizePassthrough.White;
- }
- }
- }
- [System.Serializable]
- public class LevelComponent // Be sure not to remove or edit any of these or their values will be lost in Unity.
- {
- public string Name;
- public ComponentList.Components AttachedComponent;
- public bool OneSize;
- public bool Colored;
- public GameObject AttachedBase;
- public ColorComponent AttachedColor;
- public SizeComponent AttachedSize;
- public ColoredSizeComponent AttachedSizeColor;
- [System.Serializable]
- public class ColorComponent
- {
- public GameObject Red;
- public GameObject Yellow;
- public GameObject Green;
- public GameObject Blue;
- public GameObject Purple;
- public GameObject Black;
- public GameObject White;
- }
- [System.Serializable]
- public class SizeComponent
- {
- public GameObject x1;
- public GameObject x2;
- public GameObject x3;
- public GameObject x4;
- public GameObject x5;
- }
- [System.Serializable]
- public class ColoredSizeComponent
- {
- public ColorComponent x1;
- public ColorComponent x2;
- public ColorComponent x3;
- public ColorComponent x4;
- public ColorComponent x5;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement