本文主要是介绍骑砍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)-常用功能组件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!