aboutsummaryrefslogtreecommitdiff
path: root/Assets/Cinemachine/Base/Editor
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Cinemachine/Base/Editor')
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors.meta9
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineBasicMultiChannelPerlinEditor.cs156
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineBasicMultiChannelPerlinEditor.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineBlendListCameraEditor.cs206
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineBlendListCameraEditor.cs.meta13
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineBlenderSettingsEditor.cs161
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineBlenderSettingsEditor.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineBrainEditor.cs168
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineBrainEditor.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineClearShotEditor.cs211
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineClearShotEditor.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineColliderEditor.cs76
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineColliderEditor.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineComposerEditor.cs89
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineComposerEditor.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineConfinerEditor.cs161
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineConfinerEditor.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineExternalCameraEditor.cs17
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineExternalCameraEditor.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineFramingTransposerEditor.cs174
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineFramingTransposerEditor.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineFreeLookEditor.cs206
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineFreeLookEditor.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineGroupComposerEditor.cs83
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineGroupComposerEditor.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineHardLockToTargetEditor.cs23
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineHardLockToTargetEditor.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineHardLookAtEditor.cs23
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineHardLookAtEditor.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineMixingCameraEditor.cs104
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineMixingCameraEditor.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineOrbitalTransposerEditor.cs103
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineOrbitalTransposerEditor.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachinePOVEditor.cs9
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachinePOVEditor.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachinePathEditor.cs387
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachinePathEditor.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineScreenComposerGuides.cs191
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineScreenComposerGuides.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineSmoothPathEditor.cs225
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineSmoothPathEditor.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineStateDrivenCameraEditor.cs444
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineStateDrivenCameraEditor.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineTargetGroupEditor.cs94
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineTargetGroupEditor.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineTrackedDollyEditor.cs60
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineTrackedDollyEditor.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineTransposerEditor.cs73
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineTransposerEditor.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineVirtualCameraBaseEditor.cs202
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineVirtualCameraBaseEditor.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineVirtualCameraEditor.cs432
-rw-r--r--Assets/Cinemachine/Base/Editor/Editors/CinemachineVirtualCameraEditor.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Menus.meta9
-rw-r--r--Assets/Cinemachine/Base/Editor/Menus/CinemachineMenu.cs248
-rw-r--r--Assets/Cinemachine/Base/Editor/Menus/CinemachineMenu.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/PropertyDrawers.meta9
-rw-r--r--Assets/Cinemachine/Base/Editor/PropertyDrawers/CinemachineBlendDefinitionPropertyDrawer.cs38
-rw-r--r--Assets/Cinemachine/Base/Editor/PropertyDrawers/CinemachineBlendDefinitionPropertyDrawer.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/PropertyDrawers/CinemachineTagFieldPropertyDrawer.cs28
-rw-r--r--Assets/Cinemachine/Base/Editor/PropertyDrawers/CinemachineTagFieldPropertyDrawer.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/PropertyDrawers/GetSetDrawer.cs1
-rw-r--r--Assets/Cinemachine/Base/Editor/PropertyDrawers/GetSetDrawer.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/PropertyDrawers/LensSettingsPropertyDrawer.cs61
-rw-r--r--Assets/Cinemachine/Base/Editor/PropertyDrawers/LensSettingsPropertyDrawer.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/PropertyDrawers/MinDrawer.cs1
-rw-r--r--Assets/Cinemachine/Base/Editor/PropertyDrawers/MinDrawer.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Resources.meta9
-rw-r--r--Assets/Cinemachine/Base/Editor/Resources/Cinemachine_header.tif3
-rw-r--r--Assets/Cinemachine/Base/Editor/Resources/Cinemachine_header.tif.meta74
-rw-r--r--Assets/Cinemachine/Base/Editor/Resources/cm_logo_sm.png3
-rw-r--r--Assets/Cinemachine/Base/Editor/Resources/cm_logo_sm.png.meta82
-rw-r--r--Assets/Cinemachine/Base/Editor/Utility.meta9
-rw-r--r--Assets/Cinemachine/Base/Editor/Utility/BaseEditor.cs79
-rw-r--r--Assets/Cinemachine/Base/Editor/Utility/BaseEditor.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Utility/EmbeddedAssetHelpers.cs177
-rw-r--r--Assets/Cinemachine/Base/Editor/Utility/EmbeddedAssetHelpers.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Utility/SaveDuringPlay.cs529
-rw-r--r--Assets/Cinemachine/Base/Editor/Utility/SaveDuringPlay.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Utility/ScriptableObjectUtility.cs160
-rw-r--r--Assets/Cinemachine/Base/Editor/Utility/ScriptableObjectUtility.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Utility/SerializedPropertyHelper.cs59
-rw-r--r--Assets/Cinemachine/Base/Editor/Utility/SerializedPropertyHelper.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Windows.meta9
-rw-r--r--Assets/Cinemachine/Base/Editor/Windows/AboutWindow.cs149
-rw-r--r--Assets/Cinemachine/Base/Editor/Windows/AboutWindow.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Windows/CinemachineColliderPrefs.cs85
-rw-r--r--Assets/Cinemachine/Base/Editor/Windows/CinemachineColliderPrefs.cs.meta12
-rw-r--r--Assets/Cinemachine/Base/Editor/Windows/CinemachineSettings.cs454
-rw-r--r--Assets/Cinemachine/Base/Editor/Windows/CinemachineSettings.cs.meta12
90 files changed, 6844 insertions, 0 deletions
diff --git a/Assets/Cinemachine/Base/Editor/Editors.meta b/Assets/Cinemachine/Base/Editor/Editors.meta
new file mode 100644
index 0000000..b8af86b
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors.meta
@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: 6b46e8ffe448f084ab12938cb774d063
+folderAsset: yes
+timeCreated: 1489096338
+licenseType: Store
+DefaultImporter:
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineBasicMultiChannelPerlinEditor.cs b/Assets/Cinemachine/Base/Editor/Editors/CinemachineBasicMultiChannelPerlinEditor.cs
new file mode 100644
index 0000000..4110174
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineBasicMultiChannelPerlinEditor.cs
@@ -0,0 +1,156 @@
+using System.Collections.Generic;
+using System.IO;
+using UnityEditor;
+using UnityEngine;
+
+namespace Cinemachine.Editor
+{
+ [CustomEditor(typeof(CinemachineBasicMultiChannelPerlin))]
+ internal sealed class CinemachineBasicMultiChannelPerlinEditor
+ : BaseEditor<CinemachineBasicMultiChannelPerlin>
+ {
+ List<NoiseSettings> mNoisePresets;
+ string[] mNoisePresetNames;
+ SerializedProperty m_Profile;
+
+ protected override List<string> GetExcludedPropertiesInInspector()
+ {
+ List<string> excluded = base.GetExcludedPropertiesInInspector();
+ excluded.Add(FieldPath(x => x.m_NoiseProfile));
+ return excluded;
+ }
+
+ private void OnEnable()
+ {
+ m_Profile = FindProperty(x => x.m_NoiseProfile);
+ RebuildProfileList();
+ }
+
+ void RebuildProfileList()
+ {
+ mNoisePresets = FindAssetsByType<NoiseSettings>();
+#if UNITY_2018_1_OR_NEWER
+ if (ScriptableObjectUtility.CinemachineIsPackage)
+ AddAssetsFromDirectory(
+ mNoisePresets,
+ ScriptableObjectUtility.CinemachineInstallAssetPath + "/Presets/Noise");
+#endif
+ mNoisePresets.Insert(0, null);
+ List<string> presetNameList = new List<string>();
+ foreach (var n in mNoisePresets)
+ presetNameList.Add((n == null) ? "(none)" : n.name);
+ mNoisePresetNames = presetNameList.ToArray();
+ }
+
+ public override void OnInspectorGUI()
+ {
+ BeginInspector();
+
+ if (m_Profile.objectReferenceValue == null)
+ EditorGUILayout.HelpBox(
+ "A Noise Profile is required. You may choose from among the NoiseSettings assets defined in the project.",
+ MessageType.Warning);
+
+ Rect rect = EditorGUILayout.GetControlRect(true);
+ float iconSize = rect.height + 4;
+ rect.width -= iconSize;
+ int preset = mNoisePresets.IndexOf((NoiseSettings)m_Profile.objectReferenceValue);
+ preset = EditorGUI.Popup(rect, "Noise Profile", preset, mNoisePresetNames);
+ NoiseSettings newProfile = preset < 0 ? null : mNoisePresets[preset];
+ if ((NoiseSettings)m_Profile.objectReferenceValue != newProfile)
+ {
+ m_Profile.objectReferenceValue = newProfile;
+ serializedObject.ApplyModifiedProperties();
+ }
+ rect.x += rect.width; rect.width = iconSize; rect.height = iconSize;
+ if (GUI.Button(rect, EditorGUIUtility.IconContent("_Popup"), GUI.skin.label))
+ {
+ GenericMenu menu = new GenericMenu();
+ if (m_Profile.objectReferenceValue != null)
+ {
+ menu.AddItem(new GUIContent("Edit"), false, () => Selection.activeObject = m_Profile.objectReferenceValue);
+ menu.AddItem(new GUIContent("Clone"), false, () =>
+ {
+ m_Profile.objectReferenceValue = CreateProfile(
+ (NoiseSettings)m_Profile.objectReferenceValue);
+ RebuildProfileList();
+ serializedObject.ApplyModifiedProperties();
+ });
+ menu.AddItem(new GUIContent("Locate"), false, () => EditorGUIUtility.PingObject(m_Profile.objectReferenceValue));
+ }
+ menu.AddItem(new GUIContent("New"), false, () =>
+ {
+ //Undo.RecordObject(Target, "Change Noise Profile");
+ m_Profile.objectReferenceValue = CreateProfile(null);
+ RebuildProfileList();
+ serializedObject.ApplyModifiedProperties();
+ });
+ menu.ShowAsContext();
+ }
+
+ DrawRemainingPropertiesInInspector();
+ }
+
+ public static List<T> FindAssetsByType<T>() where T : UnityEngine.Object
+ {
+ List<T> assets = new List<T>();
+ string[] guids = AssetDatabase.FindAssets(string.Format("t:{0}", typeof(T)));
+ for (int i = 0; i < guids.Length; i++)
+ {
+ string assetPath = AssetDatabase.GUIDToAssetPath(guids[i]);
+ T asset = AssetDatabase.LoadAssetAtPath<T>(assetPath);
+ if (asset != null)
+ {
+ assets.Add(asset);
+ }
+ }
+ return assets;
+ }
+
+ static void AddAssetsFromDirectory<T>(List<T> assets, string path) where T : UnityEngine.Object
+ {
+ try
+ {
+ var info = new DirectoryInfo(path);
+ var fileInfo = info.GetFiles();
+ foreach (var file in fileInfo)
+ {
+ string name = path + "/" + file.Name;
+ T a = AssetDatabase.LoadAssetAtPath(name, typeof(T)) as T;
+ if (a != null)
+ assets.Add(a);
+ }
+ }
+ catch
+ {
+ }
+ }
+
+ NoiseSettings CreateProfile(NoiseSettings copyFrom)
+ {
+ var path = string.Empty;
+ var scene = Target.gameObject.scene;
+ if (string.IsNullOrEmpty(scene.path))
+ path = "Assets/";
+ else
+ {
+ var scenePath = Path.GetDirectoryName(scene.path);
+ var extPath = scene.name + "_Profiles";
+ var profilePath = scenePath + "/" + extPath;
+ if (!AssetDatabase.IsValidFolder(profilePath))
+ AssetDatabase.CreateFolder(scenePath, extPath);
+ path = profilePath + "/";
+ }
+
+ var profile = ScriptableObject.CreateInstance<NoiseSettings>();
+ if (copyFrom != null)
+ profile.CopyFrom(copyFrom);
+ path += Target.VirtualCamera.Name + " Noise.asset";
+ path = AssetDatabase.GenerateUniqueAssetPath(path);
+ AssetDatabase.CreateAsset(profile, path);
+ AssetDatabase.SaveAssets();
+ AssetDatabase.Refresh();
+ return profile;
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineBasicMultiChannelPerlinEditor.cs.meta b/Assets/Cinemachine/Base/Editor/Editors/CinemachineBasicMultiChannelPerlinEditor.cs.meta
new file mode 100644
index 0000000..1e1ca16
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineBasicMultiChannelPerlinEditor.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: ee42f1964a0e8224c90be81905946699
+timeCreated: 1484091313
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineBlendListCameraEditor.cs b/Assets/Cinemachine/Base/Editor/Editors/CinemachineBlendListCameraEditor.cs
new file mode 100644
index 0000000..6a976ac
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineBlendListCameraEditor.cs
@@ -0,0 +1,206 @@
+using System.Collections.Generic;
+using UnityEditor;
+using UnityEngine;
+
+namespace Cinemachine.Editor
+{
+ [CustomEditor(typeof(CinemachineBlendListCamera))]
+ internal sealed class CinemachineBlendListCameraEditor
+ : CinemachineVirtualCameraBaseEditor<CinemachineBlendListCamera>
+ {
+ protected override List<string> GetExcludedPropertiesInInspector()
+ {
+ List<string> excluded = base.GetExcludedPropertiesInInspector();
+ excluded.Add(FieldPath(x => x.m_Instructions));
+ return excluded;
+ }
+
+ private UnityEditorInternal.ReorderableList mChildList;
+ private UnityEditorInternal.ReorderableList mInstructionList;
+
+ protected override void OnEnable()
+ {
+ base.OnEnable();
+ mChildList = null;
+ mInstructionList = null;
+ }
+
+ protected override void OnDisable()
+ {
+ base.OnDisable();
+ }
+
+ public override void OnInspectorGUI()
+ {
+ BeginInspector();
+ if (mInstructionList == null)
+ SetupInstructionList();
+ if (mChildList == null)
+ SetupChildList();
+
+ // Ordinary properties
+ DrawHeaderInInspector();
+ DrawPropertyInInspector(FindProperty(x => x.m_Priority));
+ DrawTargetsInInspector(FindProperty(x => x.m_Follow), FindProperty(x => x.m_LookAt));
+ DrawRemainingPropertiesInInspector();
+
+ // Instructions
+ UpdateCameraCandidates();
+ EditorGUI.BeginChangeCheck();
+ EditorGUILayout.Separator();
+ mInstructionList.DoLayoutList();
+
+ // vcam children
+ EditorGUILayout.Separator();
+ mChildList.DoLayoutList();
+ if (EditorGUI.EndChangeCheck())
+ {
+ serializedObject.ApplyModifiedProperties();
+ Target.ValidateInstructions();
+ }
+
+ // Extensions
+ DrawExtensionsWidgetInInspector();
+ }
+
+ private string[] mCameraCandidates;
+ private Dictionary<CinemachineVirtualCameraBase, int> mCameraIndexLookup;
+ private void UpdateCameraCandidates()
+ {
+ List<string> vcams = new List<string>();
+ mCameraIndexLookup = new Dictionary<CinemachineVirtualCameraBase, int>();
+ vcams.Add("(none)");
+ CinemachineVirtualCameraBase[] children = Target.ChildCameras;
+ foreach (var c in children)
+ {
+ mCameraIndexLookup[c] = vcams.Count;
+ vcams.Add(c.Name);
+ }
+ mCameraCandidates = vcams.ToArray();
+ }
+
+ private int GetCameraIndex(Object obj)
+ {
+ if (obj == null || mCameraIndexLookup == null)
+ return 0;
+ CinemachineVirtualCameraBase vcam = obj as CinemachineVirtualCameraBase;
+ if (vcam == null)
+ return 0;
+ if (!mCameraIndexLookup.ContainsKey(vcam))
+ return 0;
+ return mCameraIndexLookup[vcam];
+ }
+
+ void SetupInstructionList()
+ {
+ mInstructionList = new UnityEditorInternal.ReorderableList(serializedObject,
+ serializedObject.FindProperty(() => Target.m_Instructions),
+ true, true, true, true);
+
+ // Needed for accessing field names as strings
+ CinemachineBlendListCamera.Instruction def = new CinemachineBlendListCamera.Instruction();
+
+ float vSpace = 2;
+ float hSpace = 3;
+ float floatFieldWidth = EditorGUIUtility.singleLineHeight * 2.5f;
+ float hBigSpace = EditorGUIUtility.singleLineHeight * 2 / 3;
+ mInstructionList.drawHeaderCallback = (Rect rect) =>
+ {
+ float sharedWidth = rect.width - EditorGUIUtility.singleLineHeight
+ - floatFieldWidth - hSpace - hBigSpace;
+ rect.x += EditorGUIUtility.singleLineHeight; rect.width = sharedWidth / 2;
+ EditorGUI.LabelField(rect, "Child");
+
+ rect.x += rect.width + hSpace;
+ EditorGUI.LabelField(rect, "Blend in");
+
+ rect.x += rect.width + hBigSpace; rect.width = floatFieldWidth;
+ EditorGUI.LabelField(rect, "Hold");
+ };
+
+ mInstructionList.drawElementCallback
+ = (Rect rect, int index, bool isActive, bool isFocused) =>
+ {
+ SerializedProperty instProp = mInstructionList.serializedProperty.GetArrayElementAtIndex(index);
+ float sharedWidth = rect.width - floatFieldWidth - hSpace - hBigSpace;
+ rect.y += vSpace; rect.height = EditorGUIUtility.singleLineHeight;
+
+ rect.width = sharedWidth / 2;
+ SerializedProperty vcamSelProp = instProp.FindPropertyRelative(() => def.m_VirtualCamera);
+ int currentVcam = GetCameraIndex(vcamSelProp.objectReferenceValue);
+ int vcamSelection = EditorGUI.Popup(rect, currentVcam, mCameraCandidates);
+ if (currentVcam != vcamSelection)
+ vcamSelProp.objectReferenceValue = (vcamSelection == 0)
+ ? null : Target.ChildCameras[vcamSelection - 1];
+
+ rect.x += rect.width + hSpace; rect.width = sharedWidth / 2;
+ if (index > 0)
+ EditorGUI.PropertyField(rect, instProp.FindPropertyRelative(() => def.m_Blend),
+ GUIContent.none);
+
+ if (index < mInstructionList.count - 1)
+ {
+ float oldWidth = EditorGUIUtility.labelWidth;
+ EditorGUIUtility.labelWidth = hBigSpace;
+
+ rect.x += rect.width; rect.width = floatFieldWidth + hBigSpace;
+ SerializedProperty holdProp = instProp.FindPropertyRelative(() => def.m_Hold);
+ EditorGUI.PropertyField(rect, holdProp, new GUIContent(" ", holdProp.tooltip));
+ holdProp.floatValue = Mathf.Max(holdProp.floatValue, 0);
+
+ EditorGUIUtility.labelWidth = oldWidth;
+ }
+ };
+ }
+
+ void SetupChildList()
+ {
+ float vSpace = 2;
+ mChildList = new UnityEditorInternal.ReorderableList(serializedObject,
+ serializedObject.FindProperty(() => Target.m_ChildCameras),
+ true, true, true, true);
+
+ mChildList.drawHeaderCallback = (Rect rect) =>
+ {
+ EditorGUI.LabelField(rect, "Virtual Camera Children");
+ };
+ mChildList.drawElementCallback
+ = (Rect rect, int index, bool isActive, bool isFocused) =>
+ {
+ rect.y += vSpace;
+ Vector2 pos = rect.position;
+ rect.height = EditorGUIUtility.singleLineHeight;
+ SerializedProperty element
+ = mChildList.serializedProperty.GetArrayElementAtIndex(index);
+ EditorGUI.PropertyField(rect, element, GUIContent.none);
+ };
+ mChildList.onChangedCallback = (UnityEditorInternal.ReorderableList l) =>
+ {
+ if (l.index < 0 || l.index >= l.serializedProperty.arraySize)
+ return;
+ Object o = l.serializedProperty.GetArrayElementAtIndex(
+ l.index).objectReferenceValue;
+ CinemachineVirtualCameraBase vcam = (o != null)
+ ? (o as CinemachineVirtualCameraBase) : null;
+ if (vcam != null)
+ vcam.transform.SetSiblingIndex(l.index);
+ };
+ mChildList.onAddCallback = (UnityEditorInternal.ReorderableList l) =>
+ {
+ var index = l.serializedProperty.arraySize;
+ var vcam = CinemachineMenu.CreateDefaultVirtualCamera();
+ Undo.SetTransformParent(vcam.transform, Target.transform, "");
+ vcam.transform.SetSiblingIndex(index);
+ };
+ mChildList.onRemoveCallback = (UnityEditorInternal.ReorderableList l) =>
+ {
+ Object o = l.serializedProperty.GetArrayElementAtIndex(
+ l.index).objectReferenceValue;
+ CinemachineVirtualCameraBase vcam = (o != null)
+ ? (o as CinemachineVirtualCameraBase) : null;
+ if (vcam != null)
+ Undo.DestroyObjectImmediate(vcam.gameObject);
+ };
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineBlendListCameraEditor.cs.meta b/Assets/Cinemachine/Base/Editor/Editors/CinemachineBlendListCameraEditor.cs.meta
new file mode 100644
index 0000000..e00e0fb
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineBlendListCameraEditor.cs.meta
@@ -0,0 +1,13 @@
+fileFormatVersion: 2
+guid: 0181db608628b494d8ae50728e507ce1
+timeCreated: 1509479768
+licenseType: Store
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineBlenderSettingsEditor.cs b/Assets/Cinemachine/Base/Editor/Editors/CinemachineBlenderSettingsEditor.cs
new file mode 100644
index 0000000..8eddd12
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineBlenderSettingsEditor.cs
@@ -0,0 +1,161 @@
+using UnityEngine;
+using UnityEditor;
+using UnityEditorInternal;
+using System.Collections.Generic;
+
+namespace Cinemachine.Editor
+{
+ [CustomEditor(typeof(CinemachineBlenderSettings))]
+ internal sealed class CinemachineBlenderSettingsEditor : BaseEditor<CinemachineBlenderSettings>
+ {
+ private ReorderableList mBlendList;
+
+ /// <summary>
+ /// Called when building the Camera popup menus, to get the domain of possible
+ /// cameras. If no delegate is set, will find all top-level (non-slave)
+ /// virtual cameras in the scene.
+ /// </summary>
+ public GetAllVirtualCamerasDelegate GetAllVirtualCameras;
+ public delegate CinemachineVirtualCameraBase[] GetAllVirtualCamerasDelegate();
+
+ protected override List<string> GetExcludedPropertiesInInspector()
+ {
+ List<string> excluded = base.GetExcludedPropertiesInInspector();
+ excluded.Add(FieldPath(x => x.m_CustomBlends));
+ return excluded;
+ }
+
+ public override void OnInspectorGUI()
+ {
+ BeginInspector();
+ if (mBlendList == null)
+ SetupBlendList();
+
+ DrawRemainingPropertiesInInspector();
+
+ UpdateCameraCandidates();
+ mBlendList.DoLayoutList();
+ serializedObject.ApplyModifiedProperties();
+ }
+
+ private string[] mCameraCandidates;
+ private Dictionary<string, int> mCameraIndexLookup;
+ private void UpdateCameraCandidates()
+ {
+ List<string> vcams = new List<string>();
+ mCameraIndexLookup = new Dictionary<string, int>();
+
+ CinemachineVirtualCameraBase[] candidates;
+ if (GetAllVirtualCameras != null)
+ candidates = GetAllVirtualCameras();
+ else
+ {
+ // Get all top-level (i.e. non-slave) virtual cameras
+ candidates = Resources.FindObjectsOfTypeAll(
+ typeof(CinemachineVirtualCameraBase)) as CinemachineVirtualCameraBase[];
+
+ for (int i = 0; i < candidates.Length; ++i)
+ if (candidates[i].ParentCamera != null)
+ candidates[i] = null;
+ }
+ vcams.Add("(none)");
+ vcams.Add(CinemachineBlenderSettings.kBlendFromAnyCameraLabel);
+ foreach (CinemachineVirtualCameraBase c in candidates)
+ if (c != null && !vcams.Contains(c.Name))
+ vcams.Add(c.Name);
+
+ mCameraCandidates = vcams.ToArray();
+ for (int i = 0; i < mCameraCandidates.Length; ++i)
+ mCameraIndexLookup[mCameraCandidates[i]] = i;
+ }
+
+ private int GetCameraIndex(string name)
+ {
+ if (name == null || mCameraIndexLookup == null)
+ return 0;
+ if (!mCameraIndexLookup.ContainsKey(name))
+ return 0;
+ return mCameraIndexLookup[name];
+ }
+
+ void SetupBlendList()
+ {
+ mBlendList = new ReorderableList(serializedObject,
+ serializedObject.FindProperty(() => Target.m_CustomBlends),
+ true, true, true, true);
+
+ // Needed for accessing string names of fields
+ CinemachineBlenderSettings.CustomBlend def = new CinemachineBlenderSettings.CustomBlend();
+ CinemachineBlendDefinition def2 = new CinemachineBlendDefinition();
+
+ float vSpace = 2;
+ float hSpace = 3;
+ float floatFieldWidth = EditorGUIUtility.singleLineHeight * 2.5f;
+ mBlendList.drawHeaderCallback = (Rect rect) =>
+ {
+ rect.width -= (EditorGUIUtility.singleLineHeight + 2 * hSpace);
+ rect.width /= 3;
+ Vector2 pos = rect.position; pos.x += EditorGUIUtility.singleLineHeight;
+ rect.position = pos;
+ EditorGUI.LabelField(rect, "From");
+
+ pos.x += rect.width + hSpace; rect.position = pos;
+ EditorGUI.LabelField(rect, "To");
+
+ pos.x += rect.width + hSpace; rect.width -= floatFieldWidth + hSpace; rect.position = pos;
+ EditorGUI.LabelField(rect, "Style");
+
+ pos.x += rect.width + hSpace; rect.width = floatFieldWidth; rect.position = pos;
+ EditorGUI.LabelField(rect, "Time");
+ };
+
+ mBlendList.drawElementCallback
+ = (Rect rect, int index, bool isActive, bool isFocused) =>
+ {
+ SerializedProperty element
+ = mBlendList.serializedProperty.GetArrayElementAtIndex(index);
+
+ rect.y += vSpace;
+ rect.height = EditorGUIUtility.singleLineHeight;
+ Vector2 pos = rect.position;
+ rect.width -= 2 * hSpace; rect.width /= 3;
+ SerializedProperty fromProp = element.FindPropertyRelative(() => def.m_From);
+ int current = GetCameraIndex(fromProp.stringValue);
+ int sel = EditorGUI.Popup(rect, current, mCameraCandidates);
+ if (current != sel)
+ fromProp.stringValue = mCameraCandidates[sel];
+
+ pos.x += rect.width + hSpace; rect.position = pos;
+ SerializedProperty toProp = element.FindPropertyRelative(() => def.m_To);
+ current = GetCameraIndex(toProp.stringValue);
+ sel = EditorGUI.Popup(rect, current, mCameraCandidates);
+ if (current != sel)
+ toProp.stringValue = mCameraCandidates[sel];
+
+ SerializedProperty blendProp = element.FindPropertyRelative(() => def.m_Blend);
+ pos.x += rect.width + hSpace; rect.width -= floatFieldWidth; rect.position = pos;
+ SerializedProperty styleProp = blendProp.FindPropertyRelative(() => def2.m_Style);
+ EditorGUI.PropertyField(rect, styleProp, GUIContent.none);
+
+ if (styleProp.intValue != (int)CinemachineBlendDefinition.Style.Cut)
+ {
+ pos.x += rect.width + hSpace; rect.width = floatFieldWidth; rect.position = pos;
+ SerializedProperty timeProp = blendProp.FindPropertyRelative(() => def2.m_Time);
+ EditorGUI.PropertyField(rect, timeProp, GUIContent.none);
+ }
+ };
+
+ mBlendList.onAddCallback = (ReorderableList l) =>
+ {
+ var index = l.serializedProperty.arraySize;
+ ++l.serializedProperty.arraySize;
+ SerializedProperty blendProp = l.serializedProperty.GetArrayElementAtIndex(
+ index).FindPropertyRelative(() => def.m_Blend);
+
+ blendProp.FindPropertyRelative(() => def2.m_Style).enumValueIndex
+ = (int)CinemachineBlendDefinition.Style.EaseInOut;
+ blendProp.FindPropertyRelative(() => def2.m_Time).floatValue = 2f;
+ };
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineBlenderSettingsEditor.cs.meta b/Assets/Cinemachine/Base/Editor/Editors/CinemachineBlenderSettingsEditor.cs.meta
new file mode 100644
index 0000000..9b41fd6
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineBlenderSettingsEditor.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 1ff9d8296ed1f02419bf4f417ff2265e
+timeCreated: 1486495673
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineBrainEditor.cs b/Assets/Cinemachine/Base/Editor/Editors/CinemachineBrainEditor.cs
new file mode 100644
index 0000000..20604b6
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineBrainEditor.cs
@@ -0,0 +1,168 @@
+using UnityEngine;
+using UnityEditor;
+using System.Collections.Generic;
+using Cinemachine.Utility;
+using System.IO;
+
+namespace Cinemachine.Editor
+{
+ [CustomEditor(typeof(CinemachineBrain))]
+ internal sealed class CinemachineBrainEditor : BaseEditor<CinemachineBrain>
+ {
+ EmbeddeAssetEditor<CinemachineBlenderSettings> m_BlendsEditor;
+ bool mEventsExpanded = false;
+
+ protected override List<string> GetExcludedPropertiesInInspector()
+ {
+ List<string> excluded = base.GetExcludedPropertiesInInspector();
+ excluded.Add(FieldPath(x => x.m_CameraCutEvent));
+ excluded.Add(FieldPath(x => x.m_CameraActivatedEvent));
+ excluded.Add(FieldPath(x => x.m_CustomBlends));
+ return excluded;
+ }
+
+ private void OnEnable()
+ {
+ m_BlendsEditor = new EmbeddeAssetEditor<CinemachineBlenderSettings>(
+ FieldPath(x => x.m_CustomBlends), this);
+ m_BlendsEditor.OnChanged = (CinemachineBlenderSettings b) =>
+ {
+ UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
+ };
+ }
+
+ private void OnDisable()
+ {
+ if (m_BlendsEditor != null)
+ m_BlendsEditor.OnDisable();
+ }
+
+ public override void OnInspectorGUI()
+ {
+ BeginInspector();
+
+ // Show the active camera and blend
+ GUI.enabled = false;
+ ICinemachineCamera vcam = Target.ActiveVirtualCamera;
+ Transform activeCam = (vcam != null && vcam.VirtualCameraGameObject != null)
+ ? vcam.VirtualCameraGameObject.transform : null;
+ EditorGUILayout.ObjectField("Live Camera", activeCam, typeof(Transform), true);
+ EditorGUILayout.DelayedTextField(
+ "Live Blend", Target.ActiveBlend != null
+ ? Target.ActiveBlend.Description : string.Empty);
+ GUI.enabled = true;
+
+ // Normal properties
+ DrawRemainingPropertiesInInspector();
+
+ // Blender
+ m_BlendsEditor.DrawEditorCombo(
+ "Create New Blender Asset",
+ Target.gameObject.name + " Blends", "asset", string.Empty,
+ "Custom Blends", false);
+
+ mEventsExpanded = EditorGUILayout.Foldout(mEventsExpanded, "Events");
+ if (mEventsExpanded)
+ {
+ EditorGUILayout.PropertyField(FindProperty(x => x.m_CameraCutEvent));
+ EditorGUILayout.PropertyField(FindProperty(x => x.m_CameraActivatedEvent));
+ }
+ serializedObject.ApplyModifiedProperties();
+ }
+
+ [DrawGizmo(GizmoType.Selected | GizmoType.NonSelected, typeof(CinemachineBrain))]
+ private static void DrawBrainGizmos(CinemachineBrain brain, GizmoType drawType)
+ {
+ if (brain.OutputCamera != null && brain.m_ShowCameraFrustum)
+ {
+ DrawCameraFrustumGizmo(
+ brain, LensSettings.FromCamera(brain.OutputCamera),
+ brain.transform.localToWorldMatrix,
+ Color.white); // GML why is this color hardcoded?
+ }
+ }
+
+ internal static void DrawCameraFrustumGizmo(
+ CinemachineBrain brain, LensSettings lens,
+ Matrix4x4 transform, Color color)
+ {
+ float aspect = 1;
+ bool ortho = false;
+ if (brain != null)
+ {
+ aspect = brain.OutputCamera.aspect;
+ ortho = brain.OutputCamera.orthographic;
+ }
+
+ Matrix4x4 originalMatrix = Gizmos.matrix;
+ Color originalGizmoColour = Gizmos.color;
+ Gizmos.color = color;
+ Gizmos.matrix = transform;
+ if (ortho)
+ {
+ Vector3 size = new Vector3(
+ aspect * lens.OrthographicSize * 2,
+ lens.OrthographicSize * 2,
+ lens.NearClipPlane + lens.FarClipPlane);
+ Gizmos.DrawWireCube(
+ new Vector3(0, 0, (size.z / 2) + lens.NearClipPlane), size);
+ }
+ else
+ {
+ Gizmos.DrawFrustum(
+ Vector3.zero, lens.FieldOfView,
+ lens.FarClipPlane, lens.NearClipPlane, aspect);
+ }
+ Gizmos.matrix = originalMatrix;
+ Gizmos.color = originalGizmoColour;
+ }
+
+ [DrawGizmo(GizmoType.Active | GizmoType.InSelectionHierarchy | GizmoType.Pickable, typeof(CinemachineVirtualCameraBase))]
+ internal static void DrawVirtualCameraBaseGizmos(CinemachineVirtualCameraBase vcam, GizmoType selectionType)
+ {
+ // Don't draw gizmos on hidden stuff
+ if ((vcam.VirtualCameraGameObject.hideFlags & (HideFlags.HideInHierarchy | HideFlags.HideInInspector)) != 0)
+ return;
+
+ if (vcam.ParentCamera != null && (selectionType & GizmoType.Active) == 0)
+ return;
+
+ CameraState state = vcam.State;
+ Gizmos.DrawIcon(state.FinalPosition, kGizmoFileName, true);
+
+ DrawCameraFrustumGizmo(
+ CinemachineCore.Instance.FindPotentialTargetBrain(vcam),
+ state.Lens,
+ Matrix4x4.TRS(
+ state.FinalPosition,
+ UnityQuaternionExtensions.Normalized(state.FinalOrientation), Vector3.one),
+ CinemachineCore.Instance.IsLive(vcam)
+ ? CinemachineSettings.CinemachineCoreSettings.ActiveGizmoColour
+ : CinemachineSettings.CinemachineCoreSettings.InactiveGizmoColour);
+ }
+
+ static string kGizmoFileName = "Cinemachine/cm_logo_lg.png";
+ [InitializeOnLoad]
+ static class InstallGizmos
+ {
+ static InstallGizmos()
+ {
+ string srcFile = ScriptableObjectUtility.CinemachineInstallPath + "/Gizmos/" + kGizmoFileName;
+ if (File.Exists(srcFile))
+ {
+ string dstFile = Application.dataPath + "/Gizmos";
+ if (!Directory.Exists(dstFile))
+ Directory.CreateDirectory(dstFile);
+ dstFile += "/" + kGizmoFileName;
+ if (!File.Exists(dstFile)
+ || File.GetCreationTime(dstFile) < File.GetCreationTime(srcFile))
+ {
+ if (!Directory.Exists(Path.GetDirectoryName(dstFile)))
+ Directory.CreateDirectory(Path.GetDirectoryName(dstFile));
+ File.Copy(srcFile, dstFile, true);
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineBrainEditor.cs.meta b/Assets/Cinemachine/Base/Editor/Editors/CinemachineBrainEditor.cs.meta
new file mode 100644
index 0000000..728e8f5
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineBrainEditor.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 711aad28b4057bd4783120e26ff2ee25
+timeCreated: 1483406727
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineClearShotEditor.cs b/Assets/Cinemachine/Base/Editor/Editors/CinemachineClearShotEditor.cs
new file mode 100644
index 0000000..0068d16
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineClearShotEditor.cs
@@ -0,0 +1,211 @@
+using UnityEditor;
+using UnityEngine;
+using System.Collections.Generic;
+
+namespace Cinemachine.Editor
+{
+ [CustomEditor(typeof(CinemachineClearShot))]
+ internal sealed class CinemachineClearShotEditor
+ : CinemachineVirtualCameraBaseEditor<CinemachineClearShot>
+ {
+ EmbeddeAssetEditor<CinemachineBlenderSettings> m_BlendsEditor;
+ ColliderState m_ColliderState;
+
+ private UnityEditorInternal.ReorderableList mChildList;
+
+ protected override void OnEnable()
+ {
+ base.OnEnable();
+ m_BlendsEditor = new EmbeddeAssetEditor<CinemachineBlenderSettings>(
+ FieldPath(x => x.m_CustomBlends), this);
+ m_BlendsEditor.OnChanged = (CinemachineBlenderSettings b) =>
+ {
+ UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
+ };
+ m_BlendsEditor.OnCreateEditor = (UnityEditor.Editor ed) =>
+ {
+ CinemachineBlenderSettingsEditor editor = ed as CinemachineBlenderSettingsEditor;
+ if (editor != null)
+ editor.GetAllVirtualCameras = () => { return Target.ChildCameras; };
+ };
+ mChildList = null;
+ }
+
+ protected override void OnDisable()
+ {
+ base.OnDisable();
+ if (m_BlendsEditor != null)
+ m_BlendsEditor.OnDisable();
+ }
+
+ public override void OnInspectorGUI()
+ {
+ BeginInspector();
+ if (mChildList == null)
+ SetupChildList();
+
+ m_ColliderState = GetColliderState();
+ switch (m_ColliderState)
+ {
+ case ColliderState.ColliderOnParent:
+ case ColliderState.ColliderOnAllChildren:
+ break;
+ case ColliderState.NoCollider:
+ EditorGUILayout.HelpBox(
+ "ClearShot requires a Collider extension to rank the shots. Either add one to the ClearShot itself, or to each of the child cameras.",
+ MessageType.Warning);
+ break;
+ case ColliderState.ColliderOnSomeChildren:
+ EditorGUILayout.HelpBox(
+ "Some child cameras do not have a Collider extension. ClearShot requires a Collider on all the child cameras, or alternatively on the ClearShot iself.",
+ MessageType.Warning);
+ break;
+ case ColliderState.ColliderOnChildrenAndParent:
+ EditorGUILayout.HelpBox(
+ "There is a Collider extention on the ClearShot camera, and also on some of its child cameras. You can't have both.",
+ MessageType.Error);
+ break;
+ }
+
+ DrawHeaderInInspector();
+ DrawPropertyInInspector(FindProperty(x => x.m_Priority));
+ DrawTargetsInInspector(FindProperty(x => x.m_Follow), FindProperty(x => x.m_LookAt));
+ DrawRemainingPropertiesInInspector();
+
+ // Blends
+ m_BlendsEditor.DrawEditorCombo(
+ "Create New Blender Asset",
+ Target.gameObject.name + " Blends", "asset", string.Empty,
+ "Custom Blends", false);
+
+ // vcam children
+ EditorGUILayout.Separator();
+ EditorGUI.BeginChangeCheck();
+ mChildList.DoLayoutList();
+ if (EditorGUI.EndChangeCheck())
+ serializedObject.ApplyModifiedProperties();
+
+ // Extensions
+ DrawExtensionsWidgetInInspector();
+ }
+
+ enum ColliderState
+ {
+ NoCollider,
+ ColliderOnAllChildren,
+ ColliderOnSomeChildren,
+ ColliderOnParent,
+ ColliderOnChildrenAndParent
+ }
+
+ ColliderState GetColliderState()
+ {
+ int numChildren = 0;
+ int numColliderChildren = 0;
+ bool colliderOnParent = ObjectHasCollider(Target);
+
+ var children = Target.m_ChildCameras;
+ numChildren = children == null ? 0 : children.Length;
+ for (int i = 0; i < numChildren; ++i)
+ if (ObjectHasCollider(children[i]))
+ ++numColliderChildren;
+ if (colliderOnParent)
+ return (numColliderChildren > 0)
+ ? ColliderState.ColliderOnChildrenAndParent : ColliderState.ColliderOnParent;
+ if (numColliderChildren > 0)
+ return (numColliderChildren == numChildren)
+ ? ColliderState.ColliderOnAllChildren : ColliderState.ColliderOnSomeChildren;
+ return ColliderState.NoCollider;
+ }
+
+ bool ObjectHasCollider(object obj)
+ {
+ CinemachineVirtualCameraBase vcam = obj as CinemachineVirtualCameraBase;
+ var collider = (vcam == null) ? null : vcam.GetComponent<CinemachineCollider>();
+ return (collider != null && collider.enabled);
+ }
+
+ void SetupChildList()
+ {
+ float vSpace = 2;
+ float hSpace = 3;
+ float floatFieldWidth = EditorGUIUtility.singleLineHeight * 2.5f;
+
+ mChildList = new UnityEditorInternal.ReorderableList(
+ serializedObject, FindProperty(x => x.m_ChildCameras), true, true, true, true);
+
+ mChildList.drawHeaderCallback = (Rect rect) =>
+ {
+ EditorGUI.LabelField(rect, "Virtual Camera Children");
+ GUIContent priorityText = new GUIContent("Priority");
+ var textDimensions = GUI.skin.label.CalcSize(priorityText);
+ rect.x += rect.width - textDimensions.x;
+ rect.width = textDimensions.x;
+ EditorGUI.LabelField(rect, priorityText);
+ };
+ mChildList.drawElementCallback
+ = (Rect rect, int index, bool isActive, bool isFocused) =>
+ {
+ rect.y += vSpace;
+ rect.width -= floatFieldWidth + hSpace;
+ rect.height = EditorGUIUtility.singleLineHeight;
+ SerializedProperty element = mChildList.serializedProperty.GetArrayElementAtIndex(index);
+ if (m_ColliderState == ColliderState.ColliderOnSomeChildren
+ || m_ColliderState == ColliderState.ColliderOnChildrenAndParent)
+ {
+ bool hasCollider = ObjectHasCollider(element.objectReferenceValue);
+ if ((m_ColliderState == ColliderState.ColliderOnSomeChildren && !hasCollider)
+ || (m_ColliderState == ColliderState.ColliderOnChildrenAndParent && hasCollider))
+ {
+ float width = rect.width;
+ rect.width = rect.height;
+ GUIContent label = new GUIContent("");
+ label.image = EditorGUIUtility.IconContent("console.warnicon.sml").image;
+ EditorGUI.LabelField(rect, label);
+ width -= rect.width; rect.x += rect.width; rect.width = width;
+ }
+ }
+ EditorGUI.PropertyField(rect, element, GUIContent.none);
+
+ SerializedObject obj = new SerializedObject(element.objectReferenceValue);
+ rect.x += rect.width + hSpace; rect.width = floatFieldWidth;
+ SerializedProperty priorityProp = obj.FindProperty(() => Target.m_Priority);
+ float oldWidth = EditorGUIUtility.labelWidth;
+ EditorGUIUtility.labelWidth = hSpace * 2;
+ EditorGUI.PropertyField(rect, priorityProp, new GUIContent(" "));
+ EditorGUIUtility.labelWidth = oldWidth;
+ obj.ApplyModifiedProperties();
+ };
+ mChildList.onChangedCallback = (UnityEditorInternal.ReorderableList l) =>
+ {
+ if (l.index < 0 || l.index >= l.serializedProperty.arraySize)
+ return;
+ Object o = l.serializedProperty.GetArrayElementAtIndex(
+ l.index).objectReferenceValue;
+ CinemachineVirtualCameraBase vcam = (o != null)
+ ? (o as CinemachineVirtualCameraBase) : null;
+ if (vcam != null)
+ vcam.transform.SetSiblingIndex(l.index);
+ };
+ mChildList.onAddCallback = (UnityEditorInternal.ReorderableList l) =>
+ {
+ var index = l.serializedProperty.arraySize;
+ var vcam = CinemachineMenu.CreateDefaultVirtualCamera();
+ Undo.SetTransformParent(vcam.transform, Target.transform, "");
+ var collider = Undo.AddComponent<CinemachineCollider>(vcam.gameObject);
+ collider.m_AvoidObstacles = false;
+ Undo.RecordObject(collider, "create ClearShot child");
+ vcam.transform.SetSiblingIndex(index);
+ };
+ mChildList.onRemoveCallback = (UnityEditorInternal.ReorderableList l) =>
+ {
+ Object o = l.serializedProperty.GetArrayElementAtIndex(
+ l.index).objectReferenceValue;
+ CinemachineVirtualCameraBase vcam = (o != null)
+ ? (o as CinemachineVirtualCameraBase) : null;
+ if (vcam != null)
+ Undo.DestroyObjectImmediate(vcam.gameObject);
+ };
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineClearShotEditor.cs.meta b/Assets/Cinemachine/Base/Editor/Editors/CinemachineClearShotEditor.cs.meta
new file mode 100644
index 0000000..8cb1d9e
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineClearShotEditor.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 6036af5730313e54699c5a693891fe90
+timeCreated: 1484508430
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineColliderEditor.cs b/Assets/Cinemachine/Base/Editor/Editors/CinemachineColliderEditor.cs
new file mode 100644
index 0000000..074b153
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineColliderEditor.cs
@@ -0,0 +1,76 @@
+using UnityEngine;
+using UnityEditor;
+using System.Collections.Generic;
+
+namespace Cinemachine.Editor
+{
+ [CustomEditor(typeof(CinemachineCollider))]
+ public sealed class CinemachineColliderEditor : BaseEditor<CinemachineCollider>
+ {
+ protected override List<string> GetExcludedPropertiesInInspector()
+ {
+ List<string> excluded = base.GetExcludedPropertiesInInspector();
+ if (!Target.m_AvoidObstacles)
+ {
+ excluded.Add(FieldPath(x => x.m_DistanceLimit));
+ excluded.Add(FieldPath(x => x.m_CameraRadius));
+ excluded.Add(FieldPath(x => x.m_Strategy));
+ excluded.Add(FieldPath(x => x.m_MaximumEffort));
+ excluded.Add(FieldPath(x => x.m_Damping));
+ }
+ else if (Target.m_Strategy == CinemachineCollider.ResolutionStrategy.PullCameraForward)
+ {
+ excluded.Add(FieldPath(x => x.m_MaximumEffort));
+ }
+ return excluded;
+ }
+
+ public override void OnInspectorGUI()
+ {
+ BeginInspector();
+
+ if (Target.m_AvoidObstacles && !Target.VirtualCamera.State.HasLookAt)
+ EditorGUILayout.HelpBox(
+ "Preserve Line Of Sight requires a LookAt target.",
+ MessageType.Warning);
+
+ DrawRemainingPropertiesInInspector();
+ }
+
+ [DrawGizmo(GizmoType.Active | GizmoType.Selected, typeof(CinemachineCollider))]
+ private static void DrawColliderGizmos(CinemachineCollider collider, GizmoType type)
+ {
+ CinemachineVirtualCameraBase vcam = (collider != null) ? collider.VirtualCamera : null;
+ if (vcam != null && collider.enabled)
+ {
+ Color oldColor = Gizmos.color;
+ Vector3 pos = vcam.State.FinalPosition;
+ if (collider.m_AvoidObstacles && vcam.State.HasLookAt)
+ {
+ Gizmos.color = CinemachineColliderPrefs.FeelerColor;
+ if (collider.m_CameraRadius > 0)
+ Gizmos.DrawWireSphere(pos, collider.m_CameraRadius);
+
+ Vector3 forwardFeelerVector = (vcam.State.ReferenceLookAt - pos).normalized;
+ float distance = collider.m_DistanceLimit;
+ Gizmos.DrawLine(pos, pos + forwardFeelerVector * distance);
+
+ // Show the avoidance path, for debugging
+ List<List<Vector3>> debugPaths = collider.DebugPaths;
+ foreach (var path in debugPaths)
+ {
+ Gizmos.color = CinemachineColliderPrefs.FeelerHitColor;
+ Vector3 p0 = vcam.State.ReferenceLookAt;
+ foreach (var p in path)
+ {
+ Gizmos.DrawLine(p0, p);
+ p0 = p;
+ }
+ Gizmos.DrawLine(p0, pos);
+ }
+ }
+ Gizmos.color = oldColor;
+ }
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineColliderEditor.cs.meta b/Assets/Cinemachine/Base/Editor/Editors/CinemachineColliderEditor.cs.meta
new file mode 100644
index 0000000..56b31b8
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineColliderEditor.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: bf34fbe7a6e71634493d770ed0031f9d
+timeCreated: 1486652356
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineComposerEditor.cs b/Assets/Cinemachine/Base/Editor/Editors/CinemachineComposerEditor.cs
new file mode 100644
index 0000000..e0029b9
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineComposerEditor.cs
@@ -0,0 +1,89 @@
+using UnityEngine;
+using UnityEditor;
+using Cinemachine.Utility;
+
+namespace Cinemachine.Editor
+{
+ [CustomEditor(typeof(CinemachineComposer))]
+ internal class CinemachineComposerEditor : BaseEditor<CinemachineComposer>
+ {
+ CinemachineScreenComposerGuides mScreenGuideEditor;
+
+ protected virtual void OnEnable()
+ {
+ mScreenGuideEditor = new CinemachineScreenComposerGuides();
+ mScreenGuideEditor.GetHardGuide = () => { return Target.HardGuideRect; };
+ mScreenGuideEditor.GetSoftGuide = () => { return Target.SoftGuideRect; };
+ mScreenGuideEditor.SetHardGuide = (Rect r) => { Target.HardGuideRect = r; };
+ mScreenGuideEditor.SetSoftGuide = (Rect r) => { Target.SoftGuideRect = r; };
+ mScreenGuideEditor.Target = () => { return serializedObject; };
+
+ Target.OnGUICallback += OnGUI;
+ UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
+ }
+
+ protected virtual void OnDisable()
+ {
+ if (Target != null)
+ Target.OnGUICallback -= OnGUI;
+ UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
+ }
+
+ public override void OnInspectorGUI()
+ {
+ BeginInspector();
+ if (Target.LookAtTarget == null)
+ EditorGUILayout.HelpBox(
+ "A LookAt target is required. Change Aim to Do Nothing if you don't want a LookAt target.",
+ MessageType.Warning);
+
+ // First snapshot some settings
+ Rect oldHard = Target.HardGuideRect;
+ Rect oldSoft = Target.SoftGuideRect;
+
+ // Draw the properties
+ DrawRemainingPropertiesInInspector();
+ mScreenGuideEditor.SetNewBounds(oldHard, oldSoft, Target.HardGuideRect, Target.SoftGuideRect);
+ }
+
+ protected virtual void OnGUI()
+ {
+ // Draw the camera guides
+ if (!Target.IsValid || !CinemachineSettings.CinemachineCoreSettings.ShowInGameGuides)
+ return;
+
+ CinemachineBrain brain = CinemachineCore.Instance.FindPotentialTargetBrain(Target.VirtualCamera);
+ if (brain == null || brain.OutputCamera.activeTexture != null)
+ return;
+
+ bool isLive = CinemachineCore.Instance.IsLive(Target.VirtualCamera);
+
+ // Screen guides
+ mScreenGuideEditor.OnGUI_DrawGuides(isLive, brain.OutputCamera, Target.VcamState.Lens, true);
+
+ // Draw an on-screen gizmo for the target
+ if (Target.LookAtTarget != null && isLive)
+ {
+ Vector3 targetScreenPosition = brain.OutputCamera.WorldToScreenPoint(Target.TrackedPoint);
+ if (targetScreenPosition.z > 0)
+ {
+ targetScreenPosition.y = Screen.height - targetScreenPosition.y;
+
+ GUI.color = CinemachineSettings.ComposerSettings.TargetColour;
+ Rect r = new Rect(targetScreenPosition, Vector2.zero);
+ float size = (CinemachineSettings.ComposerSettings.TargetSize
+ + CinemachineScreenComposerGuides.kGuideBarWidthPx) / 2;
+ GUI.DrawTexture(r.Inflated(new Vector2(size, size)), Texture2D.whiteTexture);
+ size -= CinemachineScreenComposerGuides.kGuideBarWidthPx;
+ if (size > 0)
+ {
+ Vector4 overlayOpacityScalar
+ = new Vector4(1f, 1f, 1f, CinemachineSettings.ComposerSettings.OverlayOpacity);
+ GUI.color = Color.black * overlayOpacityScalar;
+ GUI.DrawTexture(r.Inflated(new Vector2(size, size)), Texture2D.whiteTexture);
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineComposerEditor.cs.meta b/Assets/Cinemachine/Base/Editor/Editors/CinemachineComposerEditor.cs.meta
new file mode 100644
index 0000000..d68d7f9
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineComposerEditor.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 2bb09c3bc24a82648a2e4fc008a28d8b
+timeCreated: 1484088329
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineConfinerEditor.cs b/Assets/Cinemachine/Base/Editor/Editors/CinemachineConfinerEditor.cs
new file mode 100644
index 0000000..8fac565
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineConfinerEditor.cs
@@ -0,0 +1,161 @@
+using UnityEngine;
+using UnityEditor;
+using System;
+using System.Collections.Generic;
+
+namespace Cinemachine.Editor
+{
+ [CustomEditor(typeof(CinemachineConfiner))]
+ public sealed class CinemachineConfinerEditor : BaseEditor<CinemachineConfiner>
+ {
+ protected override List<string> GetExcludedPropertiesInInspector()
+ {
+ List<string> excluded = base.GetExcludedPropertiesInInspector();
+ CinemachineBrain brain = CinemachineCore.Instance.FindPotentialTargetBrain(Target.VirtualCamera);
+ bool ortho = brain != null ? brain.OutputCamera.orthographic : false;
+ if (!ortho)
+ excluded.Add(FieldPath(x => x.m_ConfineScreenEdges));
+ if (Target.m_ConfineMode == CinemachineConfiner.Mode.Confine2D)
+ excluded.Add(FieldPath(x => x.m_BoundingVolume));
+ else
+ excluded.Add(FieldPath(x => x.m_BoundingShape2D));
+ return excluded;
+ }
+
+ public override void OnInspectorGUI()
+ {
+ BeginInspector();
+ if (Target.m_ConfineMode == CinemachineConfiner.Mode.Confine2D)
+ {
+ if (Target.m_BoundingShape2D == null)
+ EditorGUILayout.HelpBox("A Bounding Shape is required.", MessageType.Warning);
+ else if (Target.m_BoundingShape2D.GetType() != typeof(PolygonCollider2D)
+ && Target.m_BoundingShape2D.GetType() != typeof(CompositeCollider2D))
+ {
+ EditorGUILayout.HelpBox(
+ "Must be a PolygonCollider2D or CompositeCollider2D.",
+ MessageType.Warning);
+ }
+ else if (Target.m_BoundingShape2D.GetType() == typeof(CompositeCollider2D))
+ {
+ CompositeCollider2D poly = Target.m_BoundingShape2D as CompositeCollider2D;
+ if (poly.geometryType != CompositeCollider2D.GeometryType.Polygons)
+ {
+ EditorGUILayout.HelpBox(
+ "CompositeCollider2D geometry type must be Polygons",
+ MessageType.Warning);
+ }
+ }
+ }
+ else
+ {
+ if (Target.m_BoundingVolume == null)
+ EditorGUILayout.HelpBox("A Bounding Volume is required.", MessageType.Warning);
+ else if (Target.m_BoundingVolume.GetType() != typeof(BoxCollider)
+ && Target.m_BoundingVolume.GetType() != typeof(SphereCollider)
+ && Target.m_BoundingVolume.GetType() != typeof(CapsuleCollider))
+ {
+ EditorGUILayout.HelpBox(
+ "Must be a BoxCollider, SphereCollider, or CapsuleCollider.",
+ MessageType.Warning);
+ }
+ }
+ DrawRemainingPropertiesInInspector();
+ }
+
+ [DrawGizmo(GizmoType.Active | GizmoType.Selected, typeof(CinemachineConfiner))]
+ private static void DrawColliderGizmos(CinemachineConfiner confiner, GizmoType type)
+ {
+ CinemachineVirtualCameraBase vcam = (confiner != null) ? confiner.VirtualCamera : null;
+ if (vcam != null && confiner.IsValid)
+ {
+ Matrix4x4 oldMatrix = Gizmos.matrix;
+ Color oldColor = Gizmos.color;
+ Gizmos.color = Color.yellow;
+
+ if (confiner.m_ConfineMode == CinemachineConfiner.Mode.Confine3D)
+ {
+ Transform t = confiner.m_BoundingVolume.transform;
+ Gizmos.matrix = Matrix4x4.TRS(t.position, t.rotation, t.lossyScale);
+
+ Type colliderType = confiner.m_BoundingVolume.GetType();
+ if (colliderType == typeof(BoxCollider))
+ {
+ BoxCollider c = confiner.m_BoundingVolume as BoxCollider;
+ Gizmos.DrawWireCube(c.center, c.size);
+ }
+ else if (colliderType == typeof(SphereCollider))
+ {
+ SphereCollider c = confiner.m_BoundingVolume as SphereCollider;
+ Gizmos.DrawWireSphere(c.center, c.radius);
+ }
+ else if (colliderType == typeof(CapsuleCollider))
+ {
+ CapsuleCollider c = confiner.m_BoundingVolume as CapsuleCollider;
+ Vector3 size = Vector3.one * c.radius * 2;
+ switch (c.direction)
+ {
+ case 0: size.x = c.height; break;
+ case 1: size.y = c.height; break;
+ case 2: size.z = c.height; break;
+ }
+ Gizmos.DrawWireCube(c.center, size);
+ }
+ else if (colliderType == typeof(MeshCollider))
+ {
+ MeshCollider c = confiner.m_BoundingVolume as MeshCollider;
+ Gizmos.DrawWireMesh(c.sharedMesh);
+ }
+ else
+ {
+ // Just draw an AABB - not very nice!
+ Gizmos.matrix = oldMatrix;
+ Bounds bounds = confiner.m_BoundingVolume.bounds;
+ Gizmos.DrawWireCube(t.position, bounds.extents * 2);
+ }
+ }
+ else
+ {
+ Transform t = confiner.m_BoundingShape2D.transform;
+ Gizmos.matrix = Matrix4x4.TRS(t.position, t.rotation, t.lossyScale);
+
+ Type colliderType = confiner.m_BoundingShape2D.GetType();
+ if (colliderType == typeof(PolygonCollider2D))
+ {
+ PolygonCollider2D poly = confiner.m_BoundingShape2D as PolygonCollider2D;
+ for (int i = 0; i < poly.pathCount; ++i)
+ DrawPath(poly.GetPath(i), -1);
+ }
+ else if (colliderType == typeof(CompositeCollider2D))
+ {
+ CompositeCollider2D poly = confiner.m_BoundingShape2D as CompositeCollider2D;
+ Vector2[] path = new Vector2[poly.pointCount];
+ for (int i = 0; i < poly.pathCount; ++i)
+ {
+ int numPoints = poly.GetPath(i, path);
+ DrawPath(path, numPoints);
+ }
+ }
+ }
+ Gizmos.color = oldColor;
+ Gizmos.matrix = oldMatrix;
+ }
+ }
+
+ static void DrawPath(Vector2[] path, int numPoints)
+ {
+ if (numPoints < 0)
+ numPoints = path.Length;
+ if (numPoints > 0)
+ {
+ Vector2 v0 = path[numPoints-1];
+ for (int j = 0; j < numPoints; ++j)
+ {
+ Vector2 v = path[j];
+ Gizmos.DrawLine(v0, v);
+ v0 = v;
+ }
+ }
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineConfinerEditor.cs.meta b/Assets/Cinemachine/Base/Editor/Editors/CinemachineConfinerEditor.cs.meta
new file mode 100644
index 0000000..a25f82f
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineConfinerEditor.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 3f7c779802a73d5448e38af7c39fbaa5
+timeCreated: 1503423096
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineExternalCameraEditor.cs b/Assets/Cinemachine/Base/Editor/Editors/CinemachineExternalCameraEditor.cs
new file mode 100644
index 0000000..083badb
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineExternalCameraEditor.cs
@@ -0,0 +1,17 @@
+using System.Collections.Generic;
+using UnityEditor;
+
+namespace Cinemachine.Editor
+{
+ [CustomEditor(typeof(CinemachineExternalCamera))]
+ internal class CinemachineExternalCameraEditor
+ : CinemachineVirtualCameraBaseEditor<CinemachineExternalCamera>
+ {
+ protected override List<string> GetExcludedPropertiesInInspector()
+ {
+ List<string> excluded = base.GetExcludedPropertiesInInspector();
+ excluded.Add("Extensions");
+ return excluded;
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineExternalCameraEditor.cs.meta b/Assets/Cinemachine/Base/Editor/Editors/CinemachineExternalCameraEditor.cs.meta
new file mode 100644
index 0000000..0d0d6f6
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineExternalCameraEditor.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 3226d9f88577be74197693bd17cff8c3
+timeCreated: 1506455627
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineFramingTransposerEditor.cs b/Assets/Cinemachine/Base/Editor/Editors/CinemachineFramingTransposerEditor.cs
new file mode 100644
index 0000000..8f635dd
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineFramingTransposerEditor.cs
@@ -0,0 +1,174 @@
+using UnityEngine;
+using UnityEditor;
+using Cinemachine.Utility;
+using System.Collections.Generic;
+
+namespace Cinemachine.Editor
+{
+ [CustomEditor(typeof(CinemachineFramingTransposer))]
+ internal class CinemachineFramingTransposerEditor : BaseEditor<CinemachineFramingTransposer>
+ {
+ CinemachineScreenComposerGuides mScreenGuideEditor;
+
+ protected override List<string> GetExcludedPropertiesInInspector()
+ {
+ List<string> excluded = base.GetExcludedPropertiesInInspector();
+ if (Target.m_UnlimitedSoftZone)
+ {
+ excluded.Add(FieldPath(x => x.m_SoftZoneWidth));
+ excluded.Add(FieldPath(x => x.m_SoftZoneHeight));
+ excluded.Add(FieldPath(x => x.m_BiasX));
+ excluded.Add(FieldPath(x => x.m_BiasY));
+ }
+ CinemachineTargetGroup group = Target.TargetGroup;
+ if (group == null || Target.m_GroupFramingMode == CinemachineFramingTransposer.FramingMode.None)
+ {
+ excluded.Add(FieldPath(x => x.m_GroupFramingSize));
+ excluded.Add(FieldPath(x => x.m_AdjustmentMode));
+ excluded.Add(FieldPath(x => x.m_MaxDollyIn));
+ excluded.Add(FieldPath(x => x.m_MaxDollyOut));
+ excluded.Add(FieldPath(x => x.m_MinimumDistance));
+ excluded.Add(FieldPath(x => x.m_MaximumDistance));
+ excluded.Add(FieldPath(x => x.m_MinimumFOV));
+ excluded.Add(FieldPath(x => x.m_MaximumFOV));
+ excluded.Add(FieldPath(x => x.m_MinimumOrthoSize));
+ excluded.Add(FieldPath(x => x.m_MaximumOrthoSize));
+ if (group == null)
+ excluded.Add(FieldPath(x => x.m_GroupFramingMode));
+ }
+ else
+ {
+ CinemachineBrain brain = CinemachineCore.Instance.FindPotentialTargetBrain(Target.VirtualCamera);
+ bool ortho = brain != null ? brain.OutputCamera.orthographic : false;
+ if (ortho)
+ {
+ excluded.Add(FieldPath(x => x.m_AdjustmentMode));
+ excluded.Add(FieldPath(x => x.m_MaxDollyIn));
+ excluded.Add(FieldPath(x => x.m_MaxDollyOut));
+ excluded.Add(FieldPath(x => x.m_MinimumDistance));
+ excluded.Add(FieldPath(x => x.m_MaximumDistance));
+ excluded.Add(FieldPath(x => x.m_MinimumFOV));
+ excluded.Add(FieldPath(x => x.m_MaximumFOV));
+ }
+ else
+ {
+ excluded.Add(FieldPath(x => x.m_MinimumOrthoSize));
+ excluded.Add(FieldPath(x => x.m_MaximumOrthoSize));
+ switch (Target.m_AdjustmentMode)
+ {
+ case CinemachineFramingTransposer.AdjustmentMode.DollyOnly:
+ excluded.Add(FieldPath(x => x.m_MinimumFOV));
+ excluded.Add(FieldPath(x => x.m_MaximumFOV));
+ break;
+ case CinemachineFramingTransposer.AdjustmentMode.ZoomOnly:
+ excluded.Add(FieldPath(x => x.m_MaxDollyIn));
+ excluded.Add(FieldPath(x => x.m_MaxDollyOut));
+ excluded.Add(FieldPath(x => x.m_MinimumDistance));
+ excluded.Add(FieldPath(x => x.m_MaximumDistance));
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ return excluded;
+ }
+
+ protected virtual void OnEnable()
+ {
+ mScreenGuideEditor = new CinemachineScreenComposerGuides();
+ mScreenGuideEditor.GetHardGuide = () => { return Target.HardGuideRect; };
+ mScreenGuideEditor.GetSoftGuide = () => { return Target.SoftGuideRect; };
+ mScreenGuideEditor.SetHardGuide = (Rect r) => { Target.HardGuideRect = r; };
+ mScreenGuideEditor.SetSoftGuide = (Rect r) => { Target.SoftGuideRect = r; };
+ mScreenGuideEditor.Target = () => { return serializedObject; };
+
+ Target.OnGUICallback += OnGUI;
+ UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
+ }
+
+ protected virtual void OnDisable()
+ {
+ if (Target != null)
+ Target.OnGUICallback -= OnGUI;
+ UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
+ }
+
+ public override void OnInspectorGUI()
+ {
+ BeginInspector();
+ if (Target.FollowTarget == null)
+ EditorGUILayout.HelpBox(
+ "Framing Transposer requires a Follow target. Change Body to Do Nothing if you don't want a Follow target.",
+ MessageType.Warning);
+ if (Target.LookAtTarget != null)
+ EditorGUILayout.HelpBox(
+ "The LookAt target must be null. The Follow target will be used in place of the LookAt target.",
+ MessageType.Warning);
+
+ // First snapshot some settings
+ Rect oldHard = Target.HardGuideRect;
+ Rect oldSoft = Target.SoftGuideRect;
+
+ // Draw the properties
+ DrawRemainingPropertiesInInspector();
+ mScreenGuideEditor.SetNewBounds(oldHard, oldSoft, Target.HardGuideRect, Target.SoftGuideRect);
+ }
+
+ protected virtual void OnGUI()
+ {
+ // Draw the camera guides
+ if (!Target.IsValid || !CinemachineSettings.CinemachineCoreSettings.ShowInGameGuides)
+ return;
+
+ CinemachineBrain brain = CinemachineCore.Instance.FindPotentialTargetBrain(Target.VirtualCamera);
+ if (brain == null || brain.OutputCamera.activeTexture != null)
+ return;
+
+ bool isLive = CinemachineCore.Instance.IsLive(Target.VirtualCamera);
+
+ // Screen guides
+ mScreenGuideEditor.OnGUI_DrawGuides(isLive, brain.OutputCamera, Target.VcamState.Lens, !Target.m_UnlimitedSoftZone);
+
+ // Draw an on-screen gizmo for the target
+ if (Target.FollowTarget != null && isLive)
+ {
+ Vector3 targetScreenPosition = brain.OutputCamera.WorldToScreenPoint(Target.TrackedPoint);
+ if (targetScreenPosition.z > 0)
+ {
+ targetScreenPosition.y = Screen.height - targetScreenPosition.y;
+
+ GUI.color = CinemachineSettings.ComposerSettings.TargetColour;
+ Rect r = new Rect(targetScreenPosition, Vector2.zero);
+ float size = (CinemachineSettings.ComposerSettings.TargetSize
+ + CinemachineScreenComposerGuides.kGuideBarWidthPx) / 2;
+ GUI.DrawTexture(r.Inflated(new Vector2(size, size)), Texture2D.whiteTexture);
+ size -= CinemachineScreenComposerGuides.kGuideBarWidthPx;
+ if (size > 0)
+ {
+ Vector4 overlayOpacityScalar
+ = new Vector4(1f, 1f, 1f, CinemachineSettings.ComposerSettings.OverlayOpacity);
+ GUI.color = Color.black * overlayOpacityScalar;
+ GUI.DrawTexture(r.Inflated(new Vector2(size, size)), Texture2D.whiteTexture);
+ }
+ }
+ }
+ }
+
+ [DrawGizmo(GizmoType.Active | GizmoType.InSelectionHierarchy, typeof(CinemachineFramingTransposer))]
+ private static void DrawGroupComposerGizmos(CinemachineFramingTransposer target, GizmoType selectionType)
+ {
+ // Show the group bounding box, as viewed from the camera position
+ CinemachineTargetGroup group = target.TargetGroup;
+ if (group != null)
+ {
+ Matrix4x4 m = Gizmos.matrix;
+ Bounds b = target.m_LastBounds;
+ Gizmos.matrix = target.m_lastBoundsMatrix;
+ Gizmos.color = Color.yellow;
+ Gizmos.DrawWireCube(b.center, b.size);
+ Gizmos.matrix = m;
+ }
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineFramingTransposerEditor.cs.meta b/Assets/Cinemachine/Base/Editor/Editors/CinemachineFramingTransposerEditor.cs.meta
new file mode 100644
index 0000000..d843e03
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineFramingTransposerEditor.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 620aee1bd928b2a4981896c6b4e1bf0d
+timeCreated: 1502046367
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineFreeLookEditor.cs b/Assets/Cinemachine/Base/Editor/Editors/CinemachineFreeLookEditor.cs
new file mode 100644
index 0000000..bb9f6d4
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineFreeLookEditor.cs
@@ -0,0 +1,206 @@
+using UnityEngine;
+using UnityEditor;
+using Cinemachine.Editor;
+using System.Collections.Generic;
+using Cinemachine.Utility;
+
+namespace Cinemachine
+{
+ [CustomEditor(typeof(CinemachineFreeLook))]
+ internal sealed class CinemachineFreeLookEditor
+ : CinemachineVirtualCameraBaseEditor<CinemachineFreeLook>
+ {
+ protected override List<string> GetExcludedPropertiesInInspector()
+ {
+ List<string> excluded = base.GetExcludedPropertiesInInspector();
+ excluded.Add(FieldPath(x => x.m_Orbits));
+ if (!Target.m_CommonLens)
+ excluded.Add(FieldPath(x => x.m_Lens));
+ if (Target.m_BindingMode == CinemachineTransposer.BindingMode.SimpleFollowWithWorldUp)
+ {
+ excluded.Add(FieldPath(x => x.m_Heading));
+ excluded.Add(FieldPath(x => x.m_RecenterToTargetHeading));
+ }
+ return excluded;
+ }
+
+ protected override void OnDisable()
+ {
+ base.OnDisable();
+
+ // Must destroy child editors or we get exceptions
+ if (m_editors != null)
+ foreach (UnityEditor.Editor e in m_editors)
+ if (e != null)
+ UnityEngine.Object.DestroyImmediate(e);
+ }
+
+ public override void OnInspectorGUI()
+ {
+ // Ordinary properties
+ BeginInspector();
+ DrawHeaderInInspector();
+ DrawPropertyInInspector(FindProperty(x => x.m_Priority));
+ DrawTargetsInInspector(FindProperty(x => x.m_Follow), FindProperty(x => x.m_LookAt));
+ DrawRemainingPropertiesInInspector();
+
+ // Orbits
+ EditorGUI.BeginChangeCheck();
+ SerializedProperty orbits = FindProperty(x => x.m_Orbits);
+ for (int i = 0; i < CinemachineFreeLook.RigNames.Length; ++i)
+ {
+ float hSpace = 3;
+ SerializedProperty orbit = orbits.GetArrayElementAtIndex(i);
+ Rect rect = EditorGUILayout.GetControlRect(true);
+ rect = EditorGUI.PrefixLabel(rect, new GUIContent(CinemachineFreeLook.RigNames[i]));
+ rect.height = EditorGUIUtility.singleLineHeight;
+ rect.width = rect.width / 2 - hSpace;
+
+ float oldWidth = EditorGUIUtility.labelWidth;
+ EditorGUIUtility.labelWidth = rect.width / 2;
+ SerializedProperty heightProp = orbit.FindPropertyRelative(() => Target.m_Orbits[i].m_Height);
+ EditorGUI.PropertyField(rect, heightProp, new GUIContent("Height"));
+ rect.x += rect.width + hSpace;
+ SerializedProperty radiusProp = orbit.FindPropertyRelative(() => Target.m_Orbits[i].m_Radius);
+ EditorGUI.PropertyField(rect, radiusProp, new GUIContent("Radius"));
+ EditorGUIUtility.labelWidth = oldWidth;
+ }
+ if (EditorGUI.EndChangeCheck())
+ serializedObject.ApplyModifiedProperties();
+
+ // Rigs
+ UpdateRigEditors();
+ for (int i = 0; i < m_editors.Length; ++i)
+ {
+ if (m_editors[i] == null)
+ continue;
+ EditorGUILayout.Separator();
+ EditorGUILayout.BeginVertical(GUI.skin.box);
+ EditorGUILayout.LabelField(RigNames[i], EditorStyles.boldLabel);
+ ++EditorGUI.indentLevel;
+ m_editors[i].OnInspectorGUI();
+ --EditorGUI.indentLevel;
+ EditorGUILayout.EndVertical();
+ }
+
+ // Extensions
+ DrawExtensionsWidgetInInspector();
+ }
+
+ string[] RigNames;
+ CinemachineVirtualCameraBase[] m_rigs;
+ UnityEditor.Editor[] m_editors;
+ void UpdateRigEditors()
+ {
+ RigNames = CinemachineFreeLook.RigNames;
+ if (m_rigs == null)
+ m_rigs = new CinemachineVirtualCameraBase[RigNames.Length];
+ if (m_editors == null)
+ m_editors = new UnityEditor.Editor[RigNames.Length];
+ for (int i = 0; i < RigNames.Length; ++i)
+ {
+ CinemachineVirtualCamera rig = Target.GetRig(i);
+ if (rig == null || rig != m_rigs[i])
+ {
+ m_rigs[i] = rig;
+ if (m_editors[i] != null)
+ UnityEngine.Object.DestroyImmediate(m_editors[i]);
+ m_editors[i] = null;
+ if (rig != null)
+ CreateCachedEditor(rig, null, ref m_editors[i]);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Register with CinemachineFreeLook to create the pipeline in an undo-friendly manner
+ /// </summary>
+ [InitializeOnLoad]
+ class CreateRigWithUndo
+ {
+ static CreateRigWithUndo()
+ {
+ CinemachineFreeLook.CreateRigOverride
+ = (CinemachineFreeLook vcam, string name, CinemachineVirtualCamera copyFrom) =>
+ {
+ // Create a new rig with default components
+ GameObject go = new GameObject(name);
+ Undo.RegisterCreatedObjectUndo(go, "created rig");
+ Undo.SetTransformParent(go.transform, vcam.transform, "parenting rig");
+ CinemachineVirtualCamera rig = Undo.AddComponent<CinemachineVirtualCamera>(go);
+ Undo.RecordObject(rig, "creating rig");
+ if (copyFrom != null)
+ ReflectionHelpers.CopyFields(copyFrom, rig);
+ else
+ {
+ go = rig.GetComponentOwner().gameObject;
+ Undo.RecordObject(Undo.AddComponent<CinemachineOrbitalTransposer>(go), "creating rig");
+ Undo.RecordObject(Undo.AddComponent<CinemachineComposer>(go), "creating rig");
+ }
+ return rig;
+ };
+ CinemachineFreeLook.DestroyRigOverride = (GameObject rig) =>
+ {
+ Undo.DestroyObjectImmediate(rig);
+ };
+ }
+ }
+
+ [DrawGizmo(GizmoType.Active | GizmoType.Selected, typeof(CinemachineFreeLook))]
+ private static void DrawFreeLookGizmos(CinemachineFreeLook vcam, GizmoType selectionType)
+ {
+ // Standard frustum and logo
+ CinemachineBrainEditor.DrawVirtualCameraBaseGizmos(vcam, selectionType);
+
+ Color originalGizmoColour = Gizmos.color;
+ bool isActiveVirtualCam = CinemachineCore.Instance.IsLive(vcam);
+ Gizmos.color = isActiveVirtualCam
+ ? CinemachineSettings.CinemachineCoreSettings.ActiveGizmoColour
+ : CinemachineSettings.CinemachineCoreSettings.InactiveGizmoColour;
+
+ if (vcam.Follow != null)
+ {
+ Vector3 pos = vcam.Follow.position;
+ Vector3 up = Vector3.up;
+ CinemachineBrain brain = CinemachineCore.Instance.FindPotentialTargetBrain(vcam);
+ if (brain != null)
+ up = brain.DefaultWorldUp;
+
+ var MiddleRig = vcam.GetRig(1).GetCinemachineComponent<CinemachineOrbitalTransposer>();
+ Quaternion orient = MiddleRig.GetReferenceOrientation(up);
+ up = orient * Vector3.up;
+ float rotation = vcam.m_XAxis.Value + vcam.m_Heading.m_HeadingBias;
+ orient = Quaternion.AngleAxis(rotation, up) * orient;
+
+ CinemachineOrbitalTransposerEditor.DrawCircleAtPointWithRadius(
+ pos + up * vcam.m_Orbits[0].m_Height, orient, vcam.m_Orbits[0].m_Radius);
+ CinemachineOrbitalTransposerEditor.DrawCircleAtPointWithRadius(
+ pos + up * vcam.m_Orbits[1].m_Height, orient, vcam.m_Orbits[1].m_Radius);
+ CinemachineOrbitalTransposerEditor.DrawCircleAtPointWithRadius(
+ pos + up * vcam.m_Orbits[2].m_Height, orient, vcam.m_Orbits[2].m_Radius);
+
+ DrawCameraPath(pos, orient, vcam);
+ }
+
+ Gizmos.color = originalGizmoColour;
+ }
+
+ private static void DrawCameraPath(Vector3 atPos, Quaternion orient, CinemachineFreeLook vcam)
+ {
+ Matrix4x4 prevMatrix = Gizmos.matrix;
+ Gizmos.matrix = Matrix4x4.TRS(atPos, orient, Vector3.one);
+
+ const int kNumStepsPerPair = 30;
+ Vector3 currPos = vcam.GetLocalPositionForCameraFromInput(0f);
+ for (int i = 1; i < kNumStepsPerPair + 1; ++i)
+ {
+ float t = (float)i / (float)kNumStepsPerPair;
+ Vector3 nextPos = vcam.GetLocalPositionForCameraFromInput(t);
+ Gizmos.DrawLine(currPos, nextPos);
+ Gizmos.DrawWireSphere(nextPos, 0.02f);
+ currPos = nextPos;
+ }
+ Gizmos.matrix = prevMatrix;
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineFreeLookEditor.cs.meta b/Assets/Cinemachine/Base/Editor/Editors/CinemachineFreeLookEditor.cs.meta
new file mode 100644
index 0000000..ba3f0f1
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineFreeLookEditor.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 04e6f1d86089cda409e925cd975436d9
+timeCreated: 1485281953
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineGroupComposerEditor.cs b/Assets/Cinemachine/Base/Editor/Editors/CinemachineGroupComposerEditor.cs
new file mode 100644
index 0000000..42f551b
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineGroupComposerEditor.cs
@@ -0,0 +1,83 @@
+using System;
+using System.Collections.Generic;
+using System.Linq.Expressions;
+using UnityEditor;
+using UnityEngine;
+using Cinemachine.Utility;
+
+namespace Cinemachine.Editor
+{
+ [CustomEditor(typeof(CinemachineGroupComposer))]
+ internal class CinemachineGroupComposerEditor : CinemachineComposerEditor
+ {
+ // Specialization
+ private CinemachineGroupComposer MyTarget { get { return target as CinemachineGroupComposer; } }
+ protected string FieldPath<TValue>(Expression<Func<CinemachineGroupComposer, TValue>> expr)
+ {
+ return ReflectionHelpers.GetFieldPath(expr);
+ }
+
+ protected override List<string> GetExcludedPropertiesInInspector()
+ {
+ List<string> excluded = base.GetExcludedPropertiesInInspector();
+ CinemachineBrain brain = CinemachineCore.Instance.FindPotentialTargetBrain(MyTarget.VirtualCamera);
+ bool ortho = brain != null ? brain.OutputCamera.orthographic : false;
+ if (ortho)
+ {
+ excluded.Add(FieldPath(x => x.m_AdjustmentMode));
+ excluded.Add(FieldPath(x => x.m_MinimumFOV));
+ excluded.Add(FieldPath(x => x.m_MaximumFOV));
+ excluded.Add(FieldPath(x => x.m_MaxDollyIn));
+ excluded.Add(FieldPath(x => x.m_MaxDollyOut));
+ excluded.Add(FieldPath(x => x.m_MinimumDistance));
+ excluded.Add(FieldPath(x => x.m_MaximumDistance));
+ }
+ else
+ {
+ excluded.Add(FieldPath(x => x.m_MinimumOrthoSize));
+ excluded.Add(FieldPath(x => x.m_MaximumOrthoSize));
+ switch (MyTarget.m_AdjustmentMode)
+ {
+ case CinemachineGroupComposer.AdjustmentMode.DollyOnly:
+ excluded.Add(FieldPath(x => x.m_MinimumFOV));
+ excluded.Add(FieldPath(x => x.m_MaximumFOV));
+ break;
+ case CinemachineGroupComposer.AdjustmentMode.ZoomOnly:
+ excluded.Add(FieldPath(x => x.m_MaxDollyIn));
+ excluded.Add(FieldPath(x => x.m_MaxDollyOut));
+ excluded.Add(FieldPath(x => x.m_MinimumDistance));
+ excluded.Add(FieldPath(x => x.m_MaximumDistance));
+ break;
+ default:
+ break;
+ }
+ }
+ return excluded;
+ }
+
+ public override void OnInspectorGUI()
+ {
+ if (MyTarget.IsValid && MyTarget.TargetGroup == null)
+ EditorGUILayout.HelpBox(
+ "The Framing settings will be ignored because the LookAt target is not a kind of CinemachineTargetGroup",
+ MessageType.Info);
+
+ base.OnInspectorGUI();
+ }
+
+ [DrawGizmo(GizmoType.Active | GizmoType.InSelectionHierarchy, typeof(CinemachineGroupComposer))]
+ private static void DrawGroupComposerGizmos(CinemachineGroupComposer target, GizmoType selectionType)
+ {
+ // Show the group bounding box, as viewed from the camera position
+ if (target.TargetGroup != null)
+ {
+ Matrix4x4 m = Gizmos.matrix;
+ Bounds b = target.m_LastBounds;
+ Gizmos.matrix = target.m_lastBoundsMatrix;
+ Gizmos.color = Color.yellow;
+ Gizmos.DrawWireCube(b.center, b.size);
+ Gizmos.matrix = m;
+ }
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineGroupComposerEditor.cs.meta b/Assets/Cinemachine/Base/Editor/Editors/CinemachineGroupComposerEditor.cs.meta
new file mode 100644
index 0000000..e47e9ac
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineGroupComposerEditor.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: c5da6ce9225f948438f7d6a072499ecd
+timeCreated: 1496702989
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineHardLockToTargetEditor.cs b/Assets/Cinemachine/Base/Editor/Editors/CinemachineHardLockToTargetEditor.cs
new file mode 100644
index 0000000..d80c828
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineHardLockToTargetEditor.cs
@@ -0,0 +1,23 @@
+using UnityEditor;
+using UnityEngine;
+
+namespace Cinemachine.Editor
+{
+ [CustomEditor(typeof(CinemachineHardLockToTarget))]
+ public sealed class CinemachineHardLockToTargetEditor : BaseEditor<CinemachineHardLockToTarget>
+ {
+ public override void OnInspectorGUI()
+ {
+ BeginInspector();
+ if (Target.FollowTarget == null)
+ EditorGUILayout.HelpBox(
+ "Hard Lock requires a Follow Target. Change Body to Do Nothing if you don't want a Follow target.",
+ MessageType.Warning);
+ EditorGUI.BeginChangeCheck();
+ GUI.enabled = false;
+ EditorGUILayout.LabelField(" ", "Hard Lock has no settings", EditorStyles.miniLabel);
+ GUI.enabled = true;
+ DrawRemainingPropertiesInInspector();
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineHardLockToTargetEditor.cs.meta b/Assets/Cinemachine/Base/Editor/Editors/CinemachineHardLockToTargetEditor.cs.meta
new file mode 100644
index 0000000..4a383aa
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineHardLockToTargetEditor.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: e44b92e217bfdf24d99acb4344918eeb
+timeCreated: 1506541599
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineHardLookAtEditor.cs b/Assets/Cinemachine/Base/Editor/Editors/CinemachineHardLookAtEditor.cs
new file mode 100644
index 0000000..c3c1df8
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineHardLookAtEditor.cs
@@ -0,0 +1,23 @@
+using UnityEditor;
+using UnityEngine;
+
+namespace Cinemachine.Editor
+{
+ [CustomEditor(typeof(CinemachineHardLookAt))]
+ public sealed class CinemachineHardLookAtEditor : BaseEditor<CinemachineHardLookAt>
+ {
+ public override void OnInspectorGUI()
+ {
+ BeginInspector();
+ if (Target.LookAtTarget == null)
+ EditorGUILayout.HelpBox(
+ "Hard Look At requires a LookAt target. Change Aim to Do Nothing if you don't want a LookAt target.",
+ MessageType.Warning);
+ EditorGUI.BeginChangeCheck();
+ GUI.enabled = false;
+ EditorGUILayout.LabelField(" ", "Hard Look At has no settings", EditorStyles.miniLabel);
+ GUI.enabled = true;
+ DrawRemainingPropertiesInInspector();
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineHardLookAtEditor.cs.meta b/Assets/Cinemachine/Base/Editor/Editors/CinemachineHardLookAtEditor.cs.meta
new file mode 100644
index 0000000..1794560
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineHardLookAtEditor.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 9ce16cd7e31794b48b2843381cd87d31
+timeCreated: 1506541599
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineMixingCameraEditor.cs b/Assets/Cinemachine/Base/Editor/Editors/CinemachineMixingCameraEditor.cs
new file mode 100644
index 0000000..0f99c95
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineMixingCameraEditor.cs
@@ -0,0 +1,104 @@
+using UnityEditor;
+using UnityEngine;
+using Cinemachine.Utility;
+using System.Collections.Generic;
+
+namespace Cinemachine.Editor
+{
+ [CustomEditor(typeof(CinemachineMixingCamera))]
+ internal sealed class CinemachineMixingCameraEditor
+ : CinemachineVirtualCameraBaseEditor<CinemachineMixingCamera>
+ {
+ protected override List<string> GetExcludedPropertiesInInspector()
+ {
+ List<string> excluded = base.GetExcludedPropertiesInInspector();
+ for (int i = 0; i < CinemachineMixingCamera.MaxCameras; ++i)
+ excluded.Add(WeightPropertyName(i));
+ return excluded;
+ }
+
+ static string WeightPropertyName(int i) { return "m_Weight" + i; }
+
+ public override void OnInspectorGUI()
+ {
+ BeginInspector();
+ DrawHeaderInInspector();
+ DrawRemainingPropertiesInInspector();
+
+ float totalWeight = 0;
+ CinemachineVirtualCameraBase[] children = Target.ChildCameras;
+ int numCameras = Mathf.Min(CinemachineMixingCamera.MaxCameras, children.Length);
+ for (int i = 0; i < numCameras; ++i)
+ if (children[i].isActiveAndEnabled)
+ totalWeight += Target.GetWeight(i);
+
+ if (numCameras == 0)
+ EditorGUILayout.HelpBox("There are no Virtual Camera children", MessageType.Warning);
+ else
+ {
+ EditorGUILayout.Separator();
+ EditorGUILayout.LabelField("Child Camera Weights", EditorStyles.boldLabel);
+ for (int i = 0; i < numCameras; ++i)
+ {
+ SerializedProperty prop = serializedObject.FindProperty(WeightPropertyName(i));
+ if (prop != null)
+ EditorGUILayout.PropertyField(prop, new GUIContent(children[i].Name));
+ }
+ serializedObject.ApplyModifiedProperties();
+
+ if (totalWeight <= UnityVectorExtensions.Epsilon)
+ EditorGUILayout.HelpBox("No input channels are active", MessageType.Warning);
+
+ if (children.Length > numCameras)
+ EditorGUILayout.HelpBox(
+ "There are " + children.Length
+ + " child cameras. A maximum of " + numCameras + " is supported.",
+ MessageType.Warning);
+
+ // Camera proportion indicator
+ EditorGUILayout.Separator();
+ EditorGUILayout.LabelField("Mix Result", EditorStyles.boldLabel);
+ DrawProportionIndicator(children, numCameras, totalWeight);
+ }
+
+ // Extensions
+ DrawExtensionsWidgetInInspector();
+ }
+
+ void DrawProportionIndicator(
+ CinemachineVirtualCameraBase[] children, int numCameras, float totalWeight)
+ {
+ GUIStyle style = EditorStyles.centeredGreyMiniLabel;
+ Color bkg = new Color(0.27f, 0.27f, 0.27f); // ack! no better way than this?
+ Color fg = Color.Lerp(CinemachineBrain.GetSoloGUIColor(), bkg, 0.8f);
+ float totalHeight = (style.lineHeight + style.margin.vertical) * numCameras;
+ Rect r = EditorGUILayout.GetControlRect(true, totalHeight);
+ r.height /= numCameras; r.height -= 1;
+ float fullWidth = r.width;
+ for (int i = 0; i < numCameras; ++i)
+ {
+ float p = 0;
+ string label = children[i].Name;
+ if (totalWeight > UnityVectorExtensions.Epsilon)
+ {
+ if (children[i].isActiveAndEnabled)
+ p = Target.GetWeight(i) / totalWeight;
+ else
+ label += " (disabled)";
+ }
+ r.width = fullWidth * p;
+ EditorGUI.DrawRect(r, fg);
+
+ Rect r2 = r;
+ r2.x += r.width;
+ r2.width = fullWidth - r.width;
+ EditorGUI.DrawRect(r2, bkg);
+
+ r.width = fullWidth;
+ EditorGUI.LabelField(r, label, style);
+
+ r.y += r.height + 1;
+ }
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineMixingCameraEditor.cs.meta b/Assets/Cinemachine/Base/Editor/Editors/CinemachineMixingCameraEditor.cs.meta
new file mode 100644
index 0000000..1d7c354
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineMixingCameraEditor.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 8ad60cb17f7694c43a8190c617281753
+timeCreated: 1502201539
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineOrbitalTransposerEditor.cs b/Assets/Cinemachine/Base/Editor/Editors/CinemachineOrbitalTransposerEditor.cs
new file mode 100644
index 0000000..0064730
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineOrbitalTransposerEditor.cs
@@ -0,0 +1,103 @@
+using UnityEngine;
+using UnityEditor;
+using System.Collections.Generic;
+
+namespace Cinemachine.Editor
+{
+ [CustomEditor(typeof(CinemachineOrbitalTransposer))]
+ internal class CinemachineOrbitalTransposerEditor : BaseEditor<CinemachineOrbitalTransposer>
+ {
+ protected override List<string> GetExcludedPropertiesInInspector()
+ {
+ List<string> excluded = base.GetExcludedPropertiesInInspector();
+ if (Target.m_HeadingIsSlave)
+ {
+ excluded.Add(FieldPath(x => x.m_FollowOffset));
+ excluded.Add(FieldPath(x => x.m_BindingMode));
+ excluded.Add(FieldPath(x => x.m_Heading));
+ excluded.Add(FieldPath(x => x.m_XAxis));
+ excluded.Add(FieldPath(x => x.m_RecenterToTargetHeading));
+ }
+ switch (Target.m_BindingMode)
+ {
+ default:
+ case CinemachineTransposer.BindingMode.LockToTarget:
+ break;
+ case CinemachineTransposer.BindingMode.LockToTargetNoRoll:
+ excluded.Add(FieldPath(x => x.m_RollDamping));
+ break;
+ case CinemachineTransposer.BindingMode.LockToTargetWithWorldUp:
+ excluded.Add(FieldPath(x => x.m_PitchDamping));
+ excluded.Add(FieldPath(x => x.m_RollDamping));
+ break;
+ case CinemachineTransposer.BindingMode.LockToTargetOnAssign:
+ case CinemachineTransposer.BindingMode.WorldSpace:
+ excluded.Add(FieldPath(x => x.m_PitchDamping));
+ excluded.Add(FieldPath(x => x.m_YawDamping));
+ excluded.Add(FieldPath(x => x.m_RollDamping));
+ break;
+ case CinemachineTransposer.BindingMode.SimpleFollowWithWorldUp:
+ excluded.Add(FieldPath(x => x.m_XDamping));
+ excluded.Add(FieldPath(x => x.m_PitchDamping));
+ excluded.Add(FieldPath(x => x.m_YawDamping));
+ excluded.Add(FieldPath(x => x.m_RollDamping));
+ excluded.Add(FieldPath(x => x.m_Heading));
+ excluded.Add(FieldPath(x => x.m_RecenterToTargetHeading));
+ break;
+ }
+ return excluded;
+ }
+
+ public override void OnInspectorGUI()
+ {
+ BeginInspector();
+ if (Target.FollowTarget == null)
+ EditorGUILayout.HelpBox(
+ "Orbital Transposer requires a Follow target.",
+ MessageType.Warning);
+ DrawRemainingPropertiesInInspector();
+ }
+
+ [DrawGizmo(GizmoType.Active | GizmoType.Selected, typeof(CinemachineOrbitalTransposer))]
+ static void DrawTransposerGizmos(CinemachineOrbitalTransposer target, GizmoType selectionType)
+ {
+ if (target.IsValid)
+ {
+ Color originalGizmoColour = Gizmos.color;
+ Gizmos.color = CinemachineCore.Instance.IsLive(target.VirtualCamera)
+ ? CinemachineSettings.CinemachineCoreSettings.ActiveGizmoColour
+ : CinemachineSettings.CinemachineCoreSettings.InactiveGizmoColour;
+
+ Vector3 up = Vector3.up;
+ CinemachineBrain brain = CinemachineCore.Instance.FindPotentialTargetBrain(target.VirtualCamera);
+ if (brain != null)
+ up = brain.DefaultWorldUp;
+ Vector3 pos = target.FollowTarget.position;
+
+ Quaternion orient = target.GetReferenceOrientation(up);
+ up = orient * Vector3.up;
+ DrawCircleAtPointWithRadius
+ (pos + up * target.m_FollowOffset.y, orient, target.m_FollowOffset.z);
+
+ Gizmos.color = originalGizmoColour;
+ }
+ }
+
+ internal static void DrawCircleAtPointWithRadius(Vector3 point, Quaternion orient, float radius)
+ {
+ Matrix4x4 prevMatrix = Gizmos.matrix;
+ Gizmos.matrix = Matrix4x4.TRS(point, orient, radius * Vector3.one);
+
+ const int kNumPoints = 25;
+ Vector3 currPoint = Vector3.forward;
+ Quaternion rot = Quaternion.AngleAxis(360f / (float)kNumPoints, Vector3.up);
+ for (int i = 0; i < kNumPoints + 1; ++i)
+ {
+ Vector3 nextPoint = rot * currPoint;
+ Gizmos.DrawLine(currPoint, nextPoint);
+ currPoint = nextPoint;
+ }
+ Gizmos.matrix = prevMatrix;
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineOrbitalTransposerEditor.cs.meta b/Assets/Cinemachine/Base/Editor/Editors/CinemachineOrbitalTransposerEditor.cs.meta
new file mode 100644
index 0000000..a570f3a
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineOrbitalTransposerEditor.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 247be52eadac5044e9f8b7b4d8d0ada9
+timeCreated: 1485443456
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachinePOVEditor.cs b/Assets/Cinemachine/Base/Editor/Editors/CinemachinePOVEditor.cs
new file mode 100644
index 0000000..195a522
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachinePOVEditor.cs
@@ -0,0 +1,9 @@
+using UnityEditor;
+
+namespace Cinemachine.Editor
+{
+ [CustomEditor(typeof(CinemachinePOV))]
+ public sealed class CinemachinePOVEditor : BaseEditor<CinemachinePOV>
+ {
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachinePOVEditor.cs.meta b/Assets/Cinemachine/Base/Editor/Editors/CinemachinePOVEditor.cs.meta
new file mode 100644
index 0000000..80582f5
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachinePOVEditor.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 1186b8795dc3fc84e8ec53bd314d8e91
+timeCreated: 1504801965
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachinePathEditor.cs b/Assets/Cinemachine/Base/Editor/Editors/CinemachinePathEditor.cs
new file mode 100644
index 0000000..b6af44d
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachinePathEditor.cs
@@ -0,0 +1,387 @@
+using UnityEditor;
+using UnityEngine;
+using System.Collections.Generic;
+using UnityEditorInternal;
+using Cinemachine.Utility;
+
+namespace Cinemachine.Editor
+{
+ [CustomEditor(typeof(CinemachinePath))]
+ internal sealed class CinemachinePathEditor : BaseEditor<CinemachinePath>
+ {
+ private ReorderableList mWaypointList;
+ static bool mWaypointsExpanded;
+ static bool mPreferHandleSelection = true;
+
+ protected override List<string> GetExcludedPropertiesInInspector()
+ {
+ List<string> excluded = base.GetExcludedPropertiesInInspector();
+ excluded.Add(FieldPath(x => x.m_Waypoints));
+ return excluded;
+ }
+
+ void OnEnable()
+ {
+ mWaypointList = null;
+ }
+
+ public override void OnInspectorGUI()
+ {
+ BeginInspector();
+ if (mWaypointList == null)
+ SetupWaypointList();
+ if (mWaypointList.index >= mWaypointList.count)
+ mWaypointList.index = mWaypointList.count - 1;
+
+ // Ordinary properties
+ DrawRemainingPropertiesInInspector();
+
+ GUILayout.Label(new GUIContent("Selected Waypoint:"));
+ EditorGUILayout.BeginVertical(GUI.skin.box);
+ Rect rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight * 3 + 10);
+ if (mWaypointList.index >= 0)
+ {
+ DrawWaypointEditor(rect, mWaypointList.index);
+ serializedObject.ApplyModifiedProperties();
+ }
+ else
+ {
+ if (Target.m_Waypoints.Length > 0)
+ {
+ EditorGUI.HelpBox(rect,
+ "Click on a waypoint in the scene view\nor in the Path Details list",
+ MessageType.Info);
+ }
+ else if (GUI.Button(rect, new GUIContent("Add a waypoint to the path")))
+ {
+ InsertWaypointAtIndex(mWaypointList.index);
+ mWaypointList.index = 0;
+ }
+ }
+ EditorGUILayout.EndVertical();
+
+ mPreferHandleSelection = EditorGUILayout.Toggle(
+ new GUIContent("Prefer Tangent Drag",
+ "When editing the path, if waypoint position and tangent coincide, dragging will apply preferentially to the tangent"),
+ mPreferHandleSelection);
+
+ mWaypointsExpanded = EditorGUILayout.Foldout(mWaypointsExpanded, "Path Details");
+ if (mWaypointsExpanded)
+ {
+ EditorGUI.BeginChangeCheck();
+ mWaypointList.DoLayoutList();
+ if (EditorGUI.EndChangeCheck())
+ serializedObject.ApplyModifiedProperties();
+ }
+ }
+
+ void SetupWaypointList()
+ {
+ mWaypointList = new ReorderableList(
+ serializedObject, FindProperty(x => x.m_Waypoints),
+ true, true, true, true);
+ mWaypointList.elementHeight *= 3;
+
+ mWaypointList.drawHeaderCallback = (Rect rect) =>
+ {
+ EditorGUI.LabelField(rect, "Waypoints");
+ };
+
+ mWaypointList.drawElementCallback
+ = (Rect rect, int index, bool isActive, bool isFocused) =>
+ {
+ DrawWaypointEditor(rect, index);
+ };
+
+ mWaypointList.onAddCallback = (ReorderableList l) =>
+ {
+ InsertWaypointAtIndex(l.index);
+ };
+ }
+
+ void DrawWaypointEditor(Rect rect, int index)
+ {
+ // Needed for accessing string names of fields
+ CinemachinePath.Waypoint def = new CinemachinePath.Waypoint();
+
+ Vector2 numberDimension = GUI.skin.button.CalcSize(new GUIContent("999"));
+ Vector2 labelDimension = GUI.skin.label.CalcSize(new GUIContent("Position"));
+ Vector2 addButtonDimension = new Vector2(labelDimension.y + 5, labelDimension.y + 1);
+ float vSpace = 2;
+ float hSpace = 3;
+
+ SerializedProperty element = mWaypointList.serializedProperty.GetArrayElementAtIndex(index);
+ rect.y += vSpace / 2;
+
+ Rect r = new Rect(rect.position, numberDimension);
+ Color color = GUI.color;
+ // GUI.color = Target.m_Appearance.pathColor;
+ if (GUI.Button(r, new GUIContent(index.ToString(), "Go to the waypoint in the scene view")))
+ {
+ mWaypointList.index = index;
+ SceneView.lastActiveSceneView.pivot = Target.EvaluatePosition(index);
+ SceneView.lastActiveSceneView.size = 3;
+ SceneView.lastActiveSceneView.Repaint();
+ }
+ GUI.color = color;
+
+ r = new Rect(rect.position, labelDimension);
+ r.x += hSpace + numberDimension.x;
+ EditorGUI.LabelField(r, "Position");
+ r.x += hSpace + r.width;
+ r.width = rect.width - (numberDimension.x + hSpace + r.width + hSpace + addButtonDimension.x + hSpace);
+ EditorGUI.PropertyField(r, element.FindPropertyRelative(() => def.position), GUIContent.none);
+ r.x += r.width + hSpace;
+ r.size = addButtonDimension;
+ GUIContent buttonContent = EditorGUIUtility.IconContent("d_RectTransform Icon");
+ buttonContent.tooltip = "Set to scene-view camera position";
+ GUIStyle style = new GUIStyle(GUI.skin.label);
+ style.alignment = TextAnchor.MiddleCenter;
+ if (GUI.Button(r, buttonContent, style))
+ {
+ Undo.RecordObject(Target, "Set waypoint");
+ CinemachinePath.Waypoint wp = Target.m_Waypoints[index];
+ Vector3 pos = SceneView.lastActiveSceneView.camera.transform.position;
+ wp.position = Target.transform.InverseTransformPoint(pos);
+ Target.m_Waypoints[index] = wp;
+ }
+
+ r = new Rect(rect.position, labelDimension);
+ r.y += numberDimension.y + vSpace;
+ r.x += hSpace + numberDimension.x; r.width = labelDimension.x;
+ EditorGUI.LabelField(r, "Tangent");
+ r.x += hSpace + r.width;
+ r.width = rect.width - (numberDimension.x + hSpace + r.width + hSpace + addButtonDimension.x + hSpace);
+ EditorGUI.PropertyField(r, element.FindPropertyRelative(() => def.tangent), GUIContent.none);
+ r.x += r.width + hSpace;
+ r.size = addButtonDimension;
+ buttonContent = EditorGUIUtility.IconContent("ol minus@2x");
+ buttonContent.tooltip = "Remove this waypoint";
+ if (GUI.Button(r, buttonContent, style))
+ {
+ Undo.RecordObject(Target, "Delete waypoint");
+ var list = new List<CinemachinePath.Waypoint>(Target.m_Waypoints);
+ list.RemoveAt(index);
+ Target.m_Waypoints = list.ToArray();
+ if (index == Target.m_Waypoints.Length)
+ mWaypointList.index = index - 1;
+ }
+
+ r = new Rect(rect.position, labelDimension);
+ r.y += 2 * (numberDimension.y + vSpace);
+ r.x += hSpace + numberDimension.x; r.width = labelDimension.x;
+ EditorGUI.LabelField(r, "Roll");
+ r.x += hSpace + labelDimension.x;
+ r.width = rect.width
+ - (numberDimension.x + hSpace)
+ - (labelDimension.x + hSpace)
+ - (addButtonDimension.x + hSpace);
+ r.width /= 3;
+ EditorGUI.MultiPropertyField(r, new GUIContent[] { new GUIContent(" ") },
+ element.FindPropertyRelative(() => def.roll));
+
+ r.x = rect.x + rect.width - addButtonDimension.x;
+ r.size = addButtonDimension;
+ buttonContent = EditorGUIUtility.IconContent("ol plus@2x");
+ buttonContent.tooltip = "Add a new waypoint after this one";
+ if (GUI.Button(r, buttonContent, style))
+ {
+ mWaypointList.index = index;
+ InsertWaypointAtIndex(index);
+ }
+ }
+
+ void InsertWaypointAtIndex(int indexA)
+ {
+ Vector3 pos = Vector3.forward;
+ Vector3 tangent = Vector3.right;
+ float roll = 0;
+
+ // Get new values from the current indexA (if any)
+ int numWaypoints = Target.m_Waypoints.Length;
+ if (indexA < 0)
+ indexA = numWaypoints - 1;
+ if (indexA >= 0)
+ {
+ int indexB = indexA + 1;
+ if (Target.m_Looped && indexB >= numWaypoints)
+ indexB = 0;
+ if (indexB >= numWaypoints)
+ {
+ // Extrapolate the end
+ if (!Target.m_Waypoints[indexA].tangent.AlmostZero())
+ tangent = Target.m_Waypoints[indexA].tangent;
+ pos = Target.m_Waypoints[indexA].position + tangent;
+ roll = Target.m_Waypoints[indexA].roll;
+ }
+ else
+ {
+ // Interpolate
+ pos = Target.transform.InverseTransformPoint(
+ Target.EvaluatePosition(0.5f + indexA));
+ tangent = Target.transform.InverseTransformDirection(
+ Target.EvaluateTangent(0.5f + indexA).normalized);
+ roll = Mathf.Lerp(
+ Target.m_Waypoints[indexA].roll, Target.m_Waypoints[indexB].roll, 0.5f);
+ }
+ }
+ Undo.RecordObject(Target, "Add waypoint");
+ var wp = new CinemachinePath.Waypoint();
+ wp.position = pos;
+ wp.tangent = tangent;
+ wp.roll = roll;
+ var list = new List<CinemachinePath.Waypoint>(Target.m_Waypoints);
+ list.Insert(indexA + 1, wp);
+ Target.m_Waypoints = list.ToArray();
+ mWaypointList.index = indexA + 1; // select it
+ }
+
+ void OnSceneGUI()
+ {
+ if (mWaypointList == null)
+ SetupWaypointList();
+
+ if (Tools.current == Tool.Move)
+ {
+ Matrix4x4 mOld = Handles.matrix;
+ Color colorOld = Handles.color;
+
+ Handles.matrix = Target.transform.localToWorldMatrix;
+ for (int i = 0; i < Target.m_Waypoints.Length; ++i)
+ {
+ DrawSelectionHandle(i);
+ if (mWaypointList.index == i)
+ {
+ // Waypoint is selected
+ if (mPreferHandleSelection)
+ {
+ DrawPositionControl(i);
+ DrawTangentControl(i);
+ }
+ else
+ {
+ DrawTangentControl(i);
+ DrawPositionControl(i);
+ }
+ }
+ }
+ Handles.color = colorOld;
+ Handles.matrix = mOld;
+ }
+ }
+
+ void DrawSelectionHandle(int i)
+ {
+ if (Event.current.button != 1)
+ {
+ Vector3 pos = Target.m_Waypoints[i].position;
+ float size = HandleUtility.GetHandleSize(pos) * 0.2f;
+ Handles.color = Color.white;
+ if (Handles.Button(pos, Quaternion.identity, size, size, Handles.SphereHandleCap)
+ && mWaypointList.index != i)
+ {
+ mWaypointList.index = i;
+ InternalEditorUtility.RepaintAllViews();
+ }
+ // Label it
+ Handles.BeginGUI();
+ Vector2 labelSize = new Vector2(
+ EditorGUIUtility.singleLineHeight * 2, EditorGUIUtility.singleLineHeight);
+ Vector2 labelPos = HandleUtility.WorldToGUIPoint(pos);
+ labelPos.y -= labelSize.y / 2;
+ labelPos.x -= labelSize.x / 2;
+ GUILayout.BeginArea(new Rect(labelPos, labelSize));
+ GUIStyle style = new GUIStyle();
+ style.normal.textColor = Color.black;
+ style.alignment = TextAnchor.MiddleCenter;
+ GUILayout.Label(new GUIContent(i.ToString(), "Waypoint " + i), style);
+ GUILayout.EndArea();
+ Handles.EndGUI();
+ }
+ }
+
+ void DrawTangentControl(int i)
+ {
+ CinemachinePath.Waypoint wp = Target.m_Waypoints[i];
+ Vector3 hPos = wp.position + wp.tangent;
+
+ Handles.color = Color.yellow;
+ Handles.DrawLine(wp.position, hPos);
+
+ EditorGUI.BeginChangeCheck();
+ Quaternion rotation = (Tools.pivotRotation == PivotRotation.Local)
+ ? Quaternion.identity : Quaternion.Inverse(Target.transform.rotation);
+ float size = HandleUtility.GetHandleSize(hPos) * 0.1f;
+ Handles.SphereHandleCap(0, hPos, rotation, size, EventType.Repaint);
+ Vector3 newPos = Handles.PositionHandle(hPos, rotation);
+ if (EditorGUI.EndChangeCheck())
+ {
+ Undo.RecordObject(target, "Change Waypoint Tangent");
+ wp.tangent = newPos - wp.position;
+ Target.m_Waypoints[i] = wp;
+ Target.InvalidateDistanceCache();
+ }
+ }
+
+ void DrawPositionControl(int i)
+ {
+ CinemachinePath.Waypoint wp = Target.m_Waypoints[i];
+ EditorGUI.BeginChangeCheck();
+ Handles.color = Target.m_Appearance.pathColor;
+ Quaternion rotation = (Tools.pivotRotation == PivotRotation.Local)
+ ? Quaternion.identity : Quaternion.Inverse(Target.transform.rotation);
+ float size = HandleUtility.GetHandleSize(wp.position) * 0.1f;
+ Handles.SphereHandleCap(0, wp.position, rotation, size, EventType.Repaint);
+ Vector3 pos = Handles.PositionHandle(wp.position, rotation);
+ if (EditorGUI.EndChangeCheck())
+ {
+ Undo.RecordObject(target, "Move Waypoint");
+ wp.position = pos;
+ Target.m_Waypoints[i] = wp;
+ Target.InvalidateDistanceCache();
+ }
+ }
+
+ internal static void DrawPathGizmo(CinemachinePathBase path, Color pathColor)
+ {
+ // Draw the path
+ Color colorOld = Gizmos.color;
+ Gizmos.color = pathColor;
+ float step = 1f / path.m_Resolution;
+ Vector3 lastPos = path.EvaluatePosition(path.MinPos);
+ Vector3 lastW = (path.EvaluateOrientation(path.MinPos)
+ * Vector3.right) * path.m_Appearance.width / 2;
+ for (float t = path.MinPos + step; t <= path.MaxPos + step / 2; t += step)
+ {
+ Vector3 p = path.EvaluatePosition(t);
+ Quaternion q = path.EvaluateOrientation(t);
+ Vector3 w = (q * Vector3.right) * path.m_Appearance.width / 2;
+ Vector3 w2 = w * 1.2f;
+ Vector3 p0 = p - w2;
+ Vector3 p1 = p + w2;
+ Gizmos.DrawLine(p0, p1);
+ Gizmos.DrawLine(lastPos - lastW, p - w);
+ Gizmos.DrawLine(lastPos + lastW, p + w);
+#if false
+ // Show the normals, for debugging
+ Gizmos.color = Color.red;
+ Vector3 y = (q * Vector3.up) * width / 2;
+ Gizmos.DrawLine(p, p + y);
+ Gizmos.color = pathColor;
+#endif
+ lastPos = p;
+ lastW = w;
+ }
+ Gizmos.color = colorOld;
+ }
+
+ [DrawGizmo(GizmoType.Active | GizmoType.NotInSelectionHierarchy
+ | GizmoType.InSelectionHierarchy | GizmoType.Pickable, typeof(CinemachinePath))]
+ static void DrawGizmos(CinemachinePath path, GizmoType selectionType)
+ {
+ DrawPathGizmo(path,
+ (Selection.activeGameObject == path.gameObject)
+ ? path.m_Appearance.pathColor : path.m_Appearance.inactivePathColor);
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachinePathEditor.cs.meta b/Assets/Cinemachine/Base/Editor/Editors/CinemachinePathEditor.cs.meta
new file mode 100644
index 0000000..d66e7f9
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachinePathEditor.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: c88d2a04cc828c044b0fcc133fd481e6
+timeCreated: 1493316676
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineScreenComposerGuides.cs b/Assets/Cinemachine/Base/Editor/Editors/CinemachineScreenComposerGuides.cs
new file mode 100644
index 0000000..92fb23c
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineScreenComposerGuides.cs
@@ -0,0 +1,191 @@
+using UnityEngine;
+using UnityEditor;
+using Cinemachine.Utility;
+
+namespace Cinemachine.Editor
+{
+ internal class CinemachineScreenComposerGuides
+ {
+ public delegate Rect RectGetter();
+ public delegate void RectSetter(Rect r);
+ public delegate SerializedObject ObjectGetter();
+
+ // Clients MUST implement all of these
+ public RectGetter GetHardGuide;
+ public RectGetter GetSoftGuide;
+ public RectSetter SetHardGuide;
+ public RectSetter SetSoftGuide;
+ public ObjectGetter Target;
+
+ public const float kGuideBarWidthPx = 3f;
+
+ public void SetNewBounds(Rect oldHard, Rect oldSoft, Rect newHard, Rect newSoft)
+ {
+ if ((oldSoft != newSoft) || (oldHard != newHard))
+ {
+ Undo.RecordObject(Target().targetObject, "Composer Bounds");
+ if (oldSoft != newSoft)
+ SetSoftGuide(newSoft);
+ if (oldHard != newHard)
+ SetHardGuide(newHard);
+ Target().ApplyModifiedProperties();
+ }
+ }
+
+ public void OnGUI_DrawGuides(bool isLive, Camera outputCamera, LensSettings lens, bool showHardGuides)
+ {
+ Rect cameraRect = outputCamera.pixelRect;
+ float screenWidth = cameraRect.width;
+ float screenHeight = cameraRect.height;
+ cameraRect.yMax = Screen.height - cameraRect.yMin;
+ cameraRect.yMin = cameraRect.yMax - screenHeight;
+
+ // Rotate the guides along with the dutch
+ Matrix4x4 oldMatrix = GUI.matrix;
+ GUI.matrix = Matrix4x4.Translate(cameraRect.min);
+ GUIUtility.RotateAroundPivot(lens.Dutch, cameraRect.center);
+
+ Color hardBarsColour = CinemachineSettings.ComposerSettings.HardBoundsOverlayColour;
+ Color softBarsColour = CinemachineSettings.ComposerSettings.SoftBoundsOverlayColour;
+ float overlayOpacity = CinemachineSettings.ComposerSettings.OverlayOpacity;
+ if (!isLive)
+ {
+ softBarsColour = CinemachineSettings.CinemachineCoreSettings.InactiveGizmoColour;
+ hardBarsColour = Color.Lerp(softBarsColour, Color.black, 0.5f);
+ overlayOpacity /= 2;
+ }
+ hardBarsColour.a *= overlayOpacity;
+ softBarsColour.a *= overlayOpacity;
+
+ Rect r = showHardGuides ? GetHardGuide() : new Rect(-2, -2, 4, 4);
+ float hardEdgeLeft = r.xMin * screenWidth;
+ float hardEdgeTop = r.yMin * screenHeight;
+ float hardEdgeRight = r.xMax * screenWidth;
+ float hardEdgeBottom = r.yMax * screenHeight;
+
+ mDragBars[(int)DragBar.HardBarLineLeft] = new Rect(hardEdgeLeft - kGuideBarWidthPx / 2f, 0f, kGuideBarWidthPx, screenHeight);
+ mDragBars[(int)DragBar.HardBarLineTop] = new Rect(0f, hardEdgeTop - kGuideBarWidthPx / 2f, screenWidth, kGuideBarWidthPx);
+ mDragBars[(int)DragBar.HardBarLineRight] = new Rect(hardEdgeRight - kGuideBarWidthPx / 2f, 0f, kGuideBarWidthPx, screenHeight);
+ mDragBars[(int)DragBar.HardBarLineBottom] = new Rect(0f, hardEdgeBottom - kGuideBarWidthPx / 2f, screenWidth, kGuideBarWidthPx);
+
+ r = GetSoftGuide();
+ float softEdgeLeft = r.xMin * screenWidth;
+ float softEdgeTop = r.yMin * screenHeight;
+ float softEdgeRight = r.xMax * screenWidth;
+ float softEdgeBottom = r.yMax * screenHeight;
+
+ mDragBars[(int)DragBar.SoftBarLineLeft] = new Rect(softEdgeLeft - kGuideBarWidthPx / 2f, 0f, kGuideBarWidthPx, screenHeight);
+ mDragBars[(int)DragBar.SoftBarLineTop] = new Rect(0f, softEdgeTop - kGuideBarWidthPx / 2f, screenWidth, kGuideBarWidthPx);
+ mDragBars[(int)DragBar.SoftBarLineRight] = new Rect(softEdgeRight - kGuideBarWidthPx / 2f, 0f, kGuideBarWidthPx, screenHeight);
+ mDragBars[(int)DragBar.SoftBarLineBottom] = new Rect(0f, softEdgeBottom - kGuideBarWidthPx / 2f, screenWidth, kGuideBarWidthPx);
+
+ mDragBars[(int)DragBar.Center] = new Rect(softEdgeLeft, softEdgeTop, softEdgeRight - softEdgeLeft, softEdgeBottom - softEdgeTop);
+
+ // Handle dragging bars
+ if (isLive)
+ OnGuiHandleBarDragging(screenWidth, screenHeight);
+
+ // Draw the masks
+ GUI.color = hardBarsColour;
+ Rect hardBarLeft = new Rect(0, hardEdgeTop, Mathf.Max(0, hardEdgeLeft), hardEdgeBottom - hardEdgeTop);
+ Rect hardBarRight = new Rect(hardEdgeRight, hardEdgeTop,
+ Mathf.Max(0, screenWidth - hardEdgeRight), hardEdgeBottom - hardEdgeTop);
+ Rect hardBarTop = new Rect(Mathf.Min(0, hardEdgeLeft), 0,
+ Mathf.Max(screenWidth, hardEdgeRight) - Mathf.Min(0, hardEdgeLeft), Mathf.Max(0, hardEdgeTop));
+ Rect hardBarBottom = new Rect(Mathf.Min(0, hardEdgeLeft), hardEdgeBottom,
+ Mathf.Max(screenWidth, hardEdgeRight) - Mathf.Min(0, hardEdgeLeft),
+ Mathf.Max(0, screenHeight - hardEdgeBottom));
+ GUI.DrawTexture(hardBarLeft, Texture2D.whiteTexture, ScaleMode.StretchToFill);
+ GUI.DrawTexture(hardBarTop, Texture2D.whiteTexture, ScaleMode.StretchToFill);
+ GUI.DrawTexture(hardBarRight, Texture2D.whiteTexture, ScaleMode.StretchToFill);
+ GUI.DrawTexture(hardBarBottom, Texture2D.whiteTexture, ScaleMode.StretchToFill);
+
+ GUI.color = softBarsColour;
+ Rect softBarLeft = new Rect(hardEdgeLeft, softEdgeTop, softEdgeLeft - hardEdgeLeft, softEdgeBottom - softEdgeTop);
+ Rect softBarTop = new Rect(hardEdgeLeft, hardEdgeTop, hardEdgeRight - hardEdgeLeft, softEdgeTop - hardEdgeTop);
+ Rect softBarRight = new Rect(softEdgeRight, softEdgeTop, hardEdgeRight - softEdgeRight, softEdgeBottom - softEdgeTop);
+ Rect softBarBottom = new Rect(hardEdgeLeft, softEdgeBottom, hardEdgeRight - hardEdgeLeft, hardEdgeBottom - softEdgeBottom);
+ GUI.DrawTexture(softBarLeft, Texture2D.whiteTexture, ScaleMode.StretchToFill);
+ GUI.DrawTexture(softBarTop, Texture2D.whiteTexture, ScaleMode.StretchToFill);
+ GUI.DrawTexture(softBarRight, Texture2D.whiteTexture, ScaleMode.StretchToFill);
+ GUI.DrawTexture(softBarBottom, Texture2D.whiteTexture, ScaleMode.StretchToFill);
+
+ // Draw the drag bars
+ GUI.DrawTexture(mDragBars[(int)DragBar.SoftBarLineLeft], Texture2D.whiteTexture, ScaleMode.StretchToFill);
+ GUI.DrawTexture(mDragBars[(int)DragBar.SoftBarLineTop], Texture2D.whiteTexture, ScaleMode.StretchToFill);
+ GUI.DrawTexture(mDragBars[(int)DragBar.SoftBarLineRight], Texture2D.whiteTexture, ScaleMode.StretchToFill);
+ GUI.DrawTexture(mDragBars[(int)DragBar.SoftBarLineBottom], Texture2D.whiteTexture, ScaleMode.StretchToFill);
+
+ GUI.color = hardBarsColour;
+ GUI.DrawTexture(mDragBars[(int)DragBar.HardBarLineLeft], Texture2D.whiteTexture, ScaleMode.StretchToFill);
+ GUI.DrawTexture(mDragBars[(int)DragBar.HardBarLineTop], Texture2D.whiteTexture, ScaleMode.StretchToFill);
+ GUI.DrawTexture(mDragBars[(int)DragBar.HardBarLineRight], Texture2D.whiteTexture, ScaleMode.StretchToFill);
+ GUI.DrawTexture(mDragBars[(int)DragBar.HardBarLineBottom], Texture2D.whiteTexture, ScaleMode.StretchToFill);
+
+ GUI.matrix = oldMatrix;
+ }
+
+ // For dragging the bars - order defines precedence
+ private enum DragBar
+ {
+ Center,
+ SoftBarLineLeft, SoftBarLineTop, SoftBarLineRight, SoftBarLineBottom,
+ HardBarLineLeft, HardBarLineTop, HardBarLineRight, HardBarLineBottom,
+ NONE
+ };
+ private DragBar mDragging = DragBar.NONE;
+ private Rect[] mDragBars = new Rect[9];
+
+ private void OnGuiHandleBarDragging(float screenWidth, float screenHeight)
+ {
+ if (Event.current.type == EventType.MouseUp)
+ mDragging = DragBar.NONE;
+ if (Event.current.type == EventType.MouseDown)
+ {
+ mDragging = DragBar.NONE;
+ for (DragBar i = DragBar.Center; i < DragBar.NONE && mDragging == DragBar.NONE; ++i)
+ {
+ Vector2 slop = new Vector2(5f, 5f);
+ if (i == DragBar.Center)
+ {
+ if (mDragBars[(int)i].width > 3f * slop.x)
+ slop.x = -slop.x;
+ if (mDragBars[(int)i].height > 3f * slop.y)
+ slop.y = -slop.y;
+ }
+ Rect r = mDragBars[(int)i].Inflated(slop);
+ if (r.Contains(Event.current.mousePosition))
+ mDragging = i;
+ }
+ }
+
+ if (mDragging != DragBar.NONE && Event.current.type == EventType.MouseDrag)
+ {
+ Vector2 d = new Vector2(
+ Event.current.delta.x / screenWidth,
+ Event.current.delta.y / screenHeight);
+
+ // First snapshot some settings
+ Rect newHard = GetHardGuide();
+ Rect newSoft = GetSoftGuide();
+ Vector2 changed = Vector2.zero;
+ switch (mDragging)
+ {
+ case DragBar.Center: newSoft.position += d; break;
+ case DragBar.SoftBarLineLeft: newSoft = newSoft.Inflated(new Vector2(-d.x, 0)); break;
+ case DragBar.SoftBarLineRight: newSoft = newSoft.Inflated(new Vector2(d.x, 0)); break;
+ case DragBar.SoftBarLineTop: newSoft = newSoft.Inflated(new Vector2(0, -d.y)); break;
+ case DragBar.SoftBarLineBottom: newSoft = newSoft.Inflated(new Vector2(0, d.y)); break;
+ case DragBar.HardBarLineLeft: newHard = newHard.Inflated(new Vector2(-d.x, 0)); break;
+ case DragBar.HardBarLineRight: newHard = newHard.Inflated(new Vector2(d.x, 0)); break;
+ case DragBar.HardBarLineBottom: newHard = newHard.Inflated(new Vector2(0, d.y)); break;
+ case DragBar.HardBarLineTop: newHard = newHard.Inflated(new Vector2(0, -d.y)); break;
+ }
+
+ // Apply the changes, enforcing the bounds
+ SetNewBounds(GetHardGuide(), GetSoftGuide(), newHard, newSoft);
+ UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
+ }
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineScreenComposerGuides.cs.meta b/Assets/Cinemachine/Base/Editor/Editors/CinemachineScreenComposerGuides.cs.meta
new file mode 100644
index 0000000..1eb4add
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineScreenComposerGuides.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 2a15a1e455bcc7543872f50762449739
+timeCreated: 1502028239
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineSmoothPathEditor.cs b/Assets/Cinemachine/Base/Editor/Editors/CinemachineSmoothPathEditor.cs
new file mode 100644
index 0000000..b4d4e12
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineSmoothPathEditor.cs
@@ -0,0 +1,225 @@
+using UnityEditor;
+using UnityEngine;
+using System.Collections.Generic;
+using UnityEditorInternal;
+
+namespace Cinemachine.Editor
+{
+ [CustomEditor(typeof(CinemachineSmoothPath))]
+ internal sealed class CinemachineSmoothPathEditor : BaseEditor<CinemachineSmoothPath>
+ {
+ private ReorderableList mWaypointList;
+
+ protected override List<string> GetExcludedPropertiesInInspector()
+ {
+ List<string> excluded = base.GetExcludedPropertiesInInspector();
+ excluded.Add(FieldPath(x => x.m_Waypoints));
+ return excluded;
+ }
+
+ void OnEnable()
+ {
+ mWaypointList = null;
+ }
+
+ public override void OnInspectorGUI()
+ {
+ BeginInspector();
+ if (mWaypointList == null)
+ SetupWaypointList();
+
+ if (mWaypointList.index >= mWaypointList.count)
+ mWaypointList.index = mWaypointList.count - 1;
+
+ // Ordinary properties
+ DrawRemainingPropertiesInInspector();
+
+ // Waypoints
+ EditorGUI.BeginChangeCheck();
+ mWaypointList.DoLayoutList();
+ if (EditorGUI.EndChangeCheck())
+ serializedObject.ApplyModifiedProperties();
+ }
+
+ void SetupWaypointList()
+ {
+ mWaypointList = new ReorderableList(
+ serializedObject, FindProperty(x => x.m_Waypoints),
+ true, true, true, true);
+
+ mWaypointList.drawHeaderCallback = (Rect rect) =>
+ { EditorGUI.LabelField(rect, "Waypoints"); };
+
+ mWaypointList.drawElementCallback
+ = (Rect rect, int index, bool isActive, bool isFocused) =>
+ { DrawWaypointEditor(rect, index); };
+
+ mWaypointList.onAddCallback = (ReorderableList l) =>
+ { InsertWaypointAtIndex(l.index); };
+ }
+
+ void DrawWaypointEditor(Rect rect, int index)
+ {
+ // Needed for accessing string names of fields
+ CinemachineSmoothPath.Waypoint def = new CinemachineSmoothPath.Waypoint();
+ SerializedProperty element = mWaypointList.serializedProperty.GetArrayElementAtIndex(index);
+
+ float hSpace = 3;
+ rect.width -= hSpace; rect.y += 1;
+ Vector2 numberDimension = GUI.skin.label.CalcSize(new GUIContent("999"));
+ Rect r = new Rect(rect.position, numberDimension);
+ if (GUI.Button(r, new GUIContent(index.ToString(), "Go to the waypoint in the scene view")))
+ {
+ mWaypointList.index = index;
+ SceneView.lastActiveSceneView.pivot = Target.EvaluatePosition(index);
+ SceneView.lastActiveSceneView.size = 4;
+ SceneView.lastActiveSceneView.Repaint();
+ }
+
+ float floatFieldWidth = EditorGUIUtility.singleLineHeight * 2f;
+ GUIContent rollLabel = new GUIContent("Roll");
+ Vector2 labelDimension = GUI.skin.label.CalcSize(rollLabel);
+ float rollWidth = labelDimension.x + floatFieldWidth;
+ r.x += r.width + hSpace; r.width = rect.width - (r.width + hSpace + rollWidth) - (r.height + hSpace);
+ EditorGUI.PropertyField(r, element.FindPropertyRelative(() => def.position), GUIContent.none);
+
+ r.x += r.width + hSpace; r.width = rollWidth;
+ float oldWidth = EditorGUIUtility.labelWidth;
+ EditorGUIUtility.labelWidth = labelDimension.x;
+ EditorGUI.PropertyField(r, element.FindPropertyRelative(() => def.roll), rollLabel);
+ EditorGUIUtility.labelWidth = oldWidth;
+
+ r.x += r.width + hSpace; r.height += 1; r.width = r.height;
+ GUIContent setButtonContent = EditorGUIUtility.IconContent("d_RectTransform Icon");
+ setButtonContent.tooltip = "Set to scene-view camera position";
+ if (GUI.Button(r, setButtonContent, GUI.skin.label))
+ {
+ Undo.RecordObject(Target, "Set waypoint");
+ CinemachineSmoothPath.Waypoint wp = Target.m_Waypoints[index];
+ Vector3 pos = SceneView.lastActiveSceneView.camera.transform.position;
+ wp.position = Target.transform.InverseTransformPoint(pos);
+ Target.m_Waypoints[index] = wp;
+ }
+ }
+
+ void InsertWaypointAtIndex(int indexA)
+ {
+ Vector3 pos = Vector3.right;
+ float roll = 0;
+
+ // Get new values from the current indexA (if any)
+ int numWaypoints = Target.m_Waypoints.Length;
+ if (indexA < 0)
+ indexA = numWaypoints - 1;
+ if (indexA >= 0)
+ {
+ int indexB = indexA + 1;
+ if (Target.m_Looped && indexB >= numWaypoints)
+ indexB = 0;
+ if (indexB >= numWaypoints)
+ {
+ Vector3 delta = Vector3.right;
+ if (indexA > 0)
+ delta = Target.m_Waypoints[indexA].position - Target.m_Waypoints[indexA-1].position;
+ pos = Target.m_Waypoints[indexA].position + delta;
+ roll = Target.m_Waypoints[indexA].roll;
+ }
+ else
+ {
+ // Interpolate
+ pos = Target.transform.InverseTransformPoint(Target.EvaluatePosition(0.5f + indexA));
+ roll = Mathf.Lerp(Target.m_Waypoints[indexA].roll, Target.m_Waypoints[indexB].roll, 0.5f);
+ }
+ }
+ Undo.RecordObject(Target, "Add waypoint");
+ var wp = new CinemachineSmoothPath.Waypoint();
+ wp.position = pos;
+ wp.roll = roll;
+ var list = new List<CinemachineSmoothPath.Waypoint>(Target.m_Waypoints);
+ list.Insert(indexA + 1, wp);
+ Target.m_Waypoints = list.ToArray();
+ InternalEditorUtility.RepaintAllViews();
+ mWaypointList.index = indexA + 1; // select it
+ }
+
+ void OnSceneGUI()
+ {
+ if (mWaypointList == null)
+ SetupWaypointList();
+
+ if (Tools.current == Tool.Move)
+ {
+ Matrix4x4 mOld = Handles.matrix;
+ Color colorOld = Handles.color;
+
+ Handles.matrix = Target.transform.localToWorldMatrix;
+ for (int i = 0; i < Target.m_Waypoints.Length; ++i)
+ {
+ DrawSelectionHandle(i);
+ if (mWaypointList.index == i)
+ DrawPositionControl(i); // Waypoint is selected
+ }
+ Handles.color = colorOld;
+ Handles.matrix = mOld;
+ }
+ }
+
+ void DrawSelectionHandle(int i)
+ {
+ if (Event.current.button != 1)
+ {
+ Vector3 pos = Target.m_Waypoints[i].position;
+ float size = HandleUtility.GetHandleSize(pos) * 0.2f;
+ Handles.color = Color.white;
+ if (Handles.Button(pos, Quaternion.identity, size, size, Handles.SphereHandleCap)
+ && mWaypointList.index != i)
+ {
+ mWaypointList.index = i;
+ InternalEditorUtility.RepaintAllViews();
+ }
+ // Label it
+ Handles.BeginGUI();
+ Vector2 labelSize = new Vector2(
+ EditorGUIUtility.singleLineHeight * 2, EditorGUIUtility.singleLineHeight);
+ Vector2 labelPos = HandleUtility.WorldToGUIPoint(pos);
+ labelPos.y -= labelSize.y / 2;
+ labelPos.x -= labelSize.x / 2;
+ GUILayout.BeginArea(new Rect(labelPos, labelSize));
+ GUIStyle style = new GUIStyle();
+ style.normal.textColor = Color.black;
+ style.alignment = TextAnchor.MiddleCenter;
+ GUILayout.Label(new GUIContent(i.ToString(), "Waypoint " + i), style);
+ GUILayout.EndArea();
+ Handles.EndGUI();
+ }
+ }
+
+ void DrawPositionControl(int i)
+ {
+ CinemachineSmoothPath.Waypoint wp = Target.m_Waypoints[i];
+ EditorGUI.BeginChangeCheck();
+ Handles.color = Target.m_Appearance.pathColor;
+ Quaternion rotation = (Tools.pivotRotation == PivotRotation.Local)
+ ? Quaternion.identity : Quaternion.Inverse(Target.transform.rotation);
+ float size = HandleUtility.GetHandleSize(wp.position) * 0.1f;
+ Handles.SphereHandleCap(0, wp.position, rotation, size, EventType.Repaint);
+ Vector3 pos = Handles.PositionHandle(wp.position, rotation);
+ if (EditorGUI.EndChangeCheck())
+ {
+ Undo.RecordObject(target, "Move Waypoint");
+ wp.position = pos;
+ Target.m_Waypoints[i] = wp;
+ Target.InvalidateDistanceCache();
+ }
+ }
+
+ [DrawGizmo(GizmoType.Active | GizmoType.NotInSelectionHierarchy
+ | GizmoType.InSelectionHierarchy | GizmoType.Pickable, typeof(CinemachineSmoothPath))]
+ static void DrawGizmos(CinemachineSmoothPath path, GizmoType selectionType)
+ {
+ CinemachinePathEditor.DrawPathGizmo(path,
+ (Selection.activeGameObject == path.gameObject)
+ ? path.m_Appearance.pathColor : path.m_Appearance.inactivePathColor);
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineSmoothPathEditor.cs.meta b/Assets/Cinemachine/Base/Editor/Editors/CinemachineSmoothPathEditor.cs.meta
new file mode 100644
index 0000000..550b31c
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineSmoothPathEditor.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 1123a444101eb774ba7490990b50736a
+timeCreated: 1505831686
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineStateDrivenCameraEditor.cs b/Assets/Cinemachine/Base/Editor/Editors/CinemachineStateDrivenCameraEditor.cs
new file mode 100644
index 0000000..cab39bb
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineStateDrivenCameraEditor.cs
@@ -0,0 +1,444 @@
+using System.Collections.Generic;
+using UnityEditor;
+using UnityEngine;
+using UnityEditor.Animations;
+
+namespace Cinemachine.Editor
+{
+ [CustomEditor(typeof(CinemachineStateDrivenCamera))]
+ internal sealed class CinemachineStateDrivenCameraEditor
+ : CinemachineVirtualCameraBaseEditor<CinemachineStateDrivenCamera>
+ {
+ EmbeddeAssetEditor<CinemachineBlenderSettings> m_BlendsEditor;
+
+ protected override List<string> GetExcludedPropertiesInInspector()
+ {
+ List<string> excluded = base.GetExcludedPropertiesInInspector();
+ excluded.Add(FieldPath(x => x.m_CustomBlends));
+ excluded.Add(FieldPath(x => x.m_Instructions));
+ return excluded;
+ }
+
+ private UnityEditorInternal.ReorderableList mChildList;
+ private UnityEditorInternal.ReorderableList mInstructionList;
+
+ protected override void OnEnable()
+ {
+ base.OnEnable();
+ m_BlendsEditor = new EmbeddeAssetEditor<CinemachineBlenderSettings>(
+ FieldPath(x => x.m_CustomBlends), this);
+ m_BlendsEditor.OnChanged = (CinemachineBlenderSettings b) =>
+ {
+ UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
+ };
+ m_BlendsEditor.OnCreateEditor = (UnityEditor.Editor ed) =>
+ {
+ CinemachineBlenderSettingsEditor editor = ed as CinemachineBlenderSettingsEditor;
+ if (editor != null)
+ editor.GetAllVirtualCameras = () => { return Target.ChildCameras; };
+ };
+ mChildList = null;
+ mInstructionList = null;
+ }
+
+ protected override void OnDisable()
+ {
+ base.OnDisable();
+ if (m_BlendsEditor != null)
+ m_BlendsEditor.OnDisable();
+ }
+
+ public override void OnInspectorGUI()
+ {
+ BeginInspector();
+ if (mInstructionList == null)
+ SetupInstructionList();
+ if (mChildList == null)
+ SetupChildList();
+
+ if (Target.m_AnimatedTarget == null)
+ EditorGUILayout.HelpBox("An Animated Target is required", MessageType.Warning);
+
+ // Ordinary properties
+ DrawHeaderInInspector();
+ DrawPropertyInInspector(FindProperty(x => x.m_Priority));
+ DrawTargetsInInspector(FindProperty(x => x.m_Follow), FindProperty(x => x.m_LookAt));
+ DrawPropertyInInspector(FindProperty(x => x.m_AnimatedTarget));
+
+ // Layer index
+ EditorGUI.BeginChangeCheck();
+ UpdateTargetStates();
+ UpdateCameraCandidates();
+ SerializedProperty layerProp = FindAndExcludeProperty(x => x.m_LayerIndex);
+ int currentLayer = layerProp.intValue;
+ int layerSelection = EditorGUILayout.Popup("Layer", currentLayer, mLayerNames);
+ if (currentLayer != layerSelection)
+ layerProp.intValue = layerSelection;
+ if (EditorGUI.EndChangeCheck())
+ {
+ serializedObject.ApplyModifiedProperties();
+ Target.ValidateInstructions();
+ }
+
+ DrawRemainingPropertiesInInspector();
+
+ // Blends
+ m_BlendsEditor.DrawEditorCombo(
+ "Create New Blender Asset",
+ Target.gameObject.name + " Blends", "asset", string.Empty,
+ "Custom Blends", false);
+
+ // Instructions
+ EditorGUI.BeginChangeCheck();
+ EditorGUILayout.Separator();
+ mInstructionList.DoLayoutList();
+
+ // vcam children
+ EditorGUILayout.Separator();
+ mChildList.DoLayoutList();
+ if (EditorGUI.EndChangeCheck())
+ {
+ serializedObject.ApplyModifiedProperties();
+ Target.ValidateInstructions();
+ }
+
+ // Extensions
+ DrawExtensionsWidgetInInspector();
+ }
+
+ private string[] mLayerNames;
+ private int[] mTargetStates;
+ private string[] mTargetStateNames;
+ private Dictionary<int, int> mStateIndexLookup;
+ private void UpdateTargetStates()
+ {
+ // Scrape the Animator Controller for states
+ AnimatorController ac = (Target.m_AnimatedTarget == null)
+ ? null : Target.m_AnimatedTarget.runtimeAnimatorController as AnimatorController;
+ StateCollector collector = new StateCollector();
+ collector.CollectStates(ac, Target.m_LayerIndex);
+ mTargetStates = collector.mStates.ToArray();
+ mTargetStateNames = collector.mStateNames.ToArray();
+ mStateIndexLookup = collector.mStateIndexLookup;
+
+ if (ac == null)
+ mLayerNames = new string[0];
+ else
+ {
+ mLayerNames = new string[ac.layers.Length];
+ for (int i = 0; i < ac.layers.Length; ++i)
+ mLayerNames[i] = ac.layers[i].name;
+ }
+
+ // Create the parent map in the target
+ List<CinemachineStateDrivenCamera.ParentHash> parents
+ = new List<CinemachineStateDrivenCamera.ParentHash>();
+ foreach (var i in collector.mStateParentLookup)
+ parents.Add(new CinemachineStateDrivenCamera.ParentHash(i.Key, i.Value));
+ Target.m_ParentHash = parents.ToArray();
+ }
+
+ class StateCollector
+ {
+ public List<int> mStates;
+ public List<string> mStateNames;
+ public Dictionary<int, int> mStateIndexLookup;
+ public Dictionary<int, int> mStateParentLookup;
+
+ public void CollectStates(AnimatorController ac, int layerIndex)
+ {
+ mStates = new List<int>();
+ mStateNames = new List<string>();
+ mStateIndexLookup = new Dictionary<int, int>();
+ mStateParentLookup = new Dictionary<int, int>();
+
+ mStateIndexLookup[0] = mStates.Count;
+ mStateNames.Add("(default)");
+ mStates.Add(0);
+
+ if (ac != null && layerIndex >= 0 && layerIndex < ac.layers.Length)
+ {
+ AnimatorStateMachine fsm = ac.layers[layerIndex].stateMachine;
+ string name = fsm.name;
+ int hash = Animator.StringToHash(name);
+ CollectStatesFromFSM(fsm, name + ".", hash, string.Empty);
+ }
+ }
+
+ void CollectStatesFromFSM(
+ AnimatorStateMachine fsm, string hashPrefix, int parentHash, string displayPrefix)
+ {
+ ChildAnimatorState[] states = fsm.states;
+ for (int i = 0; i < states.Length; i++)
+ {
+ AnimatorState state = states[i].state;
+ int hash = AddState(hashPrefix + state.name, parentHash, displayPrefix + state.name);
+
+ // Also process clips as pseudo-states, if more than 1 is present.
+ // Since they don't have hashes, we can manufacture some.
+ List<string> clips = CollectClipNames(state.motion);
+ if (clips.Count > 1)
+ {
+ string substatePrefix = displayPrefix + state.name + ".";
+ foreach (string name in clips)
+ AddState(
+ CinemachineStateDrivenCamera.CreateFakeHashName(hash, name),
+ hash, substatePrefix + name);
+ }
+ }
+
+ ChildAnimatorStateMachine[] fsmChildren = fsm.stateMachines;
+ foreach (var child in fsmChildren)
+ {
+ string name = hashPrefix + child.stateMachine.name;
+ string displayName = displayPrefix + child.stateMachine.name;
+ int hash = AddState(name, parentHash, displayName);
+ CollectStatesFromFSM(child.stateMachine, name + ".", hash, displayName + ".");
+ }
+ }
+
+ List<string> CollectClipNames(Motion motion)
+ {
+ List<string> names = new List<string>();
+ AnimationClip clip = motion as AnimationClip;
+ if (clip != null)
+ names.Add(clip.name);
+ BlendTree tree = motion as BlendTree;
+ if (tree != null)
+ {
+ ChildMotion[] children = tree.children;
+ foreach (var child in children)
+ names.AddRange(CollectClipNames(child.motion));
+ }
+ return names;
+ }
+
+ int AddState(string hashName, int parentHash, string displayName)
+ {
+ int hash = Animator.StringToHash(hashName);
+ if (parentHash != 0)
+ mStateParentLookup[hash] = parentHash;
+ mStateIndexLookup[hash] = mStates.Count;
+ mStateNames.Add(displayName);
+ mStates.Add(hash);
+ return hash;
+ }
+ }
+
+ private int GetStateHashIndex(int stateHash)
+ {
+ if (stateHash == 0)
+ return 0;
+ if (!mStateIndexLookup.ContainsKey(stateHash))
+ return 0;
+ return mStateIndexLookup[stateHash];
+ }
+
+ private string[] mCameraCandidates;
+ private Dictionary<CinemachineVirtualCameraBase, int> mCameraIndexLookup;
+ private void UpdateCameraCandidates()
+ {
+ List<string> vcams = new List<string>();
+ mCameraIndexLookup = new Dictionary<CinemachineVirtualCameraBase, int>();
+ vcams.Add("(none)");
+ CinemachineVirtualCameraBase[] children = Target.ChildCameras;
+ foreach (var c in children)
+ {
+ mCameraIndexLookup[c] = vcams.Count;
+ vcams.Add(c.Name);
+ }
+ mCameraCandidates = vcams.ToArray();
+ }
+
+ private int GetCameraIndex(Object obj)
+ {
+ if (obj == null || mCameraIndexLookup == null)
+ return 0;
+ CinemachineVirtualCameraBase vcam = obj as CinemachineVirtualCameraBase;
+ if (vcam == null)
+ return 0;
+ if (!mCameraIndexLookup.ContainsKey(vcam))
+ return 0;
+ return mCameraIndexLookup[vcam];
+ }
+
+ void SetupInstructionList()
+ {
+ mInstructionList = new UnityEditorInternal.ReorderableList(serializedObject,
+ serializedObject.FindProperty(() => Target.m_Instructions),
+ true, true, true, true);
+
+ // Needed for accessing field names as strings
+ CinemachineStateDrivenCamera.Instruction def = new CinemachineStateDrivenCamera.Instruction();
+
+ float vSpace = 2;
+ float hSpace = 3;
+ float floatFieldWidth = EditorGUIUtility.singleLineHeight * 2.5f;
+ float hBigSpace = EditorGUIUtility.singleLineHeight * 2 / 3;
+ mInstructionList.drawHeaderCallback = (Rect rect) =>
+ {
+ float sharedWidth = rect.width - EditorGUIUtility.singleLineHeight
+ - 2 * (hBigSpace + floatFieldWidth) - hSpace;
+ rect.x += EditorGUIUtility.singleLineHeight; rect.width = sharedWidth / 2;
+ EditorGUI.LabelField(rect, "State");
+
+ rect.x += rect.width + hSpace;
+ EditorGUI.LabelField(rect, "Camera");
+
+ rect.x += rect.width + hBigSpace; rect.width = floatFieldWidth;
+ EditorGUI.LabelField(rect, "Wait");
+
+ rect.x += rect.width + hBigSpace;
+ EditorGUI.LabelField(rect, "Min");
+ };
+
+ mInstructionList.drawElementCallback
+ = (Rect rect, int index, bool isActive, bool isFocused) =>
+ {
+ SerializedProperty instProp
+ = mInstructionList.serializedProperty.GetArrayElementAtIndex(index);
+ float sharedWidth = rect.width - 2 * (hBigSpace + floatFieldWidth) - hSpace;
+ rect.y += vSpace; rect.height = EditorGUIUtility.singleLineHeight;
+
+ rect.width = sharedWidth / 2;
+ SerializedProperty stateSelProp = instProp.FindPropertyRelative(() => def.m_FullHash);
+ int currentState = GetStateHashIndex(stateSelProp.intValue);
+ int stateSelection = EditorGUI.Popup(rect, currentState, mTargetStateNames);
+ if (currentState != stateSelection)
+ stateSelProp.intValue = mTargetStates[stateSelection];
+
+ rect.x += rect.width + hSpace;
+ SerializedProperty vcamSelProp = instProp.FindPropertyRelative(() => def.m_VirtualCamera);
+ int currentVcam = GetCameraIndex(vcamSelProp.objectReferenceValue);
+ int vcamSelection = EditorGUI.Popup(rect, currentVcam, mCameraCandidates);
+ if (currentVcam != vcamSelection)
+ vcamSelProp.objectReferenceValue = (vcamSelection == 0)
+ ? null : Target.ChildCameras[vcamSelection - 1];
+
+ float oldWidth = EditorGUIUtility.labelWidth;
+ EditorGUIUtility.labelWidth = hBigSpace;
+
+ rect.x += rect.width; rect.width = floatFieldWidth + hBigSpace;
+ SerializedProperty activeAfterProp = instProp.FindPropertyRelative(() => def.m_ActivateAfter);
+ EditorGUI.PropertyField(rect, activeAfterProp, new GUIContent(" ", activeAfterProp.tooltip));
+
+ rect.x += rect.width;
+ SerializedProperty minDurationProp = instProp.FindPropertyRelative(() => def.m_MinDuration);
+ EditorGUI.PropertyField(rect, minDurationProp, new GUIContent(" ", minDurationProp.tooltip));
+
+ EditorGUIUtility.labelWidth = oldWidth;
+ };
+
+ mInstructionList.onAddDropdownCallback = (Rect buttonRect, UnityEditorInternal.ReorderableList l) =>
+ {
+ var menu = new GenericMenu();
+ menu.AddItem(new GUIContent("New State"),
+ false, (object data) =>
+ {
+ ++mInstructionList.serializedProperty.arraySize;
+ serializedObject.ApplyModifiedProperties();
+ Target.ValidateInstructions();
+ },
+ null);
+ menu.AddItem(new GUIContent("All Unhandled States"),
+ false, (object data) =>
+ {
+ CinemachineStateDrivenCamera target = Target;
+ int len = mInstructionList.serializedProperty.arraySize;
+ for (int i = 0; i < mTargetStates.Length; ++i)
+ {
+ int hash = mTargetStates[i];
+ if (hash == 0)
+ continue;
+ bool alreadyThere = false;
+ for (int j = 0; j < len; ++j)
+ {
+ if (target.m_Instructions[j].m_FullHash == hash)
+ {
+ alreadyThere = true;
+ break;
+ }
+ }
+ if (!alreadyThere)
+ {
+ int index = mInstructionList.serializedProperty.arraySize;
+ ++mInstructionList.serializedProperty.arraySize;
+ SerializedProperty p = mInstructionList.serializedProperty.GetArrayElementAtIndex(index);
+ p.FindPropertyRelative(() => def.m_FullHash).intValue = hash;
+ }
+ }
+ serializedObject.ApplyModifiedProperties();
+ Target.ValidateInstructions();
+ },
+ null);
+ menu.ShowAsContext();
+ };
+ }
+
+ void SetupChildList()
+ {
+ float vSpace = 2;
+ float hSpace = 3;
+ float floatFieldWidth = EditorGUIUtility.singleLineHeight * 2.5f;
+ float hBigSpace = EditorGUIUtility.singleLineHeight * 2 / 3;
+
+ mChildList = new UnityEditorInternal.ReorderableList(serializedObject,
+ serializedObject.FindProperty(() => Target.m_ChildCameras),
+ true, true, true, true);
+
+ mChildList.drawHeaderCallback = (Rect rect) =>
+ {
+ EditorGUI.LabelField(rect, "Virtual Camera Children");
+ GUIContent priorityText = new GUIContent("Priority");
+ var textDimensions = GUI.skin.label.CalcSize(priorityText);
+ rect.x += rect.width - textDimensions.x;
+ rect.width = textDimensions.x;
+ EditorGUI.LabelField(rect, priorityText);
+ };
+ mChildList.drawElementCallback
+ = (Rect rect, int index, bool isActive, bool isFocused) =>
+ {
+ rect.y += vSpace; rect.height = EditorGUIUtility.singleLineHeight;
+ rect.width -= floatFieldWidth + hBigSpace;
+ SerializedProperty element = mChildList.serializedProperty.GetArrayElementAtIndex(index);
+ EditorGUI.PropertyField(rect, element, GUIContent.none);
+
+ float oldWidth = EditorGUIUtility.labelWidth;
+ EditorGUIUtility.labelWidth = hBigSpace;
+ SerializedObject obj = new SerializedObject(element.objectReferenceValue);
+ rect.x += rect.width + hSpace; rect.width = floatFieldWidth + hBigSpace;
+ SerializedProperty priorityProp = obj.FindProperty(() => Target.m_Priority);
+ EditorGUI.PropertyField(rect, priorityProp, new GUIContent(" ", priorityProp.tooltip));
+ EditorGUIUtility.labelWidth = oldWidth;
+ obj.ApplyModifiedProperties();
+ };
+ mChildList.onChangedCallback = (UnityEditorInternal.ReorderableList l) =>
+ {
+ if (l.index < 0 || l.index >= l.serializedProperty.arraySize)
+ return;
+ Object o = l.serializedProperty.GetArrayElementAtIndex(
+ l.index).objectReferenceValue;
+ CinemachineVirtualCameraBase vcam = (o != null)
+ ? (o as CinemachineVirtualCameraBase) : null;
+ if (vcam != null)
+ vcam.transform.SetSiblingIndex(l.index);
+ };
+ mChildList.onAddCallback = (UnityEditorInternal.ReorderableList l) =>
+ {
+ var index = l.serializedProperty.arraySize;
+ var vcam = CinemachineMenu.CreateDefaultVirtualCamera();
+ Undo.SetTransformParent(vcam.transform, Target.transform, "");
+ vcam.transform.SetSiblingIndex(index);
+ };
+ mChildList.onRemoveCallback = (UnityEditorInternal.ReorderableList l) =>
+ {
+ Object o = l.serializedProperty.GetArrayElementAtIndex(
+ l.index).objectReferenceValue;
+ CinemachineVirtualCameraBase vcam = (o != null)
+ ? (o as CinemachineVirtualCameraBase) : null;
+ if (vcam != null)
+ Undo.DestroyObjectImmediate(vcam.gameObject);
+ };
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineStateDrivenCameraEditor.cs.meta b/Assets/Cinemachine/Base/Editor/Editors/CinemachineStateDrivenCameraEditor.cs.meta
new file mode 100644
index 0000000..93a7e21
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineStateDrivenCameraEditor.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 0eb9f23cde3a1734da334cfa0831dd25
+timeCreated: 1486062933
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineTargetGroupEditor.cs b/Assets/Cinemachine/Base/Editor/Editors/CinemachineTargetGroupEditor.cs
new file mode 100644
index 0000000..a10aa72
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineTargetGroupEditor.cs
@@ -0,0 +1,94 @@
+using UnityEditor;
+using UnityEngine;
+using System.Collections.Generic;
+
+namespace Cinemachine.Editor
+{
+ [CustomEditor(typeof(CinemachineTargetGroup))]
+ internal sealed class CinemachineTargetGroupEditor : BaseEditor<CinemachineTargetGroup>
+ {
+ private UnityEditorInternal.ReorderableList mTargetList;
+
+ protected override List<string> GetExcludedPropertiesInInspector()
+ {
+ List<string> excluded = base.GetExcludedPropertiesInInspector();
+ excluded.Add(FieldPath(x => x.m_Targets));
+ return excluded;
+ }
+
+ void OnEnable()
+ {
+ mTargetList = null;
+ }
+
+ public override void OnInspectorGUI()
+ {
+ BeginInspector();
+ DrawRemainingPropertiesInInspector();
+
+ if (mTargetList == null)
+ SetupTargetList();
+ EditorGUI.BeginChangeCheck();
+ mTargetList.DoLayoutList();
+ if (EditorGUI.EndChangeCheck())
+ serializedObject.ApplyModifiedProperties();
+ }
+
+ void SetupTargetList()
+ {
+ float vSpace = 2;
+ float floatFieldWidth = EditorGUIUtility.singleLineHeight * 3f;
+ float hBigSpace = EditorGUIUtility.singleLineHeight * 2 / 3;
+
+ mTargetList = new UnityEditorInternal.ReorderableList(
+ serializedObject, FindProperty(x => x.m_Targets),
+ true, true, true, true);
+
+ // Needed for accessing field names as strings
+ CinemachineTargetGroup.Target def = new CinemachineTargetGroup.Target();
+
+ mTargetList.drawHeaderCallback = (Rect rect) =>
+ {
+ rect.width -= EditorGUIUtility.singleLineHeight + 2 * (floatFieldWidth + hBigSpace);
+ Vector2 pos = rect.position; pos.x += EditorGUIUtility.singleLineHeight;
+ rect.position = pos;
+ EditorGUI.LabelField(rect, "Target");
+
+ pos.x += rect.width + hBigSpace; rect.width = floatFieldWidth; rect.position = pos;
+ EditorGUI.LabelField(rect, "Weight");
+
+ pos.x += rect.width + hBigSpace; rect.position = pos;
+ EditorGUI.LabelField(rect, "Radius");
+ };
+
+ mTargetList.drawElementCallback
+ = (Rect rect, int index, bool isActive, bool isFocused) =>
+ {
+ SerializedProperty elemProp = mTargetList.serializedProperty.GetArrayElementAtIndex(index);
+
+ rect.y += vSpace;
+ rect.height = EditorGUIUtility.singleLineHeight;
+ Vector2 pos = rect.position;
+ //rect.width -= hSpace + 2 * EditorGUIUtility.singleLineHeight;
+ rect.width -= 2 * (floatFieldWidth + hBigSpace);
+ EditorGUI.PropertyField(rect, elemProp.FindPropertyRelative(() => def.target), GUIContent.none);
+
+ float oldWidth = EditorGUIUtility.labelWidth;
+ EditorGUIUtility.labelWidth = EditorGUIUtility.singleLineHeight;
+ pos.x += rect.width; rect.width = floatFieldWidth + hBigSpace; rect.position = pos;
+ EditorGUI.PropertyField(rect, elemProp.FindPropertyRelative(() => def.weight), new GUIContent(" "));
+ pos.x += rect.width; rect.position = pos;
+ EditorGUI.PropertyField(rect, elemProp.FindPropertyRelative(() => def.radius), new GUIContent(" "));
+ EditorGUIUtility.labelWidth = oldWidth;
+ };
+
+ mTargetList.onAddCallback = (UnityEditorInternal.ReorderableList l) =>
+ {
+ var index = l.serializedProperty.arraySize;
+ ++l.serializedProperty.arraySize;
+ SerializedProperty elemProp = mTargetList.serializedProperty.GetArrayElementAtIndex(index);
+ elemProp.FindPropertyRelative(() => def.weight).floatValue = 1;
+ };
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineTargetGroupEditor.cs.meta b/Assets/Cinemachine/Base/Editor/Editors/CinemachineTargetGroupEditor.cs.meta
new file mode 100644
index 0000000..3d50351
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineTargetGroupEditor.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: eb8e037cb3f873743a725427c8c22342
+timeCreated: 1496424406
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineTrackedDollyEditor.cs b/Assets/Cinemachine/Base/Editor/Editors/CinemachineTrackedDollyEditor.cs
new file mode 100644
index 0000000..6d5738f
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineTrackedDollyEditor.cs
@@ -0,0 +1,60 @@
+using System.Collections.Generic;
+using UnityEditor;
+using UnityEngine;
+
+namespace Cinemachine.Editor
+{
+ [CustomEditor(typeof(CinemachineTrackedDolly))]
+ internal sealed class CinemachineTrackedDollyEditor : BaseEditor<CinemachineTrackedDolly>
+ {
+ protected override List<string> GetExcludedPropertiesInInspector()
+ {
+ List<string> excluded = base.GetExcludedPropertiesInInspector();
+ switch (Target.m_CameraUp)
+ {
+ default:
+ break;
+ case CinemachineTrackedDolly.CameraUpMode.PathNoRoll:
+ case CinemachineTrackedDolly.CameraUpMode.FollowTargetNoRoll:
+ excluded.Add(FieldPath(x => x.m_RollDamping));
+ break;
+ case CinemachineTrackedDolly.CameraUpMode.Default:
+ excluded.Add(FieldPath(x => x.m_PitchDamping));
+ excluded.Add(FieldPath(x => x.m_YawDamping));
+ excluded.Add(FieldPath(x => x.m_RollDamping));
+ break;
+ }
+ return excluded;
+ }
+
+ public override void OnInspectorGUI()
+ {
+ BeginInspector();
+ if (Target.m_Path == null)
+ EditorGUILayout.HelpBox("A Path is required", MessageType.Warning);
+ if (Target.m_AutoDolly.m_Enabled && Target.FollowTarget == null)
+ EditorGUILayout.HelpBox("AutoDolly requires a Follow Target", MessageType.Warning);
+ DrawRemainingPropertiesInInspector();
+ }
+
+ [DrawGizmo(GizmoType.Active | GizmoType.InSelectionHierarchy, typeof(CinemachineTrackedDolly))]
+ private static void DrawTrackeDollyGizmos(CinemachineTrackedDolly target, GizmoType selectionType)
+ {
+ if (target.IsValid)
+ {
+ CinemachinePathBase path = target.m_Path;
+ if (path != null)
+ {
+ CinemachinePathEditor.DrawPathGizmo(path, path.m_Appearance.pathColor);
+ Vector3 pos = path.EvaluatePositionAtUnit(target.m_PathPosition, target.m_PositionUnits);
+ Color oldColor = Gizmos.color;
+ Gizmos.color = CinemachineCore.Instance.IsLive(target.VirtualCamera)
+ ? CinemachineSettings.CinemachineCoreSettings.ActiveGizmoColour
+ : CinemachineSettings.CinemachineCoreSettings.InactiveGizmoColour;
+ Gizmos.DrawLine(pos, target.transform.position);
+ Gizmos.color = oldColor;
+ }
+ }
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineTrackedDollyEditor.cs.meta b/Assets/Cinemachine/Base/Editor/Editors/CinemachineTrackedDollyEditor.cs.meta
new file mode 100644
index 0000000..37381f2
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineTrackedDollyEditor.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: d4a408a1b506d0046875061c677944d8
+timeCreated: 1493318518
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineTransposerEditor.cs b/Assets/Cinemachine/Base/Editor/Editors/CinemachineTransposerEditor.cs
new file mode 100644
index 0000000..37dce4f
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineTransposerEditor.cs
@@ -0,0 +1,73 @@
+using UnityEngine;
+using UnityEditor;
+using System.Collections.Generic;
+
+namespace Cinemachine.Editor
+{
+ [CustomEditor(typeof(CinemachineTransposer))]
+ internal sealed class CinemachineTransposerEditor : BaseEditor<CinemachineTransposer>
+ {
+ protected override List<string> GetExcludedPropertiesInInspector()
+ {
+ List<string> excluded = base.GetExcludedPropertiesInInspector();
+ switch (Target.m_BindingMode)
+ {
+ default:
+ case CinemachineTransposer.BindingMode.LockToTarget:
+ break;
+ case CinemachineTransposer.BindingMode.LockToTargetNoRoll:
+ excluded.Add(FieldPath(x => x.m_RollDamping));
+ break;
+ case CinemachineTransposer.BindingMode.LockToTargetWithWorldUp:
+ excluded.Add(FieldPath(x => x.m_PitchDamping));
+ excluded.Add(FieldPath(x => x.m_RollDamping));
+ break;
+ case CinemachineTransposer.BindingMode.LockToTargetOnAssign:
+ case CinemachineTransposer.BindingMode.WorldSpace:
+ excluded.Add(FieldPath(x => x.m_PitchDamping));
+ excluded.Add(FieldPath(x => x.m_YawDamping));
+ excluded.Add(FieldPath(x => x.m_RollDamping));
+ break;
+ case CinemachineTransposer.BindingMode.SimpleFollowWithWorldUp:
+ excluded.Add(FieldPath(x => x.m_XDamping));
+ excluded.Add(FieldPath(x => x.m_PitchDamping));
+ excluded.Add(FieldPath(x => x.m_YawDamping));
+ excluded.Add(FieldPath(x => x.m_RollDamping));
+ break;
+ }
+ return excluded;
+ }
+
+ public override void OnInspectorGUI()
+ {
+ BeginInspector();
+ if (Target.FollowTarget == null)
+ EditorGUILayout.HelpBox(
+ "Transposer requires a Follow Target. Change Body to Do Nothing if you don't want a Follow target.",
+ MessageType.Warning);
+ DrawRemainingPropertiesInInspector();
+ }
+
+ [DrawGizmo(GizmoType.Active | GizmoType.Selected, typeof(CinemachineTransposer))]
+ static void DrawTransposerGizmos(CinemachineTransposer target, GizmoType selectionType)
+ {
+ if (target.IsValid)
+ {
+ Color originalGizmoColour = Gizmos.color;
+ Gizmos.color = CinemachineCore.Instance.IsLive(target.VirtualCamera)
+ ? CinemachineSettings.CinemachineCoreSettings.ActiveGizmoColour
+ : CinemachineSettings.CinemachineCoreSettings.InactiveGizmoColour;
+
+ Vector3 up = Vector3.up;
+ CinemachineBrain brain = CinemachineCore.Instance.FindPotentialTargetBrain(target.VirtualCamera);
+ if (brain != null)
+ up = brain.DefaultWorldUp;
+ Vector3 targetPos = target.FollowTarget.position;
+ Vector3 desiredPos = target.GeTargetCameraPosition(up);
+ Gizmos.DrawLine(targetPos, desiredPos);
+ Gizmos.DrawWireSphere(desiredPos, HandleUtility.GetHandleSize(desiredPos) / 20);
+ Gizmos.color = originalGizmoColour;
+ }
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineTransposerEditor.cs.meta b/Assets/Cinemachine/Base/Editor/Editors/CinemachineTransposerEditor.cs.meta
new file mode 100644
index 0000000..03f51a1
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineTransposerEditor.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: f34e35dc1dc67c54c841b728548d69cc
+timeCreated: 1484088330
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineVirtualCameraBaseEditor.cs b/Assets/Cinemachine/Base/Editor/Editors/CinemachineVirtualCameraBaseEditor.cs
new file mode 100644
index 0000000..e76a0ad
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineVirtualCameraBaseEditor.cs
@@ -0,0 +1,202 @@
+using UnityEngine;
+using UnityEditor;
+using System;
+using System.Collections.Generic;
+using Cinemachine.Utility;
+
+namespace Cinemachine.Editor
+{
+ /// <summary>
+ /// Base class for virtual camera editors.
+ /// Handles drawing the header and the basic properties.
+ /// </summary>
+ public class CinemachineVirtualCameraBaseEditor<T> : BaseEditor<T> where T : CinemachineVirtualCameraBase
+ {
+ static Type[] sExtensionTypes; // First entry is null
+ static string[] sExtensionNames;
+
+ protected override List<string> GetExcludedPropertiesInInspector()
+ {
+ var excluded = base.GetExcludedPropertiesInInspector();
+ if (Target.m_ExcludedPropertiesInInspector != null)
+ excluded.AddRange(Target.m_ExcludedPropertiesInInspector);
+ return excluded;
+ }
+
+ protected virtual void OnEnable()
+ {
+ if (sExtensionTypes == null)
+ {
+ // Populate the extension list
+ List<Type> exts = new List<Type>();
+ List<string> names = new List<string>();
+ exts.Add(null);
+ names.Add("(select)");
+ var allExtensions
+ = ReflectionHelpers.GetTypesInAllLoadedAssemblies(
+ (Type t) => t.IsSubclassOf(typeof(CinemachineExtension)));
+ foreach (Type t in allExtensions)
+ {
+ exts.Add(t);
+ names.Add(t.Name);
+ }
+ sExtensionTypes = exts.ToArray();
+ sExtensionNames = names.ToArray();
+ }
+ }
+
+ protected virtual void OnDisable()
+ {
+ if (CinemachineBrain.SoloCamera == (ICinemachineCamera)Target)
+ {
+ CinemachineBrain.SoloCamera = null;
+ UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
+ }
+ }
+
+ public override void OnInspectorGUI()
+ {
+ BeginInspector();
+ DrawHeaderInInspector();
+ DrawRemainingPropertiesInInspector();
+ DrawExtensionsWidgetInInspector();
+ }
+
+ protected void DrawHeaderInInspector()
+ {
+ List<string> excluded = GetExcludedPropertiesInInspector();
+ if (!excluded.Contains("Header"))
+ {
+ DrawCameraStatusInInspector();
+ DrawGlobalControlsInInspector();
+ }
+ ExcludeProperty("Header");
+ }
+
+ protected void DrawTargetsInInspector(
+ SerializedProperty followTarget, SerializedProperty lookAtTarget)
+ {
+ List<string> excluded = GetExcludedPropertiesInInspector();
+ EditorGUI.BeginChangeCheck();
+ if (!excluded.Contains(followTarget.name))
+ {
+ if (Target.ParentCamera == null || Target.ParentCamera.Follow == null)
+ EditorGUILayout.PropertyField(followTarget);
+ else
+ EditorGUILayout.PropertyField(followTarget,
+ new GUIContent(followTarget.displayName + " Override"));
+ ExcludeProperty(followTarget.name);
+ }
+ if (!excluded.Contains(lookAtTarget.name))
+ {
+ if (Target.ParentCamera == null || Target.ParentCamera.LookAt == null)
+ EditorGUILayout.PropertyField(lookAtTarget);
+ else
+ EditorGUILayout.PropertyField(lookAtTarget,
+ new GUIContent(lookAtTarget.displayName + " Override"));
+ ExcludeProperty(lookAtTarget.name);
+ }
+ if (EditorGUI.EndChangeCheck())
+ serializedObject.ApplyModifiedProperties();
+ }
+
+ protected void DrawExtensionsWidgetInInspector()
+ {
+ List<string> excluded = GetExcludedPropertiesInInspector();
+ if (!excluded.Contains("Extensions"))
+ {
+ EditorGUILayout.Space();
+ EditorGUILayout.LabelField("Extensions", EditorStyles.boldLabel);
+ Rect rect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight);
+ rect = EditorGUI.PrefixLabel(rect, new GUIContent("Add Extension"));
+
+ int selection = EditorGUI.Popup(rect, 0, sExtensionNames);
+ if (selection > 0)
+ {
+ Type extType = sExtensionTypes[selection];
+ if (Target.GetComponent(extType) == null)
+ Undo.AddComponent(Target.gameObject, extType);
+ }
+ ExcludeProperty("Extensions");
+ }
+ }
+
+ protected void DrawCameraStatusInInspector()
+ {
+ // Is the camera navel-gazing?
+ CameraState state = Target.State;
+ if (state.HasLookAt && (state.ReferenceLookAt - state.CorrectedPosition).AlmostZero())
+ EditorGUILayout.HelpBox(
+ "The camera is positioned on the same point at which it is trying to look.",
+ MessageType.Warning);
+
+ // Active status and Solo button
+ Rect rect = EditorGUILayout.GetControlRect(true);
+ Rect rectLabel = new Rect(rect.x, rect.y, EditorGUIUtility.labelWidth, rect.height);
+ rect.width -= rectLabel.width;
+ rect.x += rectLabel.width;
+
+ Color color = GUI.color;
+ bool isSolo = (CinemachineBrain.SoloCamera == (ICinemachineCamera)Target);
+ if (isSolo)
+ GUI.color = CinemachineBrain.GetSoloGUIColor();
+
+ bool isLive = CinemachineCore.Instance.IsLive(Target);
+ GUI.enabled = isLive;
+ GUI.Label(rectLabel, isLive ? "Status: Live"
+ : (Target.isActiveAndEnabled ? "Status: Standby" : "Status: Disabled"));
+ GUI.enabled = true;
+
+ float labelWidth = 0;
+ GUIContent updateText = GUIContent.none;
+ CinemachineCore.UpdateFilter updateMode = CinemachineCore.Instance.GetVcamUpdateStatus(Target);
+ if (Application.isPlaying)
+ {
+ updateText = new GUIContent(
+ updateMode < CinemachineCore.UpdateFilter.Late ? " Fixed Update" : " Late Update");
+ var textDimensions = GUI.skin.label.CalcSize(updateText);
+ labelWidth = textDimensions.x;
+ }
+ rect.width -= labelWidth;
+ if (GUI.Button(rect, "Solo", "Button"))
+ {
+ isSolo = !isSolo;
+ CinemachineBrain.SoloCamera = isSolo ? Target : null;
+ UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
+ }
+ GUI.color = color;
+ if (isSolo)
+ UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
+
+ if (labelWidth > 0)
+ {
+ GUI.enabled = false;
+ rect.x += rect.width; rect.width = labelWidth;
+ GUI.Label(rect, updateText);
+ GUI.enabled = true;
+ }
+ }
+
+ protected void DrawGlobalControlsInInspector()
+ {
+ CinemachineSettings.CinemachineCoreSettings.ShowInGameGuides
+ = EditorGUILayout.Toggle(
+ new GUIContent(
+ "Game Window Guides",
+ "Enable the display of overlays in the Game window. You can adjust colours and opacity in Edit/Preferences/Cinemachine."),
+ CinemachineSettings.CinemachineCoreSettings.ShowInGameGuides);
+
+ SaveDuringPlay.SaveDuringPlay.Enabled
+ = EditorGUILayout.Toggle(
+ new GUIContent(
+ "Save During Play",
+ "If checked, Virtual Camera settings changes made during Play Mode will be propagated back to the scene when Play Mode is exited."),
+ SaveDuringPlay.SaveDuringPlay.Enabled);
+
+ if (Application.isPlaying && SaveDuringPlay.SaveDuringPlay.Enabled)
+ EditorGUILayout.HelpBox(
+ " Virtual Camera settings changes made during Play Mode will be propagated back to the scene when Play Mode is exited.",
+ MessageType.Info);
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineVirtualCameraBaseEditor.cs.meta b/Assets/Cinemachine/Base/Editor/Editors/CinemachineVirtualCameraBaseEditor.cs.meta
new file mode 100644
index 0000000..b7912b7
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineVirtualCameraBaseEditor.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 211d719bb25901043833928f50e9d0ea
+timeCreated: 1506603196
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineVirtualCameraEditor.cs b/Assets/Cinemachine/Base/Editor/Editors/CinemachineVirtualCameraEditor.cs
new file mode 100644
index 0000000..b9f6385
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineVirtualCameraEditor.cs
@@ -0,0 +1,432 @@
+using UnityEngine;
+using UnityEditor;
+using System;
+using System.Collections.Generic;
+using Cinemachine.Utility;
+using System.Reflection;
+
+namespace Cinemachine.Editor
+{
+ [CustomEditor(typeof(CinemachineVirtualCamera))]
+ internal class CinemachineVirtualCameraEditor
+ : CinemachineVirtualCameraBaseEditor<CinemachineVirtualCamera>
+ {
+ // Static state and caches - Call UpdateStaticData() to refresh this
+ struct StageData
+ {
+ string ExpandedKey { get { return "CNMCN_Core_Vcam_Expanded_" + Name; } }
+ public bool IsExpanded
+ {
+ get { return EditorPrefs.GetBool(ExpandedKey, false); }
+ set { EditorPrefs.SetBool(ExpandedKey, value); }
+ }
+ public string Name;
+ public Type[] types; // first entry is null
+ public GUIContent[] PopupOptions;
+ }
+ static StageData[] sStageData = null;
+
+ // Instance data - call UpdateInstanceData() to refresh this
+ int[] m_stageState = null;
+ bool[] m_stageError = null;
+ CinemachineComponentBase[] m_components;
+ UnityEditor.Editor[] m_componentEditors;
+
+ protected override void OnEnable()
+ {
+ // Build static menu arrays via reflection
+ base.OnEnable();
+ UpdateStaticData();
+ }
+
+ protected override void OnDisable()
+ {
+ base.OnDisable();
+ // Must destroy editors or we get exceptions
+ if (m_componentEditors != null)
+ foreach (UnityEditor.Editor e in m_componentEditors)
+ if (e != null)
+ UnityEngine.Object.DestroyImmediate(e);
+ }
+
+ Vector3 mPreviousPosition;
+ private void OnSceneGUI()
+ {
+ if (!Target.UserIsDragging)
+ mPreviousPosition = Target.transform.position;
+ if (Selection.Contains(Target.gameObject) && Tools.current == Tool.Move
+ && Event.current.type == EventType.MouseDrag)
+ {
+ // User might be dragging our position handle
+ Target.UserIsDragging = true;
+ Vector3 delta = Target.transform.position - mPreviousPosition;
+ if (!delta.AlmostZero())
+ {
+ Undo.RegisterFullObjectHierarchyUndo(Target.gameObject, "Camera drag");
+ Target.OnPositionDragged(delta);
+ mPreviousPosition = Target.transform.position;
+ }
+ }
+ else if (GUIUtility.hotControl == 0 && Target.UserIsDragging)
+ {
+ // We're not dragging anything now, but we were
+ UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
+ Target.UserIsDragging = false;
+ }
+ }
+
+ public override void OnInspectorGUI()
+ {
+ BeginInspector();
+ DrawHeaderInInspector();
+ DrawPropertyInInspector(FindProperty(x => x.m_Priority));
+ DrawTargetsInInspector(FindProperty(x => x.m_Follow), FindProperty(x => x.m_LookAt));
+ DrawRemainingPropertiesInInspector();
+ DrawPipelineInInspector();
+ DrawExtensionsWidgetInInspector();
+ }
+
+ protected void DrawPipelineInInspector()
+ {
+ UpdateInstanceData();
+ foreach (CinemachineCore.Stage stage in Enum.GetValues(typeof(CinemachineCore.Stage)))
+ {
+ int index = (int)stage;
+
+ // Skip pipeline stages that have no implementations
+ if (sStageData[index].PopupOptions.Length <= 1)
+ continue;
+
+ const float indentOffset = 6;
+
+ GUIStyle stageBoxStyle = GUI.skin.box;
+ EditorGUILayout.BeginVertical(stageBoxStyle);
+ Rect rect = EditorGUILayout.GetControlRect(true);
+
+ // Don't use PrefixLabel() because it will link the enabled status of field and label
+ GUIContent label = new GUIContent(NicifyName(stage.ToString()));
+ if (m_stageError[index])
+ label.image = EditorGUIUtility.IconContent("console.warnicon.sml").image;
+ float labelWidth = EditorGUIUtility.labelWidth - (indentOffset + EditorGUI.indentLevel * 15);
+ Rect r = rect; r.width = labelWidth;
+ EditorGUI.LabelField(r, label);
+ r = rect; r.width -= labelWidth; r.x += labelWidth;
+ GUI.enabled = !StageIsLocked(stage);
+ int newSelection = EditorGUI.Popup(r, m_stageState[index], sStageData[index].PopupOptions);
+ GUI.enabled = true;
+
+ Type type = sStageData[index].types[newSelection];
+ if (newSelection != m_stageState[index])
+ {
+ SetPipelineStage(stage, type);
+ if (newSelection != 0)
+ sStageData[index].IsExpanded = true;
+ UpdateInstanceData(); // because we changed it
+ return;
+ }
+ if (type != null)
+ {
+ Rect stageRect = new Rect(
+ rect.x - indentOffset, rect.y, rect.width + indentOffset, rect.height);
+ sStageData[index].IsExpanded = EditorGUI.Foldout(
+ stageRect, sStageData[index].IsExpanded, GUIContent.none);
+ if (sStageData[index].IsExpanded)
+ {
+ // Make the editor for that stage
+ UnityEditor.Editor e = GetEditorForPipelineStage(stage);
+ if (e != null)
+ {
+ ++EditorGUI.indentLevel;
+ EditorGUILayout.Separator();
+ e.OnInspectorGUI();
+ EditorGUILayout.Separator();
+ --EditorGUI.indentLevel;
+ }
+ }
+ }
+ EditorGUILayout.EndVertical();
+ }
+ }
+
+ bool StageIsLocked(CinemachineCore.Stage stage)
+ {
+ CinemachineCore.Stage[] locked = Target.m_LockStageInInspector;
+ if (locked != null)
+ for (int i = 0; i < locked.Length; ++i)
+ if (locked[i] == stage)
+ return true;
+ return false;
+ }
+
+ UnityEditor.Editor GetEditorForPipelineStage(CinemachineCore.Stage stage)
+ {
+ foreach (UnityEditor.Editor e in m_componentEditors)
+ {
+ if (e != null)
+ {
+ CinemachineComponentBase c = e.target as CinemachineComponentBase;
+ if (c != null && c.Stage == stage)
+ return e;
+ }
+ }
+ return null;
+ }
+
+ /// <summary>
+ /// Register with CinemachineVirtualCamera to create the pipeline in an undo-friendly manner
+ /// </summary>
+ [InitializeOnLoad]
+ class CreatePipelineWithUndo
+ {
+ static CreatePipelineWithUndo()
+ {
+ CinemachineVirtualCamera.CreatePipelineOverride =
+ (CinemachineVirtualCamera vcam, string name, CinemachineComponentBase[] copyFrom) =>
+ {
+ // Create a new pipeline
+ GameObject go = new GameObject(name);
+ Undo.RegisterCreatedObjectUndo(go, "created pipeline");
+ Undo.SetTransformParent(go.transform, vcam.transform, "parenting pipeline");
+ Undo.AddComponent<CinemachinePipeline>(go);
+
+ // If copying, transfer the components
+ if (copyFrom != null)
+ {
+ foreach (Component c in copyFrom)
+ {
+ Component copy = Undo.AddComponent(go, c.GetType());
+ Undo.RecordObject(copy, "copying pipeline");
+ ReflectionHelpers.CopyFields(c, copy);
+ }
+ }
+ return go.transform;
+ };
+ CinemachineVirtualCamera.DestroyPipelineOverride = (GameObject pipeline) =>
+ {
+ Undo.DestroyObjectImmediate(pipeline);
+ };
+ }
+ }
+
+ void SetPipelineStage(CinemachineCore.Stage stage, Type type)
+ {
+ Undo.SetCurrentGroupName("Cinemachine pipeline change");
+
+ // Get the existing components
+ Transform owner = Target.GetComponentOwner();
+
+ CinemachineComponentBase[] components = owner.GetComponents<CinemachineComponentBase>();
+ if (components == null)
+ components = new CinemachineComponentBase[0];
+
+ // Find an appropriate insertion point
+ int numComponents = components.Length;
+ int insertPoint = 0;
+ for (insertPoint = 0; insertPoint < numComponents; ++insertPoint)
+ if (components[insertPoint].Stage >= stage)
+ break;
+
+ // Remove the existing components at that stage
+ for (int i = numComponents - 1; i >= 0; --i)
+ {
+ if (components[i].Stage == stage)
+ {
+ Undo.DestroyObjectImmediate(components[i]);
+ components[i] = null;
+ --numComponents;
+ if (i < insertPoint)
+ --insertPoint;
+ }
+ }
+
+ // Add the new stage
+ if (type != null)
+ {
+ MonoBehaviour b = Undo.AddComponent(owner.gameObject, type) as MonoBehaviour;
+ while (numComponents-- > insertPoint)
+ UnityEditorInternal.ComponentUtility.MoveComponentDown(b);
+ }
+ }
+
+ // This code dynamically discovers eligible classes and builds the menu
+ // data for the various component pipeline stages.
+ void UpdateStaticData()
+ {
+ if (sStageData != null)
+ return;
+ sStageData = new StageData[Enum.GetValues(typeof(CinemachineCore.Stage)).Length];
+
+ var stageTypes = new List<Type>[Enum.GetValues(typeof(CinemachineCore.Stage)).Length];
+ for (int i = 0; i < stageTypes.Length; ++i)
+ {
+ sStageData[i].Name = ((CinemachineCore.Stage)i).ToString();
+ stageTypes[i] = new List<Type>();
+ }
+
+ // Get all ICinemachineComponents
+ var allTypes
+ = ReflectionHelpers.GetTypesInAllLoadedAssemblies(
+ (Type t) => t.IsSubclassOf(typeof(CinemachineComponentBase)));
+
+ // Create a temp game object so we can instance behaviours
+ GameObject go = new GameObject("Cinemachine Temp Object");
+ go.hideFlags = HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor;
+ foreach (Type t in allTypes)
+ {
+ MonoBehaviour b = go.AddComponent(t) as MonoBehaviour;
+ CinemachineComponentBase c = b != null ? (CinemachineComponentBase)b : null;
+ if (c != null)
+ {
+ CinemachineCore.Stage stage = c.Stage;
+ stageTypes[(int)stage].Add(t);
+ }
+ }
+ GameObject.DestroyImmediate(go);
+
+ // Create the static lists
+ for (int i = 0; i < stageTypes.Length; ++i)
+ {
+ stageTypes[i].Insert(0, null); // first item is "none"
+ sStageData[i].types = stageTypes[i].ToArray();
+ GUIContent[] names = new GUIContent[sStageData[i].types.Length];
+ for (int n = 0; n < names.Length; ++n)
+ {
+ if (n == 0)
+ {
+ bool useSimple
+ = (i == (int)CinemachineCore.Stage.Aim)
+ || (i == (int)CinemachineCore.Stage.Body);
+ names[n] = new GUIContent((useSimple) ? "Do nothing" : "none");
+ }
+ else
+ names[n] = new GUIContent(NicifyName(sStageData[i].types[n].Name));
+ }
+ sStageData[i].PopupOptions = names;
+ }
+ }
+
+ string NicifyName(string name)
+ {
+ if (name.StartsWith("Cinemachine"))
+ name = name.Substring(11); // Trim the prefix
+ return ObjectNames.NicifyVariableName(name);
+ }
+
+ void UpdateInstanceData()
+ {
+ // Invalidate the target's cache - this is to support Undo
+ Target.InvalidateComponentPipeline();
+ UpdateComponentEditors();
+ UpdateStageState(m_components);
+ }
+
+ // This code dynamically builds editors for the pipeline components.
+ // Expansion state is cached statically to preserve foldout state.
+ void UpdateComponentEditors()
+ {
+ CinemachineComponentBase[] components = Target.GetComponentPipeline();
+ int numComponents = components != null ? components.Length : 0;
+ if (m_components == null || m_components.Length != numComponents)
+ m_components = new CinemachineComponentBase[numComponents];
+ bool dirty = (numComponents == 0);
+ for (int i = 0; i < numComponents; ++i)
+ {
+ if (components[i] != m_components[i])
+ {
+ dirty = true;
+ m_components[i] = components[i];
+ }
+ }
+ if (dirty)
+ {
+ // Destroy the subeditors
+ if (m_componentEditors != null)
+ foreach (UnityEditor.Editor e in m_componentEditors)
+ if (e != null)
+ UnityEngine.Object.DestroyImmediate(e);
+
+ // Create new editors
+ m_componentEditors = new UnityEditor.Editor[numComponents];
+ for (int i = 0; i < numComponents; ++i)
+ {
+ MonoBehaviour b = components[i] as MonoBehaviour;
+ if (b != null)
+ CreateCachedEditor(b, null, ref m_componentEditors[i]);
+ }
+ }
+ }
+
+ void UpdateStageState(CinemachineComponentBase[] components)
+ {
+ m_stageState = new int[Enum.GetValues(typeof(CinemachineCore.Stage)).Length];
+ m_stageError = new bool[Enum.GetValues(typeof(CinemachineCore.Stage)).Length];
+ foreach (var c in components)
+ {
+ CinemachineCore.Stage stage = c.Stage;
+ int index = 0;
+ for (index = sStageData[(int)stage].types.Length - 1; index > 0; --index)
+ if (sStageData[(int)stage].types[index] == c.GetType())
+ break;
+ m_stageState[(int)stage] = index;
+ m_stageError[(int)stage] = !c.IsValid;
+ }
+ }
+
+ // Because the cinemachine components are attached to hidden objects, their
+ // gizmos don't get drawn by default. We have to do it explicitly.
+ [InitializeOnLoad]
+ static class CollectGizmoDrawers
+ {
+ static CollectGizmoDrawers()
+ {
+ m_GizmoDrawers = new Dictionary<Type, MethodInfo>();
+ Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
+ foreach (Assembly assembly in assemblies)
+ {
+ foreach (var type in assembly.GetTypes())
+ {
+ try
+ {
+ bool added = false;
+ foreach (var method in type.GetMethods(
+ BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static))
+ {
+ if (added)
+ break;
+ if (!method.IsStatic)
+ continue;
+ var attributes = method.GetCustomAttributes(typeof(DrawGizmo), true) as DrawGizmo[];
+ foreach (var a in attributes)
+ {
+ if (typeof(CinemachineComponentBase).IsAssignableFrom(a.drawnType))
+ {
+ m_GizmoDrawers.Add(a.drawnType, method);
+ added = true;
+ break;
+ }
+ }
+ }
+ }
+ catch (System.Exception)
+ {
+ // screw it
+ }
+ }
+ }
+ }
+ public static Dictionary<Type, MethodInfo> m_GizmoDrawers;
+ }
+
+ [DrawGizmo(GizmoType.Active | GizmoType.InSelectionHierarchy, typeof(CinemachineVirtualCamera))]
+ internal static void DrawVirtualCameraGizmos(CinemachineVirtualCamera vcam, GizmoType selectionType)
+ {
+ var pipeline = vcam.GetComponentPipeline();
+ foreach (var c in pipeline)
+ {
+ MethodInfo method;
+ if (CollectGizmoDrawers.m_GizmoDrawers.TryGetValue(c.GetType(), out method))
+ method.Invoke(null, new object[] { c, selectionType });
+ }
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Editors/CinemachineVirtualCameraEditor.cs.meta b/Assets/Cinemachine/Base/Editor/Editors/CinemachineVirtualCameraEditor.cs.meta
new file mode 100644
index 0000000..52f5ed5
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Editors/CinemachineVirtualCameraEditor.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: a63f9f2267c36684e855add13ad5499f
+timeCreated: 1483391371
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Menus.meta b/Assets/Cinemachine/Base/Editor/Menus.meta
new file mode 100644
index 0000000..6d7d2a1
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Menus.meta
@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: d093acf2bada69e4bbbcf0a8b4534919
+folderAsset: yes
+timeCreated: 1489096338
+licenseType: Store
+DefaultImporter:
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Menus/CinemachineMenu.cs b/Assets/Cinemachine/Base/Editor/Menus/CinemachineMenu.cs
new file mode 100644
index 0000000..b44faa8
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Menus/CinemachineMenu.cs
@@ -0,0 +1,248 @@
+using UnityEngine;
+using UnityEditor;
+using System;
+using System.IO;
+
+namespace Cinemachine.Editor
+{
+ public static class CinemachineMenu
+ {
+ public const string kCinemachineRootMenu = "Assets/Create/Cinemachine/";
+ [MenuItem(kCinemachineRootMenu + "Blender/Settings")]
+ private static void CreateBlenderSettingAsset()
+ {
+ ScriptableObjectUtility.Create<CinemachineBlenderSettings>();
+ }
+
+ [MenuItem(kCinemachineRootMenu + "Noise/Settings")]
+ private static void CreateNoiseSettingAsset()
+ {
+ ScriptableObjectUtility.Create<NoiseSettings>();
+ }
+
+ [MenuItem("Cinemachine/Create Virtual Camera", false, 1)]
+ public static CinemachineVirtualCamera CreateVirtualCamera()
+ {
+ return InternalCreateVirtualCamera(
+ "CM vcam", true, typeof(CinemachineComposer), typeof(CinemachineTransposer));
+ }
+
+ [MenuItem("Cinemachine/Create FreeLook Camera", false, 1)]
+ private static void CreateFreeLookCamera()
+ {
+ CreateCameraBrainIfAbsent();
+ GameObject go = new GameObject(
+ GenerateUniqueObjectName(typeof(CinemachineFreeLook), "CM FreeLook"));
+ Undo.RegisterCreatedObjectUndo(go, "create FreeLook");
+ Undo.AddComponent<CinemachineFreeLook>(go);
+ Selection.activeGameObject = go;
+ }
+
+ [MenuItem("Cinemachine/Create Blend List Camera", false, 1)]
+ private static void CreateBlendListCamera()
+ {
+ CreateCameraBrainIfAbsent();
+ GameObject go = new GameObject(
+ GenerateUniqueObjectName(typeof(CinemachineBlendListCamera), "CM BlendListCamera"));
+ Undo.RegisterCreatedObjectUndo(go, "create Blend List camera");
+ var vcam = Undo.AddComponent<CinemachineBlendListCamera>(go);
+ Selection.activeGameObject = go;
+
+ // Give it a couple of children
+ var child1 = CreateDefaultVirtualCamera();
+ Undo.SetTransformParent(child1.transform, go.transform, "create BlendListCam child");
+ var child2 = CreateDefaultVirtualCamera();
+ child2.m_Lens.FieldOfView = 10;
+ Undo.SetTransformParent(child2.transform, go.transform, "create BlendListCam child");
+
+ // Set up initial instruction set
+ vcam.m_Instructions = new CinemachineBlendListCamera.Instruction[2];
+ vcam.m_Instructions[0].m_VirtualCamera = child1;
+ vcam.m_Instructions[0].m_Hold = 1f;
+ vcam.m_Instructions[1].m_VirtualCamera = child2;
+ vcam.m_Instructions[1].m_Blend.m_Style = CinemachineBlendDefinition.Style.EaseInOut;
+ vcam.m_Instructions[1].m_Blend.m_Time = 2f;
+ }
+
+ [MenuItem("Cinemachine/Create State-Driven Camera", false, 1)]
+ private static void CreateStateDivenCamera()
+ {
+ CreateCameraBrainIfAbsent();
+ GameObject go = new GameObject(
+ GenerateUniqueObjectName(typeof(CinemachineStateDrivenCamera), "CM StateDrivenCamera"));
+ Undo.RegisterCreatedObjectUndo(go, "create state driven camera");
+ Undo.AddComponent<CinemachineStateDrivenCamera>(go);
+ Selection.activeGameObject = go;
+
+ // Give it a child
+ Undo.SetTransformParent(CreateDefaultVirtualCamera().transform, go.transform, "create state driven camera");
+ }
+
+ [MenuItem("Cinemachine/Create ClearShot Camera", false, 1)]
+ private static void CreateClearShotVirtualCamera()
+ {
+ CreateCameraBrainIfAbsent();
+ GameObject go = new GameObject(
+ GenerateUniqueObjectName(typeof(CinemachineClearShot), "CM ClearShot"));
+ Undo.RegisterCreatedObjectUndo(go, "create ClearShot camera");
+ Undo.AddComponent<CinemachineClearShot>(go);
+ Selection.activeGameObject = go;
+
+ // Give it a child
+ var child = CreateDefaultVirtualCamera();
+ Undo.SetTransformParent(child.transform, go.transform, "create ClearShot camera");
+ var collider = Undo.AddComponent<CinemachineCollider>(child.gameObject);
+ collider.m_AvoidObstacles = false;
+ Undo.RecordObject(collider, "create ClearShot camera");
+ }
+
+ [MenuItem("Cinemachine/Create Dolly Camera with Track", false, 1)]
+ private static void CreateDollyCameraWithPath()
+ {
+ CinemachineVirtualCamera vcam = InternalCreateVirtualCamera(
+ "CM vcam", true, typeof(CinemachineComposer), typeof(CinemachineTrackedDolly));
+ GameObject go = new GameObject(
+ GenerateUniqueObjectName(typeof(CinemachineSmoothPath), "DollyTrack"));
+ Undo.RegisterCreatedObjectUndo(go, "create track");
+ CinemachineSmoothPath path = Undo.AddComponent<CinemachineSmoothPath>(go);
+ var dolly = vcam.GetCinemachineComponent<CinemachineTrackedDolly>();
+ Undo.RecordObject(dolly, "create track");
+ dolly.m_Path = path;
+ }
+
+ [MenuItem("Cinemachine/Create Target Group Camera", false, 1)]
+ private static void CreateTargetGroupCamera()
+ {
+ CinemachineVirtualCamera vcam = InternalCreateVirtualCamera(
+ "CM vcam", true, typeof(CinemachineGroupComposer), typeof(CinemachineTransposer));
+ GameObject go = new GameObject(
+ GenerateUniqueObjectName(typeof(CinemachineTargetGroup), "TargetGroup"),
+ typeof(CinemachineTargetGroup));
+ Undo.RegisterCreatedObjectUndo(go, "create target group");
+ vcam.LookAt = go.transform;
+ vcam.Follow = go.transform;
+ }
+
+ [MenuItem("Cinemachine/Create Mixing Camera", false, 1)]
+ private static void CreateMixingCamera()
+ {
+ CreateCameraBrainIfAbsent();
+ GameObject go = new GameObject(
+ GenerateUniqueObjectName(typeof(CinemachineMixingCamera), "CM MixingCamera"));
+ Undo.RegisterCreatedObjectUndo(go, "create MixingCamera camera");
+ Undo.AddComponent<CinemachineMixingCamera>(go);
+ Selection.activeGameObject = go;
+
+ // Give it a couple of children
+ Undo.SetTransformParent(CreateDefaultVirtualCamera().transform, go.transform, "create MixedCamera child");
+ Undo.SetTransformParent(CreateDefaultVirtualCamera().transform, go.transform, "create MixingCamera child");
+ }
+
+ [MenuItem("Cinemachine/Create 2D Camera", false, 1)]
+ private static void Create2DCamera()
+ {
+ InternalCreateVirtualCamera("CM vcam", true, typeof(CinemachineFramingTransposer));
+ }
+
+ [MenuItem("Cinemachine/Create Dolly Track with Cart", false, 1)]
+ private static void CreateDollyTrackWithCart()
+ {
+ GameObject go = new GameObject(
+ GenerateUniqueObjectName(typeof(CinemachineSmoothPath), "DollyTrack"));
+ Undo.RegisterCreatedObjectUndo(go, "create track");
+ CinemachineSmoothPath path = Undo.AddComponent<CinemachineSmoothPath>(go);
+ Selection.activeGameObject = go;
+
+ go = new GameObject(GenerateUniqueObjectName(typeof(CinemachineDollyCart), "DollyCart"));
+ Undo.RegisterCreatedObjectUndo(go, "create cart");
+ CinemachineDollyCart cart = Undo.AddComponent<CinemachineDollyCart>(go);
+ Undo.RecordObject(cart, "create track");
+ cart.m_Path = path;
+ }
+
+ [MenuItem("Cinemachine/Import Example Asset Package")]
+ private static void ImportExamplePackage()
+ {
+ string pkgFile = ScriptableObjectUtility.CinemachineInstallPath
+ + "/CinemachineExamples.unitypackage";
+ if (!File.Exists(pkgFile))
+ Debug.LogError("Missing file " + pkgFile);
+ else
+ AssetDatabase.ImportPackage(pkgFile, true);
+ }
+
+ /// <summary>
+ /// Create a default Virtual Camera, with standard components
+ /// </summary>
+ public static CinemachineVirtualCamera CreateDefaultVirtualCamera()
+ {
+ return InternalCreateVirtualCamera(
+ "CM vcam", false, typeof(CinemachineComposer), typeof(CinemachineTransposer));
+ }
+
+ /// <summary>
+ /// Create a Virtual Camera, with components
+ /// </summary>
+ static CinemachineVirtualCamera InternalCreateVirtualCamera(
+ string name, bool selectIt, params Type[] components)
+ {
+ // Create a new virtual camera
+ CreateCameraBrainIfAbsent();
+ GameObject go = new GameObject(
+ GenerateUniqueObjectName(typeof(CinemachineVirtualCamera), name));
+ Undo.RegisterCreatedObjectUndo(go, "create " + name);
+ CinemachineVirtualCamera vcam = Undo.AddComponent<CinemachineVirtualCamera>(go);
+ GameObject componentOwner = vcam.GetComponentOwner().gameObject;
+ foreach (Type t in components)
+ Undo.AddComponent(componentOwner, t);
+ vcam.InvalidateComponentPipeline();
+ if (selectIt)
+ Selection.activeObject = go;
+ return vcam;
+ }
+
+ /// <summary>
+ /// If there is no CinemachineBrain in the scene, try to create one on the main camera
+ /// </summary>
+ public static void CreateCameraBrainIfAbsent()
+ {
+ CinemachineBrain[] brains = UnityEngine.Object.FindObjectsOfType(
+ typeof(CinemachineBrain)) as CinemachineBrain[];
+ if (brains == null || brains.Length == 0)
+ {
+ Camera cam = Camera.main;
+ if (cam == null)
+ {
+ Camera[] cams = UnityEngine.Object.FindObjectsOfType(
+ typeof(Camera)) as Camera[];
+ if (cams != null && cams.Length > 0)
+ cam = cams[0];
+ }
+ if (cam != null)
+ {
+ Undo.AddComponent<CinemachineBrain>(cam.gameObject);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Generate a unique name with the given prefix by adding a suffix to it
+ /// </summary>
+ public static string GenerateUniqueObjectName(Type type, string prefix)
+ {
+ int count = 0;
+ UnityEngine.Object[] all = Resources.FindObjectsOfTypeAll(type);
+ foreach (UnityEngine.Object o in all)
+ {
+ if (o != null && o.name.StartsWith(prefix))
+ {
+ string suffix = o.name.Substring(prefix.Length);
+ int i;
+ if (Int32.TryParse(suffix, out i) && i > count)
+ count = i;
+ }
+ }
+ return prefix + (count + 1);
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Menus/CinemachineMenu.cs.meta b/Assets/Cinemachine/Base/Editor/Menus/CinemachineMenu.cs.meta
new file mode 100644
index 0000000..2248a76
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Menus/CinemachineMenu.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 54b24e51e2a9fa242b38d80ee11f3b2d
+timeCreated: 1481654955
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/PropertyDrawers.meta b/Assets/Cinemachine/Base/Editor/PropertyDrawers.meta
new file mode 100644
index 0000000..17d23b0
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/PropertyDrawers.meta
@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: 31c3ab7d86d07034eb528155d40c016b
+folderAsset: yes
+timeCreated: 1489096338
+licenseType: Store
+DefaultImporter:
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/PropertyDrawers/CinemachineBlendDefinitionPropertyDrawer.cs b/Assets/Cinemachine/Base/Editor/PropertyDrawers/CinemachineBlendDefinitionPropertyDrawer.cs
new file mode 100644
index 0000000..17ac49d
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/PropertyDrawers/CinemachineBlendDefinitionPropertyDrawer.cs
@@ -0,0 +1,38 @@
+using UnityEngine;
+using UnityEditor;
+
+namespace Cinemachine.Editor
+{
+ [CustomPropertyDrawer(typeof(CinemachineBlendDefinitionPropertyAttribute))]
+ public sealed class CinemachineBlendDefinitionPropertyDrawer : PropertyDrawer
+ {
+ CinemachineBlendDefinition myClass = new CinemachineBlendDefinition(); // to access name strings
+ public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
+ {
+ float vSpace = 0;
+ float floatFieldWidth = EditorGUIUtility.singleLineHeight * 2.5f;
+
+ SerializedProperty timeProp = property.FindPropertyRelative(() => myClass.m_Time);
+ GUIContent timeText = new GUIContent(" sec ", timeProp.tooltip);
+ var textDimensions = GUI.skin.label.CalcSize(timeText);
+
+ rect = EditorGUI.PrefixLabel(rect, label);
+
+ rect.y += vSpace; rect.height = EditorGUIUtility.singleLineHeight;
+ rect.width -= floatFieldWidth + textDimensions.x;
+
+ SerializedProperty styleProp = property.FindPropertyRelative(() => myClass.m_Style);
+ EditorGUI.PropertyField(rect, styleProp, GUIContent.none);
+
+ if (styleProp.intValue != (int)CinemachineBlendDefinition.Style.Cut)
+ {
+ float oldWidth = EditorGUIUtility.labelWidth;
+ EditorGUIUtility.labelWidth = textDimensions.x;
+ rect.x += rect.width; rect.width = floatFieldWidth + EditorGUIUtility.labelWidth;
+ EditorGUI.PropertyField(rect, timeProp, timeText);
+ timeProp.floatValue = Mathf.Max(timeProp.floatValue, 0);
+ EditorGUIUtility.labelWidth = oldWidth;
+ }
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/PropertyDrawers/CinemachineBlendDefinitionPropertyDrawer.cs.meta b/Assets/Cinemachine/Base/Editor/PropertyDrawers/CinemachineBlendDefinitionPropertyDrawer.cs.meta
new file mode 100644
index 0000000..2eed780
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/PropertyDrawers/CinemachineBlendDefinitionPropertyDrawer.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 4a9c464b0191f7d4da1d129d97d8240b
+timeCreated: 1486510400
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/PropertyDrawers/CinemachineTagFieldPropertyDrawer.cs b/Assets/Cinemachine/Base/Editor/PropertyDrawers/CinemachineTagFieldPropertyDrawer.cs
new file mode 100644
index 0000000..5fba835
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/PropertyDrawers/CinemachineTagFieldPropertyDrawer.cs
@@ -0,0 +1,28 @@
+using UnityEngine;
+using UnityEditor;
+
+namespace Cinemachine.Editor
+{
+ [CustomPropertyDrawer(typeof(TagFieldAttribute))]
+ public sealed class CinemachineTagFieldPropertyDrawer : PropertyDrawer
+ {
+ public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
+ {
+ const float hSpace = 2;
+ GUIContent clearText = new GUIContent("Clear", "Set the tag to empty");
+ var textDimensions = GUI.skin.button.CalcSize(clearText);
+
+ rect.width -= textDimensions.x + hSpace;
+ string oldValue = property.stringValue;
+ string newValue = EditorGUI.TagField(rect, label, oldValue);
+
+ rect.x += rect.width; rect.width = textDimensions.x;
+ GUI.enabled = oldValue.Length > 0;
+ if (GUI.Button(rect, clearText))
+ newValue = string.Empty;
+ GUI.enabled = true;
+ if (oldValue != newValue)
+ property.stringValue = newValue;
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/PropertyDrawers/CinemachineTagFieldPropertyDrawer.cs.meta b/Assets/Cinemachine/Base/Editor/PropertyDrawers/CinemachineTagFieldPropertyDrawer.cs.meta
new file mode 100644
index 0000000..b2a73ab
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/PropertyDrawers/CinemachineTagFieldPropertyDrawer.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: ed3efd28525441947b55ec9b5d68ba31
+timeCreated: 1510677929
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/PropertyDrawers/GetSetDrawer.cs b/Assets/Cinemachine/Base/Editor/PropertyDrawers/GetSetDrawer.cs
new file mode 100644
index 0000000..8893a81
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/PropertyDrawers/GetSetDrawer.cs
@@ -0,0 +1 @@
+// This file is intentionally blank. \ No newline at end of file
diff --git a/Assets/Cinemachine/Base/Editor/PropertyDrawers/GetSetDrawer.cs.meta b/Assets/Cinemachine/Base/Editor/PropertyDrawers/GetSetDrawer.cs.meta
new file mode 100644
index 0000000..a265654
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/PropertyDrawers/GetSetDrawer.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: e54b95371574a3144b851b0ca93ceb39
+timeCreated: 1493651850
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/PropertyDrawers/LensSettingsPropertyDrawer.cs b/Assets/Cinemachine/Base/Editor/PropertyDrawers/LensSettingsPropertyDrawer.cs
new file mode 100644
index 0000000..d1a5165
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/PropertyDrawers/LensSettingsPropertyDrawer.cs
@@ -0,0 +1,61 @@
+using UnityEngine;
+using UnityEditor;
+using System.Reflection;
+
+namespace Cinemachine.Editor
+{
+ [CustomPropertyDrawer(typeof(LensSettingsPropertyAttribute))]
+ public sealed class LensSettingsPropertyDrawer : PropertyDrawer
+ {
+ const int vSpace = 2;
+ bool mExpanded = true;
+ LensSettings def = new LensSettings(); // to access name strings
+
+ public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
+ {
+ float height = EditorGUIUtility.singleLineHeight;
+ rect.height = height;
+ mExpanded = EditorGUI.Foldout(rect, mExpanded, label);
+ if (mExpanded)
+ {
+ bool ortho = false;
+ PropertyInfo pi = typeof(LensSettings).GetProperty(
+ "Orthographic", BindingFlags.NonPublic | BindingFlags.Instance);
+ if (pi != null)
+ ortho = bool.Equals(true, pi.GetValue(GetPropertyValue(property), null));
+
+ ++EditorGUI.indentLevel;
+ rect.y += height + vSpace;
+ if (ortho)
+ EditorGUI.PropertyField(rect, property.FindPropertyRelative(() => def.OrthographicSize));
+ else
+ EditorGUI.PropertyField(rect, property.FindPropertyRelative(() => def.FieldOfView));
+ rect.y += height + vSpace;
+ EditorGUI.PropertyField(rect, property.FindPropertyRelative(() => def.NearClipPlane));
+ rect.y += height + vSpace;
+ EditorGUI.PropertyField(rect, property.FindPropertyRelative(() => def.FarClipPlane));
+ rect.y += height + vSpace;
+ EditorGUI.PropertyField(rect, property.FindPropertyRelative(() => def.Dutch));
+ --EditorGUI.indentLevel;
+ }
+ }
+
+ object GetPropertyValue(SerializedProperty property)
+ {
+ var targetObject = property.serializedObject.targetObject;
+ var targetObjectClassType = targetObject.GetType();
+ var field = targetObjectClassType.GetField(property.propertyPath);
+ if (field != null)
+ return field.GetValue(targetObject);
+ return null;
+ }
+
+ public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
+ {
+ float height = EditorGUIUtility.singleLineHeight + vSpace;
+ if (mExpanded)
+ height *= 5;
+ return height;
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/PropertyDrawers/LensSettingsPropertyDrawer.cs.meta b/Assets/Cinemachine/Base/Editor/PropertyDrawers/LensSettingsPropertyDrawer.cs.meta
new file mode 100644
index 0000000..2e29f7f
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/PropertyDrawers/LensSettingsPropertyDrawer.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 2449eb616c871d044adce04ac98030a6
+timeCreated: 1496951835
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/PropertyDrawers/MinDrawer.cs b/Assets/Cinemachine/Base/Editor/PropertyDrawers/MinDrawer.cs
new file mode 100644
index 0000000..8893a81
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/PropertyDrawers/MinDrawer.cs
@@ -0,0 +1 @@
+// This file is intentionally blank. \ No newline at end of file
diff --git a/Assets/Cinemachine/Base/Editor/PropertyDrawers/MinDrawer.cs.meta b/Assets/Cinemachine/Base/Editor/PropertyDrawers/MinDrawer.cs.meta
new file mode 100644
index 0000000..66c16e4
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/PropertyDrawers/MinDrawer.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 9d5b46a4a3526d14080bfc4bb247664c
+timeCreated: 1493651850
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Resources.meta b/Assets/Cinemachine/Base/Editor/Resources.meta
new file mode 100644
index 0000000..056f100
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Resources.meta
@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: 99ab3e8b62cb69145b760fc81e2d18d6
+folderAsset: yes
+timeCreated: 1489096338
+licenseType: Store
+DefaultImporter:
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Resources/Cinemachine_header.tif b/Assets/Cinemachine/Base/Editor/Resources/Cinemachine_header.tif
new file mode 100644
index 0000000..1c80e5e
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Resources/Cinemachine_header.tif
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:6455226dac638094e01d4c39ff6cb768b7e70c33b09c0695502a8922e0bce3cf
+size 1166148
diff --git a/Assets/Cinemachine/Base/Editor/Resources/Cinemachine_header.tif.meta b/Assets/Cinemachine/Base/Editor/Resources/Cinemachine_header.tif.meta
new file mode 100644
index 0000000..bedafe7
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Resources/Cinemachine_header.tif.meta
@@ -0,0 +1,74 @@
+fileFormatVersion: 2
+guid: 372fe04232d5ed94d8d71524616c1543
+timeCreated: 1503608963
+licenseType: Store
+TextureImporter:
+ fileIDToRecycleName: {}
+ serializedVersion: 4
+ mipmaps:
+ mipMapMode: 0
+ enableMipMap: 1
+ sRGBTexture: 1
+ linearTexture: 0
+ fadeOut: 0
+ borderMipMap: 0
+ mipMapsPreserveCoverage: 0
+ alphaTestReferenceValue: 0.5
+ mipMapFadeDistanceStart: 1
+ mipMapFadeDistanceEnd: 3
+ bumpmap:
+ convertToNormalMap: 0
+ externalNormalMap: 0
+ heightScale: 0.25
+ normalMapFilter: 0
+ isReadable: 0
+ grayScaleToAlpha: 0
+ generateCubemap: 6
+ cubemapConvolution: 0
+ seamlessCubemap: 0
+ textureFormat: 1
+ maxTextureSize: 2048
+ textureSettings:
+ serializedVersion: 2
+ filterMode: -1
+ aniso: -1
+ mipBias: -1
+ wrapU: -1
+ wrapV: -1
+ wrapW: -1
+ nPOTScale: 1
+ lightmap: 0
+ compressionQuality: 50
+ spriteMode: 0
+ spriteExtrude: 1
+ spriteMeshType: 1
+ alignment: 0
+ spritePivot: {x: 0.5, y: 0.5}
+ spriteBorder: {x: 0, y: 0, z: 0, w: 0}
+ spritePixelsToUnits: 100
+ alphaUsage: 1
+ alphaIsTransparency: 0
+ spriteTessellationDetail: -1
+ textureType: 0
+ textureShape: 1
+ maxTextureSizeSet: 0
+ compressionQualitySet: 0
+ textureFormatSet: 0
+ platformSettings:
+ - buildTarget: DefaultTexturePlatform
+ maxTextureSize: 2048
+ textureFormat: -1
+ textureCompression: 1
+ compressionQuality: 50
+ crunchedCompression: 0
+ allowsAlphaSplitting: 0
+ overridden: 0
+ spriteSheet:
+ serializedVersion: 2
+ sprites: []
+ outline: []
+ physicsShape: []
+ spritePackingTag:
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Resources/cm_logo_sm.png b/Assets/Cinemachine/Base/Editor/Resources/cm_logo_sm.png
new file mode 100644
index 0000000..5ed9234
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Resources/cm_logo_sm.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:3841fa64b887ddf68d6f0175bc8e99dd32637df547bcb174b3e760bd3275f092
+size 66152
diff --git a/Assets/Cinemachine/Base/Editor/Resources/cm_logo_sm.png.meta b/Assets/Cinemachine/Base/Editor/Resources/cm_logo_sm.png.meta
new file mode 100644
index 0000000..4d0d096
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Resources/cm_logo_sm.png.meta
@@ -0,0 +1,82 @@
+fileFormatVersion: 2
+guid: 5f2a108eb023faf43a809979fd3d38f2
+timeCreated: 1481660562
+licenseType: Store
+TextureImporter:
+ fileIDToRecycleName: {}
+ serializedVersion: 4
+ mipmaps:
+ mipMapMode: 1
+ enableMipMap: 1
+ sRGBTexture: 1
+ linearTexture: 0
+ fadeOut: 0
+ borderMipMap: 0
+ mipMapsPreserveCoverage: 0
+ alphaTestReferenceValue: 0.5
+ mipMapFadeDistanceStart: 1
+ mipMapFadeDistanceEnd: 3
+ bumpmap:
+ convertToNormalMap: 0
+ externalNormalMap: 0
+ heightScale: 0.25
+ normalMapFilter: 0
+ isReadable: 0
+ grayScaleToAlpha: 0
+ generateCubemap: 6
+ cubemapConvolution: 0
+ seamlessCubemap: 0
+ textureFormat: 1
+ maxTextureSize: 2048
+ textureSettings:
+ serializedVersion: 2
+ filterMode: -1
+ aniso: -1
+ mipBias: -1
+ wrapU: -1
+ wrapV: -1
+ wrapW: -1
+ nPOTScale: 1
+ lightmap: 0
+ compressionQuality: 50
+ spriteMode: 0
+ spriteExtrude: 1
+ spriteMeshType: 1
+ alignment: 0
+ spritePivot: {x: 0.5, y: 0.5}
+ spriteBorder: {x: 0, y: 0, z: 0, w: 0}
+ spritePixelsToUnits: 100
+ alphaUsage: 1
+ alphaIsTransparency: 0
+ spriteTessellationDetail: -1
+ textureType: 0
+ textureShape: 1
+ maxTextureSizeSet: 0
+ compressionQualitySet: 0
+ textureFormatSet: 0
+ platformSettings:
+ - buildTarget: DefaultTexturePlatform
+ maxTextureSize: 2048
+ textureFormat: -1
+ textureCompression: 1
+ compressionQuality: 50
+ crunchedCompression: 0
+ allowsAlphaSplitting: 0
+ overridden: 0
+ - buildTarget: Standalone
+ maxTextureSize: 2048
+ textureFormat: -1
+ textureCompression: 1
+ compressionQuality: 50
+ crunchedCompression: 0
+ allowsAlphaSplitting: 0
+ overridden: 0
+ spriteSheet:
+ serializedVersion: 2
+ sprites: []
+ outline: []
+ physicsShape: []
+ spritePackingTag:
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Utility.meta b/Assets/Cinemachine/Base/Editor/Utility.meta
new file mode 100644
index 0000000..fcf52c5
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Utility.meta
@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: 29d58ccb958d24942bf23fafcec87c0b
+folderAsset: yes
+timeCreated: 1489096338
+licenseType: Store
+DefaultImporter:
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Utility/BaseEditor.cs b/Assets/Cinemachine/Base/Editor/Utility/BaseEditor.cs
new file mode 100644
index 0000000..88d37ff
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Utility/BaseEditor.cs
@@ -0,0 +1,79 @@
+using UnityEditor;
+using System;
+using System.Collections.Generic;
+using Cinemachine.Utility;
+using System.Linq.Expressions;
+
+namespace Cinemachine.Editor
+{
+ public class BaseEditor<T> : UnityEditor.Editor where T : class
+ {
+ protected T Target { get { return target as T; } }
+
+ protected SerializedProperty FindAndExcludeProperty<TValue>(Expression<Func<T, TValue>> expr)
+ {
+ SerializedProperty p = FindProperty(expr);
+ ExcludeProperty(p.name);
+ return p;
+ }
+
+ protected SerializedProperty FindProperty<TValue>(Expression<Func<T, TValue>> expr)
+ {
+ return serializedObject.FindProperty(FieldPath(expr));
+ }
+
+ protected string FieldPath<TValue>(Expression<Func<T, TValue>> expr)
+ {
+ return ReflectionHelpers.GetFieldPath(expr);
+ }
+
+ protected virtual List<string> GetExcludedPropertiesInInspector()
+ {
+ var excluded = new List<string>() { "m_Script" };
+ if (mAdditionalExcluded != null)
+ excluded.AddRange(mAdditionalExcluded);
+ return excluded;
+ }
+
+ List<string> mAdditionalExcluded;
+ protected void ExcludeProperty(string propertyName)
+ {
+ if (mAdditionalExcluded == null)
+ mAdditionalExcluded = new List<string>();
+ mAdditionalExcluded.Add(propertyName);
+ }
+
+ public override void OnInspectorGUI()
+ {
+ BeginInspector();
+ DrawRemainingPropertiesInInspector();
+ }
+
+ protected virtual void BeginInspector()
+ {
+ mAdditionalExcluded = null;
+ serializedObject.Update();
+ }
+
+ protected virtual void DrawPropertyInInspector(SerializedProperty p)
+ {
+ List<string> excluded = GetExcludedPropertiesInInspector();
+ if (!excluded.Contains(p.name))
+ {
+ EditorGUI.BeginChangeCheck();
+ EditorGUILayout.PropertyField(p);
+ if (EditorGUI.EndChangeCheck())
+ serializedObject.ApplyModifiedProperties();
+ ExcludeProperty(p.name);
+ }
+ }
+
+ protected void DrawRemainingPropertiesInInspector()
+ {
+ EditorGUI.BeginChangeCheck();
+ DrawPropertiesExcluding(serializedObject, GetExcludedPropertiesInInspector().ToArray());
+ if (EditorGUI.EndChangeCheck())
+ serializedObject.ApplyModifiedProperties();
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Utility/BaseEditor.cs.meta b/Assets/Cinemachine/Base/Editor/Utility/BaseEditor.cs.meta
new file mode 100644
index 0000000..2878dd7
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Utility/BaseEditor.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 15ef94834d9e4aa44ac8fe619843346b
+timeCreated: 1506620939
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Utility/EmbeddedAssetHelpers.cs b/Assets/Cinemachine/Base/Editor/Utility/EmbeddedAssetHelpers.cs
new file mode 100644
index 0000000..ee99023
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Utility/EmbeddedAssetHelpers.cs
@@ -0,0 +1,177 @@
+using UnityEngine;
+using UnityEditor;
+using System;
+
+namespace Cinemachine.Editor
+{
+ /// <summary>
+ /// Helper for drawing embedded asset editors
+ /// </summary>
+ public class EmbeddeAssetEditor<T> where T : ScriptableObject
+ {
+ /// <summary>
+ /// Create in OnEnable()
+ /// </summary>
+ public EmbeddeAssetEditor(string propertyName, UnityEditor.Editor owner)
+ {
+ m_PropertyName = propertyName;
+ m_Owner = owner;
+ m_DoVersionControlChecks = UnityEditor.VersionControl.Provider.isActive;
+ m_CreateButtonGUIContent = new GUIContent(
+ "Create Asset", "Create a new shared settings asset");
+ }
+
+ /// <summary>
+ /// Called after the asset editor is created, in case it needs
+ /// to be customized
+ /// </summary>
+ public OnCreateEditorDelegate OnCreateEditor;
+ public delegate void OnCreateEditorDelegate(UnityEditor.Editor editor);
+
+ /// <summary>
+ /// Called when the asset being edited was changed by the user.
+ /// </summary>
+ public OnChangedDelegate OnChanged;
+ public delegate void OnChangedDelegate(T obj);
+
+ /// <summary>
+ /// Free the resources in OnDisable()
+ /// </summary>
+ public void OnDisable()
+ {
+ DestroyEditor();
+ m_Owner = null;
+ }
+
+ /// <summary>
+ /// Customize this after creation if you want
+ /// </summary>
+ public GUIContent m_CreateButtonGUIContent;
+
+ private string m_PropertyName;
+ private UnityEditor.Editor m_Editor = null;
+ private UnityEditor.Editor m_Owner = null;
+ private bool m_DoVersionControlChecks = false;
+
+ const int kIndentOffset = 6;
+
+ /// <summary>
+ /// Call this from OnInspectorGUI. Will draw the asset reference field, and
+ /// the embedded editor, or a Create Asset button, if no asset is set.
+ /// </summary>
+ public void DrawEditorCombo(
+ string title, string defaultName, string extension, string message,
+ string showLabel, bool indent)
+ {
+ SerializedProperty property = m_Owner.serializedObject.FindProperty(m_PropertyName);
+ if (m_Editor == null)
+ UpdateEditor();
+ if (m_Editor == null)
+ AssetFieldWithCreateButton(property, title, defaultName, extension, message);
+ else
+ {
+ EditorGUILayout.BeginVertical(GUI.skin.box);
+ Rect rect = EditorGUILayout.GetControlRect(true);
+ rect.height = EditorGUIUtility.singleLineHeight;
+ EditorGUI.BeginChangeCheck();
+ EditorGUI.PropertyField(rect, property);
+ if (EditorGUI.EndChangeCheck())
+ {
+ m_Owner.serializedObject.ApplyModifiedProperties();
+ UpdateEditor();
+ }
+ if (m_Editor != null)
+ {
+ Rect foldoutRect = new Rect(
+ rect.x - kIndentOffset, rect.y, rect.width + kIndentOffset, rect.height);
+ property.isExpanded = EditorGUI.Foldout(
+ foldoutRect, property.isExpanded, GUIContent.none);
+
+ UnityEditor.VersionControl.Asset targetAsset
+ = UnityEditor.VersionControl.Provider.GetAssetByPath(
+ AssetDatabase.GetAssetPath(m_Editor.target));
+ bool isLockedFile = m_DoVersionControlChecks
+ && !targetAsset.IsOneOfStates(new[] {
+ UnityEditor.VersionControl.Asset.States.CheckedOutLocal,
+ UnityEditor.VersionControl.Asset.States.AddedLocal,
+ });
+
+ GUI.enabled = !isLockedFile;
+ if (property.isExpanded)
+ {
+ EditorGUILayout.Separator();
+ EditorGUILayout.HelpBox(
+ "This is a shared asset. Changes made here will apply to all users of this asset.",
+ MessageType.Info);
+ EditorGUI.BeginChangeCheck();
+ if (indent)
+ ++EditorGUI.indentLevel;
+ m_Editor.OnInspectorGUI();
+ if (indent)
+ --EditorGUI.indentLevel;
+ if (EditorGUI.EndChangeCheck() && (OnChanged != null))
+ OnChanged(property.objectReferenceValue as T);
+ }
+ GUI.enabled = true;
+ if (isLockedFile && GUILayout.Button("Check out"))
+ {
+ UnityEditor.VersionControl.Provider.Checkout(
+ targetAsset, UnityEditor.VersionControl.CheckoutMode.Both);
+ }
+ }
+ EditorGUILayout.EndVertical();
+ }
+ }
+
+ private void AssetFieldWithCreateButton(
+ SerializedProperty property,
+ string title, string defaultName, string extension, string message)
+ {
+ EditorGUI.BeginChangeCheck();
+
+ float hSpace = 5;
+ float buttonWidth = GUI.skin.button.CalcSize(m_CreateButtonGUIContent).x;
+ Rect r = EditorGUILayout.GetControlRect(true);
+ r.width -= buttonWidth + hSpace;
+ EditorGUI.PropertyField(r, property);
+ r.x += r.width + hSpace; r.width = buttonWidth;
+ if (GUI.Button(r, m_CreateButtonGUIContent))
+ {
+ string newAssetPath = EditorUtility.SaveFilePanelInProject(
+ title, defaultName, extension, message);
+ if (!string.IsNullOrEmpty(newAssetPath))
+ {
+ T asset = ScriptableObjectUtility.CreateAt<T>(newAssetPath);
+ property.objectReferenceValue = asset;
+ m_Owner.serializedObject.ApplyModifiedProperties();
+ }
+ }
+ if (EditorGUI.EndChangeCheck())
+ {
+ m_Owner.serializedObject.ApplyModifiedProperties();
+ UpdateEditor();
+ }
+ }
+
+ public void DestroyEditor()
+ {
+ if (m_Editor != null)
+ {
+ UnityEngine.Object.DestroyImmediate(m_Editor);
+ m_Editor = null;
+ }
+ }
+
+ public void UpdateEditor()
+ {
+ DestroyEditor();
+ SerializedProperty property = m_Owner.serializedObject.FindProperty(m_PropertyName);
+ if (property.objectReferenceValue != null)
+ {
+ m_Editor = UnityEditor.Editor.CreateEditor(property.objectReferenceValue);
+ if (OnCreateEditor != null)
+ OnCreateEditor(m_Editor);
+ }
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Utility/EmbeddedAssetHelpers.cs.meta b/Assets/Cinemachine/Base/Editor/Utility/EmbeddedAssetHelpers.cs.meta
new file mode 100644
index 0000000..4292865
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Utility/EmbeddedAssetHelpers.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: d30409ab90458e5409807c8b0274ac9c
+timeCreated: 1484084529
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Utility/SaveDuringPlay.cs b/Assets/Cinemachine/Base/Editor/Utility/SaveDuringPlay.cs
new file mode 100644
index 0000000..e298cd7
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Utility/SaveDuringPlay.cs
@@ -0,0 +1,529 @@
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using UnityEditor;
+using UnityEngine;
+
+namespace SaveDuringPlay
+{
+ /// <summary>A collection of tools for finding objects</summary>
+ public static class ObjectTreeUtil
+ {
+ /// <summary>
+ /// Get the full name of an object, travelling up the transform parents to the root.
+ /// </summary>
+ public static string GetFullName(GameObject current)
+ {
+ if (current == null)
+ return "";
+ if (current.transform.parent == null)
+ return "/" + current.name;
+ return GetFullName(current.transform.parent.gameObject) + "/" + current.name;
+ }
+
+ /// <summary>
+ /// Will find the named object, active or inactive, from the full path.
+ /// </summary>
+ public static GameObject FindObjectFromFullName(string fullName, GameObject[] roots)
+ {
+ if (fullName == null || fullName.Length == 0 || roots == null)
+ return null;
+
+ string[] path = fullName.Split('/');
+ if (path.Length < 2) // skip leading '/'
+ return null;
+
+ Transform root = null;
+ for (int i = 0; root == null && i < roots.Length; ++i)
+ if (roots[i].name == path[1])
+ root = roots[i].transform;
+
+ if (root == null)
+ return null;
+
+ for (int i = 2; i < path.Length; ++i) // skip root
+ {
+ bool found = false;
+ for (int c = 0; c < root.childCount; ++c)
+ {
+ Transform child = root.GetChild(c);
+ if (child.name == path[i])
+ {
+ found = true;
+ root = child;
+ break;
+ }
+ }
+ if (!found)
+ return null;
+ }
+ return root.gameObject;
+ }
+
+ /// <summary>Finds all the root objects in a scene, active or not</summary>
+ public static GameObject[] FindAllRootObjectsInScene()
+ {
+ return UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects();
+ }
+
+
+ /// <summary>
+ /// This finds all the behaviours in scene, active or inactive, excluding prefabs
+ /// </summary>
+ public static T[] FindAllBehavioursInScene<T>() where T : MonoBehaviour
+ {
+ List<T> objectsInScene = new List<T>();
+ foreach (T b in Resources.FindObjectsOfTypeAll<T>())
+ {
+ GameObject go = b.gameObject;
+ if (go.hideFlags == HideFlags.NotEditable || go.hideFlags == HideFlags.HideAndDontSave)
+ continue;
+ if (EditorUtility.IsPersistent(go.transform.root.gameObject))
+ continue;
+ objectsInScene.Add(b);
+ }
+ return objectsInScene.ToArray();
+ }
+ }
+
+ class GameObjectFieldScanner
+ {
+ /// <summary>
+ /// Called for each leaf field. Return value should be true if action was taken.
+ /// It will be propagated back to the caller.
+ /// </summary>
+ public OnLeafFieldDelegate OnLeafField;
+ public delegate bool OnLeafFieldDelegate(string fullName, Type type, ref object value);
+
+ /// <summary>
+ /// Called for each field node, if and only if OnLeafField() for it or one
+ /// of its leaves returned true.
+ /// </summary>
+ public OnFieldValueChangedDelegate OnFieldValueChanged;
+ public delegate bool OnFieldValueChangedDelegate(
+ string fullName, FieldInfo fieldInfo, object fieldOwner, object value);
+
+ /// <summary>
+ /// Called for each field, to test whether to proceed with scanning it. Return true to scan.
+ /// </summary>
+ public FilterFieldDelegate FilterField;
+ public delegate bool FilterFieldDelegate(string fullName, FieldInfo fieldInfo);
+
+ /// <summary>
+ /// Which fields will be scanned
+ /// </summary>
+ public BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Instance;
+
+ bool ScanFields(string fullName, Type type, ref object obj)
+ {
+ bool doneSomething = false;
+
+ // Check if it's a complex type
+ bool isLeaf = true;
+ if (obj != null
+ && !type.IsSubclassOf(typeof(Component))
+ && !type.IsSubclassOf(typeof(GameObject)))
+ {
+ // Is it an array?
+ if (type.IsArray)
+ {
+ isLeaf = false;
+ Array array = obj as Array;
+ object arrayLength = array.Length;
+ if (OnLeafField != null && OnLeafField(
+ fullName + ".Length", arrayLength.GetType(), ref arrayLength))
+ {
+ Array newArray = Array.CreateInstance(
+ array.GetType().GetElementType(), Convert.ToInt32(arrayLength));
+ Array.Copy(array, 0, newArray, 0, Math.Min(array.Length, newArray.Length));
+ array = newArray;
+ doneSomething = true;
+ }
+ for (int i = 0; i < array.Length; ++i)
+ {
+ object element = array.GetValue(i);
+ if (ScanFields(fullName + "[" + i + "]", array.GetType().GetElementType(), ref element))
+ {
+ array.SetValue(element, i);
+ doneSomething = true;
+ }
+ }
+ if (doneSomething)
+ obj = array;
+ }
+ else
+ {
+ // Check if it's a complex type
+ FieldInfo[] fields = obj.GetType().GetFields(bindingFlags);
+ if (fields.Length > 0)
+ {
+ isLeaf = false;
+ for (int i = 0; i < fields.Length; ++i)
+ {
+ string name = fullName + "." + fields[i].Name;
+ if (FilterField == null || FilterField(name, fields[i]))
+ {
+ object fieldValue = fields[i].GetValue(obj);
+ if (ScanFields(name, fields[i].FieldType, ref fieldValue))
+ {
+ doneSomething = true;
+ if (OnFieldValueChanged != null)
+ OnFieldValueChanged(name, fields[i], obj, fieldValue);
+ }
+ }
+ }
+ }
+ }
+ }
+ // If it's a leaf field then call the leaf handler
+ if (isLeaf && OnLeafField != null)
+ if (OnLeafField(fullName, type, ref obj))
+ doneSomething = true;
+
+ return doneSomething;
+ }
+
+ public bool ScanFields(string fullName, MonoBehaviour b)
+ {
+ bool doneSomething = false;
+ FieldInfo[] fields = b.GetType().GetFields(bindingFlags);
+ if (fields.Length > 0)
+ {
+ for (int i = 0; i < fields.Length; ++i)
+ {
+ string name = fullName + "." + fields[i].Name;
+ if (FilterField == null || FilterField(name, fields[i]))
+ {
+ object fieldValue = fields[i].GetValue(b);
+ if (ScanFields(name, fields[i].FieldType, ref fieldValue))
+ doneSomething = true;
+
+ // If leaf action was taken, propagate it up to the parent node
+ if (doneSomething && OnFieldValueChanged != null)
+ OnFieldValueChanged(fullName, fields[i], b, fieldValue);
+ }
+ }
+ }
+ return doneSomething;
+ }
+
+ /// <summary>
+ /// Recursively scan the MonoBehaviours of a GameObject and its children.
+ /// For each leaf field found, call the OnFieldValue delegate.
+ /// </summary>
+ public bool ScanFields(GameObject go, string prefix = null)
+ {
+ bool doneSomething = false;
+ if (prefix == null)
+ prefix = "";
+ else if (prefix.Length > 0)
+ prefix += ".";
+
+ MonoBehaviour[] components = go.GetComponents<MonoBehaviour>();
+ for (int i = 0; i < components.Length; ++i)
+ {
+ MonoBehaviour c = components[i];
+ if (c != null && ScanFields(prefix + c.GetType().FullName + i, c))
+ doneSomething = true;
+ }
+ return doneSomething;
+ }
+ };
+
+
+ /// <summary>
+ /// Using reflection, this class scans a GameObject (and optionally its children)
+ /// and records all the field settings. This only works for "nice" field settings
+ /// within MonoBehaviours. Changes to the behaviour stack made between saving
+ /// and restoring will fool this class.
+ /// </summary>
+ class ObjectStateSaver
+ {
+ string mObjectFullPath;
+
+ Dictionary<string, string> mValues = new Dictionary<string, string>();
+
+ /// <summary>
+ /// Recursively collect all the field values in the MonoBehaviours
+ /// owned by this object and its descendants. The values are stored
+ /// in an internal dictionary.
+ /// </summary>
+ public void CollectFieldValues(GameObject go)
+ {
+ mObjectFullPath = ObjectTreeUtil.GetFullName(go);
+ GameObjectFieldScanner scanner = new GameObjectFieldScanner();
+ scanner.FilterField = FilterField;
+ scanner.OnLeafField = (string fullName, Type type, ref object value) =>
+ {
+ // Save the value in the dictionary
+ mValues[fullName] = StringFromLeafObject(value);
+ //Debug.Log(mObjectFullPath + "." + fullName + " = " + mValues[fullName]);
+ return false;
+ };
+ scanner.ScanFields(go);
+ }
+
+ public GameObject FindSavedGameObject(GameObject[] roots)
+ {
+ return ObjectTreeUtil.FindObjectFromFullName(mObjectFullPath, roots);
+ }
+ public string ObjetFullPath { get { return mObjectFullPath; } }
+
+ /// <summary>
+ /// Recursively scan the MonoBehaviours of a GameObject and its children.
+ /// For each field found, look up its value in the internal dictionary.
+ /// If it's present and its value in the dictionary differs from the actual
+ /// value in the game object, Set the GameObject's value using the value
+ /// recorded in the dictionary.
+ /// </summary>
+ public bool PutFieldValues(GameObject go, GameObject[] roots)
+ {
+ GameObjectFieldScanner scanner = new GameObjectFieldScanner();
+ scanner.FilterField = FilterField;
+ scanner.OnLeafField = (string fullName, Type type, ref object value) =>
+ {
+ // Lookup the value in the dictionary
+ string savedValue;
+ if (mValues.TryGetValue(fullName, out savedValue)
+ && StringFromLeafObject(value) != savedValue)
+ {
+ //Debug.Log(mObjectFullPath + "." + fullName + " = " + mValues[fullName]);
+ value = LeafObjectFromString(type, mValues[fullName].Trim(), roots);
+ return true; // changed
+ }
+ return false;
+ };
+ scanner.OnFieldValueChanged = (fullName, fieldInfo, fieldOwner, value) =>
+ {
+ fieldInfo.SetValue(fieldOwner, value);
+ return true;
+ };
+ return scanner.ScanFields(go);
+ }
+
+ /// Ignore fields marked with the [NoSaveDuringPlay] attribute
+ bool FilterField(string fullName, FieldInfo fieldInfo)
+ {
+ var attrs = fieldInfo.GetCustomAttributes(false);
+ foreach (var attr in attrs)
+ if (attr.GetType().Name.Contains("NoSaveDuringPlay"))
+ return false;
+ return true;
+ }
+
+ /// <summary>
+ /// Parse a string to generate an object.
+ /// Only very limited primitive object types are supported.
+ /// Enums, Vectors and most other structures are automatically supported,
+ /// because the reflection system breaks them down into their primitive components.
+ /// You can add more support here, as needed.
+ /// </summary>
+ static object LeafObjectFromString(Type type, string value, GameObject[] roots)
+ {
+ if (type == typeof(Single))
+ return float.Parse(value);
+ if (type == typeof(Double))
+ return double.Parse(value);
+ if (type == typeof(Boolean))
+ return Boolean.Parse(value);
+ if (type == typeof(string))
+ return value;
+ if (type == typeof(Int32))
+ return Int32.Parse(value);
+ if (type == typeof(UInt32))
+ return UInt32.Parse(value);
+ if (type.IsSubclassOf(typeof(Component)))
+ {
+ // Try to find the named game object
+ GameObject go = ObjectTreeUtil.FindObjectFromFullName(value, roots);
+ return (go != null) ? go.GetComponent(type) : null;
+ }
+ if (type.IsSubclassOf(typeof(GameObject)))
+ {
+ // Try to find the named game object
+ return GameObject.Find(value);
+ }
+ return null;
+ }
+
+ static string StringFromLeafObject(object obj)
+ {
+ if (obj == null)
+ return string.Empty;
+
+ if (obj.GetType().IsSubclassOf(typeof(Component)))
+ {
+ Component c = (Component)obj;
+ if (c == null) // Component overrides the == operator, so we have to check
+ return string.Empty;
+ return ObjectTreeUtil.GetFullName(c.gameObject);
+ }
+ if (obj.GetType().IsSubclassOf(typeof(GameObject)))
+ {
+ GameObject go = (GameObject)obj;
+ if (go == null) // GameObject overrides the == operator, so we have to check
+ return string.Empty;
+ return ObjectTreeUtil.GetFullName(go);
+ }
+ return obj.ToString();
+ }
+ };
+
+
+ /// <summary>
+ /// For all registered object types, record their state when exiting Play Mode,
+ /// and restore that state to the objects in the scene. This is a very limited
+ /// implementation which has not been rigorously tested with many objects types.
+ /// It's quite possible that not everything will be saved.
+ ///
+ /// This class is expected to become obsolete when Unity implements this functionality
+ /// in a more general way.
+ ///
+ /// To use this class,
+ /// drop this script into your project, and add the [SaveDuringPlay] attribute to your class.
+ ///
+ /// Note: if you want some specific field in your class NOT to be saved during play,
+ /// add a property attribute whose class name contains the string "NoSaveDuringPlay"
+ /// and the field will not be saved.
+ /// </summary>
+ [InitializeOnLoad]
+ public class SaveDuringPlay
+ {
+ public static string kEnabledKey = "SaveDuringPlay_Enabled";
+ public static bool Enabled
+ {
+ get { return EditorPrefs.GetBool(kEnabledKey, false); }
+ set
+ {
+ if (value != Enabled)
+ {
+ EditorPrefs.SetBool(kEnabledKey, value);
+ }
+ }
+ }
+
+ static SaveDuringPlay()
+ {
+ // Install our callbacks
+#if UNITY_2017_2_OR_NEWER
+ EditorApplication.playModeStateChanged += OnPlayStateChanged;
+#else
+ EditorApplication.update += OnEditorUpdate;
+ EditorApplication.playmodeStateChanged += OnPlayStateChanged;
+#endif
+ }
+
+#if UNITY_2017_2_OR_NEWER
+ static void OnPlayStateChanged(PlayModeStateChange pmsc)
+ {
+ if (Enabled)
+ {
+ // If exiting playmode, collect the state of all interesting objects
+ if (pmsc == PlayModeStateChange.ExitingPlayMode)
+ SaveAllInterestingStates();
+ else if (pmsc == PlayModeStateChange.EnteredEditMode && sSavedStates != null)
+ RestoreAllInterestingStates();
+ }
+ }
+#else
+ static void OnPlayStateChanged()
+ {
+ // If exiting playmode, collect the state of all interesting objects
+ if (Enabled)
+ {
+ if (!EditorApplication.isPlayingOrWillChangePlaymode && EditorApplication.isPlaying)
+ SaveAllInterestingStates();
+ }
+ }
+
+ static float sWaitStartTime = 0;
+ static void OnEditorUpdate()
+ {
+ if (Enabled && sSavedStates != null && !Application.isPlaying)
+ {
+ // Wait a bit for things to settle before applying the saved state
+ const float WaitTime = 1f; // GML todo: is there a better way to do this?
+ float time = Time.realtimeSinceStartup;
+ if (sWaitStartTime == 0)
+ sWaitStartTime = time;
+ else if (time - sWaitStartTime > WaitTime)
+ {
+ RestoreAllInterestingStates();
+ sWaitStartTime = 0;
+ }
+ }
+ }
+#endif
+
+ /// <summary>
+ /// If you need to get notified before state is collected for hotsave, this is the place
+ /// </summary>
+ public static OnHotSaveDelegate OnHotSave;
+ public delegate void OnHotSaveDelegate();
+
+ /// Collect all relevant objects, active or not
+ static Transform[] FindInterestingObjects()
+ {
+ List<Transform> objects = new List<Transform>();
+ MonoBehaviour[] everything = ObjectTreeUtil.FindAllBehavioursInScene<MonoBehaviour>();
+ foreach (var b in everything)
+ {
+ var attrs = b.GetType().GetCustomAttributes(true);
+ foreach (var attr in attrs)
+ {
+ if (attr.GetType().Name.Contains("SaveDuringPlay"))
+ {
+ //Debug.Log("Found " + ObjectTreeUtil.GetFullName(b.gameObject) + " for hot-save");
+ objects.Add(b.transform);
+ break;
+ }
+ }
+ }
+ return objects.ToArray();
+ }
+
+ static List<ObjectStateSaver> sSavedStates = null;
+ static GameObject sSaveStatesGameObject;
+ static void SaveAllInterestingStates()
+ {
+ //Debug.Log("Exiting play mode: Saving state for all interesting objects");
+ if (OnHotSave != null)
+ OnHotSave();
+
+ sSavedStates = new List<ObjectStateSaver>();
+ Transform[] objects = FindInterestingObjects();
+ foreach (Transform obj in objects)
+ {
+ ObjectStateSaver saver = new ObjectStateSaver();
+ saver.CollectFieldValues(obj.gameObject);
+ sSavedStates.Add(saver);
+ }
+ if (sSavedStates.Count == 0)
+ sSavedStates = null;
+ }
+
+ static void RestoreAllInterestingStates()
+ {
+ //Debug.Log("Updating state for all interesting objects");
+ bool dirty = false;
+ GameObject[] roots = ObjectTreeUtil.FindAllRootObjectsInScene();
+ foreach (ObjectStateSaver saver in sSavedStates)
+ {
+ GameObject go = saver.FindSavedGameObject(roots);
+ if (go != null)
+ {
+ Undo.RegisterFullObjectHierarchyUndo(go, "SaveDuringPlay");
+ if (saver.PutFieldValues(go, roots))
+ {
+ //Debug.Log("SaveDuringPlay: updated settings of " + saver.ObjetFullPath);
+ EditorUtility.SetDirty(go);
+ dirty = true;
+ }
+ }
+ }
+ if (dirty)
+ UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
+ sSavedStates = null;
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Utility/SaveDuringPlay.cs.meta b/Assets/Cinemachine/Base/Editor/Utility/SaveDuringPlay.cs.meta
new file mode 100644
index 0000000..6898566
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Utility/SaveDuringPlay.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 24ec24775a1b45e4ea81ac13002dee32
+timeCreated: 1485895820
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Utility/ScriptableObjectUtility.cs b/Assets/Cinemachine/Base/Editor/Utility/ScriptableObjectUtility.cs
new file mode 100644
index 0000000..88dac2c
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Utility/ScriptableObjectUtility.cs
@@ -0,0 +1,160 @@
+using UnityEngine;
+using UnityEditor;
+using System.IO;
+using System.Linq;
+using System;
+
+namespace Cinemachine.Editor
+{
+ public class ScriptableObjectUtility : ScriptableObject
+ {
+ public static string CinemachineInstallPath
+ {
+ get { return Path.GetFullPath(CinemachineInstallAssetPath); }
+ }
+
+ public static string CinemachineInstallAssetPath
+ {
+ get
+ {
+ ScriptableObject dummy = ScriptableObject.CreateInstance<ScriptableObjectUtility>();
+ string path = AssetDatabase.GetAssetPath(MonoScript.FromScriptableObject(dummy));
+ DestroyImmediate(dummy);
+ path = path.Substring(0, path.LastIndexOf("/Base"));
+ return path;
+ }
+ }
+
+ public static bool CinemachineIsPackage
+ {
+ get { return CinemachineInstallAssetPath.StartsWith("Packages"); }
+ }
+
+ public static bool AddDefineForAllBuildTargets(string k_Define)
+ {
+ bool added = false;
+ var targets = Enum.GetValues(typeof(BuildTargetGroup))
+ .Cast<BuildTargetGroup>()
+ .Where(x => x != BuildTargetGroup.Unknown)
+ .Where(x => !BuildTargetIsObsolete(x));
+
+ foreach (var target in targets)
+ {
+ var defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(target).Trim();
+
+ var list = defines.Split(';', ' ')
+ .Where(x => !string.IsNullOrEmpty(x))
+ .ToList();
+
+ if (!list.Contains(k_Define))
+ {
+ list.Add(k_Define);
+ defines = list.Aggregate((a, b) => a + ";" + b);
+
+ PlayerSettings.SetScriptingDefineSymbolsForGroup(target, defines);
+ added = true;
+ }
+ }
+ return added;
+ }
+
+ static bool BuildTargetIsObsolete(BuildTargetGroup group)
+ {
+ var attrs = typeof(BuildTargetGroup)
+ .GetField(group.ToString())
+ .GetCustomAttributes(typeof(ObsoleteAttribute), false);
+
+ return attrs != null && attrs.Length > 0;
+ }
+
+ public static void Create<T>(bool prependFolderName = false, bool trimName = true) where T : ScriptableObject
+ {
+ string className = typeof(T).Name;
+ string assetName = className;
+ string folder = GetSelectedAssetFolder();
+
+ if (trimName)
+ {
+ string[] standardNames = new string[] { "Asset", "Attributes", "Container" };
+ foreach (string standardName in standardNames)
+ {
+ assetName = assetName.Replace(standardName, "");
+ }
+ }
+
+ if (prependFolderName)
+ {
+ string folderName = Path.GetFileName(folder);
+ assetName = (string.IsNullOrEmpty(assetName) ? folderName : string.Format("{0}_{1}", folderName, assetName));
+ }
+
+ Create(className, assetName, folder);
+ }
+
+ public static T CreateAt<T>(string assetPath) where T : ScriptableObject
+ {
+ T asset = ScriptableObject.CreateInstance<T>();
+ if (asset == null)
+ {
+ Debug.LogError("failed to create instance of " + typeof(T).Name);
+ return null;
+ }
+
+ AssetDatabase.CreateAsset(asset, assetPath);
+
+ return asset;
+ }
+
+ private static ScriptableObject Create(string className, string assetName, string folder)
+ {
+ ScriptableObject asset = ScriptableObject.CreateInstance(className);
+ if (asset == null)
+ {
+ Debug.LogError("failed to create instance of " + className);
+ return null;
+ }
+
+ asset.name = assetName ?? className;
+
+ string assetPath = GetUnusedAssetPath(folder, asset.name);
+ AssetDatabase.CreateAsset(asset, assetPath);
+
+ return asset;
+ }
+
+ private static string GetSelectedAssetFolder()
+ {
+ if ((Selection.activeObject != null) && AssetDatabase.Contains(Selection.activeObject))
+ {
+ string assetPath = AssetDatabase.GetAssetPath(Selection.activeObject);
+ string assetPathAbsolute = string.Format("{0}/{1}", Path.GetDirectoryName(Application.dataPath), assetPath);
+
+ if (Directory.Exists(assetPathAbsolute))
+ {
+ return assetPath;
+ }
+ else
+ {
+ return Path.GetDirectoryName(assetPath);
+ }
+ }
+
+ return "Assets";
+ }
+
+ private static string GetUnusedAssetPath(string folder, string assetName)
+ {
+ for (int n = 0; n < 9999; n++)
+ {
+ string assetPath = string.Format("{0}/{1}{2}.asset", folder, assetName, (n == 0 ? "" : n.ToString()));
+ string existingGUID = AssetDatabase.AssetPathToGUID(assetPath);
+ if (string.IsNullOrEmpty(existingGUID))
+ {
+ return assetPath;
+ }
+ }
+
+ return null;
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Utility/ScriptableObjectUtility.cs.meta b/Assets/Cinemachine/Base/Editor/Utility/ScriptableObjectUtility.cs.meta
new file mode 100644
index 0000000..67584e7
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Utility/ScriptableObjectUtility.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: ba59c38a116ff2f4fb69f825ba0da3bc
+timeCreated: 1481654957
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Utility/SerializedPropertyHelper.cs b/Assets/Cinemachine/Base/Editor/Utility/SerializedPropertyHelper.cs
new file mode 100644
index 0000000..e93253e
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Utility/SerializedPropertyHelper.cs
@@ -0,0 +1,59 @@
+using System;
+using System.Linq.Expressions;
+using UnityEditor;
+
+namespace Cinemachine.Editor
+{
+ public static class SerializedPropertyHelper
+ {
+ /// This is a way to get a field name string in such a manner that the compiler will
+ /// generate errors for invalid fields. Much better than directly using strings.
+ /// Usage: instead of
+ /// <example>
+ /// "m_MyField";
+ /// </example>
+ /// do this:
+ /// <example>
+ /// MyClass myclass = null;
+ /// SerializedPropertyHelper.PropertyName( () => myClass.m_MyField);
+ /// </example>
+ public static string PropertyName(Expression<Func<object>> exp)
+ {
+ var body = exp.Body as MemberExpression;
+ if (body == null)
+ {
+ var ubody = (UnaryExpression)exp.Body;
+ body = ubody.Operand as MemberExpression;
+ }
+ return body.Member.Name;
+ }
+
+ /// Usage: instead of
+ /// <example>
+ /// mySerializedObject.FindProperty("m_MyField");
+ /// </example>
+ /// do this:
+ /// <example>
+ /// MyClass myclass = null;
+ /// mySerializedObject.FindProperty( () => myClass.m_MyField);
+ /// </example>
+ public static SerializedProperty FindProperty(this SerializedObject obj, Expression<Func<object>> exp)
+ {
+ return obj.FindProperty(PropertyName(exp));
+ }
+
+ /// Usage: instead of
+ /// <example>
+ /// mySerializedProperty.FindPropertyRelative("m_MyField");
+ /// </example>
+ /// do this:
+ /// <example>
+ /// MyClass myclass = null;
+ /// mySerializedProperty.FindPropertyRelative( () => myClass.m_MyField);
+ /// </example>
+ public static SerializedProperty FindPropertyRelative(this SerializedProperty obj, Expression<Func<object>> exp)
+ {
+ return obj.FindPropertyRelative(PropertyName(exp));
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Utility/SerializedPropertyHelper.cs.meta b/Assets/Cinemachine/Base/Editor/Utility/SerializedPropertyHelper.cs.meta
new file mode 100644
index 0000000..4dd5d65
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Utility/SerializedPropertyHelper.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: a60d9407e2bb20e4ea00281b1e33eae7
+timeCreated: 1488400542
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Windows.meta b/Assets/Cinemachine/Base/Editor/Windows.meta
new file mode 100644
index 0000000..9c6af71
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Windows.meta
@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: 9c644b247df49ee47957d373411a85c3
+folderAsset: yes
+timeCreated: 1489096338
+licenseType: Store
+DefaultImporter:
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Windows/AboutWindow.cs b/Assets/Cinemachine/Base/Editor/Windows/AboutWindow.cs
new file mode 100644
index 0000000..5d43c02
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Windows/AboutWindow.cs
@@ -0,0 +1,149 @@
+using UnityEngine;
+using UnityEditor;
+using System.IO;
+
+namespace Cinemachine.Editor
+{
+ [InitializeOnLoad]
+ public class AboutWindow : EditorWindow
+ {
+ private const string kLastVersionOpened = "CNMCN_Last_Version_Loaded";
+ private const string kInvalidVersionNumber = "0.0";
+
+ private static readonly Vector2 kMinWindowSize = new Vector2(550f, 550f);
+
+ private static string LastVersionLoaded
+ {
+ get { return EditorPrefs.GetString(kLastVersionOpened, kInvalidVersionNumber); }
+ set { EditorPrefs.SetString(kLastVersionOpened, value); }
+ }
+
+ private GUIStyle mButtonStyle;
+ private GUIStyle mLabelStyle;
+ private GUIStyle mHeaderStyle;
+ private GUIStyle mNotesStyle;
+ private Vector2 mReleaseNoteScrollPos = Vector2.zero;
+
+ string mReleaseNotes;
+
+ private void OnEnable()
+ {
+ string path = ScriptableObjectUtility.CinemachineInstallPath + "/ReleaseNotes.txt";
+ try
+ {
+ StreamReader reader = new StreamReader(path);
+ mReleaseNotes = reader.ReadToEnd();
+ reader.Close();
+ }
+ catch (System.Exception)
+ {
+ mReleaseNotes = path + " not found";
+ }
+ }
+
+ private void OnGUI()
+ {
+ if (EditorApplication.isCompiling)
+ {
+ Close();
+ }
+
+ if (mButtonStyle == null)
+ {
+ mButtonStyle = new GUIStyle(GUI.skin.button);
+ mButtonStyle.richText = true;
+ }
+
+ if (mLabelStyle == null)
+ {
+ mLabelStyle = new GUIStyle(EditorStyles.label);
+ mLabelStyle.wordWrap = true;
+ mLabelStyle.richText = true;
+ }
+
+ if (mHeaderStyle == null)
+ {
+ mHeaderStyle = new GUIStyle(EditorStyles.boldLabel);
+ mHeaderStyle.wordWrap = true;
+ }
+
+ if (mNotesStyle == null)
+ {
+ mNotesStyle = new GUIStyle(EditorStyles.textArea);
+ mNotesStyle.richText = true;
+ mNotesStyle.wordWrap = true;
+ }
+
+ using (var vertScope = new EditorGUILayout.VerticalScope())
+ {
+ if (CinemachineSettings.CinemachineHeader != null)
+ {
+ float headerWidth = position.width;
+ float aspectRatio = (float)CinemachineSettings.CinemachineHeader.height / (float)CinemachineSettings.CinemachineHeader.width;
+ GUILayout.BeginScrollView(Vector2.zero, false, false, GUILayout.Width(headerWidth), GUILayout.Height(headerWidth * aspectRatio));
+ Rect texRect = new Rect(0f, 0f, headerWidth, headerWidth * aspectRatio);
+
+ GUILayout.FlexibleSpace();
+ GUILayout.BeginArea(texRect);
+ GUI.DrawTexture(texRect, CinemachineSettings.CinemachineHeader, ScaleMode.ScaleToFit);
+ GUILayout.EndArea();
+ GUILayout.FlexibleSpace();
+
+ GUILayout.EndScrollView();
+ }
+
+ EditorGUILayout.LabelField("Welcome to Cinemachine!", mLabelStyle);
+ EditorGUILayout.LabelField("Smart camera tools for passionate creators.", mLabelStyle);
+ EditorGUILayout.LabelField("Below are links to the forums, please reach out if you have any questions or feedback", mLabelStyle);
+
+ if (GUILayout.Button("<b>Forum</b>\n<i>Discuss</i>", mButtonStyle))
+ {
+ Application.OpenURL("https://forum.unity3d.com/forums/cinemachine.136/");
+ }
+
+ if (GUILayout.Button("<b>Rate it!</b>\nUnity Asset Store", mButtonStyle))
+ {
+ Application.OpenURL("https://www.assetstore.unity3d.com/en/#!/content/79898");
+ }
+
+ if (GUILayout.Button("<b>Documentation</b>\nRead it", mButtonStyle))
+ {
+ string filename = ScriptableObjectUtility.CinemachineInstallPath
+ + "/CINEMACHINE_install.pdf";
+ if (!File.Exists(filename))
+ Debug.LogError("Missing file " + filename);
+ Application.OpenURL("file://" + filename);
+ }
+ }
+
+ EditorGUILayout.LabelField("Release Notes", mHeaderStyle);
+ using (var scrollScope = new EditorGUILayout.ScrollViewScope(mReleaseNoteScrollPos, GUI.skin.box))
+ {
+ mReleaseNoteScrollPos = scrollScope.scrollPosition;
+ EditorGUILayout.LabelField(mReleaseNotes, mNotesStyle);
+ }
+ }
+
+ [MenuItem("Cinemachine/About")]
+ private static void OpenWindow()
+ {
+ EditorApplication.update += ShowWindowDeferred;
+ }
+
+ private static void ShowWindowDeferred()
+ {
+ string loadedVersion = LastVersionLoaded;
+ if (loadedVersion != CinemachineCore.kVersionString)
+ LastVersionLoaded = CinemachineCore.kVersionString;
+
+ AboutWindow window = EditorWindow.GetWindow<AboutWindow>();
+
+ window.titleContent = new UnityEngine.GUIContent(
+ "About", CinemachineSettings.CinemachineLogoTexture);
+ window.minSize = kMinWindowSize;
+ window.Show(true);
+
+ EditorApplication.update -= ShowWindowDeferred;
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Windows/AboutWindow.cs.meta b/Assets/Cinemachine/Base/Editor/Windows/AboutWindow.cs.meta
new file mode 100644
index 0000000..875f6d4
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Windows/AboutWindow.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 829e606f890b35c47aa29643517add2e
+timeCreated: 1481654956
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Windows/CinemachineColliderPrefs.cs b/Assets/Cinemachine/Base/Editor/Windows/CinemachineColliderPrefs.cs
new file mode 100644
index 0000000..4cc881a
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Windows/CinemachineColliderPrefs.cs
@@ -0,0 +1,85 @@
+using UnityEngine;
+using UnityEditor;
+
+using Cinemachine.Editor;
+
+namespace Cinemachine
+{
+ [InitializeOnLoad]
+ internal static class CinemachineColliderPrefs
+ {
+ private static bool SettingsFoldedOut
+ {
+ get { return EditorPrefs.GetBool(kColliderSettingsFoldoutKey, false); }
+ set
+ {
+ if (value != SettingsFoldedOut)
+ {
+ EditorPrefs.SetBool(kColliderSettingsFoldoutKey, value);
+ }
+ }
+ }
+
+ public static Color FeelerHitColor
+ {
+ get
+ {
+ return CinemachineSettings.UnpackColour(EditorPrefs.GetString(kFeelerHitColourKey, CinemachineSettings.PackColor(Color.yellow)));
+ }
+
+ set
+ {
+ if (value != FeelerHitColor)
+ {
+ EditorPrefs.SetString(kFeelerHitColourKey, CinemachineSettings.PackColor(value));
+ }
+ }
+ }
+
+ public static Color FeelerColor
+ {
+ get
+ {
+ return CinemachineSettings.UnpackColour(EditorPrefs.GetString(kFeelerColourKey, CinemachineSettings.PackColor(Color.gray)));
+ }
+
+ set
+ {
+ if (value != FeelerColor)
+ {
+ EditorPrefs.SetString(kFeelerColourKey, CinemachineSettings.PackColor(value));
+ }
+ }
+ }
+
+ private const string kColliderSettingsFoldoutKey = "CNMCN_Collider_Foldout";
+ private const string kFeelerHitColourKey = "CNMCN_Collider_FeelerHit_Colour";
+ private const string kFeelerColourKey = "CNMCN_Collider_Feeler_Colour";
+
+ static CinemachineColliderPrefs()
+ {
+ Cinemachine.Editor.CinemachineSettings.AdditionalCategories += DrawColliderSettings;
+ }
+
+ private static void DrawColliderSettings()
+ {
+ SettingsFoldedOut = EditorGUILayout.Foldout(SettingsFoldedOut, "Collider Settings");
+ if (SettingsFoldedOut)
+ {
+ EditorGUI.indentLevel++;
+
+ EditorGUI.BeginChangeCheck();
+
+ FeelerHitColor = EditorGUILayout.ColorField("Feeler Hit", FeelerHitColor);
+ FeelerColor = EditorGUILayout.ColorField("Feeler", FeelerColor);
+
+ if (EditorGUI.EndChangeCheck())
+ {
+ UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
+ }
+
+ EditorGUI.indentLevel--;
+ }
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Windows/CinemachineColliderPrefs.cs.meta b/Assets/Cinemachine/Base/Editor/Windows/CinemachineColliderPrefs.cs.meta
new file mode 100644
index 0000000..6604557
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Windows/CinemachineColliderPrefs.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: aceb1a3f85f55c249bba6eaade29f2aa
+timeCreated: 1484415513
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/Cinemachine/Base/Editor/Windows/CinemachineSettings.cs b/Assets/Cinemachine/Base/Editor/Windows/CinemachineSettings.cs
new file mode 100644
index 0000000..b382b32
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Windows/CinemachineSettings.cs
@@ -0,0 +1,454 @@
+using UnityEngine;
+using UnityEditor;
+using System;
+
+namespace Cinemachine.Editor
+{
+ [InitializeOnLoad]
+ internal sealed class CinemachineSettings
+ {
+ public static class CinemachineCoreSettings
+ {
+ private static readonly string hShowInGameGuidesKey = "CNMCN_Core_ShowInGameGuides";
+ public static bool ShowInGameGuides
+ {
+ get { return EditorPrefs.GetBool(hShowInGameGuidesKey, true); }
+ set
+ {
+ if (ShowInGameGuides != value)
+ {
+ EditorPrefs.SetBool(hShowInGameGuidesKey, value);
+ UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
+ }
+ }
+ }
+
+ private static readonly string kCoreActiveGizmoColourKey = "CNMCN_Core_Active_Gizmo_Colour";
+ public static readonly Color kDefaultActiveColour = new Color32(255, 0, 0, 100);
+ public static Color ActiveGizmoColour
+ {
+ get
+ {
+ string packedColour = EditorPrefs.GetString(kCoreActiveGizmoColourKey, PackColor(kDefaultActiveColour));
+ return UnpackColour(packedColour);
+ }
+
+ set
+ {
+ if (ActiveGizmoColour != value)
+ {
+ string packedColour = PackColor(value);
+ EditorPrefs.SetString(kCoreActiveGizmoColourKey, packedColour);
+ }
+ }
+ }
+
+ private static readonly string kCoreInactiveGizmoColourKey = "CNMCN_Core_Inactive_Gizmo_Colour";
+ public static readonly Color kDefaultInactiveColour = new Color32(9, 54, 87, 100);
+ public static Color InactiveGizmoColour
+ {
+ get
+ {
+ string packedColour = EditorPrefs.GetString(kCoreInactiveGizmoColourKey, PackColor(kDefaultInactiveColour));
+ return UnpackColour(packedColour);
+ }
+
+ set
+ {
+ if (InactiveGizmoColour != value)
+ {
+ string packedColour = PackColor(value);
+ EditorPrefs.SetString(kCoreInactiveGizmoColourKey, packedColour);
+ }
+ }
+ }
+ }
+
+ public static class ComposerSettings
+ {
+ private static readonly string kOverlayOpacityKey = "CNMCN_Overlay_Opacity";
+ private static readonly string kComposerHardBoundsColourKey = "CNMCN_Composer_HardBounds_Colour";
+ private static readonly string kComposerSoftBoundsColourKey = "CNMCN_Composer_SoftBounds_Colour";
+ private static readonly string kComposerTargetColourKey = "CNMCN_Composer_Target_Colour";
+ private static readonly string kComposerTargetSizeKey = "CNMCN_Composer_Target_Size";
+
+ public const float kDefaultOverlayOpacity = 0.15f;
+ public static readonly Color kDefaultHardBoundsColour = new Color32(255, 0, 72, 255);
+ public static readonly Color kDefaultSoftBoundsColour = new Color32(0, 194, 255, 255);
+ public static readonly Color kDefaultTargetColour = new Color32(255, 254, 25, 255);
+
+ public static float OverlayOpacity
+ {
+ get { return EditorPrefs.GetFloat(kOverlayOpacityKey, kDefaultOverlayOpacity); }
+ set
+ {
+ if (value != OverlayOpacity)
+ {
+ EditorPrefs.SetFloat(kOverlayOpacityKey, value);
+ }
+ }
+ }
+
+ public static Color HardBoundsOverlayColour
+ {
+ get
+ {
+ string packedColour = EditorPrefs.GetString(kComposerHardBoundsColourKey, PackColor(kDefaultHardBoundsColour));
+ return UnpackColour(packedColour);
+ }
+
+ set
+ {
+ if (HardBoundsOverlayColour != value)
+ {
+ string packedColour = PackColor(value);
+ EditorPrefs.SetString(kComposerHardBoundsColourKey, packedColour);
+ }
+ }
+ }
+
+ public static Color SoftBoundsOverlayColour
+ {
+ get
+ {
+ string packedColour = EditorPrefs.GetString(kComposerSoftBoundsColourKey, PackColor(kDefaultSoftBoundsColour));
+ return UnpackColour(packedColour);
+ }
+
+ set
+ {
+ if (SoftBoundsOverlayColour != value)
+ {
+ string packedColour = PackColor(value);
+ EditorPrefs.SetString(kComposerSoftBoundsColourKey, packedColour);
+ }
+ }
+ }
+
+ public static Color TargetColour
+ {
+ get
+ {
+ string packedColour = EditorPrefs.GetString(kComposerTargetColourKey, PackColor(kDefaultTargetColour));
+ return UnpackColour(packedColour);
+ }
+
+ set
+ {
+ if (TargetColour != value)
+ {
+ string packedColour = PackColor(value);
+ EditorPrefs.SetString(kComposerTargetColourKey, packedColour);
+ }
+ }
+ }
+
+ public static float TargetSize
+ {
+ get
+ {
+ return EditorPrefs.GetFloat(kComposerTargetSizeKey, 5f);
+ }
+
+ set
+ {
+ if (TargetSize != value)
+ {
+ EditorPrefs.SetFloat(kComposerTargetSizeKey, value);
+ }
+ }
+ }
+ }
+
+ private static bool ShowCoreSettings
+ {
+ get { return EditorPrefs.GetBool(kCoreSettingsFoldKey, false); }
+ set
+ {
+ if (value != ShowCoreSettings)
+ {
+ EditorPrefs.SetBool(kCoreSettingsFoldKey, value);
+ }
+ }
+ }
+
+ private static bool ShowComposerSettings
+ {
+ get { return EditorPrefs.GetBool(kComposerSettingsFoldKey, false); }
+ set
+ {
+ if (value != ShowComposerSettings)
+ {
+ EditorPrefs.SetBool(kComposerSettingsFoldKey, value);
+ }
+ }
+ }
+
+ private static Texture2D sCinemachineLogoTexture = null;
+ internal static Texture2D CinemachineLogoTexture
+ {
+ get
+ {
+ if (sCinemachineLogoTexture == null)
+ sCinemachineLogoTexture = Resources.Load<Texture2D>("cm_logo_sm");
+ if (sCinemachineLogoTexture != null)
+ sCinemachineLogoTexture.hideFlags = HideFlags.DontSaveInEditor;
+ return sCinemachineLogoTexture;
+ }
+ }
+
+ private static Texture2D sCinemachineHeader = null;
+ internal static Texture2D CinemachineHeader
+ {
+ get
+ {
+ if (sCinemachineHeader == null)
+ sCinemachineHeader = Resources.Load<Texture2D>("cinemachine_header");
+ ;
+ if (sCinemachineHeader != null)
+ sCinemachineHeader.hideFlags = HideFlags.DontSaveInEditor;
+ return sCinemachineHeader;
+ }
+ }
+
+ private static readonly string kCoreSettingsFoldKey = "CNMCN_Core_Folded";
+ private static readonly string kComposerSettingsFoldKey = "CNMCN_Composer_Folded";
+
+ internal static event Action AdditionalCategories = null;
+
+ static CinemachineSettings()
+ {
+ if (CinemachineLogoTexture != null)
+ {
+ EditorApplication.hierarchyWindowItemOnGUI += OnHierarchyGUI;
+ }
+ }
+
+ //private static readonly GUIContent sCoreShowHiddenObjectsToggle = new GUIContent("Show Hidden Objects", "If checked, Cinemachine hidden objects will be shown in the inspector. This might be necessary to repair broken script mappings when upgrading from a pre-release version");
+ private static readonly GUIContent sCoreActiveGizmosColour = new GUIContent("Active Virtual Camera", "The colour for the active virtual camera's gizmos");
+ private static readonly GUIContent sCoreInactiveGizmosColour = new GUIContent("Inactive Virtual Camera", "The colour for all inactive virtual camera gizmos");
+
+ private static readonly GUIContent sComposerOverlayOpacity = new GUIContent("Overlay Opacity", "The alpha of the composer's overlay when a virtual camera is selected with composer module enabled");
+ private static readonly GUIContent sComposerHardBoundsOverlay = new GUIContent("Hard Bounds Overlay", "The colour of the composer overlay's hard bounds region");
+ private static readonly GUIContent sComposerSoftBoundsOverlay = new GUIContent("Soft Bounds Overlay", "The colour of the composer overlay's soft bounds region");
+ private static readonly GUIContent sComposerTargetOverlay = new GUIContent("Composer Target", "The colour of the composer overlay's target");
+ private static readonly GUIContent sComposerTargetOverlayPixels = new GUIContent("Composer Target Size(px)", "The size of the composer overlay's target box in pixels");
+
+ private const string kCinemachineHeaderPath = "cinemachine_header.tif";
+ private const string kCinemachineDocURL = @"http://www.cinemachineimagery.com/documentation/";
+
+ private static Vector2 sScrollPosition = Vector2.zero;
+
+ [PreferenceItem("Cinemachine")]
+ private static void OnGUI()
+ {
+ if (CinemachineHeader != null)
+ {
+ const float kWidth = 350f;
+ float aspectRatio = (float)CinemachineHeader.height / (float)CinemachineHeader.width;
+ GUILayout.BeginScrollView(Vector2.zero, false, false, GUILayout.Width(kWidth), GUILayout.Height(kWidth * aspectRatio));
+ Rect texRect = new Rect(0f, 0f, kWidth, kWidth * aspectRatio);
+
+ GUILayout.BeginArea(texRect);
+ GUI.DrawTexture(texRect, CinemachineHeader, ScaleMode.ScaleToFit);
+ GUILayout.EndArea();
+
+ GUILayout.EndScrollView();
+ }
+
+ sScrollPosition = GUILayout.BeginScrollView(sScrollPosition);
+
+ //CinemachineCore.sShowHiddenObjects
+ // = EditorGUILayout.Toggle("Show Hidden Objects", CinemachineCore.sShowHiddenObjects);
+
+ ShowCoreSettings = EditorGUILayout.Foldout(ShowCoreSettings, "Runtime Settings");
+ if (ShowCoreSettings)
+ {
+ EditorGUI.indentLevel++;
+ EditorGUI.BeginChangeCheck();
+ EditorGUILayout.BeginHorizontal();
+ EditorGUI.BeginChangeCheck();
+ Color newActiveGizmoColour = EditorGUILayout.ColorField(sCoreActiveGizmosColour, CinemachineCoreSettings.ActiveGizmoColour);
+
+ if (EditorGUI.EndChangeCheck())
+ {
+ CinemachineCoreSettings.ActiveGizmoColour = newActiveGizmoColour;
+ UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
+ }
+
+ if (GUILayout.Button("Reset"))
+ {
+ CinemachineCoreSettings.ActiveGizmoColour = CinemachineCoreSettings.kDefaultActiveColour;
+ }
+ EditorGUILayout.EndHorizontal();
+
+ EditorGUILayout.BeginHorizontal();
+ EditorGUI.BeginChangeCheck();
+ Color newInactiveGizmoColour = EditorGUILayout.ColorField(sCoreInactiveGizmosColour, CinemachineCoreSettings.InactiveGizmoColour);
+
+ if (EditorGUI.EndChangeCheck())
+ {
+ CinemachineCoreSettings.InactiveGizmoColour = newInactiveGizmoColour;
+ UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
+ }
+
+ if (GUILayout.Button("Reset"))
+ {
+ CinemachineCoreSettings.InactiveGizmoColour = CinemachineCoreSettings.kDefaultInactiveColour;
+ }
+ EditorGUILayout.EndHorizontal();
+ EditorGUI.indentLevel--;
+ }
+
+ ShowComposerSettings = EditorGUILayout.Foldout(ShowComposerSettings, "Composer Settings");
+ if (ShowComposerSettings)
+ {
+ EditorGUI.indentLevel++;
+ EditorGUILayout.BeginHorizontal();
+ EditorGUI.BeginChangeCheck();
+
+ float overlayOpacity = EditorGUILayout.Slider(sComposerOverlayOpacity, ComposerSettings.OverlayOpacity, 0f, 1f);
+
+ if (EditorGUI.EndChangeCheck())
+ {
+ ComposerSettings.OverlayOpacity = overlayOpacity;
+ }
+
+ if (GUILayout.Button("Reset"))
+ {
+ ComposerSettings.OverlayOpacity = ComposerSettings.kDefaultOverlayOpacity;
+ }
+ EditorGUILayout.EndHorizontal();
+
+ EditorGUILayout.BeginHorizontal();
+ EditorGUI.BeginChangeCheck();
+ Color newHardEdgeColor = EditorGUILayout.ColorField(sComposerHardBoundsOverlay, ComposerSettings.HardBoundsOverlayColour);
+
+ if (EditorGUI.EndChangeCheck())
+ {
+ ComposerSettings.HardBoundsOverlayColour = newHardEdgeColor;
+ }
+
+ if (GUILayout.Button("Reset"))
+ {
+ ComposerSettings.HardBoundsOverlayColour = ComposerSettings.kDefaultHardBoundsColour;
+ }
+ EditorGUILayout.EndHorizontal();
+
+ EditorGUILayout.BeginHorizontal();
+ EditorGUI.BeginChangeCheck();
+ Color newSoftEdgeColor = EditorGUILayout.ColorField(sComposerSoftBoundsOverlay, ComposerSettings.SoftBoundsOverlayColour);
+
+ if (EditorGUI.EndChangeCheck())
+ {
+ ComposerSettings.SoftBoundsOverlayColour = newSoftEdgeColor;
+ }
+
+ if (GUILayout.Button("Reset"))
+ {
+ ComposerSettings.SoftBoundsOverlayColour = ComposerSettings.kDefaultSoftBoundsColour;
+ }
+ EditorGUILayout.EndHorizontal();
+
+ EditorGUILayout.BeginHorizontal();
+ EditorGUI.BeginChangeCheck();
+ Color newTargetColour = EditorGUILayout.ColorField(sComposerTargetOverlay, ComposerSettings.TargetColour);
+
+ if (EditorGUI.EndChangeCheck())
+ {
+ ComposerSettings.TargetColour = newTargetColour;
+ }
+
+ if (GUILayout.Button("Reset"))
+ {
+ ComposerSettings.TargetColour = ComposerSettings.kDefaultTargetColour;
+ }
+ EditorGUILayout.EndHorizontal();
+
+ EditorGUI.BeginChangeCheck();
+ float targetSide = EditorGUILayout.FloatField(sComposerTargetOverlayPixels, ComposerSettings.TargetSize);
+
+ if (EditorGUI.EndChangeCheck())
+ {
+ ComposerSettings.TargetSize = targetSide;
+ }
+ EditorGUI.indentLevel--;
+ }
+
+ if (AdditionalCategories != null)
+ {
+ AdditionalCategories();
+ }
+
+ GUILayout.EndScrollView();
+
+ //if (GUILayout.Button("Open Documentation"))
+ //{
+ // Application.OpenURL(kCinemachineDocURL);
+ //}
+ }
+
+ private static void OnHierarchyGUI(int instanceID, Rect selectionRect)
+ {
+ GameObject instance = EditorUtility.InstanceIDToObject(instanceID) as GameObject;
+ if (instance == null)
+ {
+ // Object in process of being deleted?
+ return;
+ }
+
+ if (instance.GetComponent<CinemachineBrain>() != null)
+ {
+ Rect texRect = new Rect(selectionRect.xMax - selectionRect.height, selectionRect.yMin, selectionRect.height, selectionRect.height);
+ GUI.DrawTexture(texRect, CinemachineLogoTexture, ScaleMode.ScaleAndCrop);
+ }
+ }
+
+ internal static Color UnpackColour(string str)
+ {
+ if (!string.IsNullOrEmpty(str))
+ {
+ byte[] bytes = Base64Decode(str);
+
+ if ((bytes != null) && bytes.Length == 16)
+ {
+ float r = BitConverter.ToSingle(bytes, 0);
+ float g = BitConverter.ToSingle(bytes, 4);
+ float b = BitConverter.ToSingle(bytes, 8);
+ float a = BitConverter.ToSingle(bytes, 12);
+
+ return new Color(r, g, b, a);
+ }
+ }
+
+ return Color.white;
+ }
+
+ internal static string PackColor(Color col)
+ {
+ byte[] bytes = new byte[16];
+
+ byte[] rBytes = BitConverter.GetBytes(col.r);
+ byte[] gBytes = BitConverter.GetBytes(col.g);
+ byte[] bBytes = BitConverter.GetBytes(col.b);
+ byte[] aBytes = BitConverter.GetBytes(col.a);
+
+ Buffer.BlockCopy(rBytes, 0, bytes, 0, 4);
+ Buffer.BlockCopy(gBytes, 0, bytes, 4, 4);
+ Buffer.BlockCopy(bBytes, 0, bytes, 8, 4);
+ Buffer.BlockCopy(aBytes, 0, bytes, 12, 4);
+
+ return Base64Encode(bytes);
+ }
+
+ private static string Base64Encode(byte[] data)
+ {
+ return Convert.ToBase64String(data);
+ }
+
+ private static byte[] Base64Decode(string base64EncodedData)
+ {
+ return Convert.FromBase64String(base64EncodedData);
+ }
+ }
+}
diff --git a/Assets/Cinemachine/Base/Editor/Windows/CinemachineSettings.cs.meta b/Assets/Cinemachine/Base/Editor/Windows/CinemachineSettings.cs.meta
new file mode 100644
index 0000000..aaaafe4
--- /dev/null
+++ b/Assets/Cinemachine/Base/Editor/Windows/CinemachineSettings.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 74d8c4d6e5d0338469ae46c13725f3ce
+timeCreated: 1488314898
+licenseType: Store
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: