模块和线的拆除以及重装
view的visual管理,重构了line的初始化方式,支持用yarn初始化
This commit is contained in:
@@ -0,0 +1,197 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!1 &3506613774900747202
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
serializedVersion: 6
|
||||
m_Component:
|
||||
- component: {fileID: 3319291487393607640}
|
||||
- component: {fileID: 230090618675107037}
|
||||
- component: {fileID: 8433616502553146576}
|
||||
- component: {fileID: 1631752023640685220}
|
||||
m_Layer: 0
|
||||
m_Name: InteractiveLineSegment
|
||||
m_TagString: Untagged
|
||||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 1
|
||||
--- !u!4 &3319291487393607640
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3506613774900747202}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 0}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!120 &230090618675107037
|
||||
LineRenderer:
|
||||
serializedVersion: 2
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3506613774900747202}
|
||||
m_Enabled: 1
|
||||
m_CastShadows: 1
|
||||
m_ReceiveShadows: 1
|
||||
m_DynamicOccludee: 1
|
||||
m_StaticShadowCaster: 0
|
||||
m_MotionVectors: 0
|
||||
m_LightProbeUsage: 0
|
||||
m_ReflectionProbeUsage: 0
|
||||
m_RayTracingMode: 0
|
||||
m_RayTraceProcedural: 0
|
||||
m_RenderingLayerMask: 1
|
||||
m_RendererPriority: 0
|
||||
m_Materials:
|
||||
- {fileID: 2100000, guid: 51099a9679b002c46b76c25f9ac139e3, type: 2}
|
||||
m_StaticBatchInfo:
|
||||
firstSubMesh: 0
|
||||
subMeshCount: 0
|
||||
m_StaticBatchRoot: {fileID: 0}
|
||||
m_ProbeAnchor: {fileID: 0}
|
||||
m_LightProbeVolumeOverride: {fileID: 0}
|
||||
m_ScaleInLightmap: 1
|
||||
m_ReceiveGI: 1
|
||||
m_PreserveUVs: 0
|
||||
m_IgnoreNormalsForChartDetection: 0
|
||||
m_ImportantGI: 0
|
||||
m_StitchLightmapSeams: 1
|
||||
m_SelectedEditorRenderState: 3
|
||||
m_MinimumChartSize: 4
|
||||
m_AutoUVMaxDistance: 0.5
|
||||
m_AutoUVMaxAngle: 89
|
||||
m_LightmapParameters: {fileID: 0}
|
||||
m_SortingLayerID: 428640211
|
||||
m_SortingLayer: 4
|
||||
m_SortingOrder: 3
|
||||
m_Positions:
|
||||
- {x: 0, y: 0, z: 0}
|
||||
- {x: 0, y: 0, z: 1}
|
||||
m_Parameters:
|
||||
serializedVersion: 3
|
||||
widthMultiplier: 1
|
||||
widthCurve:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 3
|
||||
time: 0.02299881
|
||||
value: 0.20912552
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
colorGradient:
|
||||
serializedVersion: 2
|
||||
key0: {r: 0.24528301, g: 0.24528301, b: 0.24528301, a: 1}
|
||||
key1: {r: 0.3301887, g: 0.3301887, b: 0.3301887, a: 1}
|
||||
key2: {r: 0, g: 0, b: 0, a: 0}
|
||||
key3: {r: 0, g: 0, b: 0, a: 0}
|
||||
key4: {r: 0, g: 0, b: 0, a: 0}
|
||||
key5: {r: 0, g: 0, b: 0, a: 0}
|
||||
key6: {r: 0, g: 0, b: 0, a: 0}
|
||||
key7: {r: 0, g: 0, b: 0, a: 0}
|
||||
ctime0: 0
|
||||
ctime1: 65535
|
||||
ctime2: 0
|
||||
ctime3: 0
|
||||
ctime4: 0
|
||||
ctime5: 0
|
||||
ctime6: 0
|
||||
ctime7: 0
|
||||
atime0: 0
|
||||
atime1: 65535
|
||||
atime2: 0
|
||||
atime3: 0
|
||||
atime4: 0
|
||||
atime5: 0
|
||||
atime6: 0
|
||||
atime7: 0
|
||||
m_Mode: 0
|
||||
m_ColorSpace: 0
|
||||
m_NumColorKeys: 2
|
||||
m_NumAlphaKeys: 2
|
||||
numCornerVertices: 6
|
||||
numCapVertices: 6
|
||||
alignment: 0
|
||||
textureMode: 0
|
||||
textureScale: {x: 1, y: 1}
|
||||
shadowBias: 0.5
|
||||
generateLightingData: 0
|
||||
m_MaskInteraction: 0
|
||||
m_UseWorldSpace: 1
|
||||
m_Loop: 0
|
||||
m_ApplyActiveColorSpace: 1
|
||||
--- !u!61 &8433616502553146576
|
||||
BoxCollider2D:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3506613774900747202}
|
||||
m_Enabled: 1
|
||||
m_Density: 1
|
||||
m_Material: {fileID: 0}
|
||||
m_IncludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_ExcludeLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 0
|
||||
m_LayerOverridePriority: 0
|
||||
m_ForceSendLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_ForceReceiveLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_ContactCaptureLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_CallbackLayers:
|
||||
serializedVersion: 2
|
||||
m_Bits: 4294967295
|
||||
m_IsTrigger: 0
|
||||
m_UsedByEffector: 0
|
||||
m_UsedByComposite: 0
|
||||
m_Offset: {x: 6.61, y: -0.60116494}
|
||||
m_SpriteTilingProperty:
|
||||
border: {x: 0, y: 0, z: 0, w: 0}
|
||||
pivot: {x: 0, y: 0}
|
||||
oldSize: {x: 0, y: 0}
|
||||
newSize: {x: 0, y: 0}
|
||||
adaptiveTilingThreshold: 0
|
||||
drawMode: 0
|
||||
adaptiveTiling: 0
|
||||
m_AutoTiling: 0
|
||||
serializedVersion: 2
|
||||
m_Size: {x: 1, y: 1}
|
||||
m_EdgeRadius: 0
|
||||
--- !u!114 &1631752023640685220
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 3506613774900747202}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 067e5e9e7bcd7a2429feff639d0ef630, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6723369fb5eae81409a3677ffa80f504
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -33,10 +33,12 @@ public class EyeTransitionManager : MonoBehaviour
|
||||
public Socket socket;
|
||||
//public InteractiveLineSegment lineSegment; // 线段
|
||||
public ViewState viewState;
|
||||
public Image VisualspriteRender; // 新增字段,用于保存视图的图片
|
||||
|
||||
public List<GameObject> Visuals; // 用于保存视图的图片列表
|
||||
public int currentVisualIndex = 0;
|
||||
public CrowBarSocket crowBarSocket;
|
||||
|
||||
//public GameObject extraGameobject;
|
||||
|
||||
private bool _isAvailable = false; // 视图是否可用的私有字段
|
||||
|
||||
// 视图是否可用的公有属性
|
||||
@@ -79,6 +81,8 @@ public class EyeTransitionManager : MonoBehaviour
|
||||
EmoView,
|
||||
ColorView,
|
||||
SpeakView,
|
||||
|
||||
UFViewBroken,
|
||||
//ColorView
|
||||
|
||||
|
||||
@@ -168,18 +172,14 @@ public class EyeTransitionManager : MonoBehaviour
|
||||
|
||||
// 初始化视图状态和视图配置的映射
|
||||
viewConfigDictionary = new Dictionary<ViewState, ViewConfig>();
|
||||
// foreach (var config in viewConfigs)
|
||||
// {
|
||||
// viewConfigDictionary[config.viewState] = config;
|
||||
// if (config.returnToMainViewButton != null)
|
||||
// {
|
||||
// // 绑定每个视图的返回MainView按钮
|
||||
// config.returnToMainViewButton.onClick.AddListener(() => StartTransition(ViewState.MainView));
|
||||
// }
|
||||
// // 更新按钮的可用性
|
||||
// //config.activateButton.interactable = config.IsAvailable;
|
||||
// //config.activateButton.gameObject.SetActive(false);
|
||||
// }
|
||||
foreach (var config in viewConfigs)
|
||||
{
|
||||
viewConfigDictionary[config.viewState] = config;
|
||||
if(config.Visuals.Count!=0)
|
||||
{
|
||||
SetVisualState(config.viewState.ToString(),config.currentVisualIndex);
|
||||
}
|
||||
}
|
||||
LoadState();
|
||||
}
|
||||
|
||||
@@ -244,6 +244,7 @@ public class EyeTransitionManager : MonoBehaviour
|
||||
{
|
||||
foreach (var viewConfig in viewConfigs)
|
||||
{
|
||||
if(viewConfig.viewPanel!=null)
|
||||
viewConfig.viewPanel.SetActive(false);
|
||||
}
|
||||
return;
|
||||
@@ -253,6 +254,7 @@ public class EyeTransitionManager : MonoBehaviour
|
||||
|
||||
foreach (var viewConfig in viewConfigs)
|
||||
{
|
||||
if(viewConfig.viewPanel!=null)
|
||||
viewConfig.viewPanel.SetActive(viewConfig.viewState == viewState);
|
||||
}
|
||||
}
|
||||
@@ -362,49 +364,58 @@ public void SetViewAvailability(string viewStateName, bool isAvailable)
|
||||
});
|
||||
}
|
||||
}
|
||||
[YarnCommand("Set_ViewVisual")]
|
||||
public void ChangeSprite(string viewStateName, string spriteName)
|
||||
// [YarnCommand("Set_ViewVisual")]
|
||||
// public void ChangeSprite(string viewStateName, string spriteName)
|
||||
// {
|
||||
// ViewState viewState;
|
||||
// if (!Enum.TryParse(viewStateName, out viewState))
|
||||
// {
|
||||
// Debug.LogError("Invalid ViewState name: " + viewStateName);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// if (!viewConfigDictionary.TryGetValue(viewState, out ViewConfig config)) return;
|
||||
|
||||
// // 加载新的图片
|
||||
// if (config.VisualspriteRender != null)
|
||||
// {
|
||||
// config.VisualspriteRender.sprite = Resources.Load<Sprite>(spriteName);
|
||||
|
||||
// }
|
||||
// }
|
||||
[YarnCommand("Set_ViewVisualState")]
|
||||
public void SetVisualState(string viewStateName, int visualIndex)
|
||||
{
|
||||
Debug.Log("SetVisualState: ");
|
||||
ViewState viewState;
|
||||
if (!Enum.TryParse(viewStateName, out viewState))
|
||||
{
|
||||
ViewState viewState;
|
||||
if (!Enum.TryParse(viewStateName, out viewState))
|
||||
{
|
||||
Debug.LogError("Invalid ViewState name: " + viewStateName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!viewConfigDictionary.TryGetValue(viewState, out ViewConfig config)) return;
|
||||
|
||||
// 加载新的图片
|
||||
if (config.VisualspriteRender != null)
|
||||
{
|
||||
config.VisualspriteRender.sprite = Resources.Load<Sprite>(spriteName);
|
||||
|
||||
}
|
||||
Debug.LogError("Invalid ViewState name: " + viewStateName);
|
||||
return;
|
||||
}
|
||||
[YarnCommand("Set_ViewVisualState")]
|
||||
public void SetVisualState(string viewStateName,bool isActive)
|
||||
|
||||
if (!viewConfigDictionary.TryGetValue(viewState, out ViewConfig config))
|
||||
{
|
||||
ViewState viewState;
|
||||
if (!Enum.TryParse(viewStateName, out viewState))
|
||||
{
|
||||
Debug.LogError("Invalid ViewState name: " + viewStateName);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!viewConfigDictionary.TryGetValue(viewState, out ViewConfig config)) return;
|
||||
|
||||
// 加载新的图片
|
||||
if (config.VisualspriteRender != null)
|
||||
{
|
||||
bool activeStatus = isActive;
|
||||
config.VisualspriteRender.gameObject.SetActive(activeStatus);
|
||||
}
|
||||
if (config.socket != null)
|
||||
{
|
||||
bool activeStatus = isActive;
|
||||
config.socket.gameObject.SetActive(activeStatus);
|
||||
}
|
||||
Debug.LogError("ViewState " + viewState + " not found in viewConfigDictionary");
|
||||
return;
|
||||
}
|
||||
|
||||
if (visualIndex < 0 || visualIndex >= config.Visuals.Count)
|
||||
{
|
||||
Debug.LogError("Invalid visual index for " + viewStateName);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < config.Visuals.Count; i++)
|
||||
{
|
||||
config.Visuals[i].SetActive(i == visualIndex);
|
||||
}
|
||||
|
||||
config.currentVisualIndex = visualIndex;
|
||||
|
||||
|
||||
}
|
||||
|
||||
[YarnCommand("Set_VeiwCrowSocketAvailable")]
|
||||
public void SetCrowSocketAvailable(string viewStateName,bool isActive)
|
||||
{
|
||||
|
||||
+602
-483
File diff suppressed because it is too large
Load Diff
@@ -3,13 +3,46 @@ tags:
|
||||
---
|
||||
<<indoor>>
|
||||
<<load_scene 佩佩视觉模块>>
|
||||
<<Set_ViewVisualState ViewManager "ColorView" 1>>
|
||||
[command name=activate_socket_choice /]
|
||||
<<start_transition ViewManager "MainView">>
|
||||
<<wait 2>>
|
||||
<<jump Day2>>
|
||||
//<<jump Day3>>
|
||||
|
||||
|
||||
===
|
||||
|
||||
title: Day2
|
||||
tags:
|
||||
---
|
||||
// <<set_view_availability ViewManager UFViewBroken false>>
|
||||
// <<Set_ViewVisualState ViewManager UFViewBroken false>>
|
||||
// <<set_view_availability ViewManager UFView true>>
|
||||
// <<Set_ViewVisualState ViewManager UFView true>>
|
||||
<<CrowBarIn CrowBar>>//撬棍入场
|
||||
<<Set_VeiwCrowSocketAvailable ViewManager true>>//设置这个模块是可拆的
|
||||
<<Set_VeiwCrowSocketAvailable ViewManager "UFView" true>>
|
||||
[options /]
|
||||
->UFViewCrowBar//要拆除哪个veiw就加后缀
|
||||
<<Set_ViewVisualState ViewManager UFView false>>//设置某个模块为false就是拆除
|
||||
我: 拆除UF了
|
||||
<<Set_ViewVisualState ViewManager "UFView" 1>>
|
||||
我: 拆开了
|
||||
我: 彻底拆掉吧
|
||||
<<CrowBarIn CrowBar>>//撬棍入场
|
||||
<<Set_VeiwCrowSocketAvailable ViewManager "UFView" true>>
|
||||
[options /]
|
||||
->UFViewCrowBar
|
||||
<<Set_ViewVisualState ViewManager "UFView" 3>>
|
||||
我: 彻底拆掉了
|
||||
===
|
||||
title: Day3
|
||||
tags:
|
||||
---
|
||||
<<Set_ViewVisualState ViewManager "UFView" 3>>
|
||||
我: 重新装上吧
|
||||
<<Set_ViewVisualState ViewManager "UFView" 2>>
|
||||
我: 把色觉也装上吧
|
||||
<<Set_ViewVisualState ViewManager "UFView" 1>>
|
||||
我: 盖子盖起来
|
||||
<<Set_ViewVisualState ViewManager "UFView" 0>>
|
||||
我: 把我的色觉给佩佩吧
|
||||
<<Set_ViewVisualState ViewManager "ColorView" 0>>
|
||||
|
||||
===
|
||||
|
||||
@@ -10,7 +10,9 @@ tags:
|
||||
-> MemoryEyeScissor
|
||||
我:剪断哦了
|
||||
<<set_scissors_mode LineManager false>>
|
||||
-> MemoryUFScissor
|
||||
我:这个剪不断噢
|
||||
->重新连接线
|
||||
<<fade_in 2>>
|
||||
<<reconnected_line LineManager MemoryEye>>
|
||||
<<fade_out 2>>
|
||||
|
||||
===
|
||||
|
||||
@@ -44,14 +44,14 @@ public class Plug : MonoBehaviour, IDragHandler, IPointerDownHandler, IPointerUp
|
||||
{
|
||||
// Dialogue has started, disable plug interactions
|
||||
IsInDialogue = true;
|
||||
Debug.Log("in dialogue");
|
||||
//Debug.Log("in dialogue");
|
||||
}
|
||||
|
||||
void HandleDialogueComplete()
|
||||
{
|
||||
// Dialogue has completed, enable plug interactions
|
||||
IsInDialogue = false;
|
||||
Debug.Log("dialoguecompleted");
|
||||
//Debug.Log("dialoguecompleted");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ using System.Drawing;
|
||||
public class CrowBarSocket : MonoBehaviour, ISocket
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
public bool IsAvailable { get; set; } = false;
|
||||
public bool IsAvailable { get; set; } = true;
|
||||
public Vector2 InsertionPoint => transform.position;
|
||||
public GameObject visual;
|
||||
|
||||
@@ -35,6 +35,10 @@ public class CrowBarSocket : MonoBehaviour, ISocket
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
public void EnableSocket()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public Vector2 GetPosition()
|
||||
{
|
||||
|
||||
@@ -38,7 +38,6 @@ public class Crowbar : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragH
|
||||
private void Start()
|
||||
{
|
||||
crowbarOutPosition = transform.position;
|
||||
crowbarSockets = new List<CrowBarSocket>(FindObjectsOfType<CrowBarSocket>());
|
||||
|
||||
}
|
||||
private void Initialize()
|
||||
@@ -50,6 +49,7 @@ public class Crowbar : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragH
|
||||
crowbarSocket=null;
|
||||
crowbarCanvas.sortingLayerName = "Tool";
|
||||
crowbarCanvas.sortingOrder = 6;
|
||||
crowbarSockets = new List<CrowBarSocket>(FindObjectsOfType<CrowBarSocket>());
|
||||
}
|
||||
|
||||
[YarnCommand("CrowBarIn")]
|
||||
@@ -67,6 +67,7 @@ public class Crowbar : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragH
|
||||
|
||||
// });
|
||||
box.DOMove(crowbarOutPosition, 1f);
|
||||
transform.position=crowbarOutPosition;
|
||||
}
|
||||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
@@ -87,15 +88,15 @@ public class Crowbar : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragH
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
//Debug.Log("Draging");
|
||||
Debug.Log("Draging");
|
||||
if (IsInDialogue || isPryingCompleted) return;
|
||||
|
||||
if (isInserted)
|
||||
{
|
||||
Debug.Log("insert");
|
||||
Debug.Log("insert");
|
||||
float deltaY = lastMousePosition.y - Input.mousePosition.y;
|
||||
lastMousePosition = Input.mousePosition; // 更新 lastMousePosition
|
||||
Debug.Log("Progress :"+progress);
|
||||
//Debug.Log("Progress :"+progress);
|
||||
|
||||
progress += deltaY*0.3f * Time.deltaTime;
|
||||
progress = Mathf.Clamp01(progress); // 确保 progress 不会小于0
|
||||
@@ -104,7 +105,7 @@ public void OnDrag(PointerEventData eventData)
|
||||
float startAngle = crowbarSocket.visual.transform.eulerAngles.z;
|
||||
float endAngle = startAngle + 40f;
|
||||
float currentAngle = Mathf.Lerp(startAngle, endAngle, progress);
|
||||
Debug.Log("currentAngle :"+currentAngle);
|
||||
//Debug.Log("currentAngle :"+currentAngle);
|
||||
|
||||
|
||||
// 更新撬棍的旋转角度
|
||||
@@ -113,12 +114,13 @@ public void OnDrag(PointerEventData eventData)
|
||||
if (progress >= 1f)
|
||||
{
|
||||
crowbarSocket.Completed();
|
||||
crowbarSocket.EnableSocket();
|
||||
// 触发撬动完成的逻辑
|
||||
Debug.Log("Crowbar action completed.");
|
||||
isPryingCompleted = true;
|
||||
|
||||
// 定义目标位置
|
||||
Vector3 targetPosition = transform.position + new Vector3(-1, 1, 0) * 10f; // 你可能需要根据你的场景来调整这个偏移量
|
||||
Vector3 targetPosition = transform.position + new Vector3(-1, 1, 0) * 6f; // 你可能需要根据你的场景来调整这个偏移量
|
||||
|
||||
// 使用 DOTween 来移动 crowbar
|
||||
transform.DOMove(targetPosition, 1f);
|
||||
@@ -165,6 +167,10 @@ public void OnEndDrag(PointerEventData eventData)
|
||||
|
||||
foreach (var socket in crowbarSockets)
|
||||
{
|
||||
if(!socket.gameObject.activeInHierarchy)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
float distance = Vector3.Distance(transform.position, socket.transform.position);
|
||||
if (distance <= minDistance && socket.IsAvailable)
|
||||
{
|
||||
@@ -182,10 +188,11 @@ public void OnEndDrag(PointerEventData eventData)
|
||||
crowbarVisual.rotation = nearestSocket.visual.transform.rotation;
|
||||
isInserted = true;
|
||||
nearestSocket.RemovePlug();
|
||||
nearestSocket.DisableSocket();
|
||||
nearestSocket.DisableSocket();
|
||||
crowbarSocket=nearestSocket;
|
||||
crowbarCanvas.sortingLayerName = "UnderModule";
|
||||
crowbarCanvas.sortingOrder = 6;
|
||||
Debug.Log("crowbarsocket name"+crowbarSocket.name);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -212,6 +219,10 @@ public CrowBarSocket FindNearestSocket()
|
||||
|
||||
foreach (var socket in crowbarSockets)
|
||||
{
|
||||
if(!socket.gameObject.activeInHierarchy)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
float distance = Vector3.Distance(transform.position, socket.transform.position);
|
||||
if (distance <= minDistance && socket.IsAvailable)
|
||||
{
|
||||
|
||||
@@ -4,7 +4,6 @@ using AibisDream;
|
||||
|
||||
public class InteractiveLineSegment : VisualLineSegment
|
||||
{
|
||||
[SerializeField]
|
||||
private Transform startTransform;
|
||||
public Transform StartTransform
|
||||
{
|
||||
@@ -12,7 +11,6 @@ public class InteractiveLineSegment : VisualLineSegment
|
||||
set { startTransform = value; }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private Transform endTransform;
|
||||
public Transform EndTransform
|
||||
{
|
||||
@@ -20,6 +18,8 @@ public class InteractiveLineSegment : VisualLineSegment
|
||||
set { endTransform = value; }
|
||||
}
|
||||
|
||||
private LineRenderer strokeLineRenderer; // 新的 LineRenderer 对象作为描边
|
||||
|
||||
private BoxCollider2D boxCollider;
|
||||
|
||||
private YarnOption _option;
|
||||
@@ -43,50 +43,70 @@ public class InteractiveLineSegment : VisualLineSegment
|
||||
|
||||
public void OnHover()
|
||||
{
|
||||
if (IsCuttable)
|
||||
{
|
||||
TurnGreen();
|
||||
}
|
||||
else
|
||||
{
|
||||
TurnRed();
|
||||
}
|
||||
strokeLineRenderer.enabled = true;
|
||||
// if (IsCuttable)
|
||||
// {
|
||||
// TurnGreen();
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// TurnRed();
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
public void OnHoverExit()
|
||||
{
|
||||
TurnGrey();
|
||||
// TurnGrey();
|
||||
strokeLineRenderer.enabled = false;
|
||||
}
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
boxCollider = GetComponent<BoxCollider2D>();
|
||||
|
||||
}
|
||||
public void Start()
|
||||
{
|
||||
Initialize();
|
||||
InitializeStrokeLineRenderer();
|
||||
|
||||
}
|
||||
private LineRenderer CopyLineRenderer(LineRenderer source)
|
||||
{
|
||||
LineRenderer newLineRenderer = new GameObject("StrokeLine").AddComponent<LineRenderer>();
|
||||
|
||||
// Copy the properties from the source LineRenderer to the new one
|
||||
newLineRenderer.material = source.material;
|
||||
newLineRenderer.startColor = source.startColor;
|
||||
newLineRenderer.endColor = source.endColor;
|
||||
newLineRenderer.startWidth = source.startWidth;
|
||||
newLineRenderer.endWidth = source.endWidth;
|
||||
newLineRenderer.numCornerVertices = source.numCornerVertices;
|
||||
newLineRenderer.numCapVertices = source.numCapVertices;
|
||||
newLineRenderer.positionCount = source.positionCount;
|
||||
newLineRenderer.sortingLayerName = source.sortingLayerName;
|
||||
newLineRenderer.sortingOrder = source.sortingOrder-1;
|
||||
|
||||
// Set the parent of the new GameObject to the same as the source
|
||||
newLineRenderer.transform.parent = source.transform;
|
||||
|
||||
return newLineRenderer;
|
||||
}
|
||||
private void InitializeStrokeLineRenderer()
|
||||
{
|
||||
strokeLineRenderer = CopyLineRenderer(GetComponent<LineRenderer>());
|
||||
// 设置描边的 LineRenderer 的属性
|
||||
strokeLineRenderer.SetPosition(0, StartTransform.position);
|
||||
strokeLineRenderer.SetPosition(1, EndTransform.position);
|
||||
strokeLineRenderer.endColor = Color.white;
|
||||
strokeLineRenderer.startColor = Color.white;
|
||||
strokeLineRenderer.widthMultiplier = lineRenderer.widthMultiplier * 1.2f; // 假设描边的宽度是原线条宽度的 1.2 倍
|
||||
strokeLineRenderer.enabled = false; // 初始时禁用描边
|
||||
}
|
||||
|
||||
|
||||
public void TurnGreen()
|
||||
{
|
||||
lineRenderer.material.color = Color.green; // 改变 LineRenderer 的颜色
|
||||
}
|
||||
|
||||
public void TurnGrey()
|
||||
{
|
||||
lineRenderer.material.color = Color.grey; // 改变 LineRenderer 的颜色
|
||||
}
|
||||
public void TurnRed()
|
||||
{
|
||||
lineRenderer.material.color = Color.red; // 改变 LineRenderer 的颜色
|
||||
}
|
||||
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
TurnGrey();
|
||||
if (StartTransform == null || EndTransform == null)
|
||||
{
|
||||
Debug.LogError("StartTransform or EndTransform is not set.");
|
||||
|
||||
@@ -6,10 +6,21 @@ using System.Collections;
|
||||
using AibisDream;
|
||||
using System.Linq;
|
||||
using DG.Tweening;
|
||||
|
||||
[System.Serializable]
|
||||
public class LineSegmentInfo
|
||||
{
|
||||
public string Name;
|
||||
public Transform StartTransform;
|
||||
public Transform EndTransform;
|
||||
}
|
||||
public class LineManager : MonoBehaviour
|
||||
{
|
||||
//public GameObject interactiveLineSegmentPrefab;
|
||||
public InteractiveLineSegment interactiveLineSegmentPrefab; // InteractiveLineSegment 的预制体
|
||||
[SerializeField]
|
||||
private List<LineSegmentInfo> lineSegmentInfos; // 线段信息的列表
|
||||
|
||||
// 线段字典,用于快速查找
|
||||
|
||||
public GameObject physicLineSegmentPrefab;
|
||||
|
||||
public CustomCursor customCursor; // 自定义光标,你可以在 Inspector 中设置
|
||||
@@ -44,9 +55,20 @@ public class LineManager : MonoBehaviour
|
||||
}
|
||||
private InteractiveLineSegment currentLineSegment; // 当前要被剪断的线段
|
||||
|
||||
private const float LONG_PRESS_THRESHOLD = 3.0f; // 长按阈值,可以根据需要调整
|
||||
private const float LONG_PRESS_THRESHOLD = 0.01f; // 长按阈值,可以根据需要调整
|
||||
private float longPressTime = 0.0f; // 长按时间
|
||||
private float detectionRadius=0.4f;
|
||||
private float detectionRadius=0.25f;
|
||||
|
||||
private void SaveCutLine(string lineName)
|
||||
{
|
||||
PlayerPrefs.SetString(lineName, "cut");
|
||||
PlayerPrefs.Save();
|
||||
}
|
||||
|
||||
private bool IsLineCut(string lineName)
|
||||
{
|
||||
return PlayerPrefs.HasKey(lineName);
|
||||
}
|
||||
|
||||
public void CutLine(InteractiveLineSegment originalLineSegment, Vector3 splitPoint)
|
||||
{
|
||||
@@ -60,17 +82,41 @@ public void CutLine(InteractiveLineSegment originalLineSegment, Vector3 splitPoi
|
||||
GameObject firstLineSegmentObject = Instantiate(physicLineSegmentPrefab, transform);
|
||||
PhysicLineSegment firstLineSegment = firstLineSegmentObject.GetComponent<PhysicLineSegment>();
|
||||
firstLineSegment.Initialize(originalLineSegment.StartTransform.position, splitPoint);
|
||||
firstLineSegment.lineRenderer.startColor=originalLineSegment.lineRenderer.startColor;
|
||||
firstLineSegment.lineRenderer.endColor=originalLineSegment.lineRenderer.endColor;
|
||||
|
||||
// Create the second new line segment
|
||||
GameObject secondLineSegmentObject = Instantiate(physicLineSegmentPrefab, transform);
|
||||
PhysicLineSegment secondLineSegment = secondLineSegmentObject.GetComponent<PhysicLineSegment>();
|
||||
secondLineSegment.Initialize(originalLineSegment.EndTransform.position,splitPoint);
|
||||
originalLineSegment.Option.SelectOption();
|
||||
|
||||
secondLineSegment.lineRenderer.startColor=originalLineSegment.lineRenderer.startColor;
|
||||
secondLineSegment.lineRenderer.endColor=originalLineSegment.lineRenderer.endColor;
|
||||
// Immediately destroy the original line segment
|
||||
Destroy(originalLineSegment.gameObject);
|
||||
Debug.Log("线销毁了");
|
||||
SaveCutLine(originalLineSegment.name);
|
||||
|
||||
// Start the coroutine to destroy the new line segments after fade in and out
|
||||
StartCoroutine(DestroyNewSegmentsAfterFade(firstLineSegmentObject, secondLineSegmentObject,originalLineSegment));
|
||||
}
|
||||
|
||||
private IEnumerator DestroyNewSegmentsAfterFade(GameObject firstLineSegmentObject, GameObject secondLineSegmentObject,InteractiveLineSegment originalLineSegment)
|
||||
{
|
||||
// Assume FadeIn() is a method that starts the fade in animation and returns the duration of the animation
|
||||
float fadeDuration = 2f;
|
||||
DialogController.FadeIn(fadeDuration);
|
||||
// Wait for the fade in animation to finish
|
||||
// Destroy the new line segments
|
||||
yield return new WaitForSeconds(fadeDuration);
|
||||
Destroy(firstLineSegmentObject);
|
||||
Destroy(secondLineSegmentObject);
|
||||
// Assume FadeOut() is a method that starts the fade out animation and returns the duration of the animation
|
||||
DialogController.FadeOut(fadeDuration);
|
||||
yield return new WaitForSeconds(fadeDuration);
|
||||
originalLineSegment.Option.SelectOption();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void AddPhysicsComponents(GameObject lineSegmentObject)
|
||||
{
|
||||
@@ -117,6 +163,8 @@ private void LongPressLineSegment(InteractiveLineSegment lineSegment)
|
||||
longPressTime += Time.deltaTime;
|
||||
Vector3 midpoint = (lineSegment.StartPoint + lineSegment.EndPoint) / 2;
|
||||
|
||||
float distance = Vector3.Distance(midpoint, lineSegment.StartPoint);
|
||||
|
||||
// Make the scissors shake and the line segment turn red
|
||||
if (longPressTime < LONG_PRESS_THRESHOLD)
|
||||
{
|
||||
@@ -127,11 +175,29 @@ private void LongPressLineSegment(InteractiveLineSegment lineSegment)
|
||||
|
||||
// Move the scissors towards the midpoint
|
||||
//customCursor.transform.DOMove(midpoint, 0.1f);
|
||||
|
||||
float progress = longPressTime / LONG_PRESS_THRESHOLD;
|
||||
// Calculate the new position of the color gradient
|
||||
float newPosition = progress * distance;
|
||||
|
||||
// Create a new color gradient
|
||||
// Gradient gradient = new Gradient();
|
||||
|
||||
// // Set the color keys of the gradient
|
||||
// gradient.SetKeys(
|
||||
// new GradientColorKey[] { new GradientColorKey(Color.red, 0.0f), new GradientColorKey(lineSegment.GetComponent<LineRenderer>().startColor, newPosition) },
|
||||
// new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(1.0f, newPosition) }
|
||||
// );
|
||||
|
||||
// // Set the color gradient of the LineRenderer
|
||||
// lineSegment.GetComponent<LineRenderer>().colorGradient = gradient;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Cut the line segment
|
||||
CutLine(lineSegment,midpoint);
|
||||
IsScissorsMode=false;
|
||||
Debug.Log("线剪断触发了");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +205,7 @@ private void ExitLineSegment()
|
||||
{
|
||||
if (currentLineSegment != null)
|
||||
{
|
||||
currentLineSegment.TurnGrey();
|
||||
currentLineSegment.OnHoverExit();
|
||||
}
|
||||
currentLineSegment = null;
|
||||
}
|
||||
@@ -195,16 +261,86 @@ private void ExitLineSegment()
|
||||
}
|
||||
|
||||
|
||||
[YarnCommand("reconnected_line")]
|
||||
public void Reconnected(string input)
|
||||
{
|
||||
// Use GetLineSegmentName method to find the recognized name
|
||||
string recognizedName = GetLineSegmentName(input);
|
||||
|
||||
if (recognizedName == null)
|
||||
{
|
||||
Debug.LogError("Invalid LineSegmentInfo name: " + input);
|
||||
return;
|
||||
}
|
||||
|
||||
// Find the LineSegmentInfo with the recognized name
|
||||
LineSegmentInfo lineSegmentInfo = lineSegmentInfos.Find(info => info.Name == recognizedName);
|
||||
|
||||
if (lineSegmentInfo == null)
|
||||
{
|
||||
Debug.LogError("Invalid LineSegmentInfo name: " + recognizedName);
|
||||
return;
|
||||
}
|
||||
|
||||
// If the line is already cut, skip it
|
||||
// if (!IsLineCut(lineSegmentInfo.Name))
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// Instantiate a new line segment with the given info
|
||||
InteractiveLineSegment newSegment = Instantiate(interactiveLineSegmentPrefab, transform);
|
||||
newSegment.StartTransform = lineSegmentInfo.StartTransform;
|
||||
newSegment.EndTransform = lineSegmentInfo.EndTransform;
|
||||
newSegment.Initialize();
|
||||
|
||||
// Add the new line segment to the dictionary
|
||||
//lineSegmentDictionary.Add(lineSegmentInfo.Name, newSegment);
|
||||
}
|
||||
[YarnCommand("delete_line")]
|
||||
public void DeleteLine(string input)
|
||||
{
|
||||
// Use GetLineSegmentName method to find the recognized name
|
||||
string recognizedName = GetLineSegmentName(input);
|
||||
|
||||
if (recognizedName == null)
|
||||
{
|
||||
Debug.LogError("Invalid LineSegmentInfo name: " + input);
|
||||
return;
|
||||
}
|
||||
|
||||
if (lineSegmentDictionary.ContainsKey(recognizedName))
|
||||
{
|
||||
InteractiveLineSegment lineSegmentToRemove = lineSegmentDictionary[recognizedName];
|
||||
lineSegmentDictionary.Remove(recognizedName);
|
||||
|
||||
// Destroy the line segment GameObject
|
||||
Destroy(lineSegmentToRemove.gameObject);
|
||||
|
||||
Debug.Log("Line segment removed: " + recognizedName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Line segment not found in dictionary: " + recognizedName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// 查找场景中的所有 InteractiveLineSegment 并添加到字典中
|
||||
InteractiveLineSegment[] lineSegments = FindObjectsOfType<InteractiveLineSegment>();
|
||||
foreach (InteractiveLineSegment lineSegment in lineSegments)
|
||||
{
|
||||
lineSegmentDictionary.Add(lineSegment.name, lineSegment);
|
||||
Debug.Log("Added " + lineSegment.name + " to lineSegmentDictionary");
|
||||
}
|
||||
foreach (LineSegmentInfo lineSegmentInfo in lineSegmentInfos)
|
||||
{
|
||||
if (IsLineCut(lineSegmentInfo.Name))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
InteractiveLineSegment newSegment = Instantiate(interactiveLineSegmentPrefab, transform);
|
||||
newSegment.StartTransform = lineSegmentInfo.StartTransform;
|
||||
newSegment.EndTransform = lineSegmentInfo.EndTransform;
|
||||
newSegment.Initialize();
|
||||
lineSegmentDictionary.Add(lineSegmentInfo.Name, newSegment);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public InteractiveLineSegment GetLineSegmentByName(string lineSegmentName)
|
||||
|
||||
@@ -12,7 +12,8 @@ public class PhysicLineSegment : MonoBehaviour
|
||||
|
||||
private List<VerletParticle> particles = new List<VerletParticle>();
|
||||
private List<VerletStick> sticks = new List<VerletStick>();
|
||||
private LineRenderer lineRenderer;
|
||||
[HideInInspector]
|
||||
public LineRenderer lineRenderer;
|
||||
private int segmentCount;
|
||||
public float gravity = -9.8f;
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ public class VisualLineSegment : MonoBehaviour
|
||||
{
|
||||
public Vector3 StartPoint { get; private set; }
|
||||
public Vector3 EndPoint { get; private set; }
|
||||
|
||||
protected LineRenderer lineRenderer;
|
||||
[HideInInspector]
|
||||
public LineRenderer lineRenderer;
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
@@ -23,6 +23,7 @@ public class VisualLineSegment : MonoBehaviour
|
||||
lineRenderer.SetPosition(1, EndPoint);
|
||||
}
|
||||
|
||||
|
||||
// public void ShrinkAndDisappear()
|
||||
// {
|
||||
// // Shrink the line segment from the end to the start
|
||||
|
||||
Reference in New Issue
Block a user