新增镜头锁定功能

完善虚线预制体
This commit is contained in:
shenjianxing 2024-12-19 16:38:42 +08:00
parent b58945ac2b
commit 7da2890d99
11 changed files with 180 additions and 28 deletions

View File

@ -128,7 +128,7 @@ LineRenderer:
numCapVertices: 0 numCapVertices: 0
alignment: 0 alignment: 0
textureMode: 1 textureMode: 1
textureScale: {x: 1, y: 1} textureScale: {x: 10, y: 1}
shadowBias: 0.5 shadowBias: 0.5
generateLightingData: 0 generateLightingData: 0
m_MaskInteraction: 0 m_MaskInteraction: 0

View File

@ -147,9 +147,10 @@ public class ActionHelper
var strAction = (XMLTool.StringListAction)act; var strAction = (XMLTool.StringListAction)act;
return CameraSwitchAction.Allocate(strAction.args[0], strAction.args[1], strAction.args[2], strAction.args[3], strAction.args[4], strAction.args[5], strAction.args[6]); return CameraSwitchAction.Allocate(strAction.args[0], strAction.args[1], strAction.args[2], strAction.args[3], strAction.args[4], strAction.args[5], strAction.args[6]);
} }
case "LockCamera": case "CameraLock":
{ {
return LockCameraAction.Allocate(act.Value); var strAction = (XMLTool.StringListAction)act;
return CameraLockAction.Allocate(strAction.args[0], strAction.args[1]);
} }
case "Video": case "Video":
{ {
@ -174,7 +175,11 @@ public class ActionHelper
case "Line": case "Line":
{ {
var strAction = (XMLTool.StringListAction)act; var strAction = (XMLTool.StringListAction)act;
return LineAction.Allocate(act.Name, act.Value, strAction.args[0]); return LineAction.Allocate(act.Name, act.Value, strAction.args[0], strAction.args[1], strAction.args[2]);
}
case "Destroy":
{
return DestroyAction.Allocate(act.Value);
} }
default: default:
Debug.LogError($"ûÓÐÕÒµ½´ËActionµÄÀàÐÍ{act.Type}"); Debug.LogError($"ûÓÐÕÒµ½´ËActionµÄÀàÐÍ{act.Type}");

View File

@ -3,27 +3,29 @@ using UnityEngine;
namespace QFramework namespace QFramework
{ {
internal class LockCameraAction : IAction internal class CameraLockAction : IAction
{ {
public System.Action OnFinished { get; set; } public System.Action OnFinished { get; set; }
private LockCameraAction() private CameraLockAction()
{ {
} }
private static readonly SimpleObjectPool<LockCameraAction> mPool = private static readonly SimpleObjectPool<CameraLockAction> mPool =
new SimpleObjectPool<LockCameraAction>(() => new LockCameraAction(), null, 10); new SimpleObjectPool<CameraLockAction>(() => new CameraLockAction(), null, 10);
string isLock; string isMove;
public static LockCameraAction Allocate(string isLock, System.Action OnFinished = null) string isRotate;
public static CameraLockAction Allocate(string isMove, string isRotate, System.Action OnFinished = null)
{ {
var retNode = mPool.Allocate(); var retNode = mPool.Allocate();
retNode.ActionID = ActionKit.ID_GENERATOR++; retNode.ActionID = ActionKit.ID_GENERATOR++;
retNode.Deinited = false; retNode.Deinited = false;
retNode.Reset(); retNode.Reset();
retNode.isLock = isLock; retNode.isMove = isMove;
retNode.isRotate = isRotate;
retNode.OnFinished = OnFinished; retNode.OnFinished = OnFinished;
return retNode; return retNode;
} }
@ -34,9 +36,11 @@ namespace QFramework
public void OnStart() public void OnStart()
{ {
bool cameraLock = false; bool isMov = true;
bool.TryParse(isLock, out cameraLock); bool isRot = true;
FreeCameraController.instance.SetLock(cameraLock); bool.TryParse(isMove, out isMov);
bool.TryParse(isRotate, out isRot);
FreeCameraController.instance.SetLock(isMov, isRot);
} }
public void OnExecute(float dt) public void OnExecute(float dt)

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: b3aa7c1b51454fe49a1a1646c5236be6 guid: 1a7e9684055af6048bdb95f014c3170a
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@ -0,0 +1,70 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using QFramework;
using System;
using QFramework.Example;
using DG.Tweening;
using System.ComponentModel.Design;
public class DestroyAction : IAction
{
public ulong ActionID { get; set; }
public bool Deinited { get; set; }
public bool Paused { get; set; }
public ActionStatus Status { get; set; }
private static readonly SimpleObjectPool<DestroyAction> mPool =
new SimpleObjectPool<DestroyAction>(() => new DestroyAction(), null, 10);
string path;
public static DestroyAction Allocate(string path, System.Action onDelayFinish = null)
{
var retNode = mPool.Allocate();
retNode.ActionID = ActionKit.ID_GENERATOR++;
retNode.Deinited = false;
retNode.Reset();
retNode.path = path;
return retNode;
}
public void Deinit()
{
if (!Deinited)
{
Deinited = true;
mPool.Recycle(this);
}
}
public void OnExecute(float dt)
{
}
public void OnFinish()
{
}
public void OnStart()
{
GameObject obj = Utility.FindObj(path);
if (obj == null)
{
Debug.LogError("ûÓÐÕÒµ½ÎïÌå :" + path);
}
else
{
GameObject.Destroy(obj);
}
this.Finish();
}
public void Reset()
{
Status = ActionStatus.NotStart;
Paused = false;
}
}

View File

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

View File

@ -1,6 +1,7 @@
using QFramework.Example; using QFramework.Example;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine; using UnityEngine;
using static UnityEditor.Progress; using static UnityEditor.Progress;
@ -22,7 +23,9 @@ namespace QFramework
public string paths; public string paths;
public string name; public string name;
Color color = Color.green; Color color = Color.green;
public static LineAction Allocate(string name, string paths, string color, System.Action OnFinished = null) float width = 0.1f;
Vector2 scale = Vector2.one;
public static LineAction Allocate(string name, string paths, string color, string width, string lineScale, System.Action OnFinished = null)
{ {
var retNode = mPool.Allocate(); var retNode = mPool.Allocate();
retNode.ActionID = ActionKit.ID_GENERATOR++; retNode.ActionID = ActionKit.ID_GENERATOR++;
@ -34,6 +37,11 @@ namespace QFramework
{ {
retNode.color = Utility.ToColor(color); retNode.color = Utility.ToColor(color);
} }
float.TryParse(width, out retNode.width);
if (string.IsNullOrEmpty(lineScale) == false)
{
retNode.scale = Utility.GetVector2FromStrArray(lineScale);
}
retNode.OnFinished = OnFinished; retNode.OnFinished = OnFinished;
return retNode; return retNode;
} }
@ -53,7 +61,10 @@ namespace QFramework
obj.name = name; obj.name = name;
var render = obj.GetOrAddComponent<LineRenderer>(); var render = obj.GetOrAddComponent<LineRenderer>();
render.startWidth = width;
render.endWidth = width;
render.material.color = color; render.material.color = color;
render.textureScale = scale;
var pathsArr = paths.Split('|'); var pathsArr = paths.Split('|');
for (int i = 0; i < pathsArr.Length; i++) for (int i = 0; i < pathsArr.Length; i++)
{ {

View File

@ -38,7 +38,6 @@ namespace QFramework
private void OnEventFnished() private void OnEventFnished()
{ {
Debug.LogError("111");
StringEventSystem.Global.UnRegister(key, OnEventFnished); StringEventSystem.Global.UnRegister(key, OnEventFnished);
this.Finish(); this.Finish();
} }

View File

@ -20,8 +20,8 @@ public class FreeCameraController : MonoBehaviour
private bool isDragging = false; private bool isDragging = false;
private float xRotation = 0.0f; private float xRotation = 0.0f;
private float yRotation = 0.0f; private float yRotation = 0.0f;
public bool isLock = false; public bool isMov = true;
public bool isRot = true;
private void Awake() private void Awake()
{ {
instance = this; instance = this;
@ -32,7 +32,7 @@ public class FreeCameraController : MonoBehaviour
void Update() void Update()
{ {
if (isLock == false) if (isMov == true)
{ {
// 相机移动 // 相机移动
float horizontal = Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime; float horizontal = Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime;
@ -40,8 +40,9 @@ public class FreeCameraController : MonoBehaviour
Vector3 move = transform.right * horizontal + transform.forward * vertical; Vector3 move = transform.right * horizontal + transform.forward * vertical;
transform.position += move; transform.position += move;
}
// 相机旋转 if (isRot)
{
if (Input.GetMouseButtonDown(1)) if (Input.GetMouseButtonDown(1))
{ {
lastMousePosition = Input.mousePosition; lastMousePosition = Input.mousePosition;
@ -53,9 +54,11 @@ public class FreeCameraController : MonoBehaviour
{ {
isDragging = false; isDragging = false;
} }
if (isDragging) if (isDragging)
{ {
// 相机旋转
Vector3 mouseDelta = Input.mousePosition - lastMousePosition; // 反转了鼠标差值 Vector3 mouseDelta = Input.mousePosition - lastMousePosition; // 反转了鼠标差值
lastMousePosition = Input.mousePosition; lastMousePosition = Input.mousePosition;
@ -75,6 +78,9 @@ public class FreeCameraController : MonoBehaviour
} }
} }
} }
// 公共方法:旋转相机到指定方向 // 公共方法:旋转相机到指定方向
@ -101,8 +107,9 @@ public class FreeCameraController : MonoBehaviour
//maxRotationLimitY = currentRotation.y + yRotationLimit / 2; //maxRotationLimitY = currentRotation.y + yRotationLimit / 2;
} }
public void SetLock(bool isLock) public void SetLock(bool isMov, bool isRot)
{ {
this.isLock = isLock; this.isMov = isMov;
this.isRot = isRot;
} }
} }

View File

@ -597,6 +597,30 @@ namespace XMLTool
newAction = act; newAction = act;
} }
break; break;
case "CameraLock":
{
var act = new StringListAction();
XAttribute isMove = action.Attribute("isMove");
if (isMove != null)
{
act.args.Add(isMove.Value);
}
else
{
act.args.Add("true");
}
XAttribute isRotate = action.Attribute("isRotate");
if (isRotate != null)
{
act.args.Add(isRotate.Value);
}
else
{
act.args.Add("true");
}
newAction = act;
}
break;
case "TextTip": case "TextTip":
{ {
var act = new StringListAction(); var act = new StringListAction();
@ -767,6 +791,24 @@ namespace XMLTool
{ {
act.args.Add(""); act.args.Add("");
} }
XAttribute width = action.Attribute("width");
if (width != null)
{
act.args.Add(width.Value);
}
else
{
act.args.Add("0.1");
}
XAttribute lineScale = action.Attribute("lineScale");
if (lineScale != null)
{
act.args.Add(lineScale.Value);
}
else
{
act.args.Add("1,1");
}
newAction = act; newAction = act;
} }
break; break;

View File

@ -22,7 +22,7 @@
<!--右下角生成按钮 可生成多个 用逗号分开--> <!--右下角生成按钮 可生成多个 用逗号分开-->
<Action type="Btns" value="按钮1,按钮2,按钮3"></Action> <Action type="Btns" value="按钮1,按钮2,按钮3"></Action>
<!--用于右侧道具栏选择正确的道具 event用于配合StrEventCondition 做检测 --> <!--用于右侧道具栏选择正确的道具 event用于配合StrEventCondition 做检测 -->
<Action type="UITools" devices="道具名字" answers="正确道具" <Action type="UITools" devices="道具名字1" answers="正确道具"
setActive="true" setActive="true"
rightLabel="提示:器械选择正确。" rightLabel="提示:器械选择正确。"
wrongLabel="提示:器械选择错误,\r\n当前模块中不需要该物品。" wrongLabel="提示:器械选择错误,\r\n当前模块中不需要该物品。"
@ -74,7 +74,10 @@
<Condition type="Var" name="变量名" value="1"></Condition> <Condition type="Var" name="变量名" value="1"></Condition>
<!--字符串类型的事件监听 UI中的事件监听都 也可以自定义事件监听--> <!--字符串类型的事件监听 UI中的事件监听都 也可以自定义事件监听-->
<Condition type="StrEvent" value="器械选择通过"></Condition> <Condition type="StrEvent" value="器械选择通过"></Condition>
<!--画线 途径点使用|分割 lineScale 可以调整x轴向和y轴线上的线的粗细-->
<Action type="Line" name="红线" value="-4.030808,2.689521,-1.768913|-3.759371,2.694512,-1.247592" color="255,0,0,255" width="0.05" lineScale="10,0.5"></Action>
<!--相机锁定 是否可以移动 isMove 是否可以旋转镜头 isRotate-->
<Action type="CameraLock" isMove="false" isRotate="false"></Action>
<!--预加载模块 要在app.xml的Data标签内--> <!--预加载模块 要在app.xml的Data标签内-->
<PreLoad> <PreLoad>