骑砍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

相关文章

C#中读取XML文件的四种常用方法

《C#中读取XML文件的四种常用方法》Xml是Internet环境中跨平台的,依赖于内容的技术,是当前处理结构化文档信息的有力工具,下面我们就来看看C#中读取XML文件的方法都有哪些吧... 目录XML简介格式C#读取XML文件方法使用XmlDocument使用XmlTextReader/XmlTextWr

Android 悬浮窗开发示例((动态权限请求 | 前台服务和通知 | 悬浮窗创建 )

《Android悬浮窗开发示例((动态权限请求|前台服务和通知|悬浮窗创建)》本文介绍了Android悬浮窗的实现效果,包括动态权限请求、前台服务和通知的使用,悬浮窗权限需要动态申请并引导... 目录一、悬浮窗 动态权限请求1、动态请求权限2、悬浮窗权限说明3、检查动态权限4、申请动态权限5、权限设置完毕后

CSS弹性布局常用设置方式

《CSS弹性布局常用设置方式》文章总结了CSS布局与样式的常用属性和技巧,包括视口单位、弹性盒子布局、浮动元素、背景和边框样式、文本和阴影效果、溢出隐藏、定位以及背景渐变等,通过这些技巧,可以实现复杂... 一、单位元素vm 1vm 为视口的1%vh 视口高的1%vmin 参照长边vmax 参照长边re

SpringBoot整合DeepSeek实现AI对话功能

《SpringBoot整合DeepSeek实现AI对话功能》本文介绍了如何在SpringBoot项目中整合DeepSeekAPI和本地私有化部署DeepSeekR1模型,通过SpringAI框架简化了... 目录Spring AI版本依赖整合DeepSeek API key整合本地化部署的DeepSeek

Python实现多路视频多窗口播放功能

《Python实现多路视频多窗口播放功能》这篇文章主要为大家详细介绍了Python实现多路视频多窗口播放功能的相关知识,文中的示例代码讲解详细,有需要的小伙伴可以跟随小编一起学习一下... 目录一、python实现多路视频播放功能二、代码实现三、打包代码实现总结一、python实现多路视频播放功能服务端开

基于Python开发PPTX压缩工具

《基于Python开发PPTX压缩工具》在日常办公中,PPT文件往往因为图片过大而导致文件体积过大,不便于传输和存储,所以本文将使用Python开发一个PPTX压缩工具,需要的可以了解下... 目录引言全部代码环境准备代码结构代码实现运行结果引言在日常办公中,PPT文件往往因为图片过大而导致文件体积过大,

Python中操作Redis的常用方法小结

《Python中操作Redis的常用方法小结》这篇文章主要为大家详细介绍了Python中操作Redis的常用方法,文中的示例代码简洁易懂,具有一定的借鉴价值,有需要的小伙伴可以了解一下... 目录安装Redis开启、关闭Redisredis数据结构redis-cli操作安装redis-py数据库连接和释放增

css实现图片旋转功能

《css实现图片旋转功能》:本文主要介绍了四种CSS变换效果:图片旋转90度、水平翻转、垂直翻转,并附带了相应的代码示例,详细内容请阅读本文,希望能对你有所帮助... 一 css实现图片旋转90度.icon{ -moz-transform:rotate(-90deg); -webkit-transfo

使用DeepSeek API 结合VSCode提升开发效率

《使用DeepSeekAPI结合VSCode提升开发效率》:本文主要介绍DeepSeekAPI与VisualStudioCode(VSCode)结合使用,以提升软件开发效率,具有一定的参考价值... 目录引言准备工作安装必要的 VSCode 扩展配置 DeepSeek API1. 创建 API 请求文件2.

C语言小项目实战之通讯录功能

《C语言小项目实战之通讯录功能》:本文主要介绍如何设计和实现一个简单的通讯录管理系统,包括联系人信息的存储、增加、删除、查找、修改和排序等功能,文中通过代码介绍的非常详细,需要的朋友可以参考下... 目录功能介绍:添加联系人模块显示联系人模块删除联系人模块查找联系人模块修改联系人模块排序联系人模块源代码如下