Skip to content

Commit

Permalink
Merge branch 'main' into dev/lookAtTargetsOnSpline
Browse files Browse the repository at this point in the history
  • Loading branch information
glabute committed Jun 3, 2024
2 parents d6d4340 + 99eed58 commit fa6c6ad
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 60 deletions.
1 change: 1 addition & 0 deletions com.unity.cinemachine/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Bugfix: InputAxis.TriggerRecentering() function caused the axis to immediately snap to its recenter value.
- Bugfix: When multiple CM Brains were present, FixedUpdte cameras were sometimes being updated too frequently, resulting in jittery motion.
- SimplePlayerController no longer uses PlayerController.isGrounded because it's not reliable outside of FixedUpdate.
- Regression fix: StateDrivenCamera inspector was failing to correctly set the states in the instruction list.
- Decollider ignores terrain layers when resolving obstacles.
- Bugfix: The GroupAverage Rotation Mode in CinemachineTargetGroup was not calculated properly.
- Bugfix: add missing null check in CinemachineTargetGroup.WeightedMemberBoundsForValidMember.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static void DrawBrainGizmos(CinemachineBrain brain, GizmoType drawType)
[DrawGizmo(GizmoType.Active | GizmoType.InSelectionHierarchy | GizmoType.Pickable, typeof(CinemachineVirtualCameraBase))]
public static void DrawVirtualCameraBaseGizmos(CinemachineVirtualCameraBase vcam, GizmoType selectionType)
{
const string kGizmoFileName = CinemachineCore.kPackageRoot + "/Editor/EditorResources/Icons/[email protected]";
const string kGizmoFileName = CinemachineCore.kPackageRoot + "/Editor/EditorResources/Icons/Light/[email protected]";

// Don't draw gizmos on hidden stuff
if ((vcam.gameObject.hideFlags & (HideFlags.HideInHierarchy | HideFlags.HideInInspector)) != 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Unity.Cinemachine.Editor
{
[CanEditMultipleObjects]
[CustomEditor(typeof(CinemachineStateDrivenCamera))]
class CinemachineStateDrivenCameraEditor : UnityEditor.Editor
{
Expand Down Expand Up @@ -106,9 +107,12 @@ public override VisualElement CreateInspectorGUI()
{
if (evt.target == stateSel)
{
var index = stateSel.index;
if (index >= 0 && index < m_TargetStates.Count)
stateSelProp.intValue = index;
var i = stateSel.index;
if (i >= 0 && i < m_TargetStates.Count)
{
stateSelProp.intValue = m_TargetStates[i];
stateSelProp.serializedObject.ApplyModifiedProperties();
}
evt.StopPropagation();
}
});
Expand Down Expand Up @@ -173,8 +177,6 @@ void UpdateCameraDropdowns()
if (vcamSel != null)
{
vcamSel.choices.Clear();
for (int i = 0; i < children.Count; ++i)
Debug.Log($"vcamSelector{index}: {children[i].name}");
for (int i = 0; i < children.Count; ++i)
vcamSel.choices.Add(children[i]);
}
Expand Down Expand Up @@ -237,7 +239,7 @@ void UpdateTargetStates()
while (iter.MoveNext())
parents.Add(new CinemachineStateDrivenCamera.ParentHash
{ Hash = iter.Current.Key, HashOfParent = iter.Current.Value });
Target.HashOfParent = parents.ToArray();
Target.SetParentHash(parents);
}

class StateCollector
Expand Down
23 changes: 11 additions & 12 deletions com.unity.cinemachine/Editor/SaveDuringPlay/SaveDuringPlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,10 @@ public bool ScanFields(GameObject go, string prefix = null)
/// </summary>
class ObjectStateSaver
{
string mObjectFullPath;
string m_ObjectFullPath;
readonly Dictionary<string, string> m_Values = new ();

Dictionary<string, string> mValues = new Dictionary<string, string>();

public string ObjetFullPath => mObjectFullPath;
public string ObjetFullPath => m_ObjectFullPath;

/// <summary>
/// Recursively collect all the field values in the MonoBehaviours
Expand All @@ -321,23 +320,23 @@ class ObjectStateSaver
/// </summary>
public void CollectFieldValues(GameObject go)
{
mObjectFullPath = ObjectTreeUtil.GetFullName(go);
m_ObjectFullPath = ObjectTreeUtil.GetFullName(go);
GameObjectFieldScanner scanner = new ();
scanner.FilterField = FilterField;
scanner.FilterComponent = HasSaveDuringPlay;
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]);
m_Values[fullName] = StringFromLeafObject(value);
//Debug.Log(m_ObjectFullPath + "." + fullName + " = " + m_Values[fullName]);
return false;
};
scanner.ScanFields(go);
}

public GameObject FindSavedGameObject(List<GameObject> roots)
{
return ObjectTreeUtil.FindObjectFromFullName(mObjectFullPath, roots);
return ObjectTreeUtil.FindObjectFromFullName(m_ObjectFullPath, roots);
}

/// <summary>
Expand All @@ -355,11 +354,11 @@ public bool PutFieldValues(GameObject go, List<GameObject> roots)
scanner.OnLeafField = (string fullName, Type type, ref object value) =>
{
// Lookup the value in the dictionary
if (mValues.TryGetValue(fullName, out string savedValue)
if (m_Values.TryGetValue(fullName, out string savedValue)
&& StringFromLeafObject(value) != savedValue)
{
//Debug.Log("Put " + mObjectFullPath + "." + fullName + " = " + mValues[fullName] + " --- was " + StringFromLeafObject(value));
value = LeafObjectFromString(type, mValues[fullName].Trim(), roots);
//Debug.Log("Put " + m_ObjectFullPath + "." + fullName + " = " + m_Values[fullName] + " --- was " + StringFromLeafObject(value));
value = LeafObjectFromString(type, m_Values[fullName].Trim(), roots);
return true; // changed
}
return false;
Expand Down Expand Up @@ -593,7 +592,7 @@ static void RestoreAllInterestingStates()
{
var name = saver.ObjetFullPath;
if (name[0] == '/')
name = name.Substring(1);
name = name[1..];
savedObjects += name + "\n";
}
EditorUtility.SetDirty(go);
Expand Down
3 changes: 1 addition & 2 deletions com.unity.cinemachine/Editor/Windows/CinemachineSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ public static Texture2D CinemachineLogoTexture
get
{
if (s_CinemachineLogoTexture == null)
s_CinemachineLogoTexture = AssetDatabase.LoadAssetAtPath<Texture2D>(
$"{CinemachineCore.kPackageRoot}/Editor/EditorResources/Icons/[email protected]");
s_CinemachineLogoTexture = AssetDatabase.LoadAssetAtPath<Texture2D>($"{CinemachineSceneToolHelpers.IconPath}/[email protected]");
if (s_CinemachineLogoTexture != null)
s_CinemachineLogoTexture.hideFlags = HideFlags.DontSaveInEditor;
return s_CinemachineLogoTexture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,8 @@ public override void OnTransitionFromCamera(
protected override CinemachineVirtualCameraBase ChooseCurrentCamera(Vector3 worldUp, float deltaTime)
{
if (!PreviousStateIsValid)
{
m_CurrentInstruction = -1;
ValidateInstructions();
}

AdvanceCurrentInstruction(deltaTime);
return (m_CurrentInstruction >= 0 && m_CurrentInstruction < Instructions.Count)
? Instructions[m_CurrentInstruction].Camera : null;
Expand All @@ -130,21 +128,11 @@ protected override CinemachineVirtualCameraBase ChooseCurrentCamera(Vector3 worl
protected override CinemachineBlendDefinition LookupBlend(
ICinemachineCamera outgoing, ICinemachineCamera incoming) => Instructions[m_CurrentInstruction].Blend;

/// <summary>Internal API for the inspector editor.</summary>
/// // GML todo: make this private, part of UpdateCameraCache()
internal void ValidateInstructions()
/// <inheritdoc />
protected override bool UpdateCameraCache()
{
Instructions ??= new ();
for (var i = 0; i < Instructions.Count; ++i)
{
if (Instructions[i].Camera != null
&& Instructions[i].Camera.transform.parent != transform)
{
var e = Instructions[i];
e.Camera = null;
Instructions[i] = e;
}
}
return base.UpdateCameraCache();
}

void AdvanceCurrentInstruction(float deltaTime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,14 @@ internal struct ParentHash
public int HashOfParent;
}
/// <summary>Internal API for the Inspector editor</summary>
[HideInInspector][SerializeField] internal ParentHash[] HashOfParent = null;
[HideInInspector][SerializeField] private List<ParentHash> HashOfParent = new();

/// <summary>Internal API for the Inspector editor</summary>
internal void SetParentHash(List<ParentHash> list)
{
HashOfParent.Clear();
HashOfParent.AddRange(list);
}

[SerializeField, HideInInspector, FormerlySerializedAs("m_LookAt")] Transform m_LegacyLookAt;
[SerializeField, HideInInspector, FormerlySerializedAs("m_Follow")] Transform m_LegacyFollow;
Expand Down Expand Up @@ -166,11 +173,6 @@ internal void ValidateInstructions()
m_InstructionDictionary = new Dictionary<int, List<int>>();
for (int i = 0; i < Instructions.Length; ++i)
{
if (Instructions[i].Camera != null
&& Instructions[i].Camera.transform.parent != transform)
{
Instructions[i].Camera = null;
}
if (!m_InstructionDictionary.TryGetValue(Instructions[i].FullHash, out var list))
{
list = new List<int>();
Expand All @@ -181,7 +183,7 @@ internal void ValidateInstructions()

// Create the parent lookup
m_StateParentLookup = new Dictionary<int, int>();
for (int i = 0; HashOfParent != null && i < HashOfParent.Length; ++i)
for (int i = 0; HashOfParent != null && i < HashOfParent.Count; ++i)
m_StateParentLookup[HashOfParent[i].Hash] = HashOfParent[i].HashOfParent;

// Zap the cached current instructions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ MonoBehaviour:
m_Script: {fileID: 19101, guid: 0000000000000000e000000000000000, type: 0}
m_Name: CinemachinePanelSettings
m_EditorClassIdentifier:
themeUss: {fileID: -4733365628477956816, guid: df9aec944f4474a04847b6d6375e4138,
type: 3}
themeUss: {fileID: -4733365628477956816, guid: df9aec944f4474a04847b6d6375e4138, type: 3}
m_TargetTexture: {fileID: 0}
m_RenderMode: 0
m_WorldSpaceLayer: 0
Expand Down
7 changes: 2 additions & 5 deletions com.unity.cinemachine/Runtime/Deprecated/AxisState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,7 @@ public void CancelRecentering()
}

/// <summary>Skip the wait time and start recentering now (only if enabled).</summary>
public void RecenterNow()
{
mLastAxisInputTime = 0;
}
public void RecenterNow() => mLastAxisInputTime = -1;

/// <summary>Bring the axis back to the centered state (only if enabled).</summary>
/// <param name="axis">The axis to recenter</param>
Expand Down Expand Up @@ -461,7 +458,7 @@ public void DoRecentering(ref AxisState axis, float deltaTime, float recenterTar
if (delta == 0)
return;

if (Time.realtimeSinceStartup < (mLastAxisInputTime + m_WaitTime))
if (mLastAxisInputTime >= 0 && Time.realtimeSinceStartup < (mLastAxisInputTime + m_WaitTime))
return;

// Determine the direction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Unity.Cinemachine.Samples
/// player rotation.
/// </summary>
[ExecuteAlways]
public class AimCameraRig : CinemachineCameraManagerBase, IInputAxisOwner
public class AimCameraRig : CinemachineCameraManagerBase, Unity.Cinemachine.IInputAxisOwner
{
public InputAxis AimMode = InputAxis.DefaultMomentary;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Unity.Cinemachine.Samples
{
public class CursorLockManager : MonoBehaviour, IInputAxisOwner
public class CursorLockManager : MonoBehaviour, Unity.Cinemachine.IInputAxisOwner
{
public InputAxis CursorLock = InputAxis.DefaultMomentary;

Expand All @@ -23,6 +23,7 @@ public void GetInputAxes(List<IInputAxisOwner.AxisDescriptor> axes)
}

void OnEnable() => UnlockCursor();
void OnDisable() => UnlockCursor();

void Update()
{
Expand All @@ -40,8 +41,11 @@ void Update()

public void LockCursor()
{
Cursor.lockState = CursorLockMode.Locked;
OnCursorLocked.Invoke();
if (enabled)
{
Cursor.lockState = CursorLockMode.Locked;
OnCursorLocked.Invoke();
}
}

public void UnlockCursor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Unity.Cinemachine.Samples
/// Movement is relative to the GameObject's local axes.
///
/// </summary>
public class FlyAround : MonoBehaviour, IInputAxisOwner
public class FlyAround : MonoBehaviour, Unity.Cinemachine.IInputAxisOwner
{
[Tooltip("Speed when moving")]
public float Speed = 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Unity.Cinemachine.Samples
{
public class SimpleCarController : MonoBehaviour, IInputAxisOwner
public class SimpleCarController : MonoBehaviour, Unity.Cinemachine.IInputAxisOwner
{
public float MotorStrength = 2000;
public float BrakeStrength = 5000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Unity.Cinemachine.Samples
///
/// To implement player shooting, add a SimplePlayerShoot behaviour to this GameObject.
/// </summary>
public class SimplePlayerAimController : MonoBehaviour, IInputAxisOwner
public class SimplePlayerAimController : MonoBehaviour, Unity.Cinemachine.IInputAxisOwner
{
public enum CouplingMode { Coupled, CoupledWhenMoving, Decoupled }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Unity.Cinemachine.Samples
{
public abstract class SimplePlayerControllerBase : MonoBehaviour, IInputAxisOwner
public abstract class SimplePlayerControllerBase : MonoBehaviour, Unity.Cinemachine.IInputAxisOwner
{
[Tooltip("Ground speed when walking")]
public float Speed = 1f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Unity.Cinemachine.Samples
/// or of the SimplePlayerAimController object if it exists and is not decoupled
/// from the player rotation.
/// </summary>
class SimplePlayerShoot : MonoBehaviour, IInputAxisOwner
class SimplePlayerShoot : MonoBehaviour, Unity.Cinemachine.IInputAxisOwner
{
[Tooltip("The bullet prefab to instantiate when firing")]
public GameObject BulletPrefab;
Expand Down

0 comments on commit fa6c6ad

Please sign in to comment.