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:
18
Assets/Scripts/Legacy/Item/CarryableItem.cs
Normal file
18
Assets/Scripts/Legacy/Item/CarryableItem.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using UnityEngine;
|
||||
using FishNet.Connection;
|
||||
using FishNet.Object;
|
||||
|
||||
namespace Item
|
||||
{
|
||||
[RequireComponent(typeof(Collider))]
|
||||
[RequireComponent(typeof(Rigidbody))]
|
||||
public abstract class CarryableItem : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private string itemName;
|
||||
|
||||
[SerializeField] private int itemSize = 1;
|
||||
|
||||
public string ItemName => itemName;
|
||||
public int ItemSize => itemSize;
|
||||
}
|
||||
}
|
11
Assets/Scripts/Legacy/Item/CarryableItem.cs.meta
Normal file
11
Assets/Scripts/Legacy/Item/CarryableItem.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7beeb2b1c959a8a4a89869ecf33d0f16
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
98
Assets/Scripts/Legacy/Item/DoorInteractable.cs
Normal file
98
Assets/Scripts/Legacy/Item/DoorInteractable.cs
Normal file
@ -0,0 +1,98 @@
|
||||
using UnityEngine;
|
||||
namespace Item
|
||||
{
|
||||
public class DoorInteractable : HeavyItemReceiver
|
||||
{
|
||||
[SerializeField] private Transform powerCoreCenter;
|
||||
|
||||
[SerializeField] private float minAttractDist = 5;
|
||||
|
||||
[SerializeField] private string nameSearched = "Power Core";
|
||||
|
||||
[SerializeField] private Animator[] anims;
|
||||
|
||||
private HeavyInteractableItem insertedCore;
|
||||
private Vector3 priorLocalPos;
|
||||
private Vector3 priorLocalRot;
|
||||
private Vector3 priorScale;
|
||||
|
||||
public bool Powered => insertedCore != null;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
foreach (var anim in anims) anim.SetBool("IsPowered", Powered);
|
||||
}
|
||||
|
||||
public override bool Interact()
|
||||
{
|
||||
//print("INTERACTED!");
|
||||
if (insertedCore == null)
|
||||
{
|
||||
var worldHeavyItems = FindObjectsOfType<HeavyInteractableItem>();
|
||||
//print("Found:" + worldHeavyItems.Length);
|
||||
for (var i = 0; i < worldHeavyItems.Length; i++)
|
||||
{
|
||||
var item = worldHeavyItems[i];
|
||||
|
||||
if (!item.ItemName.Contains(nameSearched)) continue;
|
||||
var dist = Vector3.Distance(item.transform.position, powerCoreCenter.transform.position);
|
||||
//print("DIST:" + dist);
|
||||
if (dist <= minAttractDist)
|
||||
{
|
||||
var _i = Player.PlayerInteractionHandler.instance.Inventory;
|
||||
Interact(ref _i, ref item);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool Interact(ref Inventory inventory, ref HeavyInteractableItem heavyInvent)
|
||||
{
|
||||
//print("INTERACTED 2");
|
||||
// print(heavyInvent);
|
||||
|
||||
if (heavyInvent != null && heavyInvent.ItemName.Contains(nameSearched))
|
||||
{
|
||||
//print("DOOR OPEN!");
|
||||
heavyInvent.GetComponent<Rigidbody>().isKinematic = true;
|
||||
|
||||
heavyInvent.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
|
||||
priorLocalPos = heavyInvent.transform.localPosition;
|
||||
priorLocalRot = heavyInvent.transform.localEulerAngles;
|
||||
priorScale = heavyInvent.transform.localScale;
|
||||
|
||||
heavyInvent.transform.parent = powerCoreCenter;
|
||||
|
||||
heavyInvent.gameObject.transform.localPosition = Vector3.zero;
|
||||
heavyInvent.gameObject.transform.localEulerAngles = Vector3.zero;
|
||||
heavyInvent.transform.parent = null;
|
||||
heavyInvent.gameObject.transform.localScale = priorScale;
|
||||
|
||||
insertedCore = heavyInvent;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (insertedCore != null && heavyInvent == null)
|
||||
{
|
||||
heavyInvent = insertedCore;
|
||||
|
||||
insertedCore = null;
|
||||
//get ref of player perhaps
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Legacy/Item/DoorInteractable.cs.meta
Normal file
11
Assets/Scripts/Legacy/Item/DoorInteractable.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f575b137603a4b4282a6551120c979a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Legacy/Item/FlareBeacon.meta
Normal file
8
Assets/Scripts/Legacy/Item/FlareBeacon.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d8f50dd997a71e548881cf0a65dff80f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
72
Assets/Scripts/Legacy/Item/FlareBeacon/FlareBeacon.cs
Normal file
72
Assets/Scripts/Legacy/Item/FlareBeacon/FlareBeacon.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
namespace Item
|
||||
{
|
||||
public class FlareBeacon : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float range = 1;
|
||||
|
||||
[SerializeField] private float duration = 5f;
|
||||
|
||||
[SerializeField] private NavMeshObstacle obstacle;
|
||||
|
||||
private readonly List<GameObject> inRange = new();
|
||||
|
||||
private Item.FlareRegister register;
|
||||
|
||||
public float Range => range;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
register = Item.FlareRegister.instance;
|
||||
register.beacons.Add(this);
|
||||
transform.localEulerAngles = new Vector3(-89.98f, 0, 0);
|
||||
var r = new Ray();
|
||||
r.direction = -transform.forward;
|
||||
r.origin = transform.position;
|
||||
RaycastHit hit;
|
||||
var rays = Physics.RaycastAll(r);
|
||||
foreach (var _hit in rays)
|
||||
{
|
||||
if (_hit.transform.gameObject.GetComponent<FlareBeacon>() != null) continue;
|
||||
transform.position = _hit.point;
|
||||
break;
|
||||
}
|
||||
|
||||
if (Physics.Raycast(r, out hit))
|
||||
{
|
||||
// transform.position = hit.point;
|
||||
}
|
||||
|
||||
if (obstacle != null)
|
||||
obstacle.radius = range / 10;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
}
|
||||
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
// Draw a yellow sphere at the transform's position
|
||||
Gizmos.color = Color.yellow;
|
||||
|
||||
Gizmos.DrawWireSphere(transform.position, range);
|
||||
}
|
||||
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
inRange.Add(other.gameObject);
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
inRange.Remove(other.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Legacy/Item/FlareBeacon/FlareBeacon.cs.meta
Normal file
11
Assets/Scripts/Legacy/Item/FlareBeacon/FlareBeacon.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 210701b0acc3ff542b0d114370d98777
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
24
Assets/Scripts/Legacy/Item/GenericInteractable.cs
Normal file
24
Assets/Scripts/Legacy/Item/GenericInteractable.cs
Normal file
@ -0,0 +1,24 @@
|
||||
namespace Item
|
||||
{
|
||||
public class GenericInteractable : InteractableItem
|
||||
{
|
||||
private void Awake()
|
||||
{
|
||||
BaseAwake();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
}
|
||||
|
||||
public override bool Interact()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool Interact(ref Inventory inventory, ref HeavyInteractableItem heavyInvent)
|
||||
{
|
||||
return Interact();
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Legacy/Item/GenericInteractable.cs.meta
Normal file
11
Assets/Scripts/Legacy/Item/GenericInteractable.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ebc98b4f9e53f6841830816aa1064d6f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
49
Assets/Scripts/Legacy/Item/HeavyInteractableItem.cs
Normal file
49
Assets/Scripts/Legacy/Item/HeavyInteractableItem.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Item
|
||||
{
|
||||
public class HeavyInteractableItem : InteractableItem
|
||||
{
|
||||
private Vector3 init_rot;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
init_rot = transform.eulerAngles;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
BaseFixedUpdate();
|
||||
//print("Alpha Target:"+ base.target_alpha);
|
||||
}
|
||||
|
||||
public void DisableAll()
|
||||
{
|
||||
GetComponent<Collider>().enabled = false;
|
||||
}
|
||||
|
||||
public override bool Interact()
|
||||
{
|
||||
//Todo
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool Interact(ref Inventory inventory, ref HeavyInteractableItem heavyInvent)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void EnableAll()
|
||||
{
|
||||
GetComponent<Collider>().enabled = true;
|
||||
transform.eulerAngles = new Vector3(init_rot.x, transform.eulerAngles.y, init_rot.z);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Legacy/Item/HeavyInteractableItem.cs.meta
Normal file
11
Assets/Scripts/Legacy/Item/HeavyInteractableItem.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 051ddd707f17e1040b0fbe15645f75b6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
13
Assets/Scripts/Legacy/Item/HeavyItemReceiver.cs
Normal file
13
Assets/Scripts/Legacy/Item/HeavyItemReceiver.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Item
|
||||
{
|
||||
public abstract class HeavyItemReceiver : InteractableItem
|
||||
{
|
||||
[SerializeField]
|
||||
[Tooltip("Specify the keyword search in the name of the item!")]
|
||||
protected string searchString;
|
||||
|
||||
protected HeavyInteractableItem item;
|
||||
}
|
||||
}
|
11
Assets/Scripts/Legacy/Item/HeavyItemReceiver.cs.meta
Normal file
11
Assets/Scripts/Legacy/Item/HeavyItemReceiver.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aef7fff75652a9a499e312b65c8f91b1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
74
Assets/Scripts/Legacy/Item/InteractableItem.cs
Normal file
74
Assets/Scripts/Legacy/Item/InteractableItem.cs
Normal file
@ -0,0 +1,74 @@
|
||||
using FishNet.Object;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Item
|
||||
{
|
||||
[RequireComponent(typeof(Collider))]
|
||||
[RequireComponent(typeof(Rigidbody))]
|
||||
public abstract class InteractableItem : CarryableItem
|
||||
{
|
||||
[SerializeField] private Canvas interactionCanvas;
|
||||
|
||||
[SerializeField] protected bool canPickup;
|
||||
|
||||
private Image[] interaction_images;
|
||||
private TMP_Text[] interaction_texts;
|
||||
protected bool isEnabled;
|
||||
protected float target_alpha;
|
||||
|
||||
public bool CanPickup => canPickup;
|
||||
public bool IsEnabled => isEnabled;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
BaseAwake();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
BaseFixedUpdate();
|
||||
}
|
||||
|
||||
public void Enable()
|
||||
{
|
||||
//print("Enabled!");
|
||||
interactionCanvas.transform.LookAt(GameObject.FindGameObjectWithTag("MainCamera").transform.position);
|
||||
interactionCanvas.transform.Rotate(0, 180, 0);
|
||||
target_alpha = 1;
|
||||
isEnabled = true;
|
||||
}
|
||||
|
||||
public void Disable()
|
||||
{
|
||||
//print("Disabled!");
|
||||
target_alpha = 0;
|
||||
isEnabled = true;
|
||||
}
|
||||
|
||||
|
||||
public abstract bool Interact();
|
||||
|
||||
public abstract bool Interact(ref Inventory inventory, ref HeavyInteractableItem heavyInvent);
|
||||
|
||||
protected void BaseAwake()
|
||||
{
|
||||
interaction_texts = interactionCanvas.GetComponentsInChildren<TMP_Text>();
|
||||
interaction_images = interactionCanvas.GetComponentsInChildren<Image>();
|
||||
foreach (var text in interaction_texts) text.color = new Color(text.color.r, text.color.g, text.color.b, 0);
|
||||
foreach (var image in interaction_images)
|
||||
image.color = new Color(image.color.r, image.color.g, image.color.b, 0);
|
||||
}
|
||||
|
||||
protected void BaseFixedUpdate()
|
||||
{
|
||||
foreach (var text in interaction_texts)
|
||||
text.color = Color.Lerp(new Color(text.color.r, text.color.g, text.color.b, text.color.a),
|
||||
new Color(text.color.r, text.color.g, text.color.b, target_alpha), 10 * Time.deltaTime);
|
||||
foreach (var image in interaction_images)
|
||||
image.color = Color.Lerp(new Color(image.color.r, image.color.g, image.color.b, image.color.a),
|
||||
new Color(image.color.r, image.color.g, image.color.b, target_alpha), 10 * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Legacy/Item/InteractableItem.cs.meta
Normal file
11
Assets/Scripts/Legacy/Item/InteractableItem.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e1b92dbad437a8241a0eef54af2becd7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
31
Assets/Scripts/Legacy/Item/KeyItem.cs
Normal file
31
Assets/Scripts/Legacy/Item/KeyItem.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
namespace Item
|
||||
{
|
||||
public class KeyItem : InteractableItem
|
||||
{
|
||||
[SerializeField] private string keyName;
|
||||
|
||||
public string KeyName => keyName;
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
BaseAwake();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
}
|
||||
|
||||
public override bool Interact()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool Interact(ref Inventory inventory, ref HeavyInteractableItem heavyInvent)
|
||||
{
|
||||
return Interact();
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Legacy/Item/KeyItem.cs.meta
Normal file
11
Assets/Scripts/Legacy/Item/KeyItem.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb21435ed07266d488d3c4116207dfd9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Legacy/Item/Pistol.meta
Normal file
8
Assets/Scripts/Legacy/Item/Pistol.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7cd9f53a6ff4b6443b3d5b95e50767e4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
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:
|
8
Assets/Scripts/Legacy/Item/Registers.meta
Normal file
8
Assets/Scripts/Legacy/Item/Registers.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90f48ba02e4248644b7c711ebd9b212f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
24
Assets/Scripts/Legacy/Item/Registers/FlareRegister.cs
Normal file
24
Assets/Scripts/Legacy/Item/Registers/FlareRegister.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Item
|
||||
{
|
||||
public class FlareRegister : MonoBehaviour
|
||||
{
|
||||
public static FlareRegister instance;
|
||||
public List<BulletComponent> bullets = new();
|
||||
|
||||
public List<FlareBeacon> beacons = new();
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
instance = this;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Legacy/Item/Registers/FlareRegister.cs.meta
Normal file
11
Assets/Scripts/Legacy/Item/Registers/FlareRegister.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 788a4240e87c8654fa8813057977c848
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
116
Assets/Scripts/Legacy/Item/SpecialItemCycler.cs
Normal file
116
Assets/Scripts/Legacy/Item/SpecialItemCycler.cs
Normal file
@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Item
|
||||
{
|
||||
[Serializable]
|
||||
public class ItemImageRef
|
||||
{
|
||||
public string name;
|
||||
public GameObject item;
|
||||
public Sprite icon;
|
||||
}
|
||||
|
||||
public class SpecialItemCycler : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private List<ItemImageRef> spawnableItems = new();
|
||||
|
||||
[SerializeField] private List<ItemImageRef> shootableItems = new();
|
||||
|
||||
[SerializeField] private Player.PlayerInteractionHandler interactionHandler;
|
||||
|
||||
[SerializeField] private Item.PistolComponent pistol;
|
||||
|
||||
[SerializeField]
|
||||
//private Inventory invent;
|
||||
private TempInventory invent;
|
||||
|
||||
[SerializeField] private Image selectedImage;
|
||||
|
||||
[SerializeField] private TMP_Text selectedQuantityText;
|
||||
|
||||
private int shootableIndex;
|
||||
private int spawnableIndex;
|
||||
private Color sqtInitColor;
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
sqtInitColor = selectedQuantityText.color;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
if (interactionHandler.GunEnabled)
|
||||
{
|
||||
pistol.projectilePrefab = shootableItems[shootableIndex % shootableItems.Count].item;
|
||||
pistol.projectileName = shootableItems[shootableIndex % shootableItems.Count].name;
|
||||
}
|
||||
|
||||
SetImage();
|
||||
if (Input.GetButtonDown("CycleItems"))
|
||||
{
|
||||
if (interactionHandler.GunEnabled)
|
||||
{
|
||||
shootableIndex = (shootableIndex + 1) % shootableItems.Count;
|
||||
selectedImage.sprite = shootableItems[shootableIndex].icon;
|
||||
}
|
||||
else
|
||||
{
|
||||
spawnableIndex = (spawnableIndex + 1) % spawnableItems.Count;
|
||||
selectedImage.sprite = spawnableItems[spawnableIndex].icon;
|
||||
}
|
||||
|
||||
if (selectedImage.sprite == null)
|
||||
selectedImage.color = new Color(selectedImage.color.r, selectedImage.color.g, selectedImage.color.b, 0);
|
||||
else
|
||||
selectedImage.color = new Color(selectedImage.color.r, selectedImage.color.g, selectedImage.color.b, 1);
|
||||
}
|
||||
|
||||
if (Input.GetButtonDown("TempPlace"))
|
||||
if (invent.GetQuantityOf(spawnableItems[spawnableIndex].name) > 0)
|
||||
if (!interactionHandler.GunEnabled && spawnableItems[spawnableIndex].item != null)
|
||||
{
|
||||
var prefab = spawnableItems[spawnableIndex].item;
|
||||
var instance = Instantiate(prefab, interactionHandler.CarryingPos);
|
||||
instance.transform.localPosition = Vector3.zero;
|
||||
instance.transform.parent = null;
|
||||
invent.Remove(spawnableItems[spawnableIndex].name);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetImage()
|
||||
{
|
||||
if (interactionHandler.GunEnabled)
|
||||
{
|
||||
selectedImage.sprite = shootableItems[shootableIndex].icon;
|
||||
selectedQuantityText.text = invent.GetQuantityOf(shootableItems[shootableIndex].name).ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
selectedImage.sprite = spawnableItems[spawnableIndex].icon;
|
||||
selectedQuantityText.text = invent.GetQuantityOf(spawnableItems[spawnableIndex].name).ToString();
|
||||
}
|
||||
|
||||
if (selectedImage.sprite == null)
|
||||
{
|
||||
selectedImage.color = new Color(selectedImage.color.r, selectedImage.color.g, selectedImage.color.b, 0);
|
||||
selectedQuantityText.gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
selectedImage.color = new Color(selectedImage.color.r, selectedImage.color.g, selectedImage.color.b, 1);
|
||||
selectedQuantityText.gameObject.SetActive(true);
|
||||
if (selectedQuantityText.text == "0")
|
||||
selectedQuantityText.color = Color.red;
|
||||
else
|
||||
selectedQuantityText.color = sqtInitColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Legacy/Item/SpecialItemCycler.cs.meta
Normal file
11
Assets/Scripts/Legacy/Item/SpecialItemCycler.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57edf3fe88ab13c42b4f2b0cab83a3b8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user