Zone View Mousedrag & Background Parallax

This commit is contained in:
hyperion51 2020-03-25 03:15:00 +00:00
commit 6dd43fc193
9 changed files with 113 additions and 5 deletions

View file

@ -9,6 +9,7 @@
<e p="Assembly-CSharp-firstpass.csproj" t="IncludeRecursive" />
<e p="Assembly-CSharp.csproj" t="IncludeRecursive" />
<e p="Assets" t="Include">
<e p="DragHandler.cs" t="Include" />
<e p="Plugins" t="Include">
<e p="AsyncAwaitUtil" t="Include">
<e p="Source" t="Include">

View file

@ -60,6 +60,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Assets\DragHandler.cs" />
<Compile Include="Assets\Scripts\BackgroundRenderer.cs" />
<Compile Include="Assets\Scripts\CultClient.cs" />
<Compile Include="Assets\Scripts\Galaxy.cs" />

22
Assets/DragHandler.cs Normal file
View file

@ -0,0 +1,22 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DragHandler : MonoBehaviour
{
public Camera Camera;
public float Scaling;
private Vector2 _previousPosition;
void Update()
{
var newPosition = Camera.ScreenToWorldPoint(Input.mousePosition);
if(Input.GetMouseButtonDown(0))
_previousPosition = newPosition;
if (Input.GetMouseButton(0))
{
Camera.transform.position -= (Vector3)((Vector2) newPosition - _previousPosition);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d172604daaa352b4784c662883d40ec9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -63,6 +63,7 @@ Material:
- NoiseLacunarity: 2.5
- NoiseOffset: 0.35
- NoisePosition: 0
- Parallax: -0.2
- ScrollSpeed: 2
- Speed: 5
- _BumpScale: 1
@ -83,6 +84,7 @@ Material:
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- ParallaxDirection: {r: 0, g: 0, b: 0, a: 0}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _Color1: {r: 0, g: 0.12804878, b: 0.25, a: 1}
- _Color2: {r: 0.15, g: 0, b: 0.0077922107, a: 1}

View file

@ -4605,6 +4605,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 04277e392af12204397c334ea824f957, type: 3}
m_Name:
m_EditorClassIdentifier:
FollowCamera: {fileID: 519420031}
BackgroundMaterial: {fileID: 2100000, guid: 90cead50364300d47bb35194fb52c117, type: 2}
GravityTexture: {fileID: 0}
GravityRenderer: {fileID: 1956833085}
@ -6133,6 +6134,66 @@ MonoBehaviour:
m_FlexibleWidth: 1
m_FlexibleHeight: -1
m_LayoutPriority: 1
--- !u!1 &565356060
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 565356062}
- component: {fileID: 565356061}
- component: {fileID: 565356063}
m_Layer: 0
m_Name: DragHandler
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &565356061
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 565356060}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: d172604daaa352b4784c662883d40ec9, type: 3}
m_Name:
m_EditorClassIdentifier:
Camera: {fileID: 519420031}
Scaling: 0
--- !u!4 &565356062
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 565356060}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 267.06277, y: 296.29117, z: -7.232751}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 7
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &565356063
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 565356060}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f60c7818169f95468915fbca3ef4773, type: 3}
m_Name:
m_EditorClassIdentifier:
TabGroup: {fileID: 143833105}
TabButton: {fileID: 618245060}
--- !u!1 &569230930
GameObject:
m_ObjectHideFlags: 0

View file

@ -10,19 +10,19 @@ public class BackgroundRenderer : MonoBehaviour
// public float RotationSpeed2 = 1;
private Camera _camera;
private float _ratio;
//private Material _material;
private Material _material;
private float _depth;
private void Start()
{
_camera = GetComponent<Camera>();
_depth = Background.position.z;
//_material = Background.GetComponent<MeshRenderer>().material;
_material = Background.GetComponent<MeshRenderer>().material;
}
private void OnPreRender()
{
//_material.SetVector("Rot1", );
_material.SetVector("ParallaxDirection", transform.position);
_ratio = (float) Screen.height / Screen.width;
Background.position = new Vector3(transform.position.x, transform.position.y, _depth);
var size = _camera.orthographicSize;

View file

@ -5,6 +5,7 @@ using UnityEngine;
public class ZoneRenderer : MonoBehaviour
{
public Camera FollowCamera;
public Material BackgroundMaterial;
public RenderTexture GravityTexture;
public MeshRenderer GravityRenderer;
@ -20,6 +21,7 @@ public class ZoneRenderer : MonoBehaviour
private void OnPreRender()
{
_camera.transform.position = FollowCamera.transform.position;
if (Screen.width != _resX || Screen.height != _resY)
{
_resX = Screen.width;

View file

@ -14,6 +14,8 @@
Speed("Speed", Float) = 1
ScrollSpeed("ScrollSpeed", Float) = 1
Distortion("Distortion", Float) = 1
ParallaxDirection("ParallaxDirection", Vector) = (0,0,0,0)
Parallax("Parallax", Float) = 1
}
SubShader
@ -57,6 +59,8 @@
float Speed;
float ScrollSpeed;
float Distortion;
float2 ParallaxDirection;
float Parallax;
v2f vert (appdata v)
{
@ -70,10 +74,12 @@
float fbm(float2 p)
{
float freq = NoiseFrequency, amp = .5;
float parallax = Parallax;
float sum = 0;
for(int i = 0; i < 4; i++)
{
sum += snoise(p * freq) * amp;
sum += snoise(p * freq + Parallax * ParallaxDirection) * amp;
parallax /= NoiseLacunarity;
freq *= NoiseLacunarity;
amp *= NoiseGain;
}
@ -84,10 +90,12 @@
float2 fbmgrad(float2 p)
{
float freq = NoiseFrequency, amp = .5;
float parallax = Parallax;
float2 sum = 0;
for(int i = 0; i < 4; i++)
{
sum += snoise_grad(p * freq) * amp;
sum += snoise_grad(p * freq + Parallax * ParallaxDirection) * amp;
parallax /= NoiseLacunarity;
freq *= NoiseLacunarity;
amp *= NoiseGain;
}