任务:编写序章场景逻辑
1.编写交互操作逻辑,我会用脚本给玩家物体添加一个子物体,子物体有一个触发器,当玩家按下交互键,通过回调看是否有Catch到的可交互物体,若有,我会触发可交互物体的OnCall,若没有,则不做反应。
2.编写可交互物体基类,可交互物体继承自Event,Start时检查碰撞盒状态。当检查到玩家进入触发器,把自己交给玩家的Catch。当检查到玩家离开触发器,看目前的Catch是否和自己一样,若一样则清除Catch,若不一样说明已经Catch了其他东西,不做反应。
3.编写绳结类,继承自可交互物体。当交互,给中介者发送信息,让中介者更改记录的当前记录的绳结是哪一个
(1.内含一个来自中介者的枚举类型的变量,记录自己属于哪一种绳结
(2.当OnCall,把自己的类型发给中介者
4.编写绳结中介者,负责玩家、皇帝和绳结的信息交流。
(1.有一个枚举类型,内含三种绳结种类
(2.有一个枚举类型的变量,记录当前记录的是哪一个绳结
(3.当绳结发来信息,更新记录的当前绳结
5.添加新的按键监听,并增加PlayerControl的虚函数
6.编写黄帝类
(1.继承自可交互物体
(2.内含一个来自中介者的枚举类型,记录皇帝对哪一种绳结提出要求
(3.当OnCall,检查中介者中记录的绳结和要求的是不是同一种,若是则触发后续流程,若不是,则触发摇头等动作,目前不做反应
(4.内含函数与后期外界对接,用来指定皇帝需要的绳结类型
*记得给Player类的Interact函数加上Base
我是每天上班提醒小助手,今天你上班了吗?😺
This commit is contained in:
parent
fa2911708d
commit
b96029fd5e
@ -62,6 +62,24 @@ public partial class @PlayerC : IInputActionCollection2, IDisposable
|
|||||||
""processors"": """",
|
""processors"": """",
|
||||||
""interactions"": """",
|
""interactions"": """",
|
||||||
""initialStateCheck"": false
|
""initialStateCheck"": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
""name"": ""LeftChange"",
|
||||||
|
""type"": ""Button"",
|
||||||
|
""id"": ""5e4b2241-fdf3-4717-9892-456eb07bff7d"",
|
||||||
|
""expectedControlType"": ""Button"",
|
||||||
|
""processors"": """",
|
||||||
|
""interactions"": """",
|
||||||
|
""initialStateCheck"": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
""name"": ""RightChange"",
|
||||||
|
""type"": ""Button"",
|
||||||
|
""id"": ""25825820-ed63-4821-a570-98c0346d0114"",
|
||||||
|
""expectedControlType"": ""Button"",
|
||||||
|
""processors"": """",
|
||||||
|
""interactions"": """",
|
||||||
|
""initialStateCheck"": false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
""bindings"": [
|
""bindings"": [
|
||||||
@ -196,6 +214,50 @@ public partial class @PlayerC : IInputActionCollection2, IDisposable
|
|||||||
""action"": ""Interact"",
|
""action"": ""Interact"",
|
||||||
""isComposite"": false,
|
""isComposite"": false,
|
||||||
""isPartOfComposite"": false
|
""isPartOfComposite"": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
""name"": """",
|
||||||
|
""id"": ""848dbb1f-2a82-4dc8-9673-c7f69bc2eaa5"",
|
||||||
|
""path"": ""<Keyboard>/q"",
|
||||||
|
""interactions"": """",
|
||||||
|
""processors"": """",
|
||||||
|
""groups"": """",
|
||||||
|
""action"": ""LeftChange"",
|
||||||
|
""isComposite"": false,
|
||||||
|
""isPartOfComposite"": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
""name"": """",
|
||||||
|
""id"": ""d1bc2781-7f70-4170-93c3-c849ff56c3cf"",
|
||||||
|
""path"": ""<Gamepad>/dpad/left"",
|
||||||
|
""interactions"": """",
|
||||||
|
""processors"": """",
|
||||||
|
""groups"": """",
|
||||||
|
""action"": ""LeftChange"",
|
||||||
|
""isComposite"": false,
|
||||||
|
""isPartOfComposite"": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
""name"": """",
|
||||||
|
""id"": ""bdd4c52b-c221-49d3-b467-201ebc18cb71"",
|
||||||
|
""path"": ""<Keyboard>/e"",
|
||||||
|
""interactions"": """",
|
||||||
|
""processors"": """",
|
||||||
|
""groups"": """",
|
||||||
|
""action"": ""RightChange"",
|
||||||
|
""isComposite"": false,
|
||||||
|
""isPartOfComposite"": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
""name"": """",
|
||||||
|
""id"": ""257c9bb8-7e77-4e5c-9caf-97284fb0adbd"",
|
||||||
|
""path"": ""<Gamepad>/dpad/right"",
|
||||||
|
""interactions"": """",
|
||||||
|
""processors"": """",
|
||||||
|
""groups"": """",
|
||||||
|
""action"": ""RightChange"",
|
||||||
|
""isComposite"": false,
|
||||||
|
""isPartOfComposite"": false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -253,6 +315,8 @@ public partial class @PlayerC : IInputActionCollection2, IDisposable
|
|||||||
m_Normal_Atk = m_Normal.FindAction("Atk", throwIfNotFound: true);
|
m_Normal_Atk = m_Normal.FindAction("Atk", throwIfNotFound: true);
|
||||||
m_Normal_Jump = m_Normal.FindAction("Jump", throwIfNotFound: true);
|
m_Normal_Jump = m_Normal.FindAction("Jump", throwIfNotFound: true);
|
||||||
m_Normal_Interact = m_Normal.FindAction("Interact", throwIfNotFound: true);
|
m_Normal_Interact = m_Normal.FindAction("Interact", throwIfNotFound: true);
|
||||||
|
m_Normal_LeftChange = m_Normal.FindAction("LeftChange", throwIfNotFound: true);
|
||||||
|
m_Normal_RightChange = m_Normal.FindAction("RightChange", throwIfNotFound: true);
|
||||||
// Null
|
// Null
|
||||||
m_Null = asset.FindActionMap("Null", throwIfNotFound: true);
|
m_Null = asset.FindActionMap("Null", throwIfNotFound: true);
|
||||||
m_Null_Newaction = m_Null.FindAction("New action", throwIfNotFound: true);
|
m_Null_Newaction = m_Null.FindAction("New action", throwIfNotFound: true);
|
||||||
@ -319,6 +383,8 @@ public partial class @PlayerC : IInputActionCollection2, IDisposable
|
|||||||
private readonly InputAction m_Normal_Atk;
|
private readonly InputAction m_Normal_Atk;
|
||||||
private readonly InputAction m_Normal_Jump;
|
private readonly InputAction m_Normal_Jump;
|
||||||
private readonly InputAction m_Normal_Interact;
|
private readonly InputAction m_Normal_Interact;
|
||||||
|
private readonly InputAction m_Normal_LeftChange;
|
||||||
|
private readonly InputAction m_Normal_RightChange;
|
||||||
public struct NormalActions
|
public struct NormalActions
|
||||||
{
|
{
|
||||||
private @PlayerC m_Wrapper;
|
private @PlayerC m_Wrapper;
|
||||||
@ -327,6 +393,8 @@ public partial class @PlayerC : IInputActionCollection2, IDisposable
|
|||||||
public InputAction @Atk => m_Wrapper.m_Normal_Atk;
|
public InputAction @Atk => m_Wrapper.m_Normal_Atk;
|
||||||
public InputAction @Jump => m_Wrapper.m_Normal_Jump;
|
public InputAction @Jump => m_Wrapper.m_Normal_Jump;
|
||||||
public InputAction @Interact => m_Wrapper.m_Normal_Interact;
|
public InputAction @Interact => m_Wrapper.m_Normal_Interact;
|
||||||
|
public InputAction @LeftChange => m_Wrapper.m_Normal_LeftChange;
|
||||||
|
public InputAction @RightChange => m_Wrapper.m_Normal_RightChange;
|
||||||
public InputActionMap Get() { return m_Wrapper.m_Normal; }
|
public InputActionMap Get() { return m_Wrapper.m_Normal; }
|
||||||
public void Enable() { Get().Enable(); }
|
public void Enable() { Get().Enable(); }
|
||||||
public void Disable() { Get().Disable(); }
|
public void Disable() { Get().Disable(); }
|
||||||
@ -348,6 +416,12 @@ public partial class @PlayerC : IInputActionCollection2, IDisposable
|
|||||||
@Interact.started -= m_Wrapper.m_NormalActionsCallbackInterface.OnInteract;
|
@Interact.started -= m_Wrapper.m_NormalActionsCallbackInterface.OnInteract;
|
||||||
@Interact.performed -= m_Wrapper.m_NormalActionsCallbackInterface.OnInteract;
|
@Interact.performed -= m_Wrapper.m_NormalActionsCallbackInterface.OnInteract;
|
||||||
@Interact.canceled -= m_Wrapper.m_NormalActionsCallbackInterface.OnInteract;
|
@Interact.canceled -= m_Wrapper.m_NormalActionsCallbackInterface.OnInteract;
|
||||||
|
@LeftChange.started -= m_Wrapper.m_NormalActionsCallbackInterface.OnLeftChange;
|
||||||
|
@LeftChange.performed -= m_Wrapper.m_NormalActionsCallbackInterface.OnLeftChange;
|
||||||
|
@LeftChange.canceled -= m_Wrapper.m_NormalActionsCallbackInterface.OnLeftChange;
|
||||||
|
@RightChange.started -= m_Wrapper.m_NormalActionsCallbackInterface.OnRightChange;
|
||||||
|
@RightChange.performed -= m_Wrapper.m_NormalActionsCallbackInterface.OnRightChange;
|
||||||
|
@RightChange.canceled -= m_Wrapper.m_NormalActionsCallbackInterface.OnRightChange;
|
||||||
}
|
}
|
||||||
m_Wrapper.m_NormalActionsCallbackInterface = instance;
|
m_Wrapper.m_NormalActionsCallbackInterface = instance;
|
||||||
if (instance != null)
|
if (instance != null)
|
||||||
@ -364,6 +438,12 @@ public partial class @PlayerC : IInputActionCollection2, IDisposable
|
|||||||
@Interact.started += instance.OnInteract;
|
@Interact.started += instance.OnInteract;
|
||||||
@Interact.performed += instance.OnInteract;
|
@Interact.performed += instance.OnInteract;
|
||||||
@Interact.canceled += instance.OnInteract;
|
@Interact.canceled += instance.OnInteract;
|
||||||
|
@LeftChange.started += instance.OnLeftChange;
|
||||||
|
@LeftChange.performed += instance.OnLeftChange;
|
||||||
|
@LeftChange.canceled += instance.OnLeftChange;
|
||||||
|
@RightChange.started += instance.OnRightChange;
|
||||||
|
@RightChange.performed += instance.OnRightChange;
|
||||||
|
@RightChange.canceled += instance.OnRightChange;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -416,6 +496,8 @@ public partial class @PlayerC : IInputActionCollection2, IDisposable
|
|||||||
void OnAtk(InputAction.CallbackContext context);
|
void OnAtk(InputAction.CallbackContext context);
|
||||||
void OnJump(InputAction.CallbackContext context);
|
void OnJump(InputAction.CallbackContext context);
|
||||||
void OnInteract(InputAction.CallbackContext context);
|
void OnInteract(InputAction.CallbackContext context);
|
||||||
|
void OnLeftChange(InputAction.CallbackContext context);
|
||||||
|
void OnRightChange(InputAction.CallbackContext context);
|
||||||
}
|
}
|
||||||
public interface INullActions
|
public interface INullActions
|
||||||
{
|
{
|
||||||
|
@ -40,6 +40,24 @@
|
|||||||
"processors": "",
|
"processors": "",
|
||||||
"interactions": "",
|
"interactions": "",
|
||||||
"initialStateCheck": false
|
"initialStateCheck": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "LeftChange",
|
||||||
|
"type": "Button",
|
||||||
|
"id": "5e4b2241-fdf3-4717-9892-456eb07bff7d",
|
||||||
|
"expectedControlType": "Button",
|
||||||
|
"processors": "",
|
||||||
|
"interactions": "",
|
||||||
|
"initialStateCheck": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "RightChange",
|
||||||
|
"type": "Button",
|
||||||
|
"id": "25825820-ed63-4821-a570-98c0346d0114",
|
||||||
|
"expectedControlType": "Button",
|
||||||
|
"processors": "",
|
||||||
|
"interactions": "",
|
||||||
|
"initialStateCheck": false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"bindings": [
|
"bindings": [
|
||||||
@ -174,6 +192,50 @@
|
|||||||
"action": "Interact",
|
"action": "Interact",
|
||||||
"isComposite": false,
|
"isComposite": false,
|
||||||
"isPartOfComposite": false
|
"isPartOfComposite": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "",
|
||||||
|
"id": "848dbb1f-2a82-4dc8-9673-c7f69bc2eaa5",
|
||||||
|
"path": "<Keyboard>/q",
|
||||||
|
"interactions": "",
|
||||||
|
"processors": "",
|
||||||
|
"groups": "",
|
||||||
|
"action": "LeftChange",
|
||||||
|
"isComposite": false,
|
||||||
|
"isPartOfComposite": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "",
|
||||||
|
"id": "d1bc2781-7f70-4170-93c3-c849ff56c3cf",
|
||||||
|
"path": "<Gamepad>/dpad/left",
|
||||||
|
"interactions": "",
|
||||||
|
"processors": "",
|
||||||
|
"groups": "",
|
||||||
|
"action": "LeftChange",
|
||||||
|
"isComposite": false,
|
||||||
|
"isPartOfComposite": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "",
|
||||||
|
"id": "bdd4c52b-c221-49d3-b467-201ebc18cb71",
|
||||||
|
"path": "<Keyboard>/e",
|
||||||
|
"interactions": "",
|
||||||
|
"processors": "",
|
||||||
|
"groups": "",
|
||||||
|
"action": "RightChange",
|
||||||
|
"isComposite": false,
|
||||||
|
"isPartOfComposite": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "",
|
||||||
|
"id": "257c9bb8-7e77-4e5c-9caf-97284fb0adbd",
|
||||||
|
"path": "<Gamepad>/dpad/right",
|
||||||
|
"interactions": "",
|
||||||
|
"processors": "",
|
||||||
|
"groups": "",
|
||||||
|
"action": "RightChange",
|
||||||
|
"isComposite": false,
|
||||||
|
"isPartOfComposite": false
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ed09910c0094cb27be8f3ca264680da3
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: cc355dd4cf1e6173beaeb22c2858cbe1
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
1075
Assets/Scenes/勍/InteractTest.unity
Normal file
1075
Assets/Scenes/勍/InteractTest.unity
Normal file
File diff suppressed because it is too large
Load Diff
7
Assets/Scenes/勍/InteractTest.unity.meta
Normal file
7
Assets/Scenes/勍/InteractTest.unity.meta
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9d2abd5208f4caf4fb48d255afe4a1c8
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
30
Assets/Scripts/勍/HuangDi.cs
Normal file
30
Assets/Scripts/勍/HuangDi.cs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using Sirenix.OdinInspector;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 皇帝类,控制皇帝的行为,继承自可交互物体
|
||||||
|
/// </summary>
|
||||||
|
public class HuangDi : Interactable
|
||||||
|
{
|
||||||
|
[SerializeField][EnumPaging]
|
||||||
|
private KnotMediator.KnotType neededType = KnotMediator.KnotType.None;
|
||||||
|
|
||||||
|
public override void OnCall()
|
||||||
|
{
|
||||||
|
if(KnotMediator.Instance.CheckKnotType(neededType))
|
||||||
|
{
|
||||||
|
Debug.Log("皇帝接受了绳结");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.Log("皇帝拒绝了绳结");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNeededType(KnotMediator.KnotType type)
|
||||||
|
{
|
||||||
|
neededType = type;
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Scripts/勍/HuangDi.cs.meta
Normal file
11
Assets/Scripts/勍/HuangDi.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e1b2323b7275ad44c94037be9f2ccec3
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
38
Assets/Scripts/勍/Interactable.cs
Normal file
38
Assets/Scripts/勍/Interactable.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 可交互物件基类
|
||||||
|
/// </summary>
|
||||||
|
public class Interactable : Event
|
||||||
|
{
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
//检查触发器
|
||||||
|
if (GetComponent<Collider2D>() == null)
|
||||||
|
{
|
||||||
|
Debug.LogError(this.GetType() + ": 没有碰撞盒");
|
||||||
|
}
|
||||||
|
else if(GetComponent<Collider2D>().isTrigger == false)
|
||||||
|
{
|
||||||
|
Debug.LogError(this.GetType() + ": 碰撞盒没有设置为触发器");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnTriggerEnter2D(Collider2D other)
|
||||||
|
{
|
||||||
|
if (other.TryGetComponent<PlayerInteract>(out PlayerInteract playerInteract))
|
||||||
|
{
|
||||||
|
playerInteract.SetCatched(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnTriggerExit2D(Collider2D other)
|
||||||
|
{
|
||||||
|
if (other.TryGetComponent<PlayerInteract>(out PlayerInteract playerInteract))
|
||||||
|
{
|
||||||
|
playerInteract.CancleCatched(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Scripts/勍/Interactable.cs.meta
Normal file
11
Assets/Scripts/勍/Interactable.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1efac6c6faf3ed94db548016ffee8ce5
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
39
Assets/Scripts/勍/KnotMediator.cs
Normal file
39
Assets/Scripts/勍/KnotMediator.cs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using Sirenix.OdinInspector;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 绳结中介者,负责交流皇帝、玩家、绳结的信息
|
||||||
|
/// </summary>
|
||||||
|
public class KnotMediator : UnitySingleton<KnotMediator>
|
||||||
|
{
|
||||||
|
public enum KnotType
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
带毛刺的绳结,
|
||||||
|
编成麻花的绳结,
|
||||||
|
有鸡毛的绳结
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 当前记录的绳结类型
|
||||||
|
/// </summary>
|
||||||
|
[Header("当前记录的绳结类型")][SerializeField][ReadOnly][EnumPaging]
|
||||||
|
private KnotType currentKnotType;
|
||||||
|
|
||||||
|
public void RecordKnotType(KnotType knotType)
|
||||||
|
{
|
||||||
|
currentKnotType = knotType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 有黄帝调用,检查当前记录的和需要的绳结类型是否一致
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="knotType">黄帝需要的绳结类型</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public bool CheckKnotType(KnotType knotType)
|
||||||
|
{
|
||||||
|
return knotType == currentKnotType;
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Scripts/勍/KnotMediator.cs.meta
Normal file
11
Assets/Scripts/勍/KnotMediator.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ad9fbcfc0d0c69744804efe3d7ad3fce
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
28
Assets/Scripts/勍/Kont.cs
Normal file
28
Assets/Scripts/勍/Kont.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using Sirenix.OdinInspector;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 绳结类,继承自可交互物体
|
||||||
|
/// </summary>
|
||||||
|
public class Kont : Interactable
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 自身绳结类型
|
||||||
|
/// </summary>
|
||||||
|
[EnumPaging][Header("自身绳结类型")]
|
||||||
|
public KnotMediator.KnotType type;
|
||||||
|
|
||||||
|
public override void OnCall()
|
||||||
|
{
|
||||||
|
// 如果绳结类型为空,则报错
|
||||||
|
if (type == KnotMediator.KnotType.None)
|
||||||
|
{
|
||||||
|
Debug.LogError("绳结类型为空,请设置绳结类型");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//切换记录的绳结类型
|
||||||
|
KnotMediator.Instance.RecordKnotType(type);
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Scripts/勍/Kont.cs.meta
Normal file
11
Assets/Scripts/勍/Kont.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: aaac64616770dce42a623c267c4d9d31
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -16,6 +16,7 @@ public class PlayerControl : MonoBehaviour
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[SerializeField][ReadOnly][Header("此帧输入方向,-1为左,1为右,0表示此帧不输入")]
|
[SerializeField][ReadOnly][Header("此帧输入方向,-1为左,1为右,0表示此帧不输入")]
|
||||||
protected int inputDir;
|
protected int inputDir;
|
||||||
|
protected PlayerInteract playerInteract;
|
||||||
|
|
||||||
protected virtual void Start()
|
protected virtual void Start()
|
||||||
{
|
{
|
||||||
@ -32,6 +33,19 @@ public class PlayerControl : MonoBehaviour
|
|||||||
playerC.Normal.Jump.performed += ctx => OnJump();
|
playerC.Normal.Jump.performed += ctx => OnJump();
|
||||||
//为交互操作订阅方法
|
//为交互操作订阅方法
|
||||||
playerC.Normal.Interact.performed += ctx => OnInteract();
|
playerC.Normal.Interact.performed += ctx => OnInteract();
|
||||||
|
//为左切换操作订阅方法
|
||||||
|
playerC.Normal.LeftChange.performed += ctx => OnLeftChange();
|
||||||
|
//为右切换操作订阅方法
|
||||||
|
playerC.Normal.RightChange.performed += ctx => OnRightChange();
|
||||||
|
|
||||||
|
|
||||||
|
//给玩家物体添加子物体:互动侦察器
|
||||||
|
GameObject checker = new GameObject("互动侦察器");//新建游戏物体:互动侦察器
|
||||||
|
checker.transform.SetParent(transform);//将其设置为玩家的子物体
|
||||||
|
playerInteract = checker.AddComponent<PlayerInteract>();//增加玩家互动侦察器组件
|
||||||
|
checker.AddComponent<BoxCollider2D>().isTrigger = true;//增加碰撞盒,并将其设置为触发器
|
||||||
|
checker.GetComponent<BoxCollider2D>().size = new Vector2(1f, 1f);//设置碰撞盒大小
|
||||||
|
checker.transform.localPosition = Vector3.zero;//设置碰撞盒位置
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -62,5 +76,17 @@ public class PlayerControl : MonoBehaviour
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 按下交互时触发
|
/// 按下交互时触发
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual void OnInteract(){}
|
protected virtual void OnInteract(){
|
||||||
|
//如果有交互事件,则调用事件
|
||||||
|
playerInteract.OnCall();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 按下十字键左或者Q触发
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void OnLeftChange(){}
|
||||||
|
/// <summary>
|
||||||
|
/// 按下十字键右或者E触发
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void OnRightChange(){}
|
||||||
}
|
}
|
||||||
|
31
Assets/Scripts/勍/PlayerInteract.cs
Normal file
31
Assets/Scripts/勍/PlayerInteract.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using Sirenix.OdinInspector;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 玩家交互组件,挂在玩家下面的子物体中
|
||||||
|
/// </summary>
|
||||||
|
public class PlayerInteract : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField][ReadOnly]
|
||||||
|
private Event catched;
|
||||||
|
public void SetCatched(Event e)
|
||||||
|
{
|
||||||
|
catched = e;
|
||||||
|
}
|
||||||
|
public void CancleCatched(Event e)
|
||||||
|
{
|
||||||
|
if (e == catched)
|
||||||
|
{
|
||||||
|
catched = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void OnCall()
|
||||||
|
{
|
||||||
|
if (catched != null)
|
||||||
|
{
|
||||||
|
catched.OnCall();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Assets/Scripts/勍/PlayerInteract.cs.meta
Normal file
11
Assets/Scripts/勍/PlayerInteract.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 53a9e33ba521aa9469cf8214c44310e5
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -38,3 +38,13 @@ C# parse time : -1ms
|
|||||||
candidates check time : -1ms
|
candidates check time : -1ms
|
||||||
console write time : -1ms
|
console write time : -1ms
|
||||||
|
|
||||||
|
[api-updater (non-obsolete-error-filter)] 2022/3/13 21:33:35 : Starting D:/unity/Editor/2020.3.30f1c1/Editor/Data/Tools/ScriptUpdater/APIUpdater.NonObsoleteApiUpdaterDetector.exe
|
||||||
|
[api-updater (non-obsolete-error-filter)]
|
||||||
|
----------------------------------
|
||||||
|
jit/startup time : 826.23ms
|
||||||
|
moved types parse time: 48ms
|
||||||
|
candidates parse time : 1ms
|
||||||
|
C# parse time : -1ms
|
||||||
|
candidates check time : -1ms
|
||||||
|
console write time : -1ms
|
||||||
|
|
||||||
|
@ -17,9 +17,12 @@ EditorUserSettings:
|
|||||||
RecentlyUsedScenePath-3:
|
RecentlyUsedScenePath-3:
|
||||||
value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d
|
value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d
|
||||||
flags: 0
|
flags: 0
|
||||||
RecentlyUsedScenePath-5:
|
RecentlyUsedScenePath-4:
|
||||||
value: 22424703114646680e0b0227036cdbc9e6582b2b21382a357c67083debf42d
|
value: 22424703114646680e0b0227036cdbc9e6582b2b21382a357c67083debf42d
|
||||||
flags: 0
|
flags: 0
|
||||||
|
RecentlyUsedScenePath-5:
|
||||||
|
value: 22424703114646680e0b0227036cdafbfb583124382d34312e3d2936f1f47a2decee22f0
|
||||||
|
flags: 0
|
||||||
vcSharedLogLevel:
|
vcSharedLogLevel:
|
||||||
value: 0d5e400f0650
|
value: 0d5e400f0650
|
||||||
flags: 0
|
flags: 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user