106 lines
2.2 KiB
C#
106 lines
2.2 KiB
C#
using UnityEngine;
|
|
|
|
namespace Artngame.SKYMASTER
|
|
{
|
|
[ExecuteInEditMode]
|
|
public class moveMapOriginSM : MonoBehaviour
|
|
{
|
|
public Transform MapToMove;
|
|
|
|
public float moveAfterDist = 1000f;
|
|
|
|
public Transform player;
|
|
|
|
public CloudScript fullvolumeClouds;
|
|
|
|
public Material shadowsMat;
|
|
|
|
public bool operateOnlyXZ = true;
|
|
|
|
private Vector3 initPlayerPos;
|
|
|
|
public bool useLateUpdate;
|
|
|
|
private void Start()
|
|
{
|
|
if (shadowsMat != null && shadowsMat.HasProperty("cameraWSOffset"))
|
|
{
|
|
shadowsMat.SetVector("cameraWSOffset", Vector3.zero);
|
|
}
|
|
if (fullvolumeClouds != null)
|
|
{
|
|
fullvolumeClouds._CameraWSOffset = Vector3.zero;
|
|
}
|
|
initPlayerPos = player.transform.position;
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if (useLateUpdate)
|
|
{
|
|
myUpdate();
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!useLateUpdate)
|
|
{
|
|
myUpdate();
|
|
}
|
|
}
|
|
|
|
private void myUpdate()
|
|
{
|
|
float num = Vector3.Distance(player.transform.position, initPlayerPos);
|
|
if (operateOnlyXZ)
|
|
{
|
|
num = Vector2.Distance(new Vector2(player.transform.position.x, player.transform.position.z), new Vector2(initPlayerPos.x, initPlayerPos.z));
|
|
}
|
|
if (shadowsMat != null && shadowsMat.HasProperty("cameraWSOffset"))
|
|
{
|
|
if (Application.isPlaying)
|
|
{
|
|
shadowsMat.SetVector("cameraWSOffset", fullvolumeClouds._CameraWSOffset);
|
|
}
|
|
else
|
|
{
|
|
shadowsMat.SetVector("cameraWSOffset", Vector3.zero);
|
|
}
|
|
}
|
|
if (!(MapToMove != null) || !(num > moveAfterDist) || !Application.isPlaying)
|
|
{
|
|
return;
|
|
}
|
|
if (fullvolumeClouds != null)
|
|
{
|
|
if (operateOnlyXZ)
|
|
{
|
|
fullvolumeClouds._CameraWSOffset += new Vector3(player.transform.position.x, 0f, player.transform.position.z);
|
|
}
|
|
else
|
|
{
|
|
fullvolumeClouds._CameraWSOffset += player.transform.position;
|
|
}
|
|
}
|
|
if (operateOnlyXZ)
|
|
{
|
|
MapToMove.transform.position -= new Vector3(player.transform.position.x, 0f, player.transform.position.z);
|
|
}
|
|
else
|
|
{
|
|
MapToMove.transform.position -= player.transform.position;
|
|
}
|
|
if (operateOnlyXZ)
|
|
{
|
|
player.transform.position = new Vector3(0f, player.transform.position.y, 0f);
|
|
}
|
|
else
|
|
{
|
|
player.transform.position = Vector3.zero;
|
|
}
|
|
initPlayerPos = player.transform.position;
|
|
}
|
|
}
|
|
}
|