static public List <float3> SampleMeshSurface(Mesh mesh, int sampleNum = 1024) { var ret = new List <float3>(); if (mesh == null || mesh.GetTopology(0) != MeshTopology.Triangles) { LogTool.Log("Invalid mesh", LogLevel.Warning); return(ret); } var triangles = mesh.triangles; var area = new List <float>(); var minArea = float.MaxValue; foreach (var idx in Enumerable.Range(0, triangles.Length / 3)) { var pa = mesh.vertices[triangles[idx * 3]]; var pb = mesh.vertices[triangles[idx * 3 + 1]]; var pc = mesh.vertices[triangles[idx * 3 + 2]]; var A = pa - pc; var B = pb - pc; var a = 0.5f * math.length(math.cross(A, B)); area.Add(a); minArea = math.min(minArea, a); } foreach (var i in Enumerable.Range(0, area.Count)) { area[i] /= minArea; } var weights = area.Select(v => Mathf.CeilToInt(v)).ToList(); var rand = new WeightRandom(weights); while (sampleNum-- > 0) { var idx = rand.Random(); var pa = mesh.vertices[triangles[idx * 3]]; var pb = mesh.vertices[triangles[idx * 3 + 1]]; var pc = mesh.vertices[triangles[idx * 3 + 2]]; var u = UnityEngine.Random.value; var v = UnityEngine.Random.value; if (u + v > 1) { u = 1 - u; v = 1 - v; } var p = u * pa + v * pb + (1 - (u + v)) * pc; ret.Add(p); } return(ret); }
//翅膀培养 public ErrorCodes WingTrain(CharacterController character, int _type, ref int result) { int type = 0;//永远都用部位0 //数据溢出 if (type < 0 || type >= 5) { return(ErrorCodes.Error_DataOverflow); } //查询翅膀 var wing = character.GetWing(); if (wing == null) { return(ErrorCodes.Error_WingNotFind); } //表格取值 var tbWing = Table.GetWingQuality(wing.GetId()); if (tbWing == null) { return(ErrorCodes.Error_WingID); } //获取类型ID var typeId = wing.GetTypeId(type); var tbWingTrain = Table.GetWingTrain(typeId); if (tbWingTrain == null) { Logger.Error("EnchanceFormation Id={0}", typeId); return(ErrorCodes.Unknow); } //这个类型的培养是否到头了 if (tbWingTrain.UpStarID == -1) { return(ErrorCodes.Error_WingTypeLevelMax); } //需求翅膀阶段等级 if (tbWingTrain.Condition > tbWing.Segment) { return(ErrorCodes.Error_NeedWingLevelMore); } //材料判断 if (character.mBag.GetItemCount(tbWingTrain.MaterialID) < tbWingTrain.MaterialCount) { return(ErrorCodes.ItemNotEnough); } if (character.mBag.GetRes(eResourcesType.GoldRes) < tbWingTrain.UsedMoney) { return(ErrorCodes.MoneyNotEnough); } //消耗 character.mBag.DeleteItem(tbWingTrain.MaterialID, tbWingTrain.MaterialCount, eDeleteItemType.WingTrain); character.mBag.DeleteItem((int)eResourcesType.GoldRes, tbWingTrain.UsedMoney, eDeleteItemType.WingTrain); //经验计算 var NowExp = wing.GetExp(type); wRandom.Clear(); wRandom.AddTargets(new WeightRandomItem() { Index = -1, Target = tbWingTrain.AddExp, Weight = tbWingTrain.CommonProb }); for (int i = 0; i < tbWingTrain.CritAddExp.Length; i++) { wRandom.AddTargets(new WeightRandomItem() { Index = i, Target = tbWingTrain.CritAddExp[i], Weight = tbWingTrain.CritProb[i] }); } wRandom.Ready(); WeightRandomItem resWR = wRandom.Random(); NowExp += Convert.ToInt32(resWR.Target); result = resWR.Index + 1;//0.普通,1.暴击1,2.暴击2,3.暴击3 //if (MyRandom.Random(10000) < tbWingTrain.CritProb) //{ // NowExp += tbWingTrain.CritAddExp; // result = 1; //} //else //{ // NowExp += tbWingTrain.AddExp; // result = 0; //} //升级计算 var oldId = tbWingTrain.Id; var oldTrainCount = tbWingTrain.TrainCount; var newId = -1; var levelup = 0; while (NowExp >= tbWingTrain.ExpLimit) { levelup++; if (tbWingTrain.UpStarID == -1) { NowExp = 0; break; } NowExp -= tbWingTrain.ExpLimit; tbWingTrain = Table.GetWingTrain(tbWingTrain.UpStarID); if (tbWingTrain == null) { break; } } if (tbWingTrain != null) { newId = tbWingTrain.Id; } //计算升级 if (levelup > 0) { character.SetRankFlag(RankType.WingsFight); wing.SetTypeId(type, tbWingTrain.Id); character.EquipChange(2, (int)eBagType.Wing, 0, wing); var newTrainCount = tbWingTrain.TrainCount; for (int upCount = oldTrainCount; upCount < newTrainCount; upCount++) { character.AddExData((int)eExdataDefine.e679, 1); } } character.AddExData((int)eExdataDefine.e326, 1); character.AddExData((int)eExdataDefine.e419, 1); wing.SetExp(type, NowExp); wing.MarkDbDirty(); try { character.mOperActivity.OnWingTrainEvent(); } catch (Exception e) { Logger.Fatal("OnWingFormation {0}\n{1}", e, e.Message); throw; } try { var klog = string.Format("wingtrain#{0}|{1}|{2}|{3}|{4}|{5}|{6}", character.mGuid, character.GetLevel(), character.serverId, type, oldId, newId, DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")); PlayerLog.Kafka(klog, 2); } catch (Exception e) { Logger.Error(e.Message); } return(ErrorCodes.OK); }