Commit 19efb4a6 authored by Tommé Nöll's avatar Tommé Nöll
Browse files

made corruption rendering work in scene view, deactivated checking file locks during build process

parent 61551fe2
......@@ -21,15 +21,18 @@ public class CameraZone : MonoBehaviour
void Start()
{
CalculateBounds();
if (!camera)
{
FindCamera();
}
FindCamera();
}
public void FindCamera()
public static void FindCamera()
{
camera = GameObject.FindWithTag("MainCamera").GetComponent<CameraController>();
if (!camera)
{
camera = GameObject.FindWithTag("MainCamera").GetComponent<CameraController>();
}
#if UNITY_EDITOR
camera.Init();
#endif
}
public void CalculateBounds()
......@@ -52,7 +55,7 @@ public class CameraZone : MonoBehaviour
if (!playerWasInZone)
{
camera.targetPos = transform.position;
camera.targetSize = CalculateCameraSize();
camera.targetSize = CalculateCameraSize(bounds, fitMode);
}
}
else
......@@ -66,7 +69,7 @@ public class CameraZone : MonoBehaviour
playerWasInZone = apply;
}
private float CalculateCameraSize()
public static float CalculateCameraSize(Bounds bounds, FitMode fitMode)
{
float aspect = camera.GetAspectRatio(); // width / height
//float cameraWidthScaled = bounds.size.y * aspect;
......
......@@ -5,6 +5,7 @@ using UnityEngine.SceneManagement;
using UnityEditor;
using UnityEditor.SceneManagement;
using System.IO;
using System;
[InitializeOnLoad]
public class NotifyForLockedFiles : UnityEditor.AssetModificationProcessor
......@@ -63,11 +64,14 @@ public class NotifyForLockedFiles : UnityEditor.AssetModificationProcessor
}
//if (oldScene.path == null || oldScene.path.Length < 5) return;
realOldScene = newScene;
FileInfo info = new FileInfo(newScene.path);
if (info.IsReadOnly)
{
UnityEditor.EditorUtility.DisplayDialog("Read-Only", "Die Scene " + newScene.path + " ist Read-Only. Sie wird nicht gespeichert werden können.", "Ok");
}
if (!BuildPipeline.isBuildingPlayer)
{
FileInfo info = new FileInfo(newScene.path);
if (info.IsReadOnly)
{
UnityEditor.EditorUtility.DisplayDialog("Read-Only", "Die Scene " + newScene.path + " ist Read-Only. Sie wird nicht gespeichert werden können.", "Ok");
}
}
}
}
\ No newline at end of file
......@@ -89,6 +89,8 @@ MonoBehaviour:
m_EditorClassIdentifier:
corruptionMap: {fileID: 0}
camera: {fileID: 8811539148413200178}
mainCamera: {fileID: 8811539149977030267}
editorCorruptionCameraScaleFactor: 20
--- !u!1 &8811539149977030262
GameObject:
m_ObjectHideFlags: 0
......
......@@ -1833,40 +1833,6 @@ Transform:
type: 3}
m_PrefabInstance: {fileID: 658338665}
m_PrefabAsset: {fileID: 0}
--- !u!84 &660183611
RenderTexture:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
serializedVersion: 3
m_Width: 1090
m_Height: 539
m_AntiAliasing: 1
m_DepthFormat: 0
m_ColorFormat: 21
m_MipMap: 0
m_GenerateMips: 1
m_SRGB: 0
m_UseDynamicScale: 0
m_BindMS: 0
m_EnableCompatibleFormat: 1
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 1
m_MipBias: 0
m_WrapU: 1
m_WrapV: 1
m_WrapW: 1
m_Dimension: 2
m_VolumeDepth: 1
--- !u!1001 &661893906
PrefabInstance:
m_ObjectHideFlags: 0
......@@ -4020,6 +3986,40 @@ PrefabInstance:
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 7ef06ffc179d97098a6c30d5f8570a4e, type: 3}
--- !u!84 &1665183317
RenderTexture:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name:
m_ImageContentsHash:
serializedVersion: 2
Hash: 00000000000000000000000000000000
m_ForcedFallbackFormat: 4
m_DownscaleFallback: 0
serializedVersion: 3
m_Width: 1090
m_Height: 539
m_AntiAliasing: 1
m_DepthFormat: 0
m_ColorFormat: 21
m_MipMap: 0
m_GenerateMips: 1
m_SRGB: 0
m_UseDynamicScale: 0
m_BindMS: 0
m_EnableCompatibleFormat: 1
m_TextureSettings:
serializedVersion: 2
m_FilterMode: 1
m_Aniso: 1
m_MipBias: 0
m_WrapU: 1
m_WrapV: 1
m_WrapW: 1
m_Dimension: 2
m_VolumeDepth: 1
--- !u!1001 &1673005932
PrefabInstance:
m_ObjectHideFlags: 0
......@@ -4265,12 +4265,12 @@ PrefabInstance:
- target: {fileID: 146384502658720480, guid: 47edb6c4e8357676a9cb004f1655d229,
type: 3}
propertyPath: m_LocalPosition.x
value: 11.24
value: 11.27
objectReference: {fileID: 0}
- target: {fileID: 146384502658720480, guid: 47edb6c4e8357676a9cb004f1655d229,
type: 3}
propertyPath: m_LocalPosition.y
value: 3.12
value: 3.76
objectReference: {fileID: 0}
- target: {fileID: 146384502658720480, guid: 47edb6c4e8357676a9cb004f1655d229,
type: 3}
......@@ -5490,12 +5490,12 @@ PrefabInstance:
- target: {fileID: 5546039070061430727, guid: 5f19e99694f67a245b4244a6b9f38023,
type: 3}
propertyPath: m_LocalPosition.x
value: 4.32
value: 4.48
objectReference: {fileID: 0}
- target: {fileID: 5546039070061430727, guid: 5f19e99694f67a245b4244a6b9f38023,
type: 3}
propertyPath: m_LocalPosition.y
value: -0.06
value: 0.37
objectReference: {fileID: 0}
- target: {fileID: 5546039070061430727, guid: 5f19e99694f67a245b4244a6b9f38023,
type: 3}
......@@ -5530,16 +5530,21 @@ PrefabInstance:
type: 3}
propertyPath: m_TargetTexture
value:
objectReference: {fileID: 660183611}
objectReference: {fileID: 1665183317}
- target: {fileID: 8811539148413200178, guid: 388a7af523fdebaafad4a5d1ae1a896b,
type: 3}
propertyPath: orthographic size
value: 5
objectReference: {fileID: 0}
- target: {fileID: 8811539149977030266, guid: 388a7af523fdebaafad4a5d1ae1a896b,
type: 3}
propertyPath: m_LocalPosition.x
value: 6.3
value: 5.35
objectReference: {fileID: 0}
- target: {fileID: 8811539149977030266, guid: 388a7af523fdebaafad4a5d1ae1a896b,
type: 3}
propertyPath: m_LocalPosition.y
value: 3.22
value: 2.04
objectReference: {fileID: 0}
- target: {fileID: 8811539149977030266, guid: 388a7af523fdebaafad4a5d1ae1a896b,
type: 3}
......@@ -5591,6 +5596,11 @@ PrefabInstance:
propertyPath: corruptionMap
value:
objectReference: {fileID: 120497678}
- target: {fileID: 8811539148413200140, guid: 388a7af523fdebaafad4a5d1ae1a896b,
type: 3}
propertyPath: corruptionCameraScaleFactor
value: 20
objectReference: {fileID: 0}
- target: {fileID: 8811539149977030271, guid: 388a7af523fdebaafad4a5d1ae1a896b,
type: 3}
propertyPath: corruptionMap
......@@ -5606,6 +5616,21 @@ PrefabInstance:
propertyPath: player
value:
objectReference: {fileID: 0}
- target: {fileID: 8811539149977030267, guid: 388a7af523fdebaafad4a5d1ae1a896b,
type: 3}
propertyPath: orthographic size
value: 5
objectReference: {fileID: 0}
- target: {fileID: 8811539148413200141, guid: 388a7af523fdebaafad4a5d1ae1a896b,
type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8811539148413200141, guid: 388a7af523fdebaafad4a5d1ae1a896b,
type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 388a7af523fdebaafad4a5d1ae1a896b, type: 3}
--- !u!1 &8811539148946952084 stripped
......@@ -5621,7 +5646,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8811539148946952084}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 63226443539043ad88666eb1da52af02, type: 3}
m_Name:
......
......@@ -7,7 +7,6 @@ public class CameraController : MonoBehaviour
{
[HideInInspector] public Player player;
private new Camera camera;
[SerializeField] private Camera corruptionCamera;
[SerializeField] private Vector3 offset;
[SerializeField] private float panSpeed = 4f;
......@@ -38,8 +37,7 @@ public class CameraController : MonoBehaviour
// Start is called before the first frame update
void Start()
{
camera = GetComponent<Camera>();
defaultSize = camera.orthographicSize * 2;
Init();
ResetTarget();
try
{
......@@ -53,6 +51,12 @@ public class CameraController : MonoBehaviour
SnapToPlayer();
}
public void Init()
{
camera = GetComponent<Camera>();
defaultSize = camera.orthographicSize * 2;
}
public void FindPlayer()
{
player = GameObject.FindWithTag("Player").GetComponent<Player>();
......@@ -168,6 +172,5 @@ public class CameraController : MonoBehaviour
private void SetSize(float size)
{
camera.orthographicSize = size;
corruptionCamera.orthographicSize = size;
}
}
......@@ -7,6 +7,8 @@ public class CorruptionCamera : MonoBehaviour
{
public CorruptionMap corruptionMap;
public new Camera camera;
public Camera mainCamera;
[SerializeField] private float editorCorruptionCameraScaleFactor = 20f;
// Start is called before the first frame update
void Start()
......@@ -14,11 +16,64 @@ public class CorruptionCamera : MonoBehaviour
corruptionMap.Init();
camera = GetComponent<Camera>();
camera.targetTexture = corruptionMap.mapTexture;
camera.backgroundColor = new Color(corruptionMap.globalCorruption, 0, 0, 1);
}
// Update is called once per frame
void Update()
{
camera.backgroundColor = new Color(corruptionMap.globalCorruption, 0, 0, 1);
camera.orthographicSize = mainCamera.orthographicSize;
#if UNITY_EDITOR
if (!Application.IsPlaying(gameObject))
{
ScaleZonesVisible();
camera.orthographicSize *= editorCorruptionCameraScaleFactor;
corruptionMap.plantSurfaceMaterial.SetFloat("_CorruptionCameraScaleFactor", editorCorruptionCameraScaleFactor);
}
#endif
}
//make sure all corruption zones are being rendered in scene view,
//by checking if they are visible to the corruption camera
private void ScaleZonesVisible()
{
Bounds bounds = new Bounds(transform.position, new Vector3(0, 0, 0));
foreach (Transform zoneTransform in corruptionMap.transform)
{
Bounds zoneBounds = zoneTransform.gameObject.GetComponent<SpriteRenderer>().bounds;
bounds.Encapsulate(zoneBounds.min);
bounds.Encapsulate(zoneBounds.max);
}
//Debug.Log(bounds.min + ", " + bounds.max);
//match bounds center to camera position by increasing bounds size
Debug.Log(bounds);
Vector3 min = bounds.min;
Vector3 max = bounds.max;
if (bounds.center.x < transform.position.x)
{
max.x = 2 * transform.position.x - min.x;
}
else
{
min.x = 2 * transform.position.x - max.x;
}
if (bounds.center.y < transform.position.y)
{
max.y = 2 * transform.position.y - min.y;
}
else
{
min.y = 2 * transform.position.y - max.y;
}
bounds.SetMinMax(min, max);
Debug.Log(bounds);
CameraZone.FindCamera();
float targetSize = CameraZone.CalculateCameraSize(bounds, CameraZone.FitMode.grow);
editorCorruptionCameraScaleFactor = Mathf.Max(1, targetSize / mainCamera.orthographicSize / 2);
}
}
......@@ -40,11 +40,13 @@ public class CorruptionMap : MonoBehaviour
void Update()
{
CheckZones();
if (!Application.IsPlaying(gameObject))
{
plantSurfaceMaterial.SetMatrix("_ToMainCameraMatrix", Camera.main.projectionMatrix * Camera.main.worldToCameraMatrix);
plantSurfaceMaterial.SetTexture("_CorruptionMap", mapTexture);
}
#if UNITY_EDITOR
if (!Application.IsPlaying(gameObject))
{
plantSurfaceMaterial.SetMatrix("_ToMainCameraMatrix", Camera.main.projectionMatrix * Camera.main.worldToCameraMatrix);
plantSurfaceMaterial.SetTexture("_CorruptionMap", mapTexture); //in every update instead of only in init while in edit mode
}
#endif
}
void CheckZones()
......
......@@ -82,16 +82,21 @@ Shader "Custom/PlantSpriteShader"
float4x4 _ToMainCameraMatrix;
float _PulsatingSpeed;
float _PulsatingStrength;
#if EDITOR_ON
float _CorruptionCameraScaleFactor;
#endif
fixed4 p_SpriteFrag(p_v2f IN) : SV_Target
{
const float2 center = (0.5, 0.5);
fixed4 color = SampleSpriteTexture (IN.texcoord) * IN.color;
//float2 screenPos = ComputeScreenPos(IN.clipPos);
float2 screenPos = ComputeScreenPos(UnityObjectToClipPos(IN.localPos));
#if EDITOR_ON
//broken
// screenPos = ComputeScreenPos(mul(_ToMainCameraMatrix, float4 (UnityObjectToClipPos(IN.localPos))));
screenPos = ComputeScreenPos(mul(_ToMainCameraMatrix, IN.localPos));
screenPos = (screenPos + center * (_CorruptionCameraScaleFactor - 1))/_CorruptionCameraScaleFactor;
#endif
//screenPos += (0.25, 0.25);
float corruption = tex2D(_CorruptionMap, screenPos) * 3;
float colorstrength = dot(_ColorStrengthFactors, color);
float colorshift = max(pow(colorstrength, _ColorStrengthExponent) * corruption * (0.5 + _PulsatingStrength / 50 * (sin(_Time[1] * _PulsatingSpeed) / 2)), 0);
......
......@@ -79,6 +79,7 @@ PlayerSettings:
usePlayerLog: 1
bakeCollisionMeshes: 0
forceSingleInstance: 0
useFlipModelSwapchain: 1
resizableWindow: 0
useMacAppStoreValidation: 0
macAppStoreCategory: public.app-category.games
......
......@@ -216,4 +216,5 @@ QualitySettings:
asyncUploadPersistentBuffer: 1
resolutionScalingFixedDPIFactor: 1
excludedTargetPlatforms: []
m_PerPlatformDefaultQuality: {}
m_PerPlatformDefaultQuality:
Standalone: 0
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment