Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using JasonStorey.Cameras;
- using UnityEditor;
- using UnityEngine;
- namespace JasonStorey
- {
- [CustomEditor(typeof(CameraSystem))]
- public class CameraSystemEditor : CustomCameraSystemEditor<CameraSystem>
- {
- private void DrawAbout() => DrawAbout(nameof(CameraSystem),
- "Camera System is the main controller of cameras. It sets a camera active, and uses a camera lookup to " +
- "allow controls like 'GotoNext' etc");
- protected override void Draw()
- {
- _index = TabHeaders(_index, "Main", "Controls", "Cams","Events", "About");
- TabPages(_index,DrawMain,DrawControls,DrawCameras,DrawEvents,DrawAbout);
- }
- private void DrawCameras() =>_scroll = DrawCameraScroller("Cameras", ref _scroll,ref ColCount, Item.All);
- public void DrawEvents() => DrawEvents("CameraChanged");
- private void DrawControls()
- {
- StartBox();
- StartRow();
- for (int i = 0; i < 9; i++)
- {
- if(Btn($"{i+1}")) Item.GotoIndex(i);
- }
- EndRow();
- Space();
- StartRow();
- if(BtnSmall("First",SMALL_BUTTON_SIZE)) Item.GotoFirst();
- if(BtnSmall("Prev",SMALL_BUTTON_SIZE)) Item.GotoPrev();
- if(BtnSmall("Random",SMALL_BUTTON_SIZE)) Item.GotoRandom();
- if(BtnSmall("Next",SMALL_BUTTON_SIZE)) Item.GotoNext();
- if(BtnSmall("Last",SMALL_BUTTON_SIZE)) Item.GotoLast();
- EndRow();
- EndBox();
- }
- private void DrawMain()
- {
- StartBox();
- DrawFixableDependency(x=>x.Lookup ==null,"Lookup","Camera system requires a CameraLookup reference to see the cameras.",TryAddLookup);
- Field("ChangeWithSet");
- EndBox();
- if (Application.isPlaying)
- DrawCurrentCamera();
- }
- private void DrawCurrentCamera()
- {
- StartBox();
- if (Item.Current == null)
- {
- Lbl("No Current Camera");
- }
- else
- {
- DrawCameraTool(Item.Current);
- }
- EndBox();
- }
- private void DrawCameraTool(SmartCamera cam)
- {
- var content = new GUIContent(cam.Name);
- Header(content.text);
- DrawCamera(cam);
- StartRow();
- var c = SceneViewFollow ? new Color(0.53f, 1f, 0.7f) : new Color(1f, 0.5f, 0.5f);
- StartColor(c);
- EditorGUILayout.Toggle(SceneViewFollow,GUILayout.Width(20));
- EndColor();
- if(Btn(SceneViewFollow ? "Stop Following" : "Follow Current Camera in Scene"))
- {
- SceneViewFollow = !SceneViewFollow;
- }
- EndRow();
- if(SceneViewFollow) SelectInScene(cam.transform);
- }
- private bool SceneViewFollow;
- private void TryAddLookup()
- {
- var lu = Item.GetComponent<CameraLookup>();
- Item.Lookup = lu != null ? lu : Item.gameObject.AddComponent<CameraLookup>();
- }
- protected override void DrawCamera(SmartCamera cam)
- {
- Color = new Color(0,0,0,0.1f);
- StartBox();
- StartRow();
- Color = new Color(1,1,0,0.8f);
- if (Btn(new GUIContent("?", "Where is this object?"), GUILayout.MaxWidth(120)))
- {
- PingInInspector(cam);
- SelectInScene(cam.transform);
- }
- Color = cam.IsLive ? JSEditorColors.GoBtn : Color.white;
- if (Btn(new GUIContent(cam.Name,"Activate this Camera"))) Item.SetCamera(cam);
- Color = new Color(1f, 0.55f, 0.35f, 0.8f);
- if (Btn(new GUIContent("goto","Select this object in the inspector"),GUILayout.MaxWidth(40))) SelectInInspector(cam);
- EndRow();
- EndBox();
- Color = Color.white;
- }
- private int _index;
- private const float SMALL_BUTTON_SIZE = 60;
- private int ColCount = 2;
- private Vector2 _scroll;
- }
- }
Add Comment
Please, Sign In to add comment