using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using UnityEngine;
///
/// 可编辑脸部部位
///
public enum EditableFacePart
{
eyebrow,
eye,
mousewidth
}
///
/// 可编辑身体部位
///
public enum EditableBodyPart
{
UpperArm = 0,
LowerArm = 1,
Hand = 2,
UpperLeg = 3,
LowerLeg = 4,
Foot = 5,
All = 6,
Neck = 7,
Clavicle = 8,
Shoulder = 9,
Chest = 10,//胸
Pleural = 11,//胸腔下部
Belly = 12,//肚子
UpperArmUp = 13,
UpperArmDown = 14,
UpperLegUp = 15,
UpperLegDown = 16,
LowerLegUp = 17,
LowerLegDown = 18,
Head = 19,
None = 20,
}
///
/// 编辑类型
///
public enum ModifyType
{
Length = 0,//长
Width = 1,//宽
Thick = 2,//厚度
LengthWidthThick = 3,//长宽厚
Angle = 4,//角度
UpDown = 5,//上下
LeftRight = 6,//左右
ForwardBehind = 7,//前后
}
public static class CustomRoleUtility
{
public static void UpdateBoneScale(Animator ani,EditableBodyPart part,float value)
{
Transform transL = null;
Transform transR = null;
Vector3 beforeScale = Vector3.one;
List childList = new List();
bool keepChildWorldScale = false;
switch (part)
{
case EditableBodyPart.UpperArm:
transL = ani.GetBoneTransform(HumanBodyBones.LeftUpperArm);
transR = ani.GetBoneTransform(HumanBodyBones.RightUpperArm);
keepChildWorldScale = true;
break;
case EditableBodyPart.LowerArm:
transL = ani.GetBoneTransform(HumanBodyBones.LeftLowerArm);
transR = ani.GetBoneTransform(HumanBodyBones.RightLowerArm);
break;
case EditableBodyPart.Hand:
transL = ani.GetBoneTransform(HumanBodyBones.LeftHand);
transR = ani.GetBoneTransform(HumanBodyBones.RightHand);
break;
case EditableBodyPart.UpperLeg:
transL = ani.GetBoneTransform(HumanBodyBones.LeftUpperLeg);
transR = ani.GetBoneTransform(HumanBodyBones.RightUpperLeg);
keepChildWorldScale = true;
break;
case EditableBodyPart.LowerLeg:
transL = ani.GetBoneTransform(HumanBodyBones.LeftLowerLeg);
transR = ani.GetBoneTransform(HumanBodyBones.RightLowerLeg);
break;
case EditableBodyPart.Foot:
transL = ani.GetBoneTransform(HumanBodyBones.LeftFoot);
transR = ani.GetBoneTransform(HumanBodyBones.RightFoot);
break;
case EditableBodyPart.None:
break;
default:
break;
}
if(transL != null)
{
beforeScale = transL.localScale;
var world_l = transL.lossyScale;
transL.SetLocalScaleX(transL.localScale.x * value / world_l.x);
transL.SetLocalScaleY(transL.localScale.y * value / world_l.y);
transL.SetLocalScaleZ(transL.localScale.z * value / world_l.z);
var lcount = transL.childCount;
for (int i = 0; i < lcount; i++)
{
childList.Add(transL.GetChild(i));
}
}
if(transR != null)
{
beforeScale = transR.localScale;
var world_r = transR.lossyScale;
transR.SetLocalScaleX(transR.localScale.x * value / world_r.x);
transR.SetLocalScaleY(transR.localScale.y * value / world_r.y);
transR.SetLocalScaleZ(transR.localScale.z * value / world_r.z);
var rcount = transR.childCount;
for (int i = 0; i < rcount; i++)
{
childList.Add(transR.GetChild(i));
}
}
if(!keepChildWorldScale)
{
return;
}
for (int i = 0; i < childList.Count; i++)
{
var childTrans = childList[i];
var oldScale = childTrans.localScale;
childTrans.SetLocalScaleX(oldScale.x * beforeScale.x / value);
childTrans.SetLocalScaleY(oldScale.y * beforeScale.y / value);
childTrans.SetLocalScaleZ(oldScale.z * beforeScale.z / value);
}
}
public static void GetNormalAniBonesScale(Animator ani,ref Dictionary boneDic)
{
for (int i = 0; i < Enum.GetValues(typeof(HumanBodyBones)).Length - 1; i++)
{
var trans = ani.GetBoneTransform((HumanBodyBones)i);
if(trans)
{
boneDic.Add(trans.name, trans.localScale);
}
}
}
public static Transform GetChild(Transform trans,string name)
{
for (int i = 0; i < trans.childCount; i++)
{
if(trans.GetChild(i).name == name)
{
return trans.GetChild(i);
}else
{
var childTrans = GetChild(trans.GetChild(i),name);
if(childTrans != null)
{
return childTrans;
}
}
}
return null;
}
public static void ShowFile()
{
FileStream fs = File.Open("E:/key.key", FileMode.Open);
FileStream fsout = File.Open("E:/keyout9.key", FileMode.Create);
BinaryReader br = new BinaryReader(fs);
BinaryWriter bw = new BinaryWriter(fsout);
Byte[] byData = br.ReadBytes((int)fs.Length);
var t = "NKnFb79Sxk+4Xw284MQleA==";
var pid = "1639047545434X1016017";
fs.Close();
//var iv = new byte[16];
//var key = new byte[16];
//for (int i = 0; i < byData.Length; i++)
//{
// if(i <= 15)
// {
// iv[i] = byData[i];
// var ivx = byData[i].ToString("x");
// Debug.Log(iv[i] + " : " + ivx);
// }
// else
// {
// key[i - 16] = byData[i];
// var keyx = byData[i].ToString("x");
// Debug.Log(key[i - 16] + " : " + keyx);
// }
//}
//var str = DecryptStringFromBytes_Aes(byData, iv, key);
//Debug.Log("result" + str);
Debug.Log(byData.Length);
IList bData = new List();
string[] strHexs = new string[16];
int[] intData = {
245,
217,
174,
210,
90,
41,
167,
178,
110,
47,
158,
193,
35,
162,
230,
97
};
for (int i = 0; i < 16; i++)
{
int a = intData[i];
strHexs[i] = a.ToString("x");
//strHexs[i] = a.ToString();
Debug.Log(a + " : " + a.ToString("x"));
}
foreach (var item in strHexs)
{
Debug.Log(Convert.ToByte(item, 16));
bData.Add(Convert.ToByte(item, 16));
}
bw.Write(bData.ToArray());
fsout.Close();
}
}