Last active
June 12, 2019 20:15
-
-
Save pr00thmatic/881a96faa9756daa6f76eee4a987c486 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.Playables; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class CinematicController : MonoBehaviour { | |
public PlayableDirector director; | |
public bool IsPaused { get => director.state == PlayState.Paused; } | |
public GameObject[] controlables; | |
public void Play () { | |
director.Play(); | |
} | |
public void TogglePause () { | |
if (IsPaused) { | |
director.Resume(); | |
} else { | |
director.Pause(); | |
} | |
} | |
public void Stop () { | |
director.Stop(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using UnityEditor.SceneManagement; | |
[CustomEditor(typeof(CinematicController))] | |
public class CinematicControllerEditor : Editor { | |
CinematicController Target { get => (CinematicController) target; } | |
public static bool isEditingGoal = false; | |
public static Tool lastTool; | |
void OnEnable () { | |
lastTool = Tools.current; | |
Tools.current = Tool.None; | |
Debug.Log("enable!"); | |
} | |
void OnDisable () { | |
Tools.current = lastTool; | |
Debug.Log("disable!"); | |
} | |
// https://docs.unity3d.com/ScriptReference/EditorGUILayout.html | |
// https://docs.unity3d.com/ScriptReference/GUILayout.html | |
public override void OnInspectorGUI () { | |
DrawDefaultInspector(); | |
if (Target.director == null) return; | |
if (GUILayout.Button("Play")) { | |
Target.Play(); | |
} | |
if (GUILayout.Button(Target.IsPaused? "Resume": "Play")) { | |
Target.TogglePause(); | |
} | |
isEditingGoal = GUILayout.Toggle(isEditingGoal, "Mover goal", "Button"); | |
if (GUI.changed && !Application.isPlaying) { | |
EditorUtility.SetDirty(Target); | |
EditorSceneManager.MarkSceneDirty(Target.gameObject.scene); | |
} | |
} | |
// https://docs.unity3d.com/ScriptReference/Gizmos.html | |
// https://docs.unity3d.com/ScriptReference/Handles.html | |
// https://docs.unity3d.com/ScriptReference/IMGUI.Controls.BoxBoundsHandle.html | |
public static void DrawGizmos (CinematicController target) { | |
Tools.current = Tool.None; | |
if (isEditingGoal) { | |
foreach (GameObject controlable in target.controlables) { | |
controlable.transform.position = | |
Handles.PositionHandle(controlable.transform.position, Quaternion.identity); | |
} | |
} | |
} | |
void OnSceneGUI () { | |
DrawGizmos(Target); | |
if (GUI.changed && !Application.isPlaying) { | |
EditorUtility.SetDirty(Target); | |
EditorSceneManager.MarkSceneDirty(Target.gameObject.scene); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment