Skip to content

Commit

Permalink
v0.512
Browse files Browse the repository at this point in the history
  • Loading branch information
ozonexo3 committed Nov 30, 2017
1 parent 126ddd3 commit 2c5678c
Show file tree
Hide file tree
Showing 15 changed files with 308 additions and 51 deletions.
Binary file modified Assets/GFX/Terrain/ScmapTerrain.asset
Binary file not shown.
16 changes: 8 additions & 8 deletions Assets/GFX/Terrain/TerrainShader.mat
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ Material:
m_Offset: {x: 0, y: 0}
m_Floats:
- _AbyssLevel: 0.25
- _Area: 1
- _Area: 0
- _AreaHeight: 102.4
- _AreaWidht: 64
- _AreaX: 38.4
Expand All @@ -245,7 +245,7 @@ Material:
- _DepthLevel: 1.5
- _GeneratingNormal: 0
- _Grid: 0
- _GridCamDist: 7.339286
- _GridCamDist: 0.72023195
- _GridScale: 102.4
- _HideSplat0: 0
- _HideSplat1: 0
Expand All @@ -263,11 +263,11 @@ Material:
- _Slope: 0
- _Splat0Scale: 256
- _Splat0ScaleNormal: 256
- _Splat1Scale: 256
- _Splat1ScaleNormal: 256
- _Splat2Scale: 256
- _Splat2ScaleNormal: 256
- _Splat3Scale: 256
- _Splat1Scale: 292.57144
- _Splat1ScaleNormal: 89.04348
- _Splat2Scale: 60.952385
- _Splat2ScaleNormal: 512
- _Splat3Scale: 170.66667
- _Splat3ScaleNormal: 256
- _Splat4Scale: 256
- _Splat4ScaleNormal: 256
Expand All @@ -281,7 +281,7 @@ Material:
- _UpperScale: 8
- _UpperScaleNormal: 1024
- _UseSlopeTex: 1
- _Water: 0
- _Water: 1
- _WaterLevel: 1.75
- _WaterScaleX: 1024
- _WaterScaleZ: 1024
Expand Down
56 changes: 28 additions & 28 deletions Assets/MapEditor.unity
Original file line number Diff line number Diff line change
Expand Up @@ -24591,6 +24591,33 @@ CanvasRenderer:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 367747491}
--- !u!84 &370103507
RenderTexture:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name:
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_Width: 256
m_Height: 256
m_AntiAliasing: 1
m_DepthFormat: 1
m_ColorFormat: 0
m_MipMap: 0
m_GenerateMips: 1
m_SRGB: 0
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 0
m_MipBias: 0
m_WrapU: 1
m_WrapV: 1
m_WrapW: 1
m_Dimension: 2
m_VolumeDepth: 1
--- !u!1 &372661097
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -35699,7 +35726,7 @@ Camera:
serializedVersion: 2
m_Bits: 2560
m_RenderingPath: 1
m_TargetTexture: {fileID: 1997548720}
m_TargetTexture: {fileID: 370103507}
m_TargetDisplay: 0
m_TargetEye: 3
m_HDR: 0
Expand Down Expand Up @@ -123857,33 +123884,6 @@ CanvasRenderer:
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1997357582}
--- !u!84 &1997548720
RenderTexture:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name:
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_Width: 256
m_Height: 256
m_AntiAliasing: 1
m_DepthFormat: 1
m_ColorFormat: 0
m_MipMap: 0
m_GenerateMips: 1
m_SRGB: 0
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 0
m_MipBias: 0
m_WrapU: 1
m_WrapV: 1
m_WrapW: 1
m_Dimension: 2
m_VolumeDepth: 1
--- !u!1 &1997963198
GameObject:
m_ObjectHideFlags: 0
Expand Down
9 changes: 9 additions & 0 deletions Assets/Scripts/Camera.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using EditMap;
using Selection;

public class CameraControler : MonoBehaviour {
public partial class CameraControler : MonoBehaviour {

public static CameraControler Current;

Expand Down Expand Up @@ -55,6 +55,11 @@ public void RestartCam(){

RealCamPos = transform.localPosition;

LastLocalCamPos = transform.localPosition;
TargetLocalCamPos = transform.localPosition;
PanOffsetX = Vector3.zero;
PanOffsetZ = Vector3.zero;

//TargetWorldPos = new Vector3(MapSize * 0.05f, 100, MapSize * -0.05f);
//CamWorldPos = TargetWorldPos;
//transform.position = CamWorldPos;
Expand Down Expand Up @@ -125,7 +130,7 @@ void Update () {

if (HUD.MapLoaded)
{
CameraMovement();
UberCameraMovement();
}

if (Menu.IsMenuOpen())
Expand Down Expand Up @@ -334,10 +339,12 @@ void CameraMovement(){

Vector3 Ray = Pivot.InverseTransformVector(ray.direction);

/*
float CamChange = Mathf.Lerp(1, 1.5f, (Rot.x / -90));
Ray.z *= CamChange;
Ray.x *= Mathf.Lerp(1, 0.85f, (Rot.x / -90));
Ray.Normalize();
*/

RealCamPos += Ray * Input.GetAxis("Mouse ScrollWheel") * CamSpeed();

Expand Down
218 changes: 218 additions & 0 deletions Assets/Scripts/Camera/CameraControlerCam.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public partial class CameraControler : MonoBehaviour {


Vector3 LastLocalCamPos;
Vector3 TargetLocalCamPos;

Vector3 PanOffsetX = Vector3.zero;
Vector3 PanOffsetZ = Vector3.zero;

const float ScrollStep = 0.033f;
const float MinDistance = 1;
static float MaxDistance = 2048;

const float SmoothZoom = 14;
const float SmoothPan = 16;
const float SmoothRot = 14;
void UberCameraMovement()
{
if (Edit.MauseOnGameplay)
{
Ray ray = Cam.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;

int MouseScrollSteps = (int)(Input.GetAxis("Mouse ScrollWheel") / ScrollStep);

while (MouseScrollSteps != 0)
{
if (MouseScrollSteps > 0)
{ // In
if (transform.localPosition.y > MinDistance && Physics.Raycast(ray, out hit, MaxDistance, Mask))
{
Vector3 Ray = Pivot.InverseTransformDirection(ray.direction);
TargetLocalCamPos += Ray * ScrollStep * SampleCamSpeed();

float Distance = Vector3.Distance(Pivot.TransformPoint(TargetLocalCamPos), hit.point);
if (Distance < MinDistance)
{
TargetLocalCamPos = Pivot.InverseTransformPoint(hit.point - ray.direction * MinDistance);
}

}
MouseScrollSteps--;
}
else if (MouseScrollSteps < 0)
{ // Out
ray = new Ray(Cam.transform.position, Cam.transform.forward);
if (transform.localPosition.y < MaxDistance && Physics.Raycast(ray, out hit, MaxDistance, Mask))
{
Vector3 Ray = Pivot.InverseTransformDirection(ray.direction);
TargetLocalCamPos -= Ray * ScrollStep * SampleCamSpeed();
}
MouseScrollSteps++;
}
}
/*
if (Input.GetAxis("Mouse ScrollWheel") < 0 && transform.localPosition.y < MaxY)
{
ray = new Ray(Cam.transform.position, Cam.transform.forward);
if (Physics.Raycast(ray, out hit, 1000, Mask))
{
Vector3 Ray = Pivot.InverseTransformDirection(ray.direction);
TargetLocalCamPos += Ray * Input.GetAxis("Mouse ScrollWheel") * CamSpeed();
}
}
else if (Input.GetAxis("Mouse ScrollWheel") > 0 && transform.localPosition.y > 1)
{
if (Physics.Raycast(ray, out hit, 1000, Mask))
{
Vector3 Ray = Pivot.InverseTransformDirection(ray.direction);
TargetLocalCamPos += Ray * Input.GetAxis("Mouse ScrollWheel") * CamSpeed();
}
}
*/
}

LastLocalCamPos = Vector3.Lerp(LastLocalCamPos, TargetLocalCamPos, Time.unscaledDeltaTime * SmoothZoom);
transform.localPosition = LastLocalCamPos;


CursorUiPos();

if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(2))
{
prevMausePos = Input.mousePosition;
}

if (Input.GetKey(KeyCode.Space))
{
Rot.y += (Input.mousePosition.x - prevMausePos.x) * 12 * Time.unscaledDeltaTime;
Rot.x -= (Input.mousePosition.y - prevMausePos.y) * 12 * Time.unscaledDeltaTime;
Rot.x = Mathf.Clamp(Rot.x, -80, 0);
prevMausePos = Input.mousePosition;
}
if (Input.GetMouseButton(2))
{
float LocalPosToPanSpeed = (transform.localPosition.y * 0.08f + 0.1f) * 13;
PanOffsetX -= transform.right * (Input.mousePosition.x - prevMausePos.x) * LocalPosToPanSpeed * Time.unscaledDeltaTime;
Vector3 up = transform.up;
up.y = 0;
up.Normalize();
PanOffsetZ -= (up) * (Input.mousePosition.y - prevMausePos.y) * LocalPosToPanSpeed * Time.unscaledDeltaTime;
PanOffsetZ.y = 0;
prevMausePos = Input.mousePosition;
}

Vector3 PivotPos = transform.position;
PivotPos += PanOffsetX * Time.unscaledDeltaTime;

Ray ray3 = new Ray(PivotPos, Cam.transform.forward);
RaycastHit hit3;
if (Physics.Raycast(ray3, out hit3, MaxDistance, Mask))
{
LastLocalCamPos += Pivot.InverseTransformVector(PanOffsetX) * Time.unscaledDeltaTime;
TargetLocalCamPos += Pivot.InverseTransformVector(PanOffsetX) * Time.unscaledDeltaTime;
transform.position = PivotPos;
}

PivotPos = transform.position;
PivotPos += PanOffsetZ * Time.unscaledDeltaTime;
ray3 = new Ray(PivotPos, Cam.transform.forward);
if (Physics.Raycast(ray3, out hit3, MaxDistance, Mask))
{
LastLocalCamPos += Pivot.InverseTransformVector(PanOffsetZ) * Time.unscaledDeltaTime;
TargetLocalCamPos += Pivot.InverseTransformVector(PanOffsetZ) * Time.unscaledDeltaTime;
transform.position = PivotPos;
}


PanOffsetX = Vector3.Lerp(PanOffsetX, Vector3.zero, Time.unscaledDeltaTime * SmoothPan);
PanOffsetZ = Vector3.Lerp(PanOffsetZ, Vector3.zero, Time.unscaledDeltaTime * SmoothPan);

if (Input.GetKeyDown(KeyCode.Home))
{
RestartCam();

if (transform.localPosition.y < MinDistance)
{
Vector3 LocalPos = transform.localPosition;
LocalPos.y = MinDistance;
transform.localPosition = LocalPos;
}
else if(transform.localPosition.y > MaxDistance)
{
Vector3 LocalPos = transform.localPosition;
LocalPos.y = MaxDistance;
transform.localPosition = LocalPos;
}
}

Ray ray2 = new Ray(transform.position, Cam.transform.forward);
RaycastHit hit2;
if (Physics.Raycast(ray2, out hit2, MaxDistance, Mask))
{
SetNewPivotPos(hit2.point);
//ClampPosY();
}
else
{

}

Pivot.localRotation = Quaternion.Lerp(Pivot.localRotation, Quaternion.Euler(Rot), Time.unscaledDeltaTime * SmoothRot);

}

void SetNewPivotPos(Vector3 Pos)
{
Vector3 WorldPos = transform.position;
Pivot.position = Pos;
Vector3 Offset = Pivot.InverseTransformVector(transform.position - WorldPos);
transform.position = WorldPos;

LastLocalCamPos -= Offset;
TargetLocalCamPos -= Offset;
}

void CursorUiPos()
{

Ray ray = Cam.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, MaxDistance, MaskCursor))
{
Vector3 GameplayCursorPos = ScmapEditor.WorldPosToScmap(hit.point);
GameplayCursorPos.y = hit.point.y * 10;
GameplayCursorPos.z = ScmapEditor.Current.map.Height - GameplayCursorPos.z;
string X = GameplayCursorPos.x.ToString("N2");
string Y = GameplayCursorPos.y.ToString("N2");
string Z = GameplayCursorPos.z.ToString("N2");

X = X.PadRight(8);
Y = Y.PadRight(8);
Z = Z.PadRight(8);

CursorInfo.text = "x: " + X + "\ty: " + Y + "\tz: " + Z;
}
else
{
CursorInfo.text = "x: -------- \ty: -------- \tz: -------- ";
}
}

float SampleCamSpeed()
{
Ray ray = new Ray(Pivot.TransformPoint(TargetLocalCamPos), transform.forward);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, MaxDistance, Mask))
{
return Mathf.Lerp(15f, 300, Mathf.Pow(hit.distance / 150, 1.2f)) * 1.2f;

}
return 0;
}
}
Loading

0 comments on commit 2c5678c

Please sign in to comment.