Assemblies Made and Refactored Code Folders
Created assemblies for the new design code. Relocated legacy scripts into a legacy folder and made a "new_design" folder for new design.
This commit is contained in:
49
Assets/Scripts/Legacy/Item/Pistol/BulletComponent.cs
Normal file
49
Assets/Scripts/Legacy/Item/Pistol/BulletComponent.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using UnityEngine;
|
||||
using FishNet.Object;
|
||||
using FishNet;
|
||||
|
||||
namespace Item
|
||||
{
|
||||
public class BulletComponent : NetworkBehaviour
|
||||
{
|
||||
[SerializeField] private float duration = 5f;
|
||||
|
||||
[SerializeField] private string type = "flare";
|
||||
|
||||
[SerializeField] private float damageRange = 20f;
|
||||
|
||||
[SerializeField] private float damageMagnitude = 1f;
|
||||
|
||||
private float existed;
|
||||
private Item.FlareRegister register;
|
||||
public float DamageMagnitude => damageMagnitude;
|
||||
public float DamageRange => damageRange;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
register = Item.FlareRegister.instance;
|
||||
register.bullets.Add(this);
|
||||
this.transform.parent = null;
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (existed >= duration)
|
||||
{
|
||||
register.bullets.Remove(this);
|
||||
InstanceFinder.ServerManager.Despawn(gameObject);
|
||||
Destroy(gameObject);
|
||||
|
||||
}
|
||||
|
||||
existed += Time.fixedDeltaTime;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Legacy/Item/Pistol/BulletComponent.cs.meta
Normal file
11
Assets/Scripts/Legacy/Item/Pistol/BulletComponent.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ea1ee4df8019a143b013f8837aa48d8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,48 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Item
|
||||
{
|
||||
public class PistolAnimationAimAssist : MonoBehaviour
|
||||
{
|
||||
public Transform leftShoulder;
|
||||
public Transform rightShoulder;
|
||||
|
||||
[SerializeField] private bool isEnabled;
|
||||
|
||||
private Animator anim;
|
||||
|
||||
private Vector3 lTarget;
|
||||
private Vector3 rTarget;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
lTarget = new Vector3(72.9f, 122.2f, -129.9f);
|
||||
rTarget = new Vector3(82f, 11f, -88f);
|
||||
anim = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
if (isEnabled)
|
||||
{
|
||||
anim.StopPlayback();
|
||||
leftShoulder.transform.eulerAngles = lTarget;
|
||||
rightShoulder.transform.eulerAngles = rTarget;
|
||||
print("Applying!");
|
||||
anim.StartPlayback();
|
||||
}
|
||||
}
|
||||
|
||||
public void Enable()
|
||||
{
|
||||
isEnabled = true;
|
||||
}
|
||||
|
||||
public void Disable()
|
||||
{
|
||||
isEnabled = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4463cddde602cde4b8fab345649839c8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
207
Assets/Scripts/Legacy/Item/Pistol/PistolComponent.cs
Normal file
207
Assets/Scripts/Legacy/Item/Pistol/PistolComponent.cs
Normal file
@ -0,0 +1,207 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.VFX;
|
||||
using FishNet.Object;
|
||||
using FishNet;
|
||||
|
||||
namespace Item
|
||||
{
|
||||
public class PistolComponent : NetworkBehaviour
|
||||
{
|
||||
public enum AimMode
|
||||
{
|
||||
GUN,
|
||||
MODIFIED,
|
||||
CAMERA
|
||||
}
|
||||
|
||||
public AimMode aimMode = AimMode.CAMERA;
|
||||
|
||||
[SerializeField] private Light targetingLight;
|
||||
|
||||
[SerializeField] private GameObject targetObjectPrefab;
|
||||
|
||||
[SerializeField] public GameObject projectilePrefab;
|
||||
|
||||
[SerializeField] public string projectileName;
|
||||
|
||||
[SerializeField] private Transform bulletSpawnPoint;
|
||||
|
||||
[SerializeField] private float firePower = 20f;
|
||||
|
||||
[SerializeField] private float maxProjectileDuration = 5f;
|
||||
|
||||
[SerializeField] private float maxTargetObjDistance = 15f;
|
||||
|
||||
[SerializeField] private VisualEffect shootEffect;
|
||||
|
||||
[SerializeField] private Light shootLight;
|
||||
|
||||
[SerializeField] private float shootLightDuration = 0.1f;
|
||||
|
||||
[SerializeField] private LayerMask ignoreLayers;
|
||||
|
||||
private bool hasCloseTarget;
|
||||
|
||||
|
||||
private bool IsEnabled;
|
||||
|
||||
private GameObject targetObject;
|
||||
private float timeSinceLightDuration;
|
||||
public bool IsLightOn => targetingLight.gameObject.activeSelf;
|
||||
|
||||
|
||||
//private Dictionary<int,float> projectiles = new Dictionary<int, float>();
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
timeSinceLightDuration += Time.deltaTime;
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (shootLight.gameObject.activeSelf && timeSinceLightDuration > shootLightDuration)
|
||||
shootLight.gameObject.SetActive(false);
|
||||
if (aimMode == AimMode.CAMERA) targetObject.gameObject.transform.position = Player.PlayerAim.active.targetPosition;
|
||||
if (IsEnabled && aimMode != AimMode.CAMERA)
|
||||
{
|
||||
var ray = new Ray(transform.position, transform.up);
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(ray, out hit, 50, ignoreLayers))
|
||||
{
|
||||
var hitDist = Vector3.Distance(hit.point, transform.position);
|
||||
if (hitDist < maxTargetObjDistance)
|
||||
{
|
||||
targetObject.gameObject.transform.position = hit.point;
|
||||
|
||||
targetObject.gameObject.GetComponent<MeshRenderer>().materials[0]
|
||||
.SetColor("_EmissiveColor", new Color(255, 0, 0));
|
||||
//Track if we have a close target
|
||||
hasCloseTarget = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
targetObject.gameObject.transform.position =
|
||||
transform.position + ray.direction * maxTargetObjDistance;
|
||||
|
||||
targetObject.gameObject.GetComponent<MeshRenderer>().materials[0]
|
||||
.SetColor("_EmissiveColor", new Color(255, 255, 255));
|
||||
//Track if we have a close target
|
||||
hasCloseTarget = false;
|
||||
}
|
||||
//float drop = CalculateDrop(this.bulletSpawnPoint.position, hit.point, this.transform.up * this.firePower);
|
||||
//print(drop);
|
||||
}
|
||||
else
|
||||
{
|
||||
targetObject.gameObject.transform.position = transform.position + ray.direction * maxTargetObjDistance;
|
||||
|
||||
targetObject.gameObject.GetComponent<MeshRenderer>().materials[0]
|
||||
.SetColor("_EmissiveColor", new Color(255, 255, 255));
|
||||
hasCloseTarget = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private float CalculateDrop(Vector3 origin, Vector3 destination, Vector3 force)
|
||||
{
|
||||
// Calculate the initial velocity required to reach the destination.
|
||||
var displacement = destination - origin;
|
||||
var time = Mathf.Sqrt(2f * displacement.magnitude / Physics.gravity.magnitude);
|
||||
var velocity = (displacement - 0.5f * Physics.gravity * time * time) / time + force;
|
||||
|
||||
// Calculate the height the object will reach during its flight.
|
||||
var maxHeight = origin.y + velocity.y * time - 0.5f * Physics.gravity.y * time * time;
|
||||
|
||||
// Calculate the distance the object will drop during its flight.
|
||||
var dropDistance = maxHeight - destination.y;
|
||||
|
||||
return dropDistance;
|
||||
}
|
||||
|
||||
public void Fire()
|
||||
{
|
||||
Fire(!hasCloseTarget);
|
||||
}
|
||||
|
||||
|
||||
[ServerRpc]
|
||||
public void Fire(bool offsetWithTargetBall)
|
||||
{
|
||||
|
||||
shootLightDuration = 0;
|
||||
shootLight.gameObject.SetActive(true);
|
||||
|
||||
// var projectile = Instantiate(projectilePrefab, bulletSpawnPoint);
|
||||
var projectile = Instantiate(projectilePrefab);
|
||||
projectile.transform.position = bulletSpawnPoint.transform.position;
|
||||
projectile.transform.rotation = bulletSpawnPoint.transform.rotation;
|
||||
//Comment this line if you want to remove the mega scale.
|
||||
projectile.transform.localScale =bulletSpawnPoint.transform.localScale;
|
||||
InstanceFinder.ServerManager.Spawn(projectile); //var projectile = Instantiate(projectilePrefab, bulletSpawnPoint);
|
||||
|
||||
//InstanceFinder.ServerManager.Spawn(projectile);
|
||||
|
||||
var pRigid = projectile.GetComponent<Rigidbody>();
|
||||
|
||||
/*Modified targeting system
|
||||
1. Since aim direction is vector from camera to ball (where player thinks its gonna go), raycast forward there, till hit. If no hit,
|
||||
then set target distance to ~50.
|
||||
2. Modify launch vector apply modified force
|
||||
*/
|
||||
var launchVector = pRigid.transform.up * firePower;
|
||||
|
||||
if (offsetWithTargetBall || aimMode == AimMode.MODIFIED)
|
||||
{
|
||||
var ballCamVector = targetObject.transform.position -
|
||||
GetComponentInParent<Player.PlayerMovementController>().cam.transform.position;
|
||||
var r = new Ray();
|
||||
r.origin = targetObject.transform.position;
|
||||
r.direction = ballCamVector.normalized;
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(r, out hit, ignoreLayers))
|
||||
{
|
||||
launchVector = (hit.point - pRigid.transform.position).normalized;
|
||||
launchVector *= firePower;
|
||||
}
|
||||
}
|
||||
else if (aimMode == AimMode.CAMERA)
|
||||
{
|
||||
var target = Player.PlayerAim.active.targetPosition;
|
||||
|
||||
var lv = target - pRigid.transform.position;
|
||||
launchVector = lv.normalized;
|
||||
launchVector *= firePower;
|
||||
}
|
||||
|
||||
pRigid.AddForce(launchVector, ForceMode.Impulse);
|
||||
projectile.transform.parent = null;
|
||||
|
||||
shootEffect.Play();
|
||||
}
|
||||
|
||||
public void Enable()
|
||||
{
|
||||
IsEnabled = true;
|
||||
if (targetObject == null) targetObject = Instantiate(targetObjectPrefab);
|
||||
}
|
||||
|
||||
public void Disable()
|
||||
{
|
||||
IsEnabled = false;
|
||||
if (targetObject != null) Destroy(targetObject);
|
||||
}
|
||||
|
||||
|
||||
public void LightToggle()
|
||||
{
|
||||
targetingLight.gameObject.SetActive(!targetingLight.gameObject.activeSelf);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Legacy/Item/Pistol/PistolComponent.cs.meta
Normal file
11
Assets/Scripts/Legacy/Item/Pistol/PistolComponent.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0bc8aa373bfbe44e91f0625324088be
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user