mirror of
https://github.com/FriendshipIsEpic/FiE-Game.git
synced 2024-11-25 06:58:00 +01:00
208 lines
6.3 KiB
C#
208 lines
6.3 KiB
C#
/*******************************************************************************************
|
|
* Author: Lane Gresham, AKA LaneMax
|
|
* Websites: http://resurgamstudios.com
|
|
* Description: Used for cgf mod, creates a pulse effect using the cgf.
|
|
*******************************************************************************************/
|
|
using UnityEngine;
|
|
using System.Collections;
|
|
|
|
namespace CircularGravityForce
|
|
{
|
|
[RequireComponent(typeof(CGF))]
|
|
public class CGF_Pulse : MonoBehaviour
|
|
{
|
|
#region Classis
|
|
|
|
//Pulse properties
|
|
[System.Serializable]
|
|
public class PulseProperties
|
|
{
|
|
[SerializeField, Tooltip("Enable/Disable's the pulse.")]
|
|
private bool pulse = true;
|
|
public bool Pulse
|
|
{
|
|
get { return pulse; }
|
|
set { pulse = value; }
|
|
}
|
|
|
|
[SerializeField, Tooltip("Speed of the pulse.")]
|
|
private float speed = 10f;
|
|
public float Speed
|
|
{
|
|
get { return speed; }
|
|
set { speed = value; }
|
|
}
|
|
|
|
[SerializeField, Tooltip("Min pulse size.")]
|
|
private float minSize = 1f;
|
|
public float MinSize
|
|
{
|
|
get { return minSize; }
|
|
set { MinSize = value; }
|
|
}
|
|
|
|
[SerializeField, Tooltip("Max pulse size.")]
|
|
private float maxSize = 5f;
|
|
public float MaxSize
|
|
{
|
|
get { return maxSize; }
|
|
set { maxSize = value; }
|
|
}
|
|
|
|
[SerializeField, Tooltip("Min pulse box size.")]
|
|
private Vector3 minBoxSize = Vector3.one;
|
|
public Vector3 MinBoxSize
|
|
{
|
|
get { return minBoxSize; }
|
|
set { minBoxSize = value; }
|
|
}
|
|
|
|
[SerializeField, Tooltip("Max pulse box size.")]
|
|
private Vector3 maxBoxSize = Vector3.one * 5f;
|
|
public Vector3 MaxBoxSize
|
|
{
|
|
get { return maxBoxSize; }
|
|
set { maxBoxSize = value; }
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Properties/Constructor
|
|
|
|
[SerializeField, Tooltip("Pulse properties.")]
|
|
private PulseProperties pulseProperties;
|
|
public PulseProperties _pulseProperties
|
|
{
|
|
get { return pulseProperties; }
|
|
set { pulseProperties = value; }
|
|
}
|
|
|
|
private CGF cgf;
|
|
|
|
//Used to tell whether to add or subtract to pulse
|
|
private bool pulse_Positive;
|
|
private bool pulse_PositiveBoxX;
|
|
private bool pulse_PositiveBoxY;
|
|
private bool pulse_PositiveBoxZ;
|
|
|
|
public CGF_Pulse()
|
|
{
|
|
_pulseProperties = new PulseProperties();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Unity Functions
|
|
|
|
void Start()
|
|
{
|
|
cgf = this.GetComponent<CGF>();
|
|
|
|
//Sets up pulse
|
|
if (_pulseProperties.Pulse)
|
|
{
|
|
cgf.Size = _pulseProperties.MinSize;
|
|
pulse_Positive = true;
|
|
pulse_PositiveBoxX = true;
|
|
pulse_PositiveBoxY = true;
|
|
pulse_PositiveBoxZ = true;
|
|
}
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (cgf.Enable)
|
|
{
|
|
if (_pulseProperties.Pulse)
|
|
{
|
|
CalculatePulse();
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Functions
|
|
|
|
//Calculatie the given pulse
|
|
void CalculatePulse()
|
|
{
|
|
if (_pulseProperties.Pulse)
|
|
{
|
|
if (cgf._shape != CGF.Shape.Box)
|
|
CalculatePulseBySize();
|
|
else
|
|
CalculatePulseByBoxSize();
|
|
}
|
|
}
|
|
|
|
void CalculatePulseBySize()
|
|
{
|
|
if (pulse_Positive)
|
|
{
|
|
if (cgf.Size <= _pulseProperties.MaxSize)
|
|
cgf.Size = cgf.Size + (_pulseProperties.Speed * Time.deltaTime);
|
|
else
|
|
pulse_Positive = false;
|
|
}
|
|
else
|
|
{
|
|
if (cgf.Size >= _pulseProperties.MinSize)
|
|
cgf.Size = cgf.Size - (_pulseProperties.Speed * Time.deltaTime);
|
|
else
|
|
pulse_Positive = true;
|
|
}
|
|
}
|
|
|
|
void CalculatePulseByBoxSize()
|
|
{
|
|
if (pulse_PositiveBoxX)
|
|
{
|
|
if (cgf.BoxSize.x <= _pulseProperties.MaxBoxSize.x)
|
|
cgf.BoxSize = new Vector3(cgf.BoxSize.x + (_pulseProperties.Speed * Time.deltaTime), cgf.BoxSize.y, cgf.BoxSize.z);
|
|
else
|
|
pulse_PositiveBoxX = false;
|
|
}
|
|
else
|
|
{
|
|
if (cgf.BoxSize.x >= _pulseProperties.MinBoxSize.x)
|
|
cgf.BoxSize = new Vector3(cgf.BoxSize.x - (_pulseProperties.Speed * Time.deltaTime), cgf.BoxSize.y, cgf.BoxSize.z);
|
|
else
|
|
pulse_PositiveBoxX = true;
|
|
}
|
|
|
|
if (pulse_PositiveBoxY)
|
|
{
|
|
if (cgf.BoxSize.y <= _pulseProperties.MaxBoxSize.y)
|
|
cgf.BoxSize = new Vector3(cgf.BoxSize.x, cgf.BoxSize.y + (_pulseProperties.Speed * Time.deltaTime), cgf.BoxSize.z);
|
|
else
|
|
pulse_PositiveBoxY = false;
|
|
}
|
|
else
|
|
{
|
|
if (cgf.BoxSize.y >= _pulseProperties.MinBoxSize.y)
|
|
cgf.BoxSize = new Vector3(cgf.BoxSize.x, cgf.BoxSize.y - (_pulseProperties.Speed * Time.deltaTime), cgf.BoxSize.z);
|
|
else
|
|
pulse_PositiveBoxY = true;
|
|
}
|
|
|
|
if (pulse_PositiveBoxZ)
|
|
{
|
|
if (cgf.BoxSize.z <= _pulseProperties.MaxBoxSize.z)
|
|
cgf.BoxSize = new Vector3(cgf.BoxSize.x, cgf.BoxSize.y, cgf.BoxSize.z + (_pulseProperties.Speed * Time.deltaTime));
|
|
else
|
|
pulse_PositiveBoxZ = false;
|
|
}
|
|
else
|
|
{
|
|
if (cgf.BoxSize.z >= _pulseProperties.MinBoxSize.z)
|
|
cgf.BoxSize = new Vector3(cgf.BoxSize.x, cgf.BoxSize.y, cgf.BoxSize.z - (_pulseProperties.Speed * Time.deltaTime));
|
|
else
|
|
pulse_PositiveBoxZ = true;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|