Update
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
namespace Invector.vShooter
|
||||
{
|
||||
public class vAimCanvas : MonoBehaviour
|
||||
{
|
||||
public RectTransform aimTarget, aimCenter;
|
||||
public bool useScopeTransition = true;
|
||||
public bool scaleAimWithMovement = true;
|
||||
[Tooltip("Set aim center to same position of aim target ")]
|
||||
public bool aimCenterToAimTarget;
|
||||
public float scaleWithMovement = 2;
|
||||
public float smoothChangeScale = 2;
|
||||
public float smoothTransitionIn = 10f;
|
||||
public float smoothTransitionOut = 5f;
|
||||
[Range(0, 1)]
|
||||
public float movementSensibility = 0.1f;
|
||||
public UnityEvent onEnableAim;
|
||||
public UnityEvent onDisableAim;
|
||||
public UnityEvent onCheckvalidAim;
|
||||
public UnityEvent onCheckInvalidAim;
|
||||
|
||||
public UnityEvent onEnableScopeCamera;
|
||||
public UnityEvent onDisableScopeCamera;
|
||||
public UnityEvent onEnableScopeUI;
|
||||
public UnityEvent onDisableScopeUI;
|
||||
|
||||
[HideInInspector]
|
||||
public bool isValid;
|
||||
[HideInInspector]
|
||||
public bool isAimActive;
|
||||
[HideInInspector]
|
||||
public bool isScopeCameraActive;
|
||||
[HideInInspector]
|
||||
public bool isScopeUIActive;
|
||||
[HideInInspector]
|
||||
public Vector2 sizeDeltaTarget;
|
||||
[HideInInspector]
|
||||
public Vector2 sizeDeltaCenter;
|
||||
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
onDisableScopeCamera.Invoke();
|
||||
onDisableScopeUI.Invoke();
|
||||
onDisableAim.Invoke();
|
||||
if (aimCenter)
|
||||
sizeDeltaCenter = aimCenter.sizeDelta;
|
||||
if (aimTarget)
|
||||
sizeDeltaTarget = aimTarget.sizeDelta;
|
||||
}
|
||||
public void DisableAll()
|
||||
{
|
||||
onDisableScopeCamera.Invoke();
|
||||
onDisableScopeUI.Invoke();
|
||||
onDisableAim.Invoke();
|
||||
isValid = false;
|
||||
isAimActive = false;
|
||||
isScopeCameraActive = false;
|
||||
isScopeUIActive = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83605fe37a1888849bc0cb40390194d6
|
||||
timeCreated: 1486057898
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,35 @@
|
||||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Invector
|
||||
{
|
||||
public class vBarrel : vHealthController
|
||||
{
|
||||
public Transform referenceTransformUP;
|
||||
public float maxAngleUp = 90;
|
||||
protected bool isBarrelRoll;
|
||||
public UnityEngine.Events.UnityEvent onBarrelRoll;
|
||||
[vEditorToolbar("Health")]
|
||||
public List<string> acceptableAttacks = new List<string>() { "explosion", "projectile" };
|
||||
|
||||
void OnCollisionEnter()
|
||||
{
|
||||
if (!referenceTransformUP) return;
|
||||
var angle = Vector3.Angle(referenceTransformUP.up, Vector3.up);
|
||||
|
||||
if (angle > maxAngleUp && !isBarrelRoll)
|
||||
{
|
||||
isBarrelRoll = true;
|
||||
onBarrelRoll.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public override void TakeDamage(vDamage damage)
|
||||
{
|
||||
if (acceptableAttacks.Contains(damage.damageType))
|
||||
{
|
||||
base.TakeDamage(damage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d9de2fb199af3244f8f32f6264dff95f
|
||||
timeCreated: 1486596287
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,339 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Invector.vShooter
|
||||
{
|
||||
using vCharacterController;
|
||||
public class vControlAimCanvas : MonoBehaviour
|
||||
{
|
||||
public static vControlAimCanvas instance;
|
||||
public RectTransform canvas;
|
||||
public List<vAimCanvas> aimCanvasCollection = new List<vAimCanvas>();
|
||||
public bool useAimCorrectionSmooth = true;
|
||||
public float aimCorrectionSmooth=20f;
|
||||
public Camera scopeBackgroundCamera;
|
||||
public bool isScopeCameraActive { get => scopeBackgroundCamera && scopeBackgroundCamera.gameObject.activeInHierarchy; set { if (scopeBackgroundCamera) scopeBackgroundCamera.gameObject.SetActive(value); } }
|
||||
public bool isValid { get { if (!currentAimCanvas) return false; return currentAimCanvas.isValid; } set { currentAimCanvas.isValid = value; } }
|
||||
public bool isAimActive { get { if (!currentAimCanvas) return false; return currentAimCanvas.isAimActive; } set { currentAimCanvas.isAimActive = value; } }
|
||||
public bool isScopeUIActive { get { if (!currentAimCanvas) return false; return currentAimCanvas.isScopeUIActive; } set { currentAimCanvas.isScopeUIActive = value; } }
|
||||
public bool useScopeTransition { get { if (!currentAimCanvas) return false; return currentAimCanvas.useScopeTransition; } set { currentAimCanvas.useScopeTransition = value; } }
|
||||
protected bool scaleAimWithMovement { get { if (!currentAimCanvas) return false; return currentAimCanvas.scaleAimWithMovement; } }
|
||||
protected float movementSensibility { get { return currentAimCanvas.movementSensibility; } }
|
||||
protected float scaleWithMovement { get { return currentAimCanvas.scaleWithMovement; } }
|
||||
protected float smoothChangeScale { get { return currentAimCanvas.smoothChangeScale; } }
|
||||
protected float smoothTransitionIn { get { return currentAimCanvas.smoothTransitionIn; } }
|
||||
protected float smoothTransitionOut { get { return currentAimCanvas.smoothTransitionOut; } }
|
||||
protected RectTransform aimTarget { get { return currentAimCanvas.aimTarget; } }
|
||||
protected RectTransform aimCenter { get { return currentAimCanvas.aimCenter; } }
|
||||
protected Vector2 sizeDeltaTarget { get { return currentAimCanvas.sizeDeltaTarget; } }
|
||||
protected Vector2 sizeDeltaCenter { get { return currentAimCanvas.sizeDeltaCenter; } }
|
||||
|
||||
protected vThirdPersonController cc;
|
||||
|
||||
protected UnityEvent onEnableAim { get { return currentAimCanvas.onEnableAim; } }
|
||||
protected UnityEvent onDisableAim { get { return currentAimCanvas.onDisableAim; } }
|
||||
protected UnityEvent onCheckvalidAim { get { return currentAimCanvas.onCheckvalidAim; } }
|
||||
protected UnityEvent onCheckInvalidAim { get { return currentAimCanvas.onCheckInvalidAim; } }
|
||||
public UnityEvent onEnableScopeCamera { get { return currentAimCanvas.onEnableScopeCamera; } }
|
||||
public UnityEvent onDisableScopeCamera { get { return currentAimCanvas.onDisableScopeCamera; } }
|
||||
protected UnityEvent onEnableScopeUI { get { return currentAimCanvas.onEnableScopeUI; } }
|
||||
protected UnityEvent onDisableScopeUI { get { return currentAimCanvas.onDisableScopeUI; } }
|
||||
|
||||
public vAimCanvas currentAimCanvas;
|
||||
|
||||
protected int currentCanvasID;
|
||||
|
||||
protected virtual float scopeCameraTransformWeight { get; set; }
|
||||
protected virtual bool scopeActive { get; set; }
|
||||
float scopeCameraTargetZoom;
|
||||
float scopeCameraOriginZoom => mainCamera.fieldOfView;
|
||||
Vector3 scopeCameraTargetDir;
|
||||
Vector3 scopeCameraUpDir;
|
||||
Quaternion scopeCameraOriginRot => mainCamera.transform.rotation;
|
||||
Vector3 scopeCameraTargetPos;
|
||||
Vector3 scopeCameraOriginPos => mainCamera.transform.position;
|
||||
public Camera mainCamera;
|
||||
|
||||
public virtual void Init(vThirdPersonController cc)
|
||||
{
|
||||
if (scopeBackgroundCamera == null)
|
||||
scopeBackgroundCamera = GetComponentInChildren<Camera>(true);
|
||||
if (scopeBackgroundCamera == null)
|
||||
{
|
||||
Debug.LogWarning("Could not find Scope Background Camera. Please assign ScopeBackgroundCamera of Control aim canvas", gameObject);
|
||||
}
|
||||
mainCamera = Camera.main;
|
||||
instance = this;
|
||||
this.cc = cc;
|
||||
currentAimCanvas = aimCanvasCollection[currentCanvasID];
|
||||
isValid = true;
|
||||
}
|
||||
|
||||
public void UpdateScopeCameraTransition()
|
||||
{
|
||||
scopeBackgroundCamera.transform.position = Vector3.Lerp(scopeCameraOriginPos, scopeCameraTargetPos, scopeCameraTransformWeight);
|
||||
|
||||
if (scopeCameraTargetDir.magnitude > 0.01f)
|
||||
scopeBackgroundCamera.transform.rotation = Quaternion.Lerp(scopeCameraOriginRot, Quaternion.LookRotation(scopeCameraTargetDir,scopeCameraUpDir), scopeCameraTransformWeight);
|
||||
|
||||
scopeBackgroundCamera.fieldOfView = Mathf.Lerp(scopeCameraOriginZoom, scopeCameraTargetZoom, scopeCameraTransformWeight);
|
||||
|
||||
if (useScopeTransition)
|
||||
{
|
||||
if (scopeActive)
|
||||
{
|
||||
scopeCameraTransformWeight = Mathf.Clamp01(scopeCameraTransformWeight += smoothTransitionIn * Time.fixedDeltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
scopeCameraTransformWeight = Mathf.Clamp01(scopeCameraTransformWeight -= smoothTransitionOut * Time.fixedDeltaTime);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
scopeCameraTransformWeight = scopeActive ? 1f : 0f;
|
||||
}
|
||||
|
||||
if (scopeActive && scopeCameraTransformWeight > 0 && isScopeCameraActive == false)
|
||||
{
|
||||
isScopeCameraActive = true;
|
||||
mainCamera.enabled = false;
|
||||
onEnableScopeCamera.Invoke();
|
||||
}
|
||||
else if (!scopeActive && scopeCameraTransformWeight == 0 && isScopeCameraActive == true)
|
||||
{
|
||||
mainCamera.enabled = true;
|
||||
isScopeCameraActive = false;
|
||||
onDisableScopeCamera.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set Current Aim to Stay in Center
|
||||
/// </summary>
|
||||
/// <param name="validPoint">Set if Aim is valid</param>
|
||||
public void SetAimToCenter(bool validPoint = true)
|
||||
{
|
||||
if (currentAimCanvas == null) return;
|
||||
if (validPoint != isValid)
|
||||
{
|
||||
isValid = validPoint;
|
||||
if (isValid) onCheckvalidAim.Invoke();
|
||||
else onCheckInvalidAim.Invoke();
|
||||
}
|
||||
|
||||
if (aimTarget)
|
||||
{
|
||||
aimTarget.anchoredPosition = Vector2.Lerp(aimTarget.anchoredPosition,Vector2.zero, useAimCorrectionSmooth ? aimCorrectionSmooth * Time.fixedDeltaTime : 1f);
|
||||
}
|
||||
if (currentAimCanvas.aimCenterToAimTarget && aimCenter)
|
||||
{
|
||||
aimCenter.anchoredPosition = Vector2.Lerp(aimCenter.anchoredPosition, Vector2.zero, useAimCorrectionSmooth ? aimCorrectionSmooth * Time.fixedDeltaTime : 1f);
|
||||
}
|
||||
UpdateAimSize();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set WordPosition of TargetAim
|
||||
/// </summary>
|
||||
/// <param name="wordPosition">Word Position</param>
|
||||
/// <param name="validPoint">Set if Aim is Valid</param>
|
||||
public void SetWordPosition(Vector3 wordPosition, bool validPoint = true)
|
||||
{
|
||||
if (currentAimCanvas == null) return;
|
||||
|
||||
if (validPoint != isValid)
|
||||
{
|
||||
isValid = validPoint;
|
||||
if (isValid) onCheckvalidAim.Invoke();
|
||||
else onCheckInvalidAim.Invoke();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Vector2 ViewportPosition = mainCamera.WorldToViewportPoint(wordPosition);
|
||||
Vector2 WorldObject_ScreenPosition = new Vector2(
|
||||
((ViewportPosition.x * canvas.sizeDelta.x) - (canvas.sizeDelta.x * 0.5f)),
|
||||
((ViewportPosition.y * canvas.sizeDelta.y) - (canvas.sizeDelta.y * 0.5f)));
|
||||
|
||||
if (currentAimCanvas.aimCenterToAimTarget && aimCenter)
|
||||
{
|
||||
aimCenter.anchoredPosition = Vector2.Lerp(aimCenter.anchoredPosition, WorldObject_ScreenPosition, useAimCorrectionSmooth?aimCorrectionSmooth * Time.fixedDeltaTime:1f);
|
||||
}
|
||||
if (aimTarget)
|
||||
{
|
||||
aimTarget.anchoredPosition = Vector2.Lerp(aimTarget.anchoredPosition, WorldObject_ScreenPosition, useAimCorrectionSmooth ? aimCorrectionSmooth * Time.fixedDeltaTime : 1f);
|
||||
}
|
||||
UpdateAimSize();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Set WordPosition of TargetAim
|
||||
/// </summary>
|
||||
/// <param name="wordPosition">Word Position</param>
|
||||
/// <param name="validPoint">Set if Aim is Valid</param>
|
||||
public void SetWordPosition(Vector3 centerPosition, Vector3 targetPosition, bool validPoint = true)
|
||||
{
|
||||
if (currentAimCanvas == null) return;
|
||||
|
||||
if (validPoint != isValid)
|
||||
{
|
||||
isValid = validPoint;
|
||||
if (isValid) onCheckvalidAim.Invoke();
|
||||
else onCheckInvalidAim.Invoke();
|
||||
}
|
||||
|
||||
if (aimCenter)
|
||||
{
|
||||
Vector2 ViewportPosition = mainCamera.WorldToViewportPoint(centerPosition);
|
||||
Vector2 WorldObject_ScreenPosition = new Vector2(
|
||||
((ViewportPosition.x * canvas.sizeDelta.x) - (canvas.sizeDelta.x * 0.5f)),
|
||||
((ViewportPosition.y * canvas.sizeDelta.y) - (canvas.sizeDelta.y * 0.5f)));
|
||||
aimCenter.anchoredPosition = Vector2.Lerp(aimCenter.anchoredPosition, WorldObject_ScreenPosition, useAimCorrectionSmooth ? aimCorrectionSmooth * Time.fixedDeltaTime : 1f);
|
||||
}
|
||||
if (aimTarget)
|
||||
{
|
||||
Vector2 ViewportPosition = mainCamera.WorldToViewportPoint(targetPosition);
|
||||
Vector2 WorldObject_ScreenPosition = new Vector2(
|
||||
((ViewportPosition.x * canvas.sizeDelta.x) - (canvas.sizeDelta.x * 0.5f)),
|
||||
((ViewportPosition.y * canvas.sizeDelta.y) - (canvas.sizeDelta.y * 0.5f)));
|
||||
aimTarget.anchoredPosition = Vector2.Lerp(aimTarget.anchoredPosition, WorldObject_ScreenPosition, useAimCorrectionSmooth ? aimCorrectionSmooth * Time.fixedDeltaTime : 1f);
|
||||
}
|
||||
UpdateAimSize();
|
||||
}
|
||||
|
||||
private void UpdateAimSize()
|
||||
{
|
||||
float scale = 1f;
|
||||
if (scaleAimWithMovement && (cc.input.magnitude > movementSensibility || Mathf.Abs(Input.GetAxis("Mouse X")) > movementSensibility || Mathf.Abs(Input.GetAxis("Mouse Y")) > movementSensibility))
|
||||
{
|
||||
scale = scaleWithMovement;
|
||||
}
|
||||
if(aimCenter) aimCenter.sizeDelta = Vector2.Lerp(aimCenter.sizeDelta, sizeDeltaCenter * Mathf.Abs(scale), smoothChangeScale * Time.fixedDeltaTime);
|
||||
if(aimTarget) aimTarget.sizeDelta = Vector2.Lerp(aimTarget.sizeDelta, sizeDeltaTarget * Mathf.Abs(scale), smoothChangeScale * Time.fixedDeltaTime);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enable or Disable the current Aim
|
||||
/// </summary>
|
||||
/// <param name="value"> active value</param>
|
||||
public void SetActiveAim(bool value)
|
||||
{
|
||||
if (currentAimCanvas == null) return;
|
||||
if (value != isAimActive)
|
||||
{
|
||||
|
||||
isAimActive = value;
|
||||
if (value)
|
||||
{
|
||||
isValid = true;
|
||||
onEnableAim.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
onDisableAim.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void DisableScopeCamera()
|
||||
{
|
||||
scopeActive = false;
|
||||
scopeCameraTransformWeight = 0;
|
||||
isScopeCameraActive = false;
|
||||
mainCamera.enabled = true;
|
||||
}
|
||||
|
||||
public void DisableAim()
|
||||
{
|
||||
SetActiveAim(false);
|
||||
DisableScopeCamera();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enable or Disable the current Scope
|
||||
/// </summary>
|
||||
/// <param name="value">active value</param>
|
||||
/// <param name="useUI">set if scope camera use the Scope UI </param>
|
||||
public void SetActiveScopeCamera(bool value, bool useUI = false)
|
||||
{
|
||||
if (currentAimCanvas == null || !scopeBackgroundCamera) return;
|
||||
|
||||
|
||||
if (scopeActive != value || isScopeUIActive != useUI)
|
||||
{
|
||||
isScopeUIActive = useUI;
|
||||
if (value)
|
||||
{
|
||||
scopeActive = true;
|
||||
|
||||
if (value && useUI)
|
||||
{
|
||||
onEnableScopeUI.Invoke();
|
||||
isScopeUIActive = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
onDisableScopeUI.Invoke();
|
||||
isScopeUIActive = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
scopeActive = false;
|
||||
isScopeUIActive = false;
|
||||
onDisableScopeUI.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update Word properties and zoom ("FieldOfView") of the Scope Camera
|
||||
/// </summary>
|
||||
/// <param name="position">word position</param>
|
||||
/// <param name="lookDirection">Word target LookAt</param>
|
||||
/// <param name="zoom">FieldOfView</param>
|
||||
public void UpdateScopeCamera(Vector3 position, Vector3 lookDirection, Vector3 upDirection, float zoom = 60, bool isAiming = false)
|
||||
{
|
||||
if (currentAimCanvas == null || !scopeBackgroundCamera) return;
|
||||
|
||||
var _zoom = Mathf.Clamp(60 - zoom, 1, 179);
|
||||
|
||||
if (isAiming)
|
||||
{
|
||||
scopeCameraTargetPos = position;
|
||||
scopeCameraTargetDir = lookDirection;
|
||||
scopeCameraUpDir = upDirection;
|
||||
scopeCameraTargetZoom = _zoom;
|
||||
}
|
||||
|
||||
UpdateScopeCameraTransition();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set AimCanvas ID
|
||||
/// if id do not exist,this change to defaultAimCanvas id 0
|
||||
/// </summary>
|
||||
/// <param name="id">index of AimCanvasCollection</param>
|
||||
public void SetAimCanvasID(int id)
|
||||
{
|
||||
if (aimCanvasCollection.Count > 0 && currentCanvasID != id)
|
||||
{
|
||||
if (currentAimCanvas != null) currentAimCanvas.DisableAll();
|
||||
if (id < aimCanvasCollection.Count)
|
||||
{
|
||||
currentAimCanvas = aimCanvasCollection[id];
|
||||
currentCanvasID = id;
|
||||
}
|
||||
else
|
||||
{
|
||||
currentAimCanvas = aimCanvasCollection[0];
|
||||
currentCanvasID = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b9685dd5dcc6d6249b77ded444bd1c41
|
||||
timeCreated: 1483379941
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,227 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Invector
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using vEventSystems;
|
||||
|
||||
[vClassHeader("Explosive", openClose = false)]
|
||||
public class vExplosive : vMonoBehaviour
|
||||
{
|
||||
[System.Serializable]
|
||||
public class OnUpdateTime : UnityEngine.Events.UnityEvent<float> { }
|
||||
[System.Serializable]
|
||||
public class ColliderEvent : UnityEngine.Events.UnityEvent<Collider> { }
|
||||
public vDamage damage;
|
||||
[vHelpBox("Use this values To define the min and max damage based on range")]
|
||||
[Range(0, 1f)]
|
||||
public float damageOnMinRangeMultiplier = 1f;
|
||||
[Range(0, 1f)]
|
||||
public float damageOnMaxRangeMultiplier = 0f;
|
||||
[Tooltip("Assign this to set other damage sender")]
|
||||
public Transform overrideDamageSender;
|
||||
public float explosionForce;
|
||||
public float minExplosionRadius;
|
||||
public float maxExplosionRadius;
|
||||
public float upwardsModifier = 1;
|
||||
public ForceMode forceMode;
|
||||
public ExplosiveMethod method;
|
||||
public LayerMask applyDamageLayer, applyForceLayer;
|
||||
public float timeToExplode = 10f;
|
||||
public bool destroyAfterExplode = true;
|
||||
[Tooltip("convert to progress 0 to 1")]
|
||||
public bool normalizeTime;
|
||||
public bool showGizmos;
|
||||
public UnityEngine.Events.UnityEvent onInitTimer;
|
||||
public OnUpdateTime onUpdateTimer;
|
||||
public UnityEngine.Events.UnityEvent onExplode;
|
||||
public ColliderEvent onHit;
|
||||
private bool inTimer;
|
||||
protected List<GameObject> collidersReached;
|
||||
|
||||
void OnDrawGizmosSelected()
|
||||
{
|
||||
if (!showGizmos) return;
|
||||
Gizmos.color = new Color(1, 0, 0, 0.2f);
|
||||
Gizmos.DrawSphere(transform.position, minExplosionRadius);
|
||||
Gizmos.color = new Color(0, 1, 0, 0.2f);
|
||||
Gizmos.DrawSphere(transform.position, maxExplosionRadius);
|
||||
}
|
||||
|
||||
public void SetOverrideDamageSender(Transform target) => overrideDamageSender = target;
|
||||
public void SetDamage(vDamage damage)
|
||||
{
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
public enum ExplosiveMethod
|
||||
{
|
||||
collisionEnter,
|
||||
collisionEnterTimer,
|
||||
remote,
|
||||
timer,
|
||||
remoteTimer
|
||||
}
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
collidersReached = new List<GameObject>();
|
||||
if (method == ExplosiveMethod.timer)
|
||||
{
|
||||
StartCoroutine(StartTimer());
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual IEnumerator StartTimer()
|
||||
{
|
||||
if (!inTimer)
|
||||
{
|
||||
onInitTimer.Invoke();
|
||||
inTimer = true;
|
||||
var startTime = Time.time;
|
||||
var time = 0f;
|
||||
while (time < timeToExplode)
|
||||
{
|
||||
yield return new WaitForEndOfFrame();
|
||||
time = Time.time - startTime;
|
||||
onUpdateTimer.Invoke(normalizeTime ? (time / timeToExplode) : time);
|
||||
}
|
||||
if (gameObject)
|
||||
{
|
||||
onUpdateTimer.Invoke(normalizeTime ? (1f) : timeToExplode);
|
||||
Explode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual IEnumerator DestroyBomb()
|
||||
{
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
protected virtual void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
if (method == ExplosiveMethod.collisionEnter)
|
||||
Explode();
|
||||
else if (method == ExplosiveMethod.collisionEnterTimer)
|
||||
StartCoroutine(StartTimer());
|
||||
}
|
||||
|
||||
protected virtual void Explode()
|
||||
{
|
||||
onExplode.Invoke();
|
||||
var colliders = Physics.OverlapSphere(transform.position, maxExplosionRadius, applyDamageLayer);
|
||||
|
||||
if (collidersReached == null)
|
||||
{
|
||||
collidersReached = new List<GameObject>();
|
||||
}
|
||||
|
||||
for (int i = 0; i < colliders.Length; ++i)
|
||||
{
|
||||
if (colliders[i] != null && colliders[i].gameObject != null && !collidersReached.Contains(colliders[i].gameObject))
|
||||
{
|
||||
collidersReached.Add(colliders[i].gameObject);
|
||||
var _damage = new vDamage(damage);
|
||||
_damage.sender = overrideDamageSender ? overrideDamageSender : transform;
|
||||
|
||||
_damage.hitPosition = colliders[i].ClosestPointOnBounds(transform.position);
|
||||
_damage.receiver = colliders[i].transform;
|
||||
var distance = Vector3.Distance(transform.position, _damage.hitPosition);
|
||||
var damageValue = distance <= minExplosionRadius ? damage.damageValue * damageOnMinRangeMultiplier : Mathf.Lerp(damage.damageValue * damageOnMaxRangeMultiplier, damage.damageValue * damageOnMinRangeMultiplier, EvaluateDistance(distance));
|
||||
_damage.activeRagdoll = distance > maxExplosionRadius * 0.5f ? false : _damage.activeRagdoll;
|
||||
|
||||
_damage.damageValue = (int)damageValue;
|
||||
onHit.Invoke(colliders[i]);
|
||||
colliders[i].gameObject.ApplyDamage(_damage, null);
|
||||
|
||||
}
|
||||
}
|
||||
StartCoroutine(ApplyExplosionForce());
|
||||
if (destroyAfterExplode) StartCoroutine(DestroyBomb());
|
||||
}
|
||||
|
||||
protected virtual IEnumerator ApplyExplosionForce()
|
||||
{
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
|
||||
var colliders = Physics.OverlapSphere(transform.position, maxExplosionRadius, applyForceLayer);
|
||||
for (int i = 0; i < colliders.Length; i++)
|
||||
{
|
||||
var _rigdbody = colliders[i].GetComponent<Rigidbody>();
|
||||
var distance = Vector3.Distance(transform.position, colliders[i].ClosestPointOnBounds(transform.position));
|
||||
var force = distance <= minExplosionRadius ? explosionForce : GetPercentageForce(distance, explosionForce);
|
||||
if (_rigdbody)
|
||||
{
|
||||
_rigdbody.AddExplosionForce(force, transform.position, maxExplosionRadius, upwardsModifier, forceMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected float EvaluateDistance(float distance)
|
||||
{
|
||||
if (distance > maxExplosionRadius) distance = maxExplosionRadius;
|
||||
|
||||
var distanceLimit = maxExplosionRadius - minExplosionRadius;
|
||||
var distanceCalc = Mathf.Clamp(distance - minExplosionRadius, 0, distanceLimit);
|
||||
var distanceResult = Mathf.Clamp(distanceLimit - (distanceCalc), 0, distanceLimit);
|
||||
var multiple = ((distanceResult / distanceLimit) * 100f) * 0.01f;
|
||||
return multiple;
|
||||
}
|
||||
protected float GetPercentageForce(float distance, float value)
|
||||
{
|
||||
|
||||
return value * EvaluateDistance(distance);
|
||||
}
|
||||
|
||||
public virtual void SetCollisionEnterMethod()
|
||||
{
|
||||
method = ExplosiveMethod.collisionEnter;
|
||||
}
|
||||
|
||||
public virtual void SetCollisionEnterTimerMethod(int timer)
|
||||
{
|
||||
method = ExplosiveMethod.collisionEnterTimer;
|
||||
this.timeToExplode = timer;
|
||||
}
|
||||
|
||||
public virtual void SetRemoveMethod()
|
||||
{
|
||||
method = ExplosiveMethod.remote;
|
||||
}
|
||||
|
||||
public virtual void SetRemoveTimerMethod(int timer)
|
||||
{
|
||||
method = ExplosiveMethod.remoteTimer;
|
||||
this.timeToExplode = timer;
|
||||
}
|
||||
|
||||
public virtual void SetTimerMethod(int timer)
|
||||
{
|
||||
method = ExplosiveMethod.timer;
|
||||
this.timeToExplode = timer;
|
||||
}
|
||||
|
||||
public virtual void ActiveExplosion()
|
||||
{
|
||||
if (method == ExplosiveMethod.remote)
|
||||
Explode();
|
||||
else if (method == ExplosiveMethod.remoteTimer)
|
||||
{
|
||||
StartCoroutine(StartTimer());
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveParent()
|
||||
{
|
||||
transform.parent = null;
|
||||
}
|
||||
|
||||
public void RemoveParentOfOther(Transform other)
|
||||
{
|
||||
other.parent = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 898a490f854251046a69c0ef94cc452b
|
||||
timeCreated: 1479432549
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Invector
|
||||
{
|
||||
public static partial class vAnimatorTags
|
||||
{
|
||||
[Tooltip("Use to identify Reloading animations")]
|
||||
public const string IsReloading = "IsReloading";
|
||||
[Tooltip("Use to Ignore IK while this animation is being played")]
|
||||
public const string IgnoreIK = "IgnoreIK";
|
||||
[Tooltip("Use to Ignore only support hand IK while this animation is being played")]
|
||||
public const string IgnoreSupportHandIK = "IgnoreSupportHandIK";
|
||||
[Tooltip("Use to identify a Shooter Upperbody Pose animation")]
|
||||
public const string UpperbodyPose = "Upperbody Pose";
|
||||
[Tooltip("Use to identify a Throw animation")]
|
||||
public const string IsThrowing = "IsThrowing";
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a2cc6f4ad0fb2fd4db4a8ed1c16edd0d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user