add behaviour and camera zoom

This commit is contained in:
Nilton Constantino 2026-05-27 10:46:43 +01:00
parent 8a299eea99
commit 9d47788f53
No known key found for this signature in database
24 changed files with 965 additions and 132 deletions

View File

@ -13,9 +13,15 @@ namespace __Prototype.Scripts
private MaterialPropertyBlock block; private MaterialPropertyBlock block;
private void OnValidate()
{
meshRenderer ??= GetComponent<MeshRenderer>();
Paint();
}
private void Awake() private void Awake()
{ {
block = new MaterialPropertyBlock(); meshRenderer ??= GetComponent<MeshRenderer>();
} }
private void Start() private void Start()
@ -26,6 +32,7 @@ namespace __Prototype.Scripts
[GroupDebug, Button(ButtonSizes.Medium)] [GroupDebug, Button(ButtonSizes.Medium)]
private void Paint() private void Paint()
{ {
block = new MaterialPropertyBlock();
meshRenderer.GetPropertyBlock(block); meshRenderer.GetPropertyBlock(block);
block.SetColor(BaseColor, color); block.SetColor(BaseColor, color);
meshRenderer.SetPropertyBlock(block); meshRenderer.SetPropertyBlock(block);

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 55184f17fec7946879dfae19e1b1550f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,15 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ab2e7a683f584962a36a133a6ac88b4a, type: 3}
m_Name: behaviour.can-interact
m_EditorClassIdentifier: Assembly-CSharp::Intrepid.Core.Tags.BehaviourTag
code: behaviour.can-interact

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 658e05d77a47d4e9591207114542f5fa
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,102 @@
using System;
using Intrepid.Core.Camera.Events;
using Intrepid.SimpleEvents;
using Intrepid.Utilities;
using Sirenix.OdinInspector;
using Unity.Cinemachine;
using UnityEngine;
namespace Intrepid.Core.Camera
{
public sealed class CameraFollowManager : EventListener
{
[GroupInjections, SerializeField] private CinemachineCamera vcam;
[GroupConfigurations, SerializeField] private float startOrthographicSize = 12f;
[GroupConfigurations, SerializeField] private float startZoomSmoothTime = 1f;
[GroupConfigurations, SerializeField] private float defaultOrthographicSize = 7f;
[GroupConfigurations, SerializeField] private float zoomInOrthographicSize = 4f;
[GroupConfigurations, SerializeField] private float zoomOutOrthographicSize = 10f;
private float TargetOrthographicSize { get; set; }
private float _zoomSmoothTime;
private float _zoomCurrentVelocity;
protected override void InitializeVariables()
{
TargetOrthographicSize = defaultOrthographicSize;
_zoomSmoothTime = startZoomSmoothTime;
_zoomCurrentVelocity = 0f;
var lens = vcam.Lens;
lens.OrthographicSize = startOrthographicSize;
vcam.Lens = lens;
}
protected override void OnBootstrap()
{
}
protected override void Subscriptions()
{
Subscribe<CameraZoomEvent>(OnCameraZoomEvent);
}
private void OnCameraZoomEvent(CameraZoomEvent e)
{
SetZoomLevel(e.ZoomLevel, e.ZoomVelocity);
}
[GroupDebug, Button(ButtonSizes.Medium, ButtonStyle.FoldoutButton)]
private void ZoomNone(float zoomSmoothTime = .25f)
{
SetZoomLevel(zoomSmoothTime: zoomSmoothTime);
}
[GroupDebug, Button(ButtonSizes.Medium, ButtonStyle.FoldoutButton)]
private void ZoomIn(float zoomSmoothTime = .25f)
{
SetZoomLevel(CameraZoomLevel.ZoomIn, zoomSmoothTime);
}
[GroupDebug, Button(ButtonSizes.Medium, ButtonStyle.FoldoutButton)]
private void ZoomOut(float zoomSmoothTime = .25f)
{
SetZoomLevel(CameraZoomLevel.ZoomOut, zoomSmoothTime);
}
private void SetZoomLevel(
CameraZoomLevel zoomLevel = CameraZoomLevel.None,
float zoomSmoothTime = .25f)
{
_zoomSmoothTime = Mathf.Max(0.01f, zoomSmoothTime);
_zoomCurrentVelocity = 0f;
TargetOrthographicSize = zoomLevel switch
{
CameraZoomLevel.None => defaultOrthographicSize,
CameraZoomLevel.ZoomIn => zoomInOrthographicSize,
CameraZoomLevel.ZoomOut => zoomOutOrthographicSize,
_ => throw new ArgumentOutOfRangeException(nameof(zoomLevel), zoomLevel, null)
};
}
private void Update()
{
var lens = vcam.Lens;
lens.OrthographicSize = Mathf.SmoothDamp(
lens.OrthographicSize,
TargetOrthographicSize,
ref _zoomCurrentVelocity,
_zoomSmoothTime,
Mathf.Infinity,
Time.deltaTime
);
vcam.Lens = lens;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a30e490ac07e4c6982fa770e3cef253f
timeCreated: 1779864891

View File

@ -0,0 +1,44 @@
using System.Collections.Generic;
using Intrepid.Core.Camera.Events;
using Intrepid.Core.Entities;
using Intrepid.Core.Tags;
using Intrepid.GameManagers;
using Intrepid.Utilities;
using UnityEngine;
namespace Intrepid.Core.Camera
{
public class CameraProximityTrigger : EntityTrigger
{
[GroupConfigurations, SerializeField, Range(.5f, 5f)] private float radius = 1.5f;
[GroupConfigurations, SerializeField] private CameraZoomLevel zoomLevel = CameraZoomLevel.ZoomIn;
[GroupConfigurations, SerializeField, Range(.05f, 3f)] private float enterZoomVelocity = .5f;
[GroupConfigurations, SerializeField, Range(.05f, 3f)] private float exitZoomVelocity = .5f;
protected override void WhenRaiseEnterEvent(Collider other, EntitySensor entitySensor, List<BehaviourTag> behaviourTags)
{
Proxy.Instance.EventBus.Raise(new CameraZoomEvent
{
ZoomLevel = zoomLevel,
ZoomVelocity = enterZoomVelocity
});
}
protected override void WhenRaiseExitEvent(Collider other, EntitySensor entitySensor)
{
Proxy.Instance.EventBus.Raise(new CameraZoomEvent
{
ZoomLevel = CameraZoomLevel.None,
ZoomVelocity = exitZoomVelocity
});
}
#if UNITY_EDITOR
private void OnDrawGizmos()
{
Gizmos.color = Color.yellow;
Gizmos.DrawWireSphere(transform.position, 2f * radius);
}
#endif
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a682f23a07cd4cfcaca3f2b5bfed2ab5
timeCreated: 1779865779

View File

@ -0,0 +1,9 @@
namespace Intrepid.Core.Camera
{
public enum CameraZoomLevel
{
None,
ZoomIn,
ZoomOut,
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a55325f141f9488db0f672f1566cfe43
timeCreated: 1779865325

View File

@ -0,0 +1,10 @@
using Intrepid.SimpleEvents;
namespace Intrepid.Core.Camera.Events
{
public class CameraZoomEvent : IEventBase
{
public CameraZoomLevel ZoomLevel { get; set; }
public float ZoomVelocity { get; set; } = .15f;
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8b77f9f8e10b42998ed3496dd5a020f7
timeCreated: 1779864929

View File

@ -9,9 +9,9 @@ namespace Intrepid.Core.Entities
public abstract class Entity : Identification, IUpdatable public abstract class Entity : Identification, IUpdatable
{ {
[GroupInjections, SerializeField] private EntityBrain brain; [GroupInjections, SerializeField] private EntityBrain brain;
[GroupInjections, SerializeField] private EntitySensor entitySensor;
protected EntityBrain EntityBrain => brain; protected EntityBrain EntityBrain => brain;
protected EntityTag EntityTag => EntityBrain.EntityTag;
protected void OnEnable() protected void OnEnable()
{ {

View File

@ -1,4 +1,3 @@
using Intrepid.Core.Tags;
using Intrepid.Core.Updatable; using Intrepid.Core.Updatable;
using Intrepid.SimpleEvents; using Intrepid.SimpleEvents;
using Intrepid.Utilities; using Intrepid.Utilities;
@ -8,11 +7,9 @@ namespace Intrepid.Core.Entities
{ {
public abstract class EntityBrain : EventListener, IUpdatable public abstract class EntityBrain : EventListener, IUpdatable
{ {
[GroupIdentification, SerializeField] private EntityTag entityTag;
[GroupInjections, SerializeField] private Entity rootEntity; [GroupInjections, SerializeField] private Entity rootEntity;
public string Id => SubscriptionId; public string Id => SubscriptionId;
public EntityTag EntityTag => entityTag;
protected Entity RootEntity => rootEntity; protected Entity RootEntity => rootEntity;
public abstract void UpdateFromUpdatable(); public abstract void UpdateFromUpdatable();

View File

@ -0,0 +1,65 @@
using System.Collections.Generic;
using System.Linq;
using Intrepid.Core.Tags;
using Intrepid.TagSystem;
using Intrepid.Utilities;
using Sirenix.OdinInspector;
using UnityEngine;
namespace Intrepid.Core.Entities
{
[RequireComponent(typeof(SphereCollider))]
public class EntitySensor : AbstractTagBehaviour<BehaviourTag>
{
[Title("I am a...")]
[GroupConfigurations, SerializeField] private EntityTag entityTag;
public SphereCollider Collider { get; private set; }
public EntityTag EntityTag => entityTag;
public bool IsEnabled { get; private set; }
private void Awake()
{
Collider = GetComponent<SphereCollider>();
Collider.isTrigger = true;
IsEnabled = true;
}
public bool ShouldBeTriggered(IEnumerable<EntityTag> entitySensors, IEnumerable<BehaviourTag> behaviourTags)
{
return entitySensors.Contains(EntityTag) && HasAnyTags(behaviourTags);
}
public bool ShouldNotBeTriggered(IEnumerable<EntityTag> entitySensors, IEnumerable<BehaviourTag> behaviourTags)
{
return !ShouldBeTriggered(entitySensors, behaviourTags);
}
public void Enable()
{
IsEnabled = true;
Collider.enabled = true;
}
public void Disable()
{
IsEnabled = false;
Collider.enabled = false;
}
public void ClearFilteringTags()
{
FilteringTags.Clear();
}
public void ActivateBehavioursOnly(IEnumerable<BehaviourTag> tags)
{
FilteringTags.RemoveAll(tags.Contains);
}
public void DeactivateBehavioursOnly(IEnumerable<BehaviourTag> tags)
{
FilteringTags.AddRange(tags);
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c464392c6a5944d6805bcdbc8080bdd3
timeCreated: 1779868810

View File

@ -0,0 +1,55 @@
using System.Collections.Generic;
using Intrepid.Core.Tags;
using Intrepid.Utilities;
using Sirenix.OdinInspector;
using UnityEngine;
namespace Intrepid.Core.Entities
{
public abstract class EntityTrigger : Identification
{
[GroupInjections, SerializeField] private Collider mainCollider;
[Title("Entity Sensors we are looking for")]
[GroupConfigurations, SerializeField, PropertySpace, PropertyOrder(10)] private List<EntityTag> entitySensors;
[Title("The behaviour which at least one should be accepted")]
[GroupConfigurations, SerializeField, PropertySpace, PropertyOrder(11)] private List<BehaviourTag> behaviourTags;
protected Collider MainCollider => mainCollider;
protected bool IsEnabled { get; private set; }
protected virtual void Awake()
{
MainCollider.isTrigger = true;
IsEnabled = true;
}
protected void OnTriggerEnter(Collider other)
{
if (!other.gameObject.TryGetComponent<EntitySensor>(out var entitySensor)) return;
if (entitySensor.ShouldNotBeTriggered(entitySensors, behaviourTags)) return;
WhenRaiseEnterEvent(other, entitySensor, behaviourTags);
}
protected void OnTriggerExit(Collider other)
{
if (!other.gameObject.TryGetComponent<EntitySensor>(out var entitySensor)) return;
if (entitySensor.ShouldNotBeTriggered(entitySensors, behaviourTags)) return;
WhenRaiseExitEvent(other, entitySensor);
}
public virtual void Enable()
{
IsEnabled = true;
MainCollider.enabled = true;
}
public virtual void Disable()
{
IsEnabled = false;
MainCollider.enabled = false;
}
protected abstract void WhenRaiseEnterEvent(Collider other, EntitySensor entitySensor, List<BehaviourTag> behaviourTags);
protected abstract void WhenRaiseExitEvent(Collider other, EntitySensor entitySensor);
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 72825fb78e3241bea78b9ca551491f23
timeCreated: 1779869029

View File

@ -0,0 +1,12 @@
using System;
using Intrepid.TagSystem;
using UnityEngine;
namespace Intrepid.Core.Tags
{
[Serializable]
[CreateAssetMenu(fileName = "New Behaviour Tag", menuName = "GON/Tag/Behaviour Tag")]
public class BehaviourTag : Tag
{
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ab2e7a683f584962a36a133a6ac88b4a
timeCreated: 1779868684

View File

@ -5,7 +5,7 @@ using UnityEngine;
namespace Intrepid.Core.Tags namespace Intrepid.Core.Tags
{ {
[Serializable] [Serializable]
[CreateAssetMenu(fileName = "Entity Tag", menuName = "Intrepid/Tag/Entity Tag")] [CreateAssetMenu(fileName = "New Entity Tag", menuName = "GON/Tag/Entity Tag")]
public class EntityTag : Tag public class EntityTag : Tag
{ {
} }

View File

@ -8,7 +8,7 @@ using UnityEngine.SceneManagement;
namespace Intrepid.Core.Tags namespace Intrepid.Core.Tags
{ {
[Serializable] [Serializable]
[CreateAssetMenu(fileName = "Scene Tag", menuName = "Intrepid/Tags/Scene Tag")] [CreateAssetMenu(fileName = "New Scene Tag", menuName = "GON/Tags/Scene Tag")]
public class SceneTag : Tag public class SceneTag : Tag
{ {
public string SceneName => Code; public string SceneName => Code;