骑砍2霸主MOD开发(13)-常用功能组件

2024-06-08 12:12

本文主要是介绍骑砍2霸主MOD开发(13)-常用功能组件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一.MOD配置文件路径

    public class PLModuleConstans{public static string ModulePath = Utilities.GetFullModulePath("NativeAssetsTest");public static string ModuleTrackConfigPath = ModulePath + "ModuleTracks/soundtrack.xml";public static string ModuleCrashLogPath = ModulePath + "crash_log.txt";}

二.Agent

    public class PLAgentUtilities{public enum Axix{X,Y,Z}public static void AgentMoveAlongAxix(Agent agent, float distance, Axix rotateAxix){MatrixFrame frame = agent.Frame;Vec3 axixVec = Vec3.Zero;if (rotateAxix == Axix.Z){axixVec = frame.rotation.u;}else if (rotateAxix == Axix.X){axixVec = frame.rotation.s;}else if (rotateAxix == Axix.Y){axixVec = frame.rotation.f * (-1);}AgentMoveAlongVector(agent, distance, axixVec);}public static void AgentMoveAlongVector(Agent agent, float distance, Vec3 axixVec){if (agent == null){return;}MatrixFrame frame = agent.Frame;Vec3 position = frame.origin;axixVec.Normalize();position += axixVec * distance;agent.TeleportToPosition(position);}public static void GiveDamageToAgent(Agent attackerAgent, Agent attackedAgent, int damage){Blow blow = new Blow(attackerAgent.Index);blow.DamageType = DamageTypes.Blunt;blow.BoneIndex = attackerAgent.Monster.HeadLookDirectionBoneIndex;blow.GlobalPosition = attackerAgent.Position;blow.GlobalPosition.z = blow.GlobalPosition.z + attackerAgent.GetEyeGlobalHeight();blow.BaseMagnitude = 2000f;blow.WeaponRecord.FillAsMeleeBlow(null, null, -1, -1);blow.InflictedDamage = damage;blow.SwingDirection = attackerAgent.LookDirection;blow.Direction = blow.SwingDirection;blow.DamageCalculated = true;sbyte mainHandItemBoneIndex = attackerAgent.Monster.MainHandItemBoneIndex;AttackCollisionData attackCollisionDataForDebugPurpose = AttackCollisionData.GetAttackCollisionDataForDebugPurpose(false, false, false, true, false, false, false, false, false, false, false, false,CombatCollisionResult.StrikeAgent, -1, 0, 2, blow.BoneIndex, BoneBodyPartType.Head, mainHandItemBoneIndex,Agent.UsageDirection.AttackLeft, -1, CombatHitResultFlags.NormalHit, 0.5f, 1f, 0f, 0f, 0f, 0f, 0f, 0f, Vec3.Up,blow.Direction, blow.GlobalPosition, Vec3.Zero, Vec3.Zero, attackerAgent.Velocity, Vec3.Up);attackedAgent.RegisterBlow(blow, attackCollisionDataForDebugPurpose);}}

三.GameEntity

    public class PLGameEntityUtilities{public enum Axix{X,Y,Z}public static void GameEntityMoveAlongAxix(GameEntity gameEntity, float distance, Axix rotateAxix){MatrixFrame frame = gameEntity.GetFrame();Vec3 axixVec = Vec3.Zero;if (rotateAxix == Axix.Z){axixVec = frame.rotation.u;}else if (rotateAxix == Axix.X){axixVec = frame.rotation.s;}else if (rotateAxix == Axix.Y){axixVec = frame.rotation.f;}GameEntityMoveAlongAxix(gameEntity, distance, axixVec);}public static void GameEntityMoveAlongAxix(GameEntity gameEntity, float distance, Vec3 axixVec){if (gameEntity == null){return;}MatrixFrame frame = gameEntity.GetFrame();Vec3 position = frame.origin;axixVec.Normalize();position += axixVec * distance;frame.origin = position;gameEntity.SetFrame(ref frame);}public static void SetGameEntityRotation(GameEntity gameEntity, Mat3 rotation){if (gameEntity == null){return;}MatrixFrame frame = gameEntity.GetFrame();frame.rotation = rotation;gameEntity.SetFrame(ref frame);}public static void SetGameEntityPosition(GameEntity gameEntity, Vec3 origin){if (gameEntity == null){return;}MatrixFrame frame = gameEntity.GetFrame();frame.origin = origin;gameEntity.SetFrame(ref frame);}public static void SetGameEntityScale(GameEntity gameEntity, Vec3 scale){if (gameEntity == null){return;}MatrixFrame frame = gameEntity.GetFrame();frame.Scale(scale);gameEntity.SetFrame(ref frame);}}

四.Camera

    public class PLCameraUtilities{public enum Axix{X,Y,Z}public static void CameraRotateAroundAxix(MissionScreen missionScreen, float angle, Axix rotateAxix){if (missionScreen == null){return;}MatrixFrame frame = missionScreen.CombatCamera.Frame;Mat3 rotation = frame.rotation;if (rotateAxix == Axix.Z){rotation.RotateAboutForward(angle * MathF.DegToRad);}else if (rotateAxix == Axix.X){rotation.RotateAboutSide(angle * MathF.DegToRad);}else if (rotateAxix == Axix.Y){rotation.RotateAboutUp(angle * MathF.DegToRad);}frame.rotation = rotation;missionScreen.CombatCamera.Frame = frame;missionScreen.SceneView.SetCamera(missionScreen.CombatCamera);}public static void CameraMoveAlongAxix(MissionScreen missionScreen, float distance, Axix rotateAxix){MatrixFrame frame = missionScreen.CombatCamera.Frame;Vec3 axixVec = Vec3.Zero;if (rotateAxix == Axix.Z){axixVec = frame.rotation.f;}else if (rotateAxix == Axix.X){axixVec = frame.rotation.s;}else if (rotateAxix == Axix.Y){axixVec = frame.rotation.u * (-1);}CameraMoveAlongVector(missionScreen, distance, axixVec);}public static void CameraMoveAlongVector(MissionScreen missionScreen, float distance, Vec3 axixVec){if (missionScreen == null){return;}MatrixFrame frame = missionScreen.CombatCamera.Frame;Vec3 position = frame.origin;axixVec.Normalize();position += axixVec * distance;frame.origin = position;missionScreen.CombatCamera.Frame = frame;missionScreen.SceneView.SetCamera(missionScreen.CombatCamera);}}

五.MissionTimer

public abstract class PLCommonBasicMissionTimer : BasicMissionTimer
{private float _triggerInterval = 0.0f;private bool _isTriggerOnce = false;private bool _isTriggered = false;public PLCommonBasicMissionTimer(float triggerInterval, bool isTriggerOnce){_triggerInterval = triggerInterval;_isTriggerOnce = isTriggerOnce;}public void TriggerTimer(){if (_isTriggered && _isTriggerOnce){return;}if (ElapsedTime > _triggerInterval){TriggerTimerScript();Reset();_isTriggered = true;}}public abstract void TriggerTimerScript();
}public class CheckFpsTimer : PLCommonBasicMissionTimer
{public CheckFpsTimer(float triggerInterval, bool isTriggerOnce) : base(triggerInterval, isTriggerOnce){}public override void TriggerTimerScript(){try{ShowFpsInformation();}catch (Exception ex){File.AppendAllLines(PLModuleConstans.ModuleCrashLogPath, new string[] { ex.ToString(), ex.Message, ex.StackTrace });}}private void ShowFpsInformation(){float fps = Utilities.GetFps();float mainFps = Utilities.GetMainFps();InformationManager.DisplayMessage(new InformationMessage(string.Format("fps:{0}, mainFps{1}", fps, mainFps)));}
}#创建MissionBehavior
[DefaultView]
public class MissionAgentBehavior : MissionView
{private List<PLCommonBasicMissionTimer> timers = new List<PLCommonBasicMissionTimer>();public override void OnCreated(){base.OnCreated();CheckFpsTimer checkFpsTimer = new CheckFpsTimer(3f, false);timers.Add(checkFpsTimer);}public override void OnMissionTick(float dt){base.OnMissionTick(dt);timers.ForEach(timer =>{timer.TriggerTimer();});}
}

这篇关于骑砍2霸主MOD开发(13)-常用功能组件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1042155

相关文章

Java 字符数组转字符串的常用方法

《Java字符数组转字符串的常用方法》文章总结了在Java中将字符数组转换为字符串的几种常用方法,包括使用String构造函数、String.valueOf()方法、StringBuilder以及A... 目录1. 使用String构造函数1.1 基本转换方法1.2 注意事项2. 使用String.valu

基于Python开发电脑定时关机工具

《基于Python开发电脑定时关机工具》这篇文章主要为大家详细介绍了如何基于Python开发一个电脑定时关机工具,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1. 简介2. 运行效果3. 相关源码1. 简介这个程序就像一个“忠实的管家”,帮你按时关掉电脑,而且全程不需要你多做

Go语言实现将中文转化为拼音功能

《Go语言实现将中文转化为拼音功能》这篇文章主要为大家详细介绍了Go语言中如何实现将中文转化为拼音功能,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 有这么一个需求:新用户入职 创建一系列账号比较麻烦,打算通过接口传入姓名进行初始化。想把姓名转化成拼音。因为有些账号即需要中文也需要英

基于WinForm+Halcon实现图像缩放与交互功能

《基于WinForm+Halcon实现图像缩放与交互功能》本文主要讲述在WinForm中结合Halcon实现图像缩放、平移及实时显示灰度值等交互功能,包括初始化窗口的不同方式,以及通过特定事件添加相应... 目录前言初始化窗口添加图像缩放功能添加图像平移功能添加实时显示灰度值功能示例代码总结最后前言本文将

Java中的Opencv简介与开发环境部署方法

《Java中的Opencv简介与开发环境部署方法》OpenCV是一个开源的计算机视觉和图像处理库,提供了丰富的图像处理算法和工具,它支持多种图像处理和计算机视觉算法,可以用于物体识别与跟踪、图像分割与... 目录1.Opencv简介Opencv的应用2.Java使用OpenCV进行图像操作opencv安装j

vue解决子组件样式覆盖问题scoped deep

《vue解决子组件样式覆盖问题scopeddeep》文章主要介绍了在Vue项目中处理全局样式和局部样式的方法,包括使用scoped属性和深度选择器(/deep/)来覆盖子组件的样式,作者建议所有组件... 目录前言scoped分析deep分析使用总结所有组件必须加scoped父组件覆盖子组件使用deep前言

VUE动态绑定class类的三种常用方式及适用场景详解

《VUE动态绑定class类的三种常用方式及适用场景详解》文章介绍了在实际开发中动态绑定class的三种常见情况及其解决方案,包括根据不同的返回值渲染不同的class样式、给模块添加基础样式以及根据设... 目录前言1.动态选择class样式(对象添加:情景一)2.动态添加一个class样式(字符串添加:情

基于Qt Qml实现时间轴组件

《基于QtQml实现时间轴组件》时间轴组件是现代用户界面中常见的元素,用于按时间顺序展示事件,本文主要为大家详细介绍了如何使用Qml实现一个简单的时间轴组件,需要的可以参考下... 目录写在前面效果图组件概述实现细节1. 组件结构2. 属性定义3. 数据模型4. 事件项的添加和排序5. 事件项的渲染如何使用

使用Python实现批量访问URL并解析XML响应功能

《使用Python实现批量访问URL并解析XML响应功能》在现代Web开发和数据抓取中,批量访问URL并解析响应内容是一个常见的需求,本文将详细介绍如何使用Python实现批量访问URL并解析XML响... 目录引言1. 背景与需求2. 工具方法实现2.1 单URL访问与解析代码实现代码说明2.2 示例调用

基于Qt开发一个简单的OFD阅读器

《基于Qt开发一个简单的OFD阅读器》这篇文章主要为大家详细介绍了如何使用Qt框架开发一个功能强大且性能优异的OFD阅读器,文中的示例代码讲解详细,有需要的小伙伴可以参考一下... 目录摘要引言一、OFD文件格式解析二、文档结构解析三、页面渲染四、用户交互五、性能优化六、示例代码七、未来发展方向八、结论摘要