UNITY:如何从另一个脚本扩展具有命名空间的类内的函数?
我正在尝试将变量添加到具有命名空间的类的函数中。
我正在使用 Game Creator,我想扩展/覆盖(无论可能)该包的类之一,该类通过自定义脚本包装在其命名空间中,这样我就不必搞乱原来的剧本了。
我当前面临的挑战是扩展位于...内部的 PlayerCharacter 类,
namespace GameCreator.Characters
我确实无法理解如何实现这一点,并且我正在尝试掌握这个概念,因为我在许多地方都看到了这种用法情况下,尝试在我的自定义代码中统一使用组件/包。所以这个问题的答案将彻底改变我的生活:)
PlayerCharacter.cs
namespace GameCreator.Characters
{
using UnityEngine;
using GameCreator.Core;
using GameCreator.Core.Hooks;
[AddComponentMenu("Game Creator/Characters/Player Character", 100)]
public class PlayerCharacter : Character
{
public enum INPUT_TYPE
{
PointAndClick,
Directional,
FollowPointer,
SideScrollX,
SideScrollZ,
TankControl
}
public enum MOUSE_BUTTON
{
LeftClick = 0,
RightClick = 1,
MiddleClick = 2,
None = -1
}
protected const string AXIS_H = "Horizontal";
protected const string AXIS_V = "Vertical";
protected static readonly Vector3 PLANE = new Vector3(1, 0, 1);
protected const string PLAYER_ID = "player";
public static OnLoadSceneData ON_LOAD_SCENE_DATA;
// PROPERTIES: ----------------------------------------------------------------------------
public INPUT_TYPE inputType = INPUT_TYPE.Directional;
public MOUSE_BUTTON mouseButtonMove = MOUSE_BUTTON.LeftClick;
public LayerMask mouseLayerMask = ~0;
public bool invertAxis;
public KeyCode jumpKey = KeyCode.Space;
protected bool uiConstrained;
protected Camera cacheCamera;
public Vector3 direction = Vector3.zero;
public Vector3 directionVelocity = Vector3.zero;
public bool useAcceleration = true;
public float acceleration = 4f;
public float deceleration = 2f;
private bool forceDisplayTouchstick = false;
// INITIALIZERS: --------------------------------------------------------------------------
protected override void Awake()
{
if (!Application.isPlaying) return;
this.CharacterAwake();
this.initSaveData = new SaveData()
{
position = transform.position,
rotation = transform.rotation,
};
if (this.save)
{
SaveLoadManager.Instance.Initialize(
this, (int)SaveLoadManager.Priority.Normal, true
);
}
HookPlayer hookPlayer = gameObject.GetComponent<HookPlayer>();
if (hookPlayer == null) gameObject.AddComponent<HookPlayer>();
if (ON_LOAD_SCENE_DATA != null && ON_LOAD_SCENE_DATA.active)
{
transform.position = ON_LOAD_SCENE_DATA.position;
transform.rotation = ON_LOAD_SCENE_DATA.rotation;
ON_LOAD_SCENE_DATA.Consume();
}
#if UNITY_EDITOR
DatabaseGeneral general = DatabaseGeneral.Load();
if (general.forceDisplayInEditor)
{
this.forceDisplayTouchstick = general.forceDisplayInEditor;
}
#endif
}
// UPDATE: --------------------------------------------------------------------------------
protected virtual void Update()
{
if (!Application.isPlaying) return;
switch (this.inputType)
{
case INPUT_TYPE.Directional: this.UpdateInputDirectional(); break;
case INPUT_TYPE.PointAndClick: this.UpdateInputPointClick(); break;
case INPUT_TYPE.FollowPointer: this.UpdateInputFollowPointer(); break;
case INPUT_TYPE.SideScrollX: this.UpdateInputSideScroll(Vector3.right); break;
case INPUT_TYPE.SideScrollZ: this.UpdateInputSideScroll(Vector3.forward); break;
case INPUT_TYPE.TankControl: this.UpdateInputTank(); break;
}
if (this.IsControllable())
{
if (Input.GetKeyDown(this.jumpKey)) this.Jump();
}
else
{
this.direction = Vector3.zero;
this.directionVelocity = Vector3.zero;
}
this.CharacterUpdate();
}
protected virtual void UpdateInputDirectional()
{
Vector3 targetDirection = Vector3.zero;
if (!this.IsControllable()) return;
if (Application.isMobilePlatform ||
TouchStickManager.FORCE_USAGE ||
this.forceDisplayTouchstick)
{
Vector2 touchDirection = TouchStickManager.Instance.GetDirection(this);
targetDirection = new Vector3(touchDirection.x, 0.0f, touchDirection.y);
}
else
{
targetDirection = new Vector3(
Input.GetAxisRaw(AXIS_H),
0.0f,
Input.GetAxisRaw(AXIS_V)
);
}
this.ComputeMovement(targetDirection);
Camera maincam = this.GetMainCamera();
if (maincam == null) return;
Vector3 moveDirection = (
Quaternion.Euler(0, maincam.transform.rotation.eulerAngles.y, 0) *
this.direction
);
this.characterLocomotion.SetDirectionalDirection(moveDirection);
}
protected virtual void UpdateInputTank()
{
Vector3 movement = Vector3.zero;
float rotationY = 0f;
if (!this.IsControllable()) return;
if (Application.isMobilePlatform ||
TouchStickManager.FORCE_USAGE ||
this.forceDisplayTouchstick)
{
Vector2 touchDirection = TouchStickManager.Instance.GetDirection(this);
movement = new Vector3(0f, 0.0f, touchDirection.y);
rotationY = touchDirection.x;
}
else
{
movement = transform.TransformDirection(new Vector3(
0f,
0f,
Input.GetAxisRaw(AXIS_V)
));
rotationY = Input.GetAxis(AXIS_H);
}
this.ComputeMovement(movement);
this.characterLocomotion.SetTankDirection(this.direction, rotationY);
}
protected virtual void UpdateInputPointClick()
{
if (!this.IsControllable()) return;
this.UpdateUIConstraints();
if (Input.GetMouseButtonDown((int)this.mouseButtonMove) && !this.uiConstrained)
{
Camera maincam = this.GetMainCamera();
if (maincam == null) return;
Ray cameraRay = maincam.ScreenPointToRay(Input.mousePosition);
this.characterLocomotion.SetTarget(cameraRay, this.mouseLayerMask, null, 0f, null);
}
}
protected virtual void UpdateInputFollowPointer()
{
if (!this.IsControllable()) return;
this.UpdateUIConstraints();
if (Input.GetMouseButton((int)this.mouseButtonMove) && !this.uiConstrained)
{
if (HookPlayer.Instance == null) return;
Camera maincam = this.GetMainCamera();
if (maincam == null) return;
Ray cameraRay = maincam.ScreenPointToRay(Input.mousePosition);
Transform player = HookPlayer.Instance.transform;
Plane groundPlane = new Plane(Vector3.up, player.position);
float rayDistance = 0f;
if (groundPlane.Raycast(cameraRay, out rayDistance))
{
Vector3 cursor = cameraRay.GetPoint(rayDistance);
if (Vector3.Distance(player.position, cursor) >= 0.05f)
{
Vector3 target = Vector3.MoveTowards(player.position, cursor, 1f);
this.characterLocomotion.SetTarget(target, null, 0f, null);
}
}
}
}
protected virtual void UpdateInputSideScroll(Vector3 axis)
{
Vector3 targetDirection = Vector3.zero;
if (!this.IsControllable()) return;
if (Application.isMobilePlatform ||
TouchStickManager.FORCE_USAGE ||
this.forceDisplayTouchstick)
{
Vector2 touchDirection = TouchStickManager.Instance.GetDirection(this);
targetDirection = axis * touchDirection.x;
}
else
{
targetDirection = axis * Input.GetAxis(AXIS_H);
}
Camera maincam = this.GetMainCamera();
if (maincam == null) return;
this.ComputeMovement(targetDirection);
float invertValue = (this.invertAxis ? -1 : 1);
Vector3 moveDirection = Vector3.Scale(this.direction, axis * invertValue);
moveDirection.Normalize();
moveDirection *= this.direction.magnitude;
this.characterLocomotion.SetDirectionalDirection(moveDirection);
}
// OTHER METHODS: -------------------------------------------------------------------------
protected Camera GetMainCamera()
{
if (HookCamera.Instance != null) return HookCamera.Instance.Get<Camera>();
if (this.cacheCamera != null) return this.cacheCamera;
this.cacheCamera = Camera.main;
if (this.cacheCamera != null)
{
return this.cacheCamera;
}
this.cacheCamera = GameObject.FindObjectOfType<Camera>();
if (this.cacheCamera != null)
{
return this.cacheCamera;
}
Debug.LogError(ERR_NOCAM, gameObject);
return null;
}
protected void UpdateUIConstraints()
{
EventSystemManager.Instance.Wakeup();
this.uiConstrained = EventSystemManager.Instance.IsPointerOverUI();
#if UNITY_IOS || UNITY_ANDROID
for (int i = 0; i < Input.touches.Length; ++i)
{
if (Input.GetTouch(i).phase != TouchPhase.Began) continue;
int fingerID = Input.GetTouch(i).fingerId;
bool pointerOverUI = EventSystemManager.Instance.IsPointerOverUI(fingerID);
if (pointerOverUI) this.uiConstrained = true;
}
#endif
}
protected void ComputeMovement(Vector3 target)
{
switch (this.useAcceleration)
{
case true:
float acceleration = Mathf.Approximately(target.sqrMagnitude, 0f)
? this.deceleration
: this.acceleration;
this.direction = Vector3.SmoothDamp(
this.direction, target,
ref this.directionVelocity,
1f / acceleration,
acceleration
);
if (Mathf.Abs(target.sqrMagnitude) < 0.05f &&
Mathf.Abs(this.direction.sqrMagnitude) < 0.05f)
{
this.direction = Vector3.zero;
}
break;
case false:
this.direction = target;
break;
}
}
// PUBLIC METHODS: ------------------------------------------------------------------------
public void ForceDirection(Vector3 forceDirection)
{
this.direction = forceDirection;
this.directionVelocity = Vector3.zero;
}
// GAME SAVE: -----------------------------------------------------------------------------
protected override string GetUniqueCharacterID()
{
return PLAYER_ID;
}
}
}
和我的自定义脚本位于游戏创建者文件夹外部的另一个文件夹中。
路径是: Assets\Plugins\GameCreator\Characters\Mono\Characters\PlayerCharacter.cs
Assets\Custom\PlayerInputExt.cs
我想要开始的只是通过复制 INPUT_TYPE Directional 具有不同的名称:
PlayerInputExt.cs
using UnityEngine;
using System.Collections;
public class PlayerInputExt
{
public enum INPUT_TYPE
{
// Want to add this Variable and make it functional based on the original script
NewInputSystem
}
// PROPERTIES: ----------------------------------------------------------------------------
public INPUT_TYPE inputType = INPUT_TYPE.NewInputSystem;
// UPDATE: --------------------------------------------------------------------------------
protected virtual void Update()
{
if (!Application.isPlaying) return;
switch (this.inputType)
{
case INPUT_TYPE.NewInputSystem: this.UpdateInputNewInputSystem(); break;
}
}
// Functions: --------------------------------------------------------------------------------
protected virtual void UpdateInputNewInputSystem()
{
Vector3 targetDirection = Vector3.zero;
if (!this.IsControllable()) return;
if (Application.isMobilePlatform ||
TouchStickManager.FORCE_USAGE ||
this.forceDisplayTouchstick)
{
Vector2 touchDirection = TouchStickManager.Instance.GetDirection(this);
targetDirection = new Vector3(touchDirection.x, 0.0f, touchDirection.y);
}
else
{
targetDirection = new Vector3(
Input.GetAxisRaw(AXIS_H),
0.0f,
Input.GetAxisRaw(AXIS_V)
);
}
this.ComputeMovement(targetDirection);
Camera maincam = this.GetMainCamera();
if (maincam == null) return;
Vector3 moveDirection = (
Quaternion.Euler(0, maincam.transform.rotation.eulerAngles.y, 0) *
this.direction
);
this.characterLocomotion.SetDirectionalDirection(moveDirection);
}
}
我希望有人能够对这种情况以及可能的类似情况做出清晰且良好的解释,并提供更多实现方法但从一个直接的例子开始,我相信我最终会开始理解它是如何工作的。
先感谢您!
I am trying to add a variable to a function of a class with a namespace.
I am using Game Creator and I would like to extend/override (whatever is possible) one of the class of this package which is wrapped within their namespace from a custom script, so that I do not have to mess up with the original script.
The current challenge I have is to extend the PlayerCharacter class which is inside the...
namespace GameCreator.Characters
I do fail to understand how that can be achieved and I am trying to grasp the concept because I see this use in many situations, trying to use a component/package in unity along my custom code. So the answer to this question will change my life completely :)
PlayerCharacter.cs
namespace GameCreator.Characters
{
using UnityEngine;
using GameCreator.Core;
using GameCreator.Core.Hooks;
[AddComponentMenu("Game Creator/Characters/Player Character", 100)]
public class PlayerCharacter : Character
{
public enum INPUT_TYPE
{
PointAndClick,
Directional,
FollowPointer,
SideScrollX,
SideScrollZ,
TankControl
}
public enum MOUSE_BUTTON
{
LeftClick = 0,
RightClick = 1,
MiddleClick = 2,
None = -1
}
protected const string AXIS_H = "Horizontal";
protected const string AXIS_V = "Vertical";
protected static readonly Vector3 PLANE = new Vector3(1, 0, 1);
protected const string PLAYER_ID = "player";
public static OnLoadSceneData ON_LOAD_SCENE_DATA;
// PROPERTIES: ----------------------------------------------------------------------------
public INPUT_TYPE inputType = INPUT_TYPE.Directional;
public MOUSE_BUTTON mouseButtonMove = MOUSE_BUTTON.LeftClick;
public LayerMask mouseLayerMask = ~0;
public bool invertAxis;
public KeyCode jumpKey = KeyCode.Space;
protected bool uiConstrained;
protected Camera cacheCamera;
public Vector3 direction = Vector3.zero;
public Vector3 directionVelocity = Vector3.zero;
public bool useAcceleration = true;
public float acceleration = 4f;
public float deceleration = 2f;
private bool forceDisplayTouchstick = false;
// INITIALIZERS: --------------------------------------------------------------------------
protected override void Awake()
{
if (!Application.isPlaying) return;
this.CharacterAwake();
this.initSaveData = new SaveData()
{
position = transform.position,
rotation = transform.rotation,
};
if (this.save)
{
SaveLoadManager.Instance.Initialize(
this, (int)SaveLoadManager.Priority.Normal, true
);
}
HookPlayer hookPlayer = gameObject.GetComponent<HookPlayer>();
if (hookPlayer == null) gameObject.AddComponent<HookPlayer>();
if (ON_LOAD_SCENE_DATA != null && ON_LOAD_SCENE_DATA.active)
{
transform.position = ON_LOAD_SCENE_DATA.position;
transform.rotation = ON_LOAD_SCENE_DATA.rotation;
ON_LOAD_SCENE_DATA.Consume();
}
#if UNITY_EDITOR
DatabaseGeneral general = DatabaseGeneral.Load();
if (general.forceDisplayInEditor)
{
this.forceDisplayTouchstick = general.forceDisplayInEditor;
}
#endif
}
// UPDATE: --------------------------------------------------------------------------------
protected virtual void Update()
{
if (!Application.isPlaying) return;
switch (this.inputType)
{
case INPUT_TYPE.Directional: this.UpdateInputDirectional(); break;
case INPUT_TYPE.PointAndClick: this.UpdateInputPointClick(); break;
case INPUT_TYPE.FollowPointer: this.UpdateInputFollowPointer(); break;
case INPUT_TYPE.SideScrollX: this.UpdateInputSideScroll(Vector3.right); break;
case INPUT_TYPE.SideScrollZ: this.UpdateInputSideScroll(Vector3.forward); break;
case INPUT_TYPE.TankControl: this.UpdateInputTank(); break;
}
if (this.IsControllable())
{
if (Input.GetKeyDown(this.jumpKey)) this.Jump();
}
else
{
this.direction = Vector3.zero;
this.directionVelocity = Vector3.zero;
}
this.CharacterUpdate();
}
protected virtual void UpdateInputDirectional()
{
Vector3 targetDirection = Vector3.zero;
if (!this.IsControllable()) return;
if (Application.isMobilePlatform ||
TouchStickManager.FORCE_USAGE ||
this.forceDisplayTouchstick)
{
Vector2 touchDirection = TouchStickManager.Instance.GetDirection(this);
targetDirection = new Vector3(touchDirection.x, 0.0f, touchDirection.y);
}
else
{
targetDirection = new Vector3(
Input.GetAxisRaw(AXIS_H),
0.0f,
Input.GetAxisRaw(AXIS_V)
);
}
this.ComputeMovement(targetDirection);
Camera maincam = this.GetMainCamera();
if (maincam == null) return;
Vector3 moveDirection = (
Quaternion.Euler(0, maincam.transform.rotation.eulerAngles.y, 0) *
this.direction
);
this.characterLocomotion.SetDirectionalDirection(moveDirection);
}
protected virtual void UpdateInputTank()
{
Vector3 movement = Vector3.zero;
float rotationY = 0f;
if (!this.IsControllable()) return;
if (Application.isMobilePlatform ||
TouchStickManager.FORCE_USAGE ||
this.forceDisplayTouchstick)
{
Vector2 touchDirection = TouchStickManager.Instance.GetDirection(this);
movement = new Vector3(0f, 0.0f, touchDirection.y);
rotationY = touchDirection.x;
}
else
{
movement = transform.TransformDirection(new Vector3(
0f,
0f,
Input.GetAxisRaw(AXIS_V)
));
rotationY = Input.GetAxis(AXIS_H);
}
this.ComputeMovement(movement);
this.characterLocomotion.SetTankDirection(this.direction, rotationY);
}
protected virtual void UpdateInputPointClick()
{
if (!this.IsControllable()) return;
this.UpdateUIConstraints();
if (Input.GetMouseButtonDown((int)this.mouseButtonMove) && !this.uiConstrained)
{
Camera maincam = this.GetMainCamera();
if (maincam == null) return;
Ray cameraRay = maincam.ScreenPointToRay(Input.mousePosition);
this.characterLocomotion.SetTarget(cameraRay, this.mouseLayerMask, null, 0f, null);
}
}
protected virtual void UpdateInputFollowPointer()
{
if (!this.IsControllable()) return;
this.UpdateUIConstraints();
if (Input.GetMouseButton((int)this.mouseButtonMove) && !this.uiConstrained)
{
if (HookPlayer.Instance == null) return;
Camera maincam = this.GetMainCamera();
if (maincam == null) return;
Ray cameraRay = maincam.ScreenPointToRay(Input.mousePosition);
Transform player = HookPlayer.Instance.transform;
Plane groundPlane = new Plane(Vector3.up, player.position);
float rayDistance = 0f;
if (groundPlane.Raycast(cameraRay, out rayDistance))
{
Vector3 cursor = cameraRay.GetPoint(rayDistance);
if (Vector3.Distance(player.position, cursor) >= 0.05f)
{
Vector3 target = Vector3.MoveTowards(player.position, cursor, 1f);
this.characterLocomotion.SetTarget(target, null, 0f, null);
}
}
}
}
protected virtual void UpdateInputSideScroll(Vector3 axis)
{
Vector3 targetDirection = Vector3.zero;
if (!this.IsControllable()) return;
if (Application.isMobilePlatform ||
TouchStickManager.FORCE_USAGE ||
this.forceDisplayTouchstick)
{
Vector2 touchDirection = TouchStickManager.Instance.GetDirection(this);
targetDirection = axis * touchDirection.x;
}
else
{
targetDirection = axis * Input.GetAxis(AXIS_H);
}
Camera maincam = this.GetMainCamera();
if (maincam == null) return;
this.ComputeMovement(targetDirection);
float invertValue = (this.invertAxis ? -1 : 1);
Vector3 moveDirection = Vector3.Scale(this.direction, axis * invertValue);
moveDirection.Normalize();
moveDirection *= this.direction.magnitude;
this.characterLocomotion.SetDirectionalDirection(moveDirection);
}
// OTHER METHODS: -------------------------------------------------------------------------
protected Camera GetMainCamera()
{
if (HookCamera.Instance != null) return HookCamera.Instance.Get<Camera>();
if (this.cacheCamera != null) return this.cacheCamera;
this.cacheCamera = Camera.main;
if (this.cacheCamera != null)
{
return this.cacheCamera;
}
this.cacheCamera = GameObject.FindObjectOfType<Camera>();
if (this.cacheCamera != null)
{
return this.cacheCamera;
}
Debug.LogError(ERR_NOCAM, gameObject);
return null;
}
protected void UpdateUIConstraints()
{
EventSystemManager.Instance.Wakeup();
this.uiConstrained = EventSystemManager.Instance.IsPointerOverUI();
#if UNITY_IOS || UNITY_ANDROID
for (int i = 0; i < Input.touches.Length; ++i)
{
if (Input.GetTouch(i).phase != TouchPhase.Began) continue;
int fingerID = Input.GetTouch(i).fingerId;
bool pointerOverUI = EventSystemManager.Instance.IsPointerOverUI(fingerID);
if (pointerOverUI) this.uiConstrained = true;
}
#endif
}
protected void ComputeMovement(Vector3 target)
{
switch (this.useAcceleration)
{
case true:
float acceleration = Mathf.Approximately(target.sqrMagnitude, 0f)
? this.deceleration
: this.acceleration;
this.direction = Vector3.SmoothDamp(
this.direction, target,
ref this.directionVelocity,
1f / acceleration,
acceleration
);
if (Mathf.Abs(target.sqrMagnitude) < 0.05f &&
Mathf.Abs(this.direction.sqrMagnitude) < 0.05f)
{
this.direction = Vector3.zero;
}
break;
case false:
this.direction = target;
break;
}
}
// PUBLIC METHODS: ------------------------------------------------------------------------
public void ForceDirection(Vector3 forceDirection)
{
this.direction = forceDirection;
this.directionVelocity = Vector3.zero;
}
// GAME SAVE: -----------------------------------------------------------------------------
protected override string GetUniqueCharacterID()
{
return PLAYER_ID;
}
}
}
And My custom Script Located in another folder outside the game creator folder.
The Paths are:
Assets\Plugins\GameCreator\Characters\Mono\Characters\PlayerCharacter.cs
Assets\Custom\PlayerInputExt.cs
What I want to start with is just to get started by replicate the INPUT_TYPE Directional with a different name:
PlayerInputExt.cs
using UnityEngine;
using System.Collections;
public class PlayerInputExt
{
public enum INPUT_TYPE
{
// Want to add this Variable and make it functional based on the original script
NewInputSystem
}
// PROPERTIES: ----------------------------------------------------------------------------
public INPUT_TYPE inputType = INPUT_TYPE.NewInputSystem;
// UPDATE: --------------------------------------------------------------------------------
protected virtual void Update()
{
if (!Application.isPlaying) return;
switch (this.inputType)
{
case INPUT_TYPE.NewInputSystem: this.UpdateInputNewInputSystem(); break;
}
}
// Functions: --------------------------------------------------------------------------------
protected virtual void UpdateInputNewInputSystem()
{
Vector3 targetDirection = Vector3.zero;
if (!this.IsControllable()) return;
if (Application.isMobilePlatform ||
TouchStickManager.FORCE_USAGE ||
this.forceDisplayTouchstick)
{
Vector2 touchDirection = TouchStickManager.Instance.GetDirection(this);
targetDirection = new Vector3(touchDirection.x, 0.0f, touchDirection.y);
}
else
{
targetDirection = new Vector3(
Input.GetAxisRaw(AXIS_H),
0.0f,
Input.GetAxisRaw(AXIS_V)
);
}
this.ComputeMovement(targetDirection);
Camera maincam = this.GetMainCamera();
if (maincam == null) return;
Vector3 moveDirection = (
Quaternion.Euler(0, maincam.transform.rotation.eulerAngles.y, 0) *
this.direction
);
this.characterLocomotion.SetDirectionalDirection(moveDirection);
}
}
I hope someone can make a clear and good explanation regarding this situation and possibly similar situations with more ways to achieve the results but to start with a direct example I am confident I would finally start to understand how it works.
Thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想要扩展的类不是密封的,这意味着您可以直接继承它。您可以将自己的脚本添加到现有的命名空间中,只要您不使用冲突的名称,就不会禁止这样做,但也许只需在顶部添加“using GameCreator.Characters”就可以了?
至于扩展枚举,这是不可能的,但您可以使用 bool 值(例如 useNewInput )绕过它,但在您的情况下,这似乎甚至没有必要,除非您想保留现有功能以防万一
The class you want to extend is not sealed, which means you can just inherit from it. You can your own script to a an existing namespace, this is not forbidden as long as you are not using colliding names, but maybe just adding "using GameCreator.Characters" at the top would do the trick?
As for extending the enum, this is not possible, but you could bypass it using a bool value (for example useNewInput), but in your case it seems this wouldn't even be necessary, unless you want to keep existing functinality just in case