Added orbit camera controller for game view
Play/pause toggled with SPACE navigate camera with mouse and WASD (forward/right) + EQ (up)more-targets
parent
bee353503e
commit
cfd5653620
|
@ -0,0 +1,33 @@
|
|||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &2001330936307234688
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 4469068623513710330}
|
||||
m_Layer: 0
|
||||
m_Name: EmptyObject
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &4469068623513710330
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2001330936307234688}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0700a0ec3029a994995a63cce63d4c91
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -160,7 +160,7 @@ Transform:
|
|||
m_GameObject: {fileID: 17322847}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 1658.5714, y: 1799.5472, z: 3209.2483}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
|
@ -1344,6 +1344,37 @@ MeshFilter:
|
|||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 530428117}
|
||||
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!1 &564968302
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 564968303}
|
||||
m_Layer: 0
|
||||
m_Name: FloorGridTarget
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &564968303
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 564968302}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &674567081
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -1381,37 +1412,6 @@ Transform:
|
|||
- {fileID: 1254435376}
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &694951365
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 694951366}
|
||||
m_Layer: 0
|
||||
m_Name: GameObject
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &694951366
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 694951365}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 44, y: 78, z: 1006.2}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &705507993
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -1542,6 +1542,7 @@ GameObject:
|
|||
- component: {fileID: 963194227}
|
||||
- component: {fileID: 963194226}
|
||||
- component: {fileID: 963194229}
|
||||
- component: {fileID: 963194230}
|
||||
m_Layer: 0
|
||||
m_Name: Main Camera
|
||||
m_TagString: MainCamera
|
||||
|
@ -1589,7 +1590,7 @@ Camera:
|
|||
width: 1
|
||||
height: 1
|
||||
near clip plane: 0.3
|
||||
far clip plane: 20000
|
||||
far clip plane: 30000
|
||||
field of view: 60
|
||||
orthographic: 0
|
||||
orthographic size: 5
|
||||
|
@ -1616,13 +1617,13 @@ Transform:
|
|||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 963194225}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0.06923829, y: -0.60505766, z: 0.052935712, w: 0.7913969}
|
||||
m_LocalPosition: {x: 1500, y: 500, z: 800}
|
||||
m_LocalRotation: {x: 0.27059805, y: -0.6532815, z: 0.27059805, w: 0.6532815}
|
||||
m_LocalPosition: {x: 1500, y: 1500, z: 800}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 10, y: -74.799, z: 0}
|
||||
m_LocalEulerAnglesHint: {x: 45, y: -90, z: 0}
|
||||
--- !u!114 &963194229
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -1667,6 +1668,40 @@ MonoBehaviour:
|
|||
m_MipBias: 0
|
||||
m_VarianceClampScale: 0.9
|
||||
m_ContrastAdaptiveSharpening: 0
|
||||
--- !u!114 &963194230
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 963194225}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 6a028bd12cca23f45a9eeb9fb0c4d1f1, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
mouseActive: 1
|
||||
autoplayCamSpeed: 2
|
||||
xAutoRotateTime: 5
|
||||
yAutoRotateTime: 5
|
||||
lockUserInput: 0
|
||||
_cameraSpeedNormal: 100
|
||||
_cameraSpeedMax: 1000
|
||||
_speedH: 2
|
||||
_speedV: 2
|
||||
autoRotate: 0
|
||||
target: {fileID: 1255004942}
|
||||
targetRenderer: {fileID: 1255004940}
|
||||
floorRenderer: {fileID: 394856875}
|
||||
matAlpha: 0
|
||||
orbitDistance: 5000
|
||||
orbitXSpeed: 0.1
|
||||
orbitYSpeed: 0.1
|
||||
orbitYMinLimit: -20
|
||||
orbitYMaxLimit: 80
|
||||
orbitDistanceMin: 10
|
||||
orbitDistanceMax: 10000
|
||||
forwardToCameraAngle: 0
|
||||
--- !u!1 &986996500
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -1873,6 +1908,89 @@ Transform:
|
|||
- {fileID: 394856873}
|
||||
m_Father: {fileID: 674567085}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &1255004938
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 1255004942}
|
||||
- component: {fileID: 1255004941}
|
||||
- component: {fileID: 1255004940}
|
||||
m_Layer: 0
|
||||
m_Name: OrbitTarget
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!23 &1255004940
|
||||
MeshRenderer:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1255004938}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 1
|
||||
m_ReceiveShadows: 1
|
||||
m_DynamicOccludee: 1
|
||||
m_StaticShadowCaster: 0
|
||||
m_MotionVectors: 1
|
||||
m_LightProbeUsage: 1
|
||||
m_ReflectionProbeUsage: 1
|
||||
m_RayTracingMode: 2
|
||||
m_RayTraceProcedural: 0
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 2100000, guid: 548fe8e516bc01e48a296f5b86c7aa18, type: 2}
|
||||
m_StaticBatchInfo:
|
||||
firstSubMesh: 0
|
||||
subMeshCount: 0
|
||||
m_StaticBatchRoot: {fileID: 0}
|
||||
m_ProbeAnchor: {fileID: 0}
|
||||
m_LightProbeVolumeOverride: {fileID: 0}
|
||||
m_ScaleInLightmap: 1
|
||||
m_ReceiveGI: 1
|
||||
m_PreserveUVs: 0
|
||||
m_IgnoreNormalsForChartDetection: 0
|
||||
m_ImportantGI: 0
|
||||
m_StitchLightmapSeams: 1
|
||||
m_SelectedEditorRenderState: 3
|
||||
m_MinimumChartSize: 4
|
||||
m_AutoUVMaxDistance: 0.5
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_SortingLayerID: 0
|
||||
m_SortingLayer: 0
|
||||
m_SortingOrder: 0
|
||||
m_AdditionalVertexStreams: {fileID: 0}
|
||||
--- !u!33 &1255004941
|
||||
MeshFilter:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1255004938}
|
||||
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!4 &1255004942
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1255004938}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 100, y: 100, z: 100}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!1 &1311731091
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -2505,6 +2623,7 @@ SceneRoots:
|
|||
- {fileID: 705507995}
|
||||
- {fileID: 674567085}
|
||||
- {fileID: 253946927}
|
||||
- {fileID: 694951366}
|
||||
- {fileID: 2052906806}
|
||||
- {fileID: 17322849}
|
||||
- {fileID: 1255004942}
|
||||
- {fileID: 564968303}
|
||||
|
|
|
@ -136,9 +136,9 @@ public abstract class Agent : MonoBehaviour {
|
|||
}
|
||||
|
||||
// Update is called once per frame
|
||||
protected virtual void Update() {
|
||||
_timeSinceLaunch += Time.deltaTime;
|
||||
_timeInPhase += Time.deltaTime;
|
||||
protected virtual void FixedUpdate() {
|
||||
_timeSinceLaunch += Time.fixedDeltaTime;
|
||||
_timeInPhase += Time.fixedDeltaTime;
|
||||
|
||||
var launch_time = _agentConfig.dynamic_config.launch_config.launch_time;
|
||||
var boost_time = launch_time + StaticConfig.boostConfig.boostTime;
|
||||
|
@ -159,14 +159,14 @@ public abstract class Agent : MonoBehaviour {
|
|||
case FlightPhase.INITIALIZED:
|
||||
break;
|
||||
case FlightPhase.READY:
|
||||
UpdateReady(Time.deltaTime);
|
||||
UpdateReady(Time.fixedDeltaTime);
|
||||
break;
|
||||
case FlightPhase.BOOST:
|
||||
UpdateBoost(Time.deltaTime);
|
||||
UpdateBoost(Time.fixedDeltaTime);
|
||||
break;
|
||||
case FlightPhase.MIDCOURSE:
|
||||
case FlightPhase.TERMINAL:
|
||||
UpdateMidCourse(Time.deltaTime);
|
||||
UpdateMidCourse(Time.fixedDeltaTime);
|
||||
break;
|
||||
case FlightPhase.TERMINATED:
|
||||
break;
|
||||
|
|
|
@ -0,0 +1,463 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
|
||||
public class InputManager : MonoBehaviour
|
||||
{
|
||||
|
||||
public static InputManager Instance { get; private set; }
|
||||
|
||||
|
||||
|
||||
public bool mouseActive = true;
|
||||
[System.Serializable]
|
||||
public struct CameraPreset
|
||||
{
|
||||
public Vector3 position;
|
||||
public Quaternion rotation;
|
||||
}
|
||||
|
||||
public float autoplayCamSpeed = 2f;
|
||||
public float xAutoRotateTime = 5f;
|
||||
public float yAutoRotateTime = 5f;
|
||||
private Coroutine autoplayRoutine;
|
||||
|
||||
|
||||
public bool lockUserInput = false;
|
||||
|
||||
private float _cameraSpeed;
|
||||
public float _cameraSpeedNormal = 5.0f;
|
||||
public float _cameraSpeedMax = 10.0f;
|
||||
|
||||
public float _speedH = 2.0f;
|
||||
public float _speedV = 2.0f;
|
||||
|
||||
private float _yaw = 0.0f;
|
||||
private float _pitch = 0.0f;
|
||||
|
||||
private float reloadModifier;
|
||||
|
||||
// Orbit controller
|
||||
public bool autoRotate = false;
|
||||
|
||||
public Transform target;
|
||||
public Renderer targetRenderer;
|
||||
public Renderer floorRenderer;
|
||||
public float matAlpha;
|
||||
public float orbitDistance = 5.0f;
|
||||
public float orbitXSpeed = 120.0f;
|
||||
public float orbitYSpeed = 120.0f;
|
||||
|
||||
public float orbitYMinLimit = -20f;
|
||||
public float orbitYMaxLimit = 80f;
|
||||
|
||||
public float orbitDistanceMin = .5f;
|
||||
public float orbitDistanceMax = 15f;
|
||||
|
||||
private Rigidbody _rigidbody;
|
||||
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
|
||||
|
||||
CameraPreset fourPos = new CameraPreset();
|
||||
CameraPreset fivePos = new CameraPreset();
|
||||
CameraPreset sixPos = new CameraPreset();
|
||||
|
||||
Vector3 wVector = Vector3.forward;
|
||||
Vector3 aVector = Vector3.left;
|
||||
Vector3 sVector = Vector3.back;
|
||||
Vector3 dVector = Vector3.right;
|
||||
|
||||
public float forwardToCameraAngle;
|
||||
|
||||
void SetCameraRotation(Quaternion rotation)
|
||||
{
|
||||
transform.rotation = rotation;
|
||||
_pitch = rotation.eulerAngles.x;
|
||||
_yaw = rotation.eulerAngles.y;
|
||||
}
|
||||
|
||||
public static float ClampAngle(float angle, float min, float max)
|
||||
{
|
||||
if (angle < -360F)
|
||||
angle += 360F;
|
||||
if (angle > 360F)
|
||||
angle -= 360F;
|
||||
return Mathf.Clamp(angle, min, max);
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance == null) {
|
||||
Instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
} else {
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
fourPos.position = new Vector3(0, 0, 0);
|
||||
fourPos.rotation = Quaternion.Euler(0,0,0);
|
||||
fivePos.position = new Vector3(0, 0, 0);
|
||||
fivePos.rotation = Quaternion.Euler(0, 0, 0);
|
||||
sixPos.position = new Vector3(0, 0, 0);
|
||||
sixPos.rotation = Quaternion.Euler(0, 0, 0);
|
||||
|
||||
Vector3 angles = transform.eulerAngles;
|
||||
x = angles.y;
|
||||
y = angles.x;
|
||||
|
||||
UpdateTargetAlpha();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
HandleInput();
|
||||
}
|
||||
|
||||
IEnumerator AutoPlayRoutine()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
float elapsedTime = 0f;
|
||||
while (elapsedTime <= xAutoRotateTime)
|
||||
{
|
||||
x += Time.unscaledDeltaTime * autoplayCamSpeed * orbitDistance * 0.02f;
|
||||
UpdateCamPosition();
|
||||
elapsedTime += Time.unscaledDeltaTime;
|
||||
yield return null;
|
||||
}
|
||||
elapsedTime = 0f;
|
||||
while (elapsedTime <= yAutoRotateTime)
|
||||
{
|
||||
y -= Time.unscaledDeltaTime * autoplayCamSpeed * orbitDistance * 0.02f;
|
||||
UpdateCamPosition();
|
||||
elapsedTime += Time.unscaledDeltaTime;
|
||||
yield return null;
|
||||
}
|
||||
elapsedTime = 0f;
|
||||
while (elapsedTime <= xAutoRotateTime)
|
||||
{
|
||||
x -= Time.unscaledDeltaTime * autoplayCamSpeed * orbitDistance * 0.02f;
|
||||
UpdateCamPosition();
|
||||
elapsedTime += Time.unscaledDeltaTime;
|
||||
yield return null;
|
||||
}
|
||||
elapsedTime = 0f;
|
||||
while (elapsedTime <= yAutoRotateTime)
|
||||
{
|
||||
y += Time.unscaledDeltaTime * autoplayCamSpeed * orbitDistance * 0.02f;
|
||||
UpdateCamPosition();
|
||||
elapsedTime += Time.unscaledDeltaTime;
|
||||
yield return null;
|
||||
}
|
||||
yield return null;
|
||||
}
|
||||
|
||||
}
|
||||
void ResetCameraTarget()
|
||||
{
|
||||
RaycastHit hit;
|
||||
if(Physics.Raycast(transform.position, transform.forward, out hit, float.MaxValue, LayerMask.GetMask("Floor"), QueryTriggerInteraction.Ignore))
|
||||
{
|
||||
target.transform.position = hit.point;
|
||||
orbitDistance = hit.distance;
|
||||
Vector3 angles = transform.eulerAngles;
|
||||
x = angles.y;
|
||||
y = angles.x;
|
||||
UpdateCamPosition();
|
||||
}
|
||||
else
|
||||
{
|
||||
target.transform.position = transform.position + (transform.forward * 100);
|
||||
orbitDistance = 100;
|
||||
Vector3 angles = transform.eulerAngles;
|
||||
x = angles.y;
|
||||
y = angles.x;
|
||||
//UpdateCamPosition();
|
||||
}
|
||||
}
|
||||
|
||||
public void EnableTargetRenderer(bool enable) { targetRenderer.enabled = enable; }
|
||||
|
||||
public void EnableFloorGridRenderer(bool enable) { floorRenderer.enabled = enable; }
|
||||
|
||||
private void HandleMouseInput()
|
||||
{
|
||||
// Orbit
|
||||
if (target)
|
||||
{
|
||||
if (Input.GetMouseButton(0))
|
||||
{
|
||||
x += Input.GetAxis("Mouse X") * orbitXSpeed * orbitDistance * 0.02f;
|
||||
y -= Input.GetAxis("Mouse Y") * orbitYSpeed * orbitDistance * 0.02f;
|
||||
|
||||
y = ClampAngle(y, orbitYMinLimit, orbitYMaxLimit);
|
||||
UpdateCamPosition();
|
||||
|
||||
}
|
||||
// Rotate
|
||||
else if (Input.GetMouseButton(1))
|
||||
{
|
||||
_yaw += _speedH * Input.GetAxis("Mouse X");
|
||||
_pitch -= _speedV * Input.GetAxis("Mouse Y");
|
||||
|
||||
transform.eulerAngles = new Vector3(_pitch, _yaw, 0.0f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void UpdateCamPosition()
|
||||
{
|
||||
Quaternion rotation = Quaternion.Euler(y, x, 0);
|
||||
RaycastHit hit;
|
||||
//Debug.DrawLine(target.position, transform.position, Color.red);
|
||||
if (Physics.Linecast(target.position, transform.position, out hit, ~LayerMask.GetMask("Floor"), QueryTriggerInteraction.Ignore))
|
||||
{
|
||||
orbitDistance -= hit.distance;
|
||||
}
|
||||
Vector3 negDistance = new Vector3(0.0f, 0.0f, -orbitDistance);
|
||||
Vector3 position = rotation * negDistance + target.position;
|
||||
UpdateTargetAlpha();
|
||||
|
||||
SetCameraRotation(rotation);
|
||||
transform.position = position;
|
||||
}
|
||||
|
||||
private void HandleInput()
|
||||
{
|
||||
if (!lockUserInput)
|
||||
{
|
||||
HandleLockableInput();
|
||||
}
|
||||
HandleNonLockableInput();
|
||||
}
|
||||
|
||||
void HandleScrollWheelInput()
|
||||
{
|
||||
if (Input.GetAxis("Mouse ScrollWheel") != 0)
|
||||
{
|
||||
orbitDistance = Mathf.Clamp(orbitDistance - Input.GetAxis("Mouse ScrollWheel") * 500, orbitDistanceMin, orbitDistanceMax);
|
||||
UpdateCamPosition();
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateTargetAlpha()
|
||||
{
|
||||
matAlpha = (orbitDistance - orbitDistanceMin) / (orbitDistanceMax - orbitDistanceMin);
|
||||
matAlpha = Mathf.Max(Mathf.Sqrt(matAlpha) - 0.5f, 0);
|
||||
Color matColor = targetRenderer.material.color;
|
||||
matColor.a = matAlpha;
|
||||
targetRenderer.material.color = matColor;
|
||||
}
|
||||
|
||||
void UpdateDirectionVectors()
|
||||
{
|
||||
Vector3 cameraToTarget = target.position - transform.position;
|
||||
cameraToTarget.y = 0;
|
||||
forwardToCameraAngle = Vector3.SignedAngle(Vector3.forward, cameraToTarget, Vector3.down);
|
||||
|
||||
if(forwardToCameraAngle >-45f && forwardToCameraAngle <= 45f)
|
||||
{
|
||||
wVector = Vector3.forward;
|
||||
aVector = Vector3.left;
|
||||
sVector = Vector3.back;
|
||||
dVector = Vector3.right;
|
||||
}
|
||||
else if(forwardToCameraAngle > 45f && forwardToCameraAngle <= 135f)
|
||||
{
|
||||
wVector = Vector3.left;
|
||||
aVector = Vector3.back;
|
||||
sVector = Vector3.right;
|
||||
dVector = Vector3.forward;
|
||||
}
|
||||
else if(forwardToCameraAngle > 135f || forwardToCameraAngle <= -135f)
|
||||
{
|
||||
wVector = Vector3.back;
|
||||
aVector = Vector3.right;
|
||||
sVector = Vector3.forward;
|
||||
dVector = Vector3.left;
|
||||
}
|
||||
else if(forwardToCameraAngle > -135f && forwardToCameraAngle <= -45f)
|
||||
{
|
||||
wVector = Vector3.right;
|
||||
aVector = Vector3.forward;
|
||||
sVector = Vector3.left;
|
||||
dVector = Vector3.back;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void HandleLockableInput()
|
||||
{
|
||||
|
||||
HandleMouseInput();
|
||||
if (Input.GetKey(KeyCode.LeftShift))
|
||||
{
|
||||
reloadModifier = -.1f;
|
||||
_cameraSpeed = _cameraSpeedMax;
|
||||
}
|
||||
else
|
||||
{
|
||||
reloadModifier = .1f;
|
||||
_cameraSpeed = _cameraSpeedNormal;
|
||||
}
|
||||
|
||||
// TRANSLATIONAL MOVEMENT
|
||||
if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
|
||||
{
|
||||
UpdateDirectionVectors();
|
||||
//transform.Translate(Vector3.forward * Time.deltaTime * _cameraSpeed);
|
||||
target.Translate(wVector * Time.unscaledDeltaTime * _cameraSpeed);
|
||||
UpdateCamPosition();
|
||||
}
|
||||
if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
|
||||
{
|
||||
UpdateDirectionVectors();
|
||||
//transform.Translate(Vector3.left * Time.deltaTime * _cameraSpeed);
|
||||
target.Translate(aVector * Time.unscaledDeltaTime * _cameraSpeed);
|
||||
UpdateCamPosition();
|
||||
}
|
||||
if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
|
||||
{
|
||||
UpdateDirectionVectors();
|
||||
//transform.Translate(Vector3.back * Time.deltaTime * _cameraSpeed);
|
||||
target.Translate(sVector * Time.unscaledDeltaTime * _cameraSpeed);
|
||||
UpdateCamPosition();
|
||||
}
|
||||
if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
|
||||
{
|
||||
UpdateDirectionVectors();
|
||||
//transform.Translate(Vector3.right * Time.deltaTime * _cameraSpeed);
|
||||
target.Translate(dVector * Time.unscaledDeltaTime * _cameraSpeed);
|
||||
UpdateCamPosition();
|
||||
}
|
||||
if (Input.GetKey(KeyCode.Q))
|
||||
{
|
||||
//transform.Translate(Vector3.up * Time.deltaTime * _cameraSpeed);
|
||||
target.Translate(Vector3.up * Time.unscaledDeltaTime * _cameraSpeed);
|
||||
|
||||
UpdateCamPosition();
|
||||
}
|
||||
if (Input.GetKey(KeyCode.E))
|
||||
{
|
||||
//transform.Translate(Vector3.down * Time.deltaTime * _cameraSpeed);
|
||||
target.Translate(Vector3.down * Time.unscaledDeltaTime * _cameraSpeed);
|
||||
|
||||
UpdateCamPosition();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void HandleNonLockableInput()
|
||||
{
|
||||
HandleScrollWheelInput();
|
||||
if (Input.GetKeyDown(KeyCode.I))
|
||||
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.C))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
// Pause the time
|
||||
if (SimManager.Instance.IsSimulationRunning()) {
|
||||
SimManager.Instance.PauseSimulation();
|
||||
} else {
|
||||
SimManager.Instance.ResumeSimulation();
|
||||
}
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.P))
|
||||
{
|
||||
autoRotate = !autoRotate;
|
||||
if (autoRotate)
|
||||
{
|
||||
autoplayRoutine = StartCoroutine(AutoPlayRoutine());
|
||||
}
|
||||
else
|
||||
{
|
||||
StopCoroutine( autoplayRoutine );
|
||||
}
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Alpha1))
|
||||
{
|
||||
// ORIGIN
|
||||
transform.position = new Vector3(0, 20, -20);
|
||||
SetCameraRotation(Quaternion.Euler(24f, -0.5f, 0));
|
||||
Camera.main.fieldOfView = 45f;
|
||||
ResetCameraTarget();
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Alpha2))
|
||||
{
|
||||
transform.position = new Vector3(0, 30, -20);
|
||||
SetCameraRotation(Quaternion.Euler(36.6f, -0.5f, 0));
|
||||
Camera.main.fieldOfView = 60f;
|
||||
ResetCameraTarget();
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Alpha4))
|
||||
{
|
||||
if (Input.GetKey(KeyCode.LeftShift))
|
||||
{
|
||||
fourPos.position = transform.position;
|
||||
fourPos.rotation = transform.rotation;
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.position = fourPos.position;
|
||||
SetCameraRotation(fourPos.rotation);
|
||||
ResetCameraTarget();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Alpha5))
|
||||
{
|
||||
if (Input.GetKey(KeyCode.LeftShift))
|
||||
{
|
||||
fivePos.position = transform.position;
|
||||
fivePos.rotation = transform.rotation;
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.position = fivePos.position;
|
||||
SetCameraRotation(fivePos.rotation);
|
||||
ResetCameraTarget();
|
||||
}
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.Alpha6))
|
||||
{
|
||||
if (Input.GetKey(KeyCode.LeftShift))
|
||||
{
|
||||
sixPos.position = transform.position;
|
||||
sixPos.rotation = transform.rotation;
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.position = sixPos.position;
|
||||
SetCameraRotation(sixPos.rotation);
|
||||
ResetCameraTarget();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6a028bd12cca23f45a9eeb9fb0c4d1f1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -7,8 +7,8 @@ public class Hydra70 : Missile {
|
|||
private Vector3 _acceleration;
|
||||
private bool _submunitionsLaunched = false;
|
||||
|
||||
protected override void Update() {
|
||||
base.Update();
|
||||
protected override void FixedUpdate() {
|
||||
base.FixedUpdate();
|
||||
|
||||
// Check if it's time to launch submunitions
|
||||
if (!_submunitionsLaunched &&
|
||||
|
|
|
@ -30,8 +30,8 @@ public class Missile : Agent {
|
|||
// GetComponent<Rigidbody>().AddForce(acceleration, ForceMode.Acceleration);
|
||||
}
|
||||
|
||||
protected override void Update() {
|
||||
base.Update();
|
||||
protected override void FixedUpdate() {
|
||||
base.FixedUpdate();
|
||||
if (_showDebugVectors) {
|
||||
DrawDebugVectors();
|
||||
}
|
||||
|
|
|
@ -49,6 +49,10 @@ public class SimManager : MonoBehaviour {
|
|||
return _activeTargets;
|
||||
}
|
||||
|
||||
public List<Agent> GetActiveAgents() {
|
||||
return _activeMissiles.ConvertAll(missile => missile as Agent).Concat(_activeTargets.ConvertAll(target => target as Agent)).ToList();
|
||||
}
|
||||
|
||||
void Awake() {
|
||||
// Ensure only one instance of SimManager exists
|
||||
if (Instance == null) {
|
||||
|
@ -62,14 +66,31 @@ public class SimManager : MonoBehaviour {
|
|||
void Start() {
|
||||
// Slow down time by simulationConfig.timeScale
|
||||
if (Instance == this) {
|
||||
Time.timeScale = simulationConfig.timeScale;
|
||||
Time.fixedDeltaTime = Time.timeScale * 0.02f;
|
||||
Time.maximumDeltaTime = Time.timeScale * 0.15f;
|
||||
InitializeSimulation();
|
||||
simulationRunning = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetTimeScale(float timeScale) {
|
||||
Time.timeScale = timeScale;
|
||||
Time.fixedDeltaTime = Time.timeScale * 0.02f;
|
||||
Time.maximumDeltaTime = Time.timeScale * 0.15f;
|
||||
}
|
||||
|
||||
public void PauseSimulation() {
|
||||
SetTimeScale(0);
|
||||
simulationRunning = false;
|
||||
}
|
||||
|
||||
public void ResumeSimulation() {
|
||||
SetTimeScale(simulationConfig.timeScale);
|
||||
simulationRunning = true;
|
||||
}
|
||||
|
||||
public bool IsSimulationRunning() {
|
||||
return simulationRunning;
|
||||
}
|
||||
|
||||
private void InitializeSimulation() {
|
||||
List<Missile> missiles = new List<Missile>();
|
||||
// Create missiles based on config
|
||||
|
|
|
@ -9,8 +9,8 @@ public class DroneTarget : Target {
|
|||
}
|
||||
|
||||
// Update is called once per frame
|
||||
protected override void Update() {
|
||||
base.Update();
|
||||
protected override void FixedUpdate() {
|
||||
base.FixedUpdate();
|
||||
}
|
||||
|
||||
protected override void UpdateReady(double deltaTime) {}
|
||||
|
|
|
@ -11,7 +11,7 @@ public abstract class Target : Agent {
|
|||
base.Start();
|
||||
}
|
||||
|
||||
protected override void Update() {
|
||||
base.Update();
|
||||
protected override void FixedUpdate() {
|
||||
base.FixedUpdate();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue