备份CatanBuilding瘦身独立工程
This commit is contained in:
72
Assets/Scripts/EventPotion/EventPotionCameraController.cs
Normal file
72
Assets/Scripts/EventPotion/EventPotionCameraController.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using GameCore;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
|
||||
namespace game
|
||||
{
|
||||
public class EventPotionCameraController : MonoBehaviour
|
||||
{
|
||||
Camera m_Main;
|
||||
Rect m_MainRect;
|
||||
float m_MainFOV;
|
||||
private Vector3 m_MainLocalScale;
|
||||
private Quaternion m_MainRotation;
|
||||
private Vector3 m_MainPosition;
|
||||
|
||||
RenderMode m_CanvasRenderMode = RenderMode.ScreenSpaceCamera;
|
||||
|
||||
Camera m_CurCamera;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
//m_CurCamera = this.transform.GetComponent<Camera>();
|
||||
|
||||
//Camera mainCamera = Camera.main;
|
||||
//UniversalAdditionalCameraData toBaseData = mainCamera.GetUniversalAdditionalCameraData();
|
||||
////toBaseData.cameraStack.Insert(0, m_CurCamera);
|
||||
//toBaseData.cameraStack.Remove(UIManager.Instance.UICamera);
|
||||
|
||||
|
||||
|
||||
//m_CanvasRenderMode = UIManager.Instance.UICanvas.renderMode;
|
||||
//UIManager.Instance.UICanvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
|
||||
//m_CurCamera = this.transform.GetComponent<Camera>();
|
||||
//m_CurCamera.enabled = false;
|
||||
|
||||
//m_Main = Camera.main;
|
||||
//m_MainRect = m_Main.rect;
|
||||
//m_MainFOV = m_Main.fieldOfView;
|
||||
//m_MainLocalScale = m_Main.transform.localScale;
|
||||
//m_MainRotation = m_Main.transform.rotation;
|
||||
//m_MainPosition = m_Main.transform.position;
|
||||
|
||||
//m_Main.rect = m_CurCamera.rect;
|
||||
//m_Main.fieldOfView = m_CurCamera.fieldOfView;
|
||||
//m_Main.transform.localScale = this.transform.localScale;
|
||||
//m_Main.transform.rotation = this.transform.rotation;
|
||||
//m_Main.transform.position = this.transform.position;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
|
||||
//m_CurCamera = this.transform.GetComponent<Camera>();
|
||||
|
||||
//Camera mainCamera = Camera.main;
|
||||
//UniversalAdditionalCameraData toBaseData = mainCamera.GetUniversalAdditionalCameraData();
|
||||
////toBaseData.cameraStack.Remove(m_CurCamera);
|
||||
//toBaseData.cameraStack.Add(UIManager.Instance.UICamera);
|
||||
|
||||
////m_Main.rect = m_MainRect;
|
||||
////m_Main.fieldOfView = m_MainFOV;
|
||||
////m_Main.transform.localScale = m_MainLocalScale;
|
||||
////m_Main.transform.rotation = m_MainRotation;
|
||||
////m_Main.transform.position = m_MainPosition;
|
||||
|
||||
//UIManager.Instance.UICanvas.renderMode = m_CanvasRenderMode;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fdf7ead2c1d37df4ab2e6df901ca1b26
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
207
Assets/Scripts/EventPotion/EventPotionController.cs
Normal file
207
Assets/Scripts/EventPotion/EventPotionController.cs
Normal file
@@ -0,0 +1,207 @@
|
||||
using asap.core;
|
||||
using GameCore;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using cfg;
|
||||
|
||||
namespace game
|
||||
{
|
||||
public class EventPotionController : MonoBehaviour
|
||||
{
|
||||
public Camera potionCamera;
|
||||
public GameObject centerPointGameObject;
|
||||
public Transform centerOfTopMouth = null;
|
||||
public List<Transform> operatingPointList = new List<Transform>();
|
||||
public List<GameObject> fountainList = new List<GameObject>();
|
||||
public List<GameObject> changingFountainEffectList = new List<GameObject>();
|
||||
|
||||
#region fountain 相关
|
||||
public int GetFountainLevel()
|
||||
{
|
||||
int index = -1;
|
||||
int count = fountainList.Count;
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
if (fountainList[i].activeSelf == true)
|
||||
{
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
return index + 1;
|
||||
}
|
||||
public void ChangeFountain(int fountainLevel, bool showEffect, float waitTime)
|
||||
{
|
||||
int index = fountainLevel - 1;
|
||||
int count = fountainList.Count;
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
if (i == index)
|
||||
{
|
||||
fountainList[i].SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
fountainList[i].SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (showEffect)
|
||||
{
|
||||
foreach (var gameObject in changingFountainEffectList)
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (waitTime > 0)
|
||||
{
|
||||
this.StartCoroutine(StopChangingFountainEffect(waitTime));
|
||||
}
|
||||
}
|
||||
public IEnumerator StopChangingFountainEffect(float time)
|
||||
{
|
||||
yield return new WaitForSeconds(time);
|
||||
|
||||
foreach (var gameObject in changingFountainEffectList)
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 外部接口
|
||||
//public void CloseCamera()
|
||||
//{
|
||||
// if (potionCamera == null) return;
|
||||
// potionCamera.gameObject.SetActive(false);
|
||||
//}
|
||||
public void OpenCamera()
|
||||
{
|
||||
if (potionCamera == null) return;
|
||||
potionCamera.gameObject.SetActive(true);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 事件相关
|
||||
public void InitEvent()
|
||||
{
|
||||
FishingPotionAct.Subscribe<EventPotionCloseCameraData>(CloseCamera);
|
||||
}
|
||||
private void CloseCamera(EventPotionCloseCameraData data)
|
||||
{
|
||||
if (potionCamera == null) return;
|
||||
potionCamera.gameObject.SetActive(false);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 生命周期
|
||||
async void Awake()
|
||||
{
|
||||
CloseCamera(null);
|
||||
|
||||
EventPotionDataManager dataManager = GContext.container.Resolve<EventPotionDataManager>();
|
||||
|
||||
EventPotionStage level = dataManager.GetCurrentPotionLevel();
|
||||
ChangeFountain(level.FountainLevel, false, 0);
|
||||
|
||||
GameObject pannelObj = await UIManager.Instance.ShowUI(dataManager.GetUIPanel());
|
||||
EventPotionPanel panel = pannelObj.transform.GetComponent<EventPotionPanel>();
|
||||
panel.SetEventPotionController(this);
|
||||
|
||||
RectTransform panelRectTransform = pannelObj.transform.GetComponent<RectTransform>();
|
||||
float screenHeight = panelRectTransform.rect.height - panelRectTransform.sizeDelta.y;
|
||||
|
||||
RectTransform rawImageRectTransform = panel.ScenePotionRawImage.transform.GetComponent<RectTransform>();
|
||||
float rawImageHeight = rawImageRectTransform.rect.height;
|
||||
|
||||
float ratioHeight = rawImageHeight / screenHeight;
|
||||
|
||||
OpenCamera();
|
||||
|
||||
potionCamera.rect = new Rect() { x = 0f, y = 0f, width = 1.0f, height = 1.0f };
|
||||
float width = Screen.width;
|
||||
float height = Screen.height * ratioHeight;
|
||||
|
||||
potionCamera.aspect = width / height;
|
||||
|
||||
// 3渲2,rawimage
|
||||
Vector2 originUIPosition = new Vector2(panel.ScenePotionRawImage.transform.position.x, panel.ScenePotionRawImage.transform.position.y);
|
||||
Vector2 pivot = panel.ScenePotionRawImage.rectTransform.pivot;
|
||||
|
||||
Vector2 tmpUIPosition = panel.ScenePotionRawImage.rectTransform.anchoredPosition;
|
||||
float imgWidth = panel.ScenePotionRawImage.rectTransform.rect.width;
|
||||
float imgHeight = panel.ScenePotionRawImage.rectTransform.rect.height;
|
||||
|
||||
// --------------------------------- 场景内物体映射到UI上的位置 Begin ---------------------------------------
|
||||
Vector3 screenPosition = potionCamera.WorldToScreenPoint(centerPointGameObject.transform.position);
|
||||
|
||||
float scaleX = screenPosition.x / Screen.width;
|
||||
float scaleY = screenPosition.y / Screen.height;
|
||||
|
||||
float pixelX = panel.ScenePotionRawImage.rectTransform.position.x + imgWidth * (scaleX - pivot.x);
|
||||
float pixelY = panel.ScenePotionRawImage.rectTransform.position.y + imgHeight * (scaleY - pivot.y);
|
||||
|
||||
Vector2 uiPosition = new Vector2(pixelX, pixelY);
|
||||
|
||||
panel.centerPointPosition = uiPosition;
|
||||
|
||||
// 操作点,倒水特效挂点
|
||||
int count = operatingPointList.Count;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
Transform transform = operatingPointList[i];
|
||||
|
||||
screenPosition = potionCamera.WorldToScreenPoint(transform.position);
|
||||
|
||||
scaleX = screenPosition.x / Screen.width;
|
||||
scaleY = screenPosition.y / Screen.height;
|
||||
|
||||
pixelX = panel.ScenePotionRawImage.rectTransform.localPosition.x + imgWidth * (scaleX - pivot.x);
|
||||
pixelY = panel.ScenePotionRawImage.rectTransform.localPosition.y + imgHeight * (scaleY - pivot.y);
|
||||
|
||||
uiPosition = new Vector2(pixelX, pixelY);
|
||||
panel.operatingPointTransformList.Add(uiPosition);
|
||||
}
|
||||
|
||||
// 圈口挂点
|
||||
if (centerOfTopMouth != null)
|
||||
{
|
||||
screenPosition = potionCamera.WorldToScreenPoint(centerOfTopMouth.position);
|
||||
scaleX = screenPosition.x / Screen.width;
|
||||
scaleY = screenPosition.y / Screen.height;
|
||||
|
||||
pixelX = panel.ScenePotionRawImage.rectTransform.localPosition.x + imgWidth * (scaleX - pivot.x);
|
||||
pixelY = panel.ScenePotionRawImage.rectTransform.localPosition.y + imgHeight * (scaleY - pivot.y);
|
||||
|
||||
panel.centerOfTopMouth = new Vector2(pixelX, pixelY);
|
||||
}
|
||||
|
||||
// --------------------------------- 场景内物体映射到UI上的位置 End ---------------------------------------
|
||||
int renderTextureWidth = (int)rawImageRectTransform.rect.width;
|
||||
int renderTextureHeight = (int)rawImageRectTransform.rect.height;
|
||||
RenderTexture renderTexture = new RenderTexture(renderTextureWidth, renderTextureHeight, 24);
|
||||
potionCamera.targetTexture = renderTexture;
|
||||
panel.ScenePotionRawImage.texture = renderTexture;
|
||||
|
||||
FishingPotionAct.IsInitControllerComplete = true;
|
||||
|
||||
InitEvent();
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/EventPotion/EventPotionController.cs.meta
Normal file
11
Assets/Scripts/EventPotion/EventPotionController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 796592f13fb9ea84ea266b1f3ccf7205
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/EventPotion/Shaders.meta
Normal file
8
Assets/Scripts/EventPotion/Shaders.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d32e68150d8da442b366dea7054b14f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
53
Assets/Scripts/EventPotion/Shaders/UVOffsetShader.shader
Normal file
53
Assets/Scripts/EventPotion/Shaders/UVOffsetShader.shader
Normal file
@@ -0,0 +1,53 @@
|
||||
Shader "Bamboo/UVOffsetShader"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_MainTex ("Texture", 2D) = "white" {}
|
||||
_UVOffsetX ("UV Offset X", Float) = 0.0
|
||||
_UVOffsetY ("UV Offset Y", Float) = 0.0
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
|
||||
LOD 200
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex vert
|
||||
#pragma fragment frag
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct appdata
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct v2f
|
||||
{
|
||||
float2 uv : TEXCOORD0;
|
||||
float4 vertex : SV_POSITION;
|
||||
};
|
||||
|
||||
sampler2D _MainTex;
|
||||
float _UVOffsetX;
|
||||
float _UVOffsetY;
|
||||
|
||||
v2f vert (appdata v)
|
||||
{
|
||||
v2f o;
|
||||
o.vertex = UnityObjectToClipPos(v.vertex);
|
||||
o.uv = v.uv + float2(_UVOffsetX, _UVOffsetY);
|
||||
return o;
|
||||
}
|
||||
|
||||
fixed4 frag (v2f i) : SV_Target
|
||||
{
|
||||
fixed4 col = tex2D(_MainTex, i.uv);
|
||||
return col;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 32306b36ce831e74b8991103c032e48d
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user