public Vector3_ Evaluate(double time) { timer += time; var throwTime = CalcSlanteThrowTime(); Vector3_ endPos = (Vector3_)end.LogicPosition + data.offset; //计算水平方向运动 Vector3_ dir = endPos - (Vector3_)start.LogicPosition; dir.Normalize(); var tp = dir * time * (data.velocity + data.acceleration * timer); if (throwTime < timer) { //向下掉落 tp += (endPos - (Vector3_)start.LogicPosition).normalized * data.velocity * time; //tp += Vector3_.down * data.velocity * data.strength * time; tp += (Vector3_)start.LogicPosition; tp.y = Mathd.Max(tp.y, endPos.y); return(tp); } //向上抛 tp += Vector3_.up * data.velocity * data.strength * time; return(tp + (Vector3_)start.LogicPosition); }
public void SetRange(Vector4 range) { size = new Vector2_(range.z, range.w); position = new Vector3_(range.x, range.y); offset = new Vector2_(0, range.w * 0.5f); PlayParticle(); }
private void CreatEnemyCreature(PMatchInfo info) { //创建敌人 ShowCreatureInfo showInfo = ConfigManager.Get <ShowCreatureInfo>(10); Vector3_ pos = new Vector3_(1.3, 0, 0); Vector3 rot = new Vector3(0, -110, 0); if (showInfo != null) { for (int i = 0; i < showInfo.forData.Length; i++) { if (showInfo.forData[i].index == info.roleProto) { pos = showInfo.forData[i].data[0].pos; rot = showInfo.forData[i].data[0].rotation; break; } } } var weaponInfo = ConfigManager.Get <PropItemInfo>(info.fashion.weapon); if (weaponInfo == null) { return; } moduleGlobal.LockUI("", 0.5f); Level.PrepareAssets(Module_Battle.BuildPlayerSimplePreloadAssets(info), (r) => { if (!r) { return; } enemy = moduleHome.CreatePlayer(info, pos, CreatureDirection.BACK); enemy.transform.localEulerAngles = rot; moduleGlobal.UnLockUI(); }); if (info.pet != null && info.pet.itemTypeId != 0) { var rPet = PetInfo.Create(info.pet); var assets = new List <string>(); Level.PrepareAssets(Module_Battle.BuildPetSimplePreloadAssets(rPet, assets, 2), b => { var rGradeInfo = rPet.UpGradeInfo; var show = ConfigManager.Get <ShowCreatureInfo>(rPet.ID); if (show == null) { Logger.LogError("没有配置config_showCreatureInfo表。宠物ID = {0}, 没有出生位置信息。宠物模型创建失败", rPet.ID); return; } var showData = show.GetDataByIndex(0); var data = showData.data.GetValue <ShowCreatureInfo.SizeAndPos>(0); enemyPet = moduleHome.CreatePet(rGradeInfo, pos + data.pos, data.rotation, Level.current.startPos, true, Module_Home.FIGHTING_PET_OBJECT_NAME + "_Enemy"); enemyPet.transform.localScale *= data.size; enemyPet.transform.localEulerAngles = data.rotation; }); } }
private void ResetMotion() { m_motion = ConfigManager.Get <AnimMotionInfo>((int)(info.animMotion.x)); motionOffset = Vector3_.zero; if (m_motion) { var count = m_motion.points.Length; if (count < 2) { count = 0; } m_motionFrame.x = Mathd.Clamp(info.animMotion.y, 1, count - 1); m_motionFrame.y = info.animMotion.z < 1 ? count - 1 : Mathd.Clamp(info.animMotion.z, info.animMotion.x, count - 1); m_motionFrame.z = (m_motionFrame.y - m_motionFrame.x + 1); m_motionFrame.w = m_motionFrame.z * 0.01; // cm -> m if (m_motion.offset != Vector3_.zero) { motionOffset += m_motion.offset * 0.01; } motionOffset.Set(motionOffset.z, motionOffset.y, motionOffset.x); } else { m_motionFrame = Vector4_.zero; } }
/// <summary> /// Moves a point current in a straight line towards a target point. /// </summary> public static Vector3_ MoveTowards(Vector3_ current, Vector3_ target, double maxDistanceDelta) { var a = target - current; var magnitude = a.magnitude; return((magnitude <= maxDistanceDelta || magnitude == 0) ? target : current + a / magnitude * maxDistanceDelta); }
private void OnSetPosition(Event_ e) { if (master) { Vector3_ offset = Vector3_.zero; if (fightingPet) { offset = fightingPet.position - master.position; } var t = (ShowCreatureInfo.SizeAndPos)e.param1; master.position_ = t.pos; master.position = t.pos; master.eulerAngles = t.rotation; master.transform.localScale = Vector3.one * t.size; if (fightingPet) { fightingPet.position_ = master.position_ + offset; } } else { recordMasterPos = ((ShowCreatureInfo.SizeAndPos)e.param1).pos; } rankCamera.cullingMask |= (Layers.MASK_MODEL | Layers.MASK_WEAPON | Layers.MASK_JEWELRY); pvpCamera.cullingMask |= (Layers.MASK_MODEL | Layers.MASK_WEAPON | Layers.MASK_JEWELRY); }
private void CreatePlayer() { if (master) { master.Destroy(); master = null; } var oc = ConfigManager.Get <ShowCreatureInfo>(20000)?.GetDataByIndex(modulePlayer.proto) ?? null; if (oc != null && oc.data != null && oc.data.Length > 0) { startCameraOffset = oc.data[0].pos; ResetMainCamera(); } PrepareAssets(Module_Battle.BuildPlayerSimplePreloadAssets(), r => { if (!r) { return; } master = moduleHome.CreatePlayer(); originMasterPos = master.position_; if (modulePVP.opType != OpenWhichPvP.None) { moduleMatch.DispatchModuleEvent(Module_Match.EventComeBackHomeScence); } }); CreateFightingPet(modulePet.FightingPet); }
public Vector3 SimulateMotion(float time, CreatureDirection dir, Vector3_ origin) { if (!m_motion || m_motionFrame.x < 1) { return(stateMachine.creature.position_); } if (time < 0) { time = 0; } var itime = (int)(time * 1000); var frame = itime / 33; var prog = (itime % 33) / 33.0; var idx = (int)m_motionFrame.x + frame; idx = Mathd.Clamp(idx, (int)m_motionFrame.x, (int)m_motionFrame.y); var next = m_motion.points[idx]; var prev = m_motion.points[idx - 1]; var tar = (Vector3_.Lerp(prev, next, prog) - m_motion.points[0]) * 0.01; tar = new Vector3_(dir == CreatureDirection.BACK ? -tar.z : tar.z, tar.y, -tar.x) + origin; if (tar.y < 0) { tar.y = 0; } return(tar); }
public Vector3_ Check2D(Vector3_ tp, Creature target) { var n = new Vector2_(creature.x, creature.cy); var t = new Vector2_(target.x, target.cy); var c = creature.colliderSize + target.colliderSize; if (t.y > n.y + creature.colliderHeight || Mathd.Abs(n.x - t.x) < c * 0.025) { return(tp); } var nx = n.x; var tx = tp.x; if (tx > nx && t.x < n.x || tx < nx && t.x > n.x) { return(tp); } var max = tx > nx ? t.x - c : t.x + c; nx = tx > nx && tx > max || tx < nx && tx < max ? max : tx; tp.x = nx; return(tp); }
/// <summary> /// Multiplies every component of this vector by the same component of scale. /// </summary> public void Scale(Vector3_ scale) { m_x *= scale.x; m_y *= scale.y; m_z *= scale.z; _CalculateParams(); }
private void CreateTeamPlayer() { var members = moduleTeam.members; if (members != null) { for (var i = 0; i < members.Length; ++i) { var pi = members[i]; var info = modulePlayer.BuildPlayerInfo(pi); var isPlayer = pi.roleId == LoadParamTeam.MasterId; var pos = new Vector3_(playerStart.x - i, 0, 0); var p = Creature.Create(info, pos, new Vector3(0, 90, 0), isPlayer, i + ":" + pi.roleId, pi.roleName); p.roleId = pi.roleId; p.roleProto = pi.roleProto; p.teamIndex = i; p.avatar = pi.avatar; p.enableUpdate = false; p.SetCreatureCamp(CreatureCamp.PlayerCamp); if (isPlayer) { m_player = p; moduleBattle.SetPlayerTeamIndex(p.teamIndex); } if (pi.teamLeader > 0) { m_teamLeader = p; } else { m_normalMember = p; } m_teamMembers.Add(p); CharacterEquip.ChangeCloth(p, pi.fashion); if (pi.pet != null && pi.pet.itemTypeId != 0) { var show = ConfigManager.Get <ShowCreatureInfo>(pi.pet.itemTypeId); if (show == null) { Logger.LogError("没有配置config_showCreatureInfo表。宠物ID = {0}, 没有出生位置信息。宠物模型创建失败", pi.pet.itemTypeId); continue; } var showData = show.GetDataByIndex(0); var data = showData.data.GetValue <ShowCreatureInfo.SizeAndPos>(0); p.pet = PetCreature.Create(p, PetInfo.Create(pi.pet), p.position_ + data.pos, p.eulerAngles, false, Module_Home.PET_OBJECT_NAME); p.pet.enableUpdate = false; } } } }
private void _Update(int diff) { if (info.fatalRadius > 0 && stateMachine.passiveSource) { var fatal_ = Vector3_.Distance(stateMachine.passiveSource.position_, stateMachine.creature.position_) < info.fatalRadius; if (fatal ^ fatal_) { stateMachine.passiveSource.stateMachine.SetParam(StateMachineParam.fatal, fatal_ ? 1 : -1, true); } fatal = fatal_; } if (m_waitToResetKey) { m_waitToResetKey = false; stateMachine.SetParam(StateMachineParam.key, 0); stateMachine.SetParam(StateMachineParam.process, 2); stateMachine.SetParam(StateMachineParam.moveBreak, true); } if (!stateMachine.playable) { return; } if (m_falling) { if (!stateMachine.creature.onGround) { m_fallTime += diff; return; } m_falling = false; m_fallTime = 0; } m_time += diff; var frames = m_time / 33 - m_currentFrame; m_normalizedTime = (float)m_time / m_length; IncreaseFrame(frames); UpdateAnimMotion(); if (loop && m_currentFrame >= frameCount) { m_waitToLoop = true; } if (ended && !noDefaultTrans && !stateMachine.GetBool(StateMachineParam.isDead)) { m_waitToDefault = true; } }
public static void CreateVector3_unityVec() { Vector3 vec = new Vector3(1.1f, 2.2f, 3.3f); Vector3_ result = UnityMessageBuilder.CreateVector(vec); Assert.AreEqual(result.x, vec.x); Assert.AreEqual(result.y, vec.y); Assert.AreEqual(result.z, vec.z); }
public static Vector3_ CreateVector(float xIn, float yIn, float zIn) { Vector3_ result = new Vector3_ { x = xIn, y = yIn, z = zIn, }; return(result); }
private void UpdateAnimMotion() { var idx = (int)m_motionFrame.x + m_currentFrame; var max = (int)m_motionFrame.y; if (!m_motion || m_falling || idx < 1 || idx > max && m_motionIndex >= max) { m_inMotion = false; return; } m_inMotion = true; if (idx > max) { idx = max; } m_motionIndex = idx; var next = m_motion.points[m_motionIndex]; var prev = m_motion.points[m_motionIndex - 1]; var prog = idx == max ? 1.0 : (m_time % 33) / 33.0; var tar = (Vector3_.Lerp(prev, next, prog) - m_motion.points[0]) * 0.01; var c = stateMachine.creature; currentMotionPos = new Vector3_(!c.isForward ? -tar.z : tar.z, tar.y, -tar.x) + c.motionOrigin; if (currentMotionPos.y < 0) { FightRecordManager.RecordLog <LogVector3>(l => { l.tag = (byte)TagType.motionOrigin; l.pos = new double[] { tar.x, tar.y, tar.z }; }); FightRecordManager.RecordLog <LogVector3>(l => { l.tag = (byte)TagType.motionOrigin; l.pos = new double[] { c.motionOrigin.x, c.motionOrigin.y, c.motionOrigin.z }; }); FightRecordManager.RecordLog <LogVector3>(l => { l.tag = (byte)TagType.currentMotionPos; l.pos = new double[3]; l.pos[0] = currentMotionPos.x; l.pos[1] = currentMotionPos.y; l.pos[2] = currentMotionPos.z; }); currentMotionPos.y = 0; } }
public static void ToUnityVector() { Vector3_ vec = new Vector3_ { x = 1.1f, y = 2.2f, z = 3.3f }; Vector3 result = vec.ToUnityVector(); Assert.AreEqual(result.x, vec.x); Assert.AreEqual(result.y, vec.y); Assert.AreEqual(result.z, vec.z); }
public static void CreateVector3_floats() { float x = 1.1f; float y = 2.2f; float z = 3.3f; Vector3_ result = MessageBuilder.CreateVector(x, y, z); Assert.AreEqual(result.x, x); Assert.AreEqual(result.y, y); Assert.AreEqual(result.z, z); }
private void OnRevertPosition() { if (master) { master.position = master.position_ = originMasterPos; } if (fightingPet) { fightingPet.position_ = originPetPos; } recordMasterPos = Vector3.zero; }
private void CreateCollider(Vector3 rot, Vector3_ _direction, Vector3_ _eular) { eular_ = _eular; direction = _direction; intDirection = direction.x > 0 ? 1 : direction.x < 0 ? -1 : 0; m_root = new GameObject(name).transform; m_root.eulerAngles = new Vector3_(eular_.z * eular_.x, Mathd.ClampAngle(rot.y)); m_root.position = position_; CreateCollider(); m_lastY = position_.y; }
public override void OnUpdate(int diff) { if (!enableUpdate) { return; } base.OnUpdate(diff); if (firstStep) { var direction = randomPosition - position_; direction.Normalize(); var p = position_ + direction * (velocity + acceleration * m_time * 0.001) * diff * 0.001; if (p.y < 0) { p.y = 0; } position = position_ = p;; if (Vector3_.Distance(position_, randomPosition) < 0.2 || Vector3_.Dot(startPos - randomPosition, position_ - randomPosition) <= 0) { enableUpdate = false; firstStep = false; } return; } var targetPos = (Vector3_)target.LogicPosition + offset; position = position_ = motion.Evaluate(diff * 0.001); var d = Vector3_.Distance(position_, targetPos); var a = Vector3_.Dot(startPos - targetPos, position_ - targetPos); FightRecordManager.RecordLog <LogEffectPos>(log => { log.tag = (byte)TagType.EffectPos; log.pos = new double[3]; log.pos[0] = position_.x; log.pos[1] = position_.y; log.pos[2] = position_.z; log.distance = d; log.angle = a; }); if (d < 0.2 || a <= 0) { Destroy(); } }
public void CreateFightingPet(PetInfo rPet) { var rGradeInfo = rPet?.UpGradeInfo; if (rGradeInfo == null) { return; } if (fightingPet && fightingPet.weaponID == rGradeInfo.UIstateMachine) { return; } PrepareAssets(Module_Battle.BuildPetSimplePreloadAssets(rPet, null, 2), b => { var show = ConfigManager.Get <ShowCreatureInfo>(rPet.ID); if (show == null) { Logger.LogError("没有配置config_showCreatureInfo表。宠物ID = {0}, 没有出生位置信息。宠物模型创建失败", rPet.ID); return; } if (fightingPet) { fightingPet.Destroy(); fightingPet = null; } var showData = show.GetDataByIndex(0); var data = showData.data.GetValue <ShowCreatureInfo.SizeAndPos>(0); fightingPet = moduleHome.CreatePet(rGradeInfo, data.pos, data.rotation, startPos, true, Module_Home.FIGHTING_PET_OBJECT_NAME); fightingPet.eulerAngles = data.rotation; fightingPet.position_ = fightingPet.localPosition = data.pos; fightingPet.transform.localScale *= data.size; originPetPos = fightingPet.position_; if (recordMasterPos != Vector3_.zero) { var offset = fightingPet.position_ - originMasterPos; fightingPet.position_ = (recordMasterPos + offset); } //切换主界面的宠物待机动作 fightingPet.stateMachine.TranslateTo("StateIdle"); }); }
public static RobotCreature Create(CreatureInfo info, Vector3_ pos, Vector3 rot, string name = "", string uiName = "") { if (info == null) { Logger.LogError("RobotCreature::Create: Create robot failed, invalid config"); return(null); } var rootNode = new GameObject().transform; if (!CreateMorphNodes(info, rootNode)) { Logger.LogError("RobotCreature::Create: Create robot [{0}:{1}] failed, main model [{2}] not loaded", info.ID, info.name, CreatureInfo.GetMorphModelName(info.models, 0)); return(null); } rootNode.position = pos; rootNode.eulerAngles = rot; // Protect invalid weapon config if (info.weaponID < 1) { info.weaponID = 1; info.weaponItemID = 1101; } var c = Create <RobotCreature>(string.IsNullOrEmpty(name) ? info.name : name, rootNode.gameObject); c.InitPosition(pos); c.isPlayer = false; c.isMonster = false; c.isRobot = true; c.isCombat = true; c.creatureCamp = CreatureCamp.MonsterCamp; // 机器人默认必须是怪物的阵营 c.uiName = string.IsNullOrEmpty(uiName) ? c.name : uiName; c.isDead = false; c.realDead = false; c.useSpringBone = true; c.teamIndex = MonsterCreature.GetMonsterRoomIndex(); c.UpdateConfig(info); c.OnCreate(info.buffs); return(c); }
public Creature CreateSceneActor(int rMonsterId, Vector3_ rPos, CreatureDirection rDir, int rGroup, int rLevel) { MonsterCreature actor = MonsterCreature.CreateMonster(rMonsterId, rGroup, rLevel, rPos, Vector3_.zero); if (!actor) { return(null); } actor.isBoss = false; actor.enabledAndVisible = true; actor.invincibleCount = int.MaxValue; actor.behaviour.hitCollider.isTrigger = false; actor.checkEdge = false; actor.SetHealthBarVisible(false); actor.forceDirection = (int)rDir; return(actor); }
public static MonsterCreature CreateBordlandMonster(PNmlMonster monsterData, Vector3_ pos, Vector3 rot, string name = "", string uiName = "") { if (monsterData == null) { Logger.LogError("MonsterCreature::CreateBordlandMonster: Create monster failed, invalid monster data"); return(null); } var rootNode = new GameObject().transform; if (!CreateMorphNodes(new string[] { monsterData.mesh.ToLower() }, rootNode)) { Logger.LogError("MonsterCreature::CreateBordlandMonster: Create monster failed, model [{0}] not loaded", monsterData.mesh.ToLower()); return(null); } rootNode.position = pos; rootNode.eulerAngles = rot; var c = Create <MonsterCreature>(string.IsNullOrEmpty(name) ? Util.Format("bordland_monster_{0}", monsterData.uid) : name, rootNode.gameObject); c.InitPosition(pos); c.isPlayer = false; c.isMonster = true; c.uiName = string.IsNullOrEmpty(uiName) ? c.name : uiName; c.monsterId = monsterData.monster; //怪物属性记录 c.monsterInfo = ConfigManager.Find <MonsterInfo>(config => config.GetModel() == monsterData.mesh.ToLower()); c.height = (c.monsterInfo && c.monsterInfo.hitColliderSize.y > 0) ? c.monsterInfo.hitColliderSize.y : 2.0f; c.monsterUID = monsterData.uid; c.monsterGroup = 0; c.creatureCamp = CreatureCamp.MonsterCamp; c.monsterLevel = 0; c.isBoss = false; c.isSendDeathCondition = false; return(c); }
protected override void OnCreateCreatures() { m_isEnding = false; EventManager.AddEventListener(CreatureEvents.DEAD, OnCreatureDead); if (!moduleAI.IsStartAI) { moduleAI.StartAI(); } var players = LoadParam.players; for (var i = 0; i < players.Length; ++i) { var pi = players[i]; var info = modulePlayer.BuildPlayerInfo(pi); var isPlayer = pi.roleId == LoadParam.MasterId; var pos = new Vector3_(i == 0 ? CombatConfig.spvpStart.x : CombatConfig.spvpStart.y, 0, 0); var p = isPlayer || !LoadParam.IsMatchRobot ? Creature.Create(info, pos, new Vector3(0, 90, 0), isPlayer, i + ":" + pi.roleId, pi.roleName) : RobotCreature.Create(info, pos, new Vector3(0, 90, 0), i + ":" + pi.roleId, pi.roleName); if (i != 0) { p.direction = CreatureDirection.BACK; } p.roleId = pi.roleId; p.roleProto = pi.roleProto; p.teamIndex = i; p.avatar = pi.avatar; p.enableUpdate = false; if (isPlayer) { m_player = p; } m_players.Add(p); if (LoadParam.IsMatchRobot) { if (!isPlayer) { moduleAI.AddPlayerAI(p); } moduleAI.AddCreatureToCampDic(p); } CharacterEquip.ChangeCloth(p, pi.fashion); if (pi.pet != null && pi.pet.itemTypeId != 0) { var show = ConfigManager.Get <ShowCreatureInfo>(pi.pet.itemTypeId); if (show == null) { Logger.LogError("没有配置config_showCreatureInfo表。宠物ID = {0}, 没有出生位置信息。宠物模型创建失败", pi.pet.itemTypeId); continue; } var showData = show.GetDataByIndex(0); var data = showData.data.GetValue <ShowCreatureInfo.SizeAndPos>(0); p.pet = PetCreature.Create(p, PetInfo.Create(pi.pet), p.position_ + data.pos, p.eulerAngles, false, Module_Home.PET_OBJECT_NAME); p.pet.enableUpdate = false; if (!moduleAI.IsStartAI) { moduleAI.StartAI(); } moduleAI.AddPetAI(p.pet); } } combatCamera.enabled = false; combatCamera.LookTo(new Vector3((float)((CombatConfig.spvpStart.x + CombatConfig.spvpStart.y) * 0.5), 0, 0)); }
/// <summary> /// Returns the distance between a and b. /// </summary> public static double Distance(Vector3_ a, Vector3_ b) { var vector = new Vector3_(a.x - b.x, a.y - b.y, a.z - b.z); return(Mathd.Sqrt(vector.x * vector.x + vector.y * vector.y + vector.z * vector.z)); }
/// <summary> /// Cross Product of two vectors. /// </summary> public static Vector3_ Cross(Vector3_ lhs, Vector3_ rhs) { return(new Vector3_(lhs.y * rhs.z - lhs.z * rhs.y, lhs.z * rhs.x - lhs.x * rhs.z, lhs.x * rhs.y - lhs.y * rhs.x)); }
/// <summary> /// Returns a copy of vector with its magnitude clamped to maxLength. /// </summary> public static Vector3_ ClampMagnitude(Vector3_ vector, double maxLength) { return(vector.sqrMagnitude > maxLength * maxLength ? vector.normalized * maxLength : vector); }
/// <summary> /// Returns the angle in degrees between from and to. /// </summary> /// <param name="from">The vector from which the angular difference is measured.</param> /// <param name="to">The vector to which the angular difference is measured.</param> public static double Angle(Vector3_ from, Vector3_ to) { return(Mathd.Acos(Mathd.Clamp(Dot(from.normalized, to.normalized), -1, 1)) * 57.29578); }
/// <summary> /// Multiplies two vectors component-wise. /// </summary> public static Vector3_ Scale(Vector3_ a, Vector3_ b) { return(new Vector3_(a.x * b.x, a.y * b.y, a.z * b.z)); }