using DG.Tweening;
using ShadowStudio.Tool;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XRTool.WorldUI;
namespace ShadowStudio.Model
{
///
/// UI容器,可以放置一些UI相关的组件
/// 记事本,画板,以及后续的相关UI组件,也有可能是视频(角色视频)
/// UI组件可以被放置在墙上进行展示,具备相关的交互操作
///
[RequireComponent(typeof(WorldDlg))]
[RequireComponent(typeof(TransferCell))]
public class WorldDlgContainer : GoodsContainer
{
private WorldDlg dlg;
private Vector3 dataV3;
private Vector3 dataDownV3;
List listV3 = new List();
///
/// 当处于黑板状态的时候,拖拽要平行于黑板,且不可穿透黑板
///
///
///
public static GameObject BackGD;
MeshRenderer bgMr;
float offsetX = 0.5f;
float offsetY = 0.5f;
float BGDX = -(1 / 1.7f);
float BGDY = (1 / 3.7f);
float BGDZ = 1 / 24f;
bool isPlaying;
ContainerState oldContainerState;
bool isFrist;
float inXFz;
public WorldDlg Dlg
{
get
{
if (!dlg)
{
dlg = GetComponent();
}
return dlg;
}
}
///
/// 添加美术资源到容器
///
///
///
public override void AddToContainer(UnityEngine.Object art, ArtInfo info)
{
base.AddToContainer(art, info);
SetContainer(art, info);
ResetEditorPosition();
PlayEffect();
}
public virtual void SetContainer(UnityEngine.Object art, ArtInfo info)
{
}
public override void OnZoomTransfer(TransferState state)
{
base.OnZoomTransfer(state);
if (state == TransferState.Stop)
{
while (Dlg.DlgSize.magnitude < (Vector2.one * 0.1f).magnitude)
{
transform.localScale *= 1.5f;
}
//SendTransfer(2, (int)state);
//TimerMgr.Instance.CreateTimer( ResetEditorPosition,0);
OnEditTransfer(state);
}
}
public override void OnEditTransfer(TransferState obj)
{
base.OnEditTransfer(obj);
//if (BoardDlg.Instance && Dlg)
//{
// BoardDlg.Instance.ExecutePicture(Dlg, obj != TransferState.Stop, true);
// checkBG();
//}
}
void setBGmat(string name, float f)
{
bgMr.material.SetFloat(name, f);
}
void checkBG()
{
if (BackGD != null)
{
// Vector3 v3 = BackGD.transform.InverseTransformPoint((Dlg.DlgRect.points[2] + Dlg.DlgRect.points[3]) / 2 + (Dlg.DlgRect.points[0] + Dlg.DlgRect.points[1]) / 2) / 2;
Vector3 v3 = ((BackGD.transform.InverseTransformPoint(Dlg.DlgRect.points[2]) + BackGD.transform.InverseTransformPoint(Dlg.DlgRect.points[3])) / 2 + (BackGD.transform.InverseTransformPoint(Dlg.DlgRect.points[0]) + BackGD.transform.InverseTransformPoint(Dlg.DlgRect.points[1])) / 2) / 2;
if (!bgMr)
{
bgMr = BackGD.transform.GetComponent();
}
if (Dlg.containerState == ContainerState.BoardMove)
{
if (oldContainerState != ContainerState.BoardMove && oldContainerState != ContainerState.OnBoard)
{
inXFz = v3.z;
isFrist = true;
}
setBGmat("_Mask2_Ani", 0);
setBGmat("_U", offsetX + v3.x / BGDX);
setBGmat("_V", offsetY + v3.y / BGDY);
if (isFrist)
{
if ((v3.z / BGDZ) < ((inXFz / BGDZ) / 2))
{
isFrist = false;
}
if (((inXFz / BGDZ)) >= (v3.z / BGDZ))
{
setBGmat("_tuqi", ((inXFz / BGDZ)) - (v3.z / BGDZ));
}
else
{
isFrist = false;
}
}
else
{
setBGmat("_tuqi", (v3.z / BGDZ));
}
}
else if (Dlg.containerState == ContainerState.OnBoard)
{
isFrist = false;
bgMr.material.DOKill(false);
setBGmat("_U", offsetX + v3.x / BGDX);
setBGmat("_V", offsetY + v3.y / BGDY);
// bgMr.material.SetFloat("_tuqi", ((0.2f - (0.2f + v3.z) * 2) - 0.207f) * 10);
setBGmat("_Mask2_Ani", 0);
bgMr.material.DOFloat(1, "_Mask2_Ani", 1f).OnComplete(() =>
{
setBGmat("_U", 2);
setBGmat("_V", 2);
});
}
else
{
if (bgMr.material.GetFloat("_U") != 2 && !isPlaying)
{
isPlaying = true;
setBGmat("_U", offsetX + v3.x / BGDX);
setBGmat("_V", offsetY + v3.y / BGDY);
// bgMr.material.SetFloat("_tuqi", ((0.2f - (0.2f + v3.z) * 2) - 0.207f) * 10);
setBGmat("_Mask2_Ani", 0);
bgMr.material.DOFloat(1, "_Mask2_Ani", 1f).OnComplete(() =>
{
setBGmat("_U", 2);
setBGmat("_V", 2);
isPlaying = false;
}).OnKill(() =>
{
isPlaying = false;
});
}
}
}
oldContainerState = Dlg.containerState;
}
public virtual void OnPointerBGDown()
{
dataV3 = this.transform.position;
if (Dlg.containerState == ContainerState.OnBoard && bgMr != null)
{
//bgMr.material.DOKill(false);
//Vector3 v3 = ((BackGD.transform.InverseTransformPoint(Dlg.DlgRect.points[2]) + BackGD.transform.InverseTransformPoint(Dlg.DlgRect.points[3])) / 2 + (BackGD.transform.InverseTransformPoint(Dlg.DlgRect.points[0]) + BackGD.transform.InverseTransformPoint(Dlg.DlgRect.points[1])) / 2) / 2;
//float offsetZ = BackGD.transform.InverseTransformPoint(this.transform.parent.TransformPoint(new Vector3(this.transform.localPosition.x, this.transform.localPosition.y, BoardDlg.Instance.boardConf.PressPonit))).z;
//setBGmat("_U", offsetX + v3.x / BGDX);
//setBGmat("_V", offsetY + v3.y / BGDY);
//setBGmat("_tuqi", (offsetZ / BGDZ));
//setBGmat("_Mask2_Ani", 1);
//bgMr.material.DOFloat(0, "_Mask2_Ani", 0.5f).OnComplete(() =>
//{
// //Vector3 pos = this.Dlg.DlgTrans.anchoredPosition3D;
// ////if (pos.z > BoardDlg.Instance.boardConf.PressPonit)
// ////{
// //// pos.z = BoardDlg.Instance.boardConf.PressPonit;
// ////}
// //this.Dlg.DlgTrans.anchoredPosition3D = pos;
//});
//this.transform.DOKill();
//this.transform.DOMove(this.transform.parent.TransformPoint(new Vector3(this.transform.localPosition.x, this.transform.localPosition.y, BoardDlg.Instance.boardConf.PressPonit)), 0.3f).SetDelay(0.2f);
}
}
public override void ResetEditorPosition()
{
if (EditorRoot)
{
Vector3 center = Vector3.down * Dlg.BG.Back.sizeDelta.y / 2;
center = Dlg.BG.Back.TransformPoint(center);
center.y -= 0.02f;
EditorRoot.position = center;
EditorRoot.rotation = transform.rotation;
}
}
public override void TransferSyn(GoodsInfo goods, bool smooth = true)
{
base.TransferSyn(goods, smooth);
if (TransferState != TransferState.Init)
{
//if (BoardDlg.Instance && Dlg)
//{
// BoardDlg.Instance.ExecutePicture(Dlg, TransferState == TransferState.Doing, false);
// checkBG();
//}
}
}
}
}