示例#1
0
        public CmpHair GetCustomHairComponent(int parts)
        {
            if (this.cmpHair == null)
            {
                return((CmpHair)null);
            }
            if (parts >= this.cmpHair.Length)
            {
                return((CmpHair)null);
            }
            CmpHair cmpHair = this.cmpHair[parts];

            return(Object.op_Equality((Object)null, (Object)cmpHair) ? (CmpHair)null : cmpHair);
        }
    public static void InitializeHair(GameObject selectedObject)
    {
        GameObject hairObject = selectedObject;

        hairObject.layer = 10;

        if (hairObject != null)
        {
            AIChara.CmpHair hairComponent = hairObject.GetComponent <AIChara.CmpHair>();
            if (hairComponent == null)
            {
                hairComponent = hairObject.AddComponent <AIChara.CmpHair>();
            }

            FindAssist findAssist = new FindAssist();
            findAssist.Initialize(hairComponent.transform);
            hairComponent.rendHair = (from x in hairComponent.GetComponentsInChildren <Renderer>(true) where !x.name.Contains("_acs") select x).ToArray();

            // remove all dynamic bones. smh...
            DynamicBone[] components = hairComponent.GetComponents <DynamicBone>();
            foreach (var comp in components)
            {
                Object.DestroyImmediate(comp);
            }

            DevPreviewHair previewComp = hairObject.GetComponent <DevPreviewHair>();
            if (previewComp == null)
            {
                previewComp = hairObject.AddComponent <DevPreviewHair>();
            }
            previewComp.hairTexturePath = ModPacker.GetProjectPath().Replace("Assets/", "");

            var dynBones = (from x in findAssist.dictObjName where x.Value.transform.name.Contains("_s") select x.Value).ToArray();
            foreach (GameObject bone in dynBones)
            {
                DynamicBone dynBone = hairObject.AddComponent <DynamicBone>();
                dynBone.m_Root              = bone.transform;
                dynBone.m_UpdateRate        = 60;
                dynBone.m_UpdateMode        = DynamicBone.UpdateMode.AnimatePhysics;
                dynBone.m_Damping           = 0.102f;
                dynBone.m_Elasticity        = 0.019f;
                dynBone.m_ElasticityDistrib = new AnimationCurve();
                dynBone.m_ElasticityDistrib.AddKey(0f, 0.969f);
                dynBone.m_ElasticityDistrib.AddKey(1f, 0.603f);
                dynBone.m_Stiffness     = 0.144f;
                dynBone.m_Inert         = 0.072f;
                dynBone.m_Radius        = 0.1f;
                dynBone.m_RadiusDistrib = new AnimationCurve();
                dynBone.m_RadiusDistrib.AddKey(0f, 1f);
                dynBone.m_RadiusDistrib.AddKey(1f, 0.5f);
                dynBone.m_EndLength = 0f;
                dynBone.m_Force     = new Vector3(0, -0.005f, 0);
            }
            components = hairComponent.GetComponents <DynamicBone>();

            KeyValuePair <string, GameObject> keyValuePair = findAssist.dictObjName.FirstOrDefault((KeyValuePair <string, GameObject> x) => x.Key.Contains("_top"));
            if (keyValuePair.Equals(default(KeyValuePair <string, GameObject>)))
            {
                return;
            }
            hairComponent.boneInfo = new AIChara.CmpHair.BoneInfo[keyValuePair.Value.transform.childCount];
            for (int i = 0; i < hairComponent.boneInfo.Length; i++)
            {
                Transform child = keyValuePair.Value.transform.GetChild(i);
                findAssist.Initialize(child);
                AIChara.CmpHair.BoneInfo          boneInfo      = new AIChara.CmpHair.BoneInfo();
                KeyValuePair <string, GameObject> keyValuePair2 = findAssist.dictObjName.FirstOrDefault((KeyValuePair <string, GameObject> x) => x.Key.Contains("_s"));
                if (!keyValuePair2.Equals(default(KeyValuePair <string, GameObject>)))
                {
                    Transform transform = keyValuePair2.Value.transform;
                    boneInfo.trfCorrect = transform;
                    boneInfo.basePos    = boneInfo.trfCorrect.transform.localPosition;
                    boneInfo.posMin.x   = boneInfo.trfCorrect.transform.localPosition.x + 0.5f;
                    boneInfo.posMin.y   = boneInfo.trfCorrect.transform.localPosition.y;
                    boneInfo.posMin.z   = boneInfo.trfCorrect.transform.localPosition.z + 0.5f;
                    boneInfo.posMax.x   = boneInfo.trfCorrect.transform.localPosition.x - 0.5f;
                    boneInfo.posMax.y   = boneInfo.trfCorrect.transform.localPosition.y - 0.5f;
                    boneInfo.posMax.z   = boneInfo.trfCorrect.transform.localPosition.z - 0.5f;
                    boneInfo.baseRot    = boneInfo.trfCorrect.transform.localEulerAngles;
                    boneInfo.rotMin.x   = boneInfo.trfCorrect.transform.localEulerAngles.x - 30f;
                    boneInfo.rotMin.y   = boneInfo.trfCorrect.transform.localEulerAngles.y - 30f;
                    boneInfo.rotMin.z   = boneInfo.trfCorrect.transform.localEulerAngles.z - 30f;
                    boneInfo.rotMax.x   = boneInfo.trfCorrect.transform.localEulerAngles.x + 30f;
                    boneInfo.rotMax.y   = boneInfo.trfCorrect.transform.localEulerAngles.y + 30f;
                    boneInfo.rotMax.z   = boneInfo.trfCorrect.transform.localEulerAngles.z + 30f;
                    boneInfo.moveRate.x = Mathf.InverseLerp(boneInfo.posMin.x, boneInfo.posMax.x, boneInfo.basePos.x);
                    boneInfo.moveRate.y = Mathf.InverseLerp(boneInfo.posMin.y, boneInfo.posMax.y, boneInfo.basePos.y);
                    boneInfo.moveRate.z = Mathf.InverseLerp(boneInfo.posMin.z, boneInfo.posMax.z, boneInfo.basePos.z);
                    boneInfo.rotRate.x  = Mathf.InverseLerp(boneInfo.rotMin.x, boneInfo.rotMax.x, boneInfo.baseRot.x);
                    boneInfo.rotRate.y  = Mathf.InverseLerp(boneInfo.rotMin.y, boneInfo.rotMax.y, boneInfo.baseRot.y);
                    boneInfo.rotRate.z  = Mathf.InverseLerp(boneInfo.rotMin.z, boneInfo.rotMax.z, boneInfo.baseRot.z);
                }
                List <DynamicBone> list  = new List <DynamicBone>();
                DynamicBone[]      array = components;
                for (int j = 0; j < array.Length; j++)
                {
                    DynamicBone n = array[j];
                    if (!findAssist.dictObjName.FirstOrDefault((KeyValuePair <string, GameObject> x) => x.Key == n.m_Root.name).Equals(default(KeyValuePair <string, GameObject>)))
                    {
                        list.Add(n);
                    }
                }
                boneInfo.dynamicBone      = list.ToArray();
                hairComponent.boneInfo[i] = boneInfo;
            }
            findAssist = new FindAssist();
            findAssist.Initialize(hairComponent.transform);
            hairComponent.rendAccessory = (from s in findAssist.dictObjName
                                           where s.Key.Contains("_acs")
                                           select s into x
                                           select x.Value.GetComponent <Renderer>() into r
                                           where null != r
                                           select r).ToArray <Renderer>();

            SkinnedMeshRenderer[] renderers = hairObject.GetComponentsInChildren <SkinnedMeshRenderer>();
            hairComponent.rendCheckVisible = new SkinnedMeshRenderer[renderers.Length];
            for (int i = 0; i < renderers.Length; i++)
            {
                renderers[i].gameObject.layer     = 10;
                hairComponent.rendCheckVisible[i] = renderers[i];
            }
        }
    }