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

相关文章

Spring Boot中WebSocket常用使用方法详解

《SpringBoot中WebSocket常用使用方法详解》本文从WebSocket的基础概念出发,详细介绍了SpringBoot集成WebSocket的步骤,并重点讲解了常用的使用方法,包括简单消... 目录一、WebSocket基础概念1.1 什么是WebSocket1.2 WebSocket与HTTP

golang中reflect包的常用方法

《golang中reflect包的常用方法》Go反射reflect包提供类型和值方法,用于获取类型信息、访问字段、调用方法等,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值... 目录reflect包方法总结类型 (Type) 方法值 (Value) 方法reflect包方法总结

C# 比较两个list 之间元素差异的常用方法

《C#比较两个list之间元素差异的常用方法》:本文主要介绍C#比较两个list之间元素差异,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录1. 使用Except方法2. 使用Except的逆操作3. 使用LINQ的Join,GroupJoin

mysql表操作与查询功能详解

《mysql表操作与查询功能详解》本文系统讲解MySQL表操作与查询,涵盖创建、修改、复制表语法,基本查询结构及WHERE、GROUPBY等子句,本文结合实例代码给大家介绍的非常详细,感兴趣的朋友跟随... 目录01.表的操作1.1表操作概览1.2创建表1.3修改表1.4复制表02.基本查询操作2.1 SE

python常用的正则表达式及作用

《python常用的正则表达式及作用》正则表达式是处理字符串的强大工具,Python通过re模块提供正则表达式支持,本文给大家介绍python常用的正则表达式及作用详解,感兴趣的朋友跟随小编一起看看吧... 目录python常用正则表达式及作用基本匹配模式常用正则表达式示例常用量词边界匹配分组和捕获常用re

Golang如何用gorm实现分页的功能

《Golang如何用gorm实现分页的功能》:本文主要介绍Golang如何用gorm实现分页的功能方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录背景go库下载初始化数据【1】建表【2】插入数据【3】查看数据4、代码示例【1】gorm结构体定义【2】分页结构体

SpringBoot开发中十大常见陷阱深度解析与避坑指南

《SpringBoot开发中十大常见陷阱深度解析与避坑指南》在SpringBoot的开发过程中,即使是经验丰富的开发者也难免会遇到各种棘手的问题,本文将针对SpringBoot开发中十大常见的“坑... 目录引言一、配置总出错?是不是同时用了.properties和.yml?二、换个位置配置就失效?搞清楚加

Java Web实现类似Excel表格锁定功能实战教程

《JavaWeb实现类似Excel表格锁定功能实战教程》本文将详细介绍通过创建特定div元素并利用CSS布局和JavaScript事件监听来实现类似Excel的锁定行和列效果的方法,感兴趣的朋友跟随... 目录1. 模拟Excel表格锁定功能2. 创建3个div元素实现表格锁定2.1 div元素布局设计2.

Python中对FFmpeg封装开发库FFmpy详解

《Python中对FFmpeg封装开发库FFmpy详解》:本文主要介绍Python中对FFmpeg封装开发库FFmpy,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录一、FFmpy简介与安装1.1 FFmpy概述1.2 安装方法二、FFmpy核心类与方法2.1 FF

HTML5实现的移动端购物车自动结算功能示例代码

《HTML5实现的移动端购物车自动结算功能示例代码》本文介绍HTML5实现移动端购物车自动结算,通过WebStorage、事件监听、DOM操作等技术,确保实时更新与数据同步,优化性能及无障碍性,提升用... 目录1. 移动端购物车自动结算概述2. 数据存储与状态保存机制2.1 浏览器端的数据存储方式2.1.