コード例 #1
0
 public CharacterLoader()
 {
     Done   = false;
     Images = new CharacterData.CharacterDataImages();
     Sizes  = new CharacterData.CharacterDataSizes();
     Name   = "unset";
 }
コード例 #2
0
    public IEnumerable <FlatBodyObject> load_sequential(CharacterData.CharacterDataImages aImages, CharacterData.CharacterDataSizes aSizes, bool useHeadOrder = false)
    {
        GameObject neck = create_object(ZgJointId.Neck, aImages.head, aSizes.mLimbSizes[0], aSizes.mMountingPositions[0]);

        yield return(null);

        GameObject leftLowerArm = create_object(ZgJointId.LeftElbow, aImages.leftLowerArm, aSizes.mLimbSizes[1], aSizes.mMountingPositions[1]);

        yield return(null);

        GameObject leftLowerLeg = create_object(ZgJointId.LeftKnee, aImages.leftLowerLeg, aSizes.mLimbSizes[2], aSizes.mMountingPositions[2]);

        yield return(null);

        GameObject leftUpperArm = create_object(ZgJointId.LeftShoulder, aImages.leftUpperArm, aSizes.mLimbSizes[3], aSizes.mMountingPositions[3]);

        yield return(null);

        GameObject leftUpperLeg = create_object(ZgJointId.LeftHip, aImages.leftUpperLeg, aSizes.mLimbSizes[4], aSizes.mMountingPositions[4]);

        yield return(null);

        GameObject rightLowerArm = create_object(ZgJointId.RightElbow, aImages.rightLowerArm, aSizes.mLimbSizes[5], aSizes.mMountingPositions[5]);

        yield return(null);

        GameObject rightLowerLeg = create_object(ZgJointId.RightKnee, aImages.rightLowerLeg, aSizes.mLimbSizes[6], aSizes.mMountingPositions[6]);

        yield return(null);

        GameObject rightUpperArm = create_object(ZgJointId.RightShoulder, aImages.rightUpperArm, aSizes.mLimbSizes[7], aSizes.mMountingPositions[7]);

        yield return(null);

        GameObject rightUpperLeg = create_object(ZgJointId.RightHip, aImages.rightUpperLeg, aSizes.mLimbSizes[8], aSizes.mMountingPositions[8]);

        yield return(null);

        GameObject torso = create_object(ZgJointId.Torso, aImages.torso, aSizes.mLimbSizes[9], aSizes.mMountingPositions[9]);

        yield return(null);

        GameObject waist = create_object(ZgJointId.Waist, aImages.waist, aSizes.mLimbSizes[10], aSizes.mMountingPositions[10]);

        yield return(null);


        GameObject leftHand   = create_extremety(ZgJointId.LeftHand);
        GameObject rightHand  = create_extremety(ZgJointId.RightHand);
        GameObject leftAnkle  = create_extremety(ZgJointId.LeftAnkle);
        GameObject rightAnkle = create_extremety(ZgJointId.RightAnkle);
        GameObject head       = create_extremety(ZgJointId.Head);



        //order things
        Dictionary <ZgJointId, GameObject> jointObject = new Dictionary <ZgJointId, GameObject>();

        //Dictionary<ZgJointId, Texture2D> jointTexture = new Dictionary<ZgJointId, Texture2D>();
        jointObject[ZgJointId.Torso]         = torso;
        jointObject[ZgJointId.Waist]         = waist;
        jointObject[ZgJointId.Neck]          = neck;
        jointObject[ZgJointId.LeftShoulder]  = leftUpperArm;
        jointObject[ZgJointId.RightShoulder] = rightUpperArm;
        jointObject[ZgJointId.LeftElbow]     = leftLowerArm;
        jointObject[ZgJointId.RightElbow]    = rightLowerArm;
        jointObject[ZgJointId.LeftHip]       = leftUpperLeg;
        jointObject[ZgJointId.RightHip]      = rightUpperLeg;
        jointObject[ZgJointId.LeftKnee]      = leftLowerLeg;
        jointObject[ZgJointId.RightKnee]     = rightLowerLeg;

        jointObject[ZgJointId.LeftHand]   = leftHand;
        jointObject[ZgJointId.RightHand]  = rightHand;
        jointObject[ZgJointId.LeftAnkle]  = leftAnkle;
        jointObject[ZgJointId.RightAnkle] = rightAnkle;
        jointObject[ZgJointId.Head]       = head;

        //these two are special
        torso.transform.position = waist.transform.position;
        //we don't check if we use headfirst z offset here because it's the same in both cases...
        torso.transform.position += get_Z_offset(ZgJointId.Torso);
        waist.transform.position += get_Z_offset(ZgJointId.Waist);
        //torso.GetComponentInChildren<Renderer>().material.renderQueue = (int)(get_Z_offset(ZigJointId.Torso).z*(10));
        //waist.GetComponentInChildren<Renderer>().material.renderQueue = (int)(get_Z_offset(ZigJointId.Waist).z*(10));

        List <KeyValuePair <ZgJointId, ZgJointId> > relations = new List <KeyValuePair <ZgJointId, ZgJointId> >();

        relations.Add(new KeyValuePair <ZgJointId, ZgJointId>(ZgJointId.LeftShoulder, ZgJointId.Torso));
        relations.Add(new KeyValuePair <ZgJointId, ZgJointId>(ZgJointId.RightShoulder, ZgJointId.Torso));
        relations.Add(new KeyValuePair <ZgJointId, ZgJointId>(ZgJointId.LeftElbow, ZgJointId.LeftShoulder));
        relations.Add(new KeyValuePair <ZgJointId, ZgJointId>(ZgJointId.RightElbow, ZgJointId.RightShoulder));
        relations.Add(new KeyValuePair <ZgJointId, ZgJointId>(ZgJointId.LeftHip, ZgJointId.Waist));
        relations.Add(new KeyValuePair <ZgJointId, ZgJointId>(ZgJointId.RightHip, ZgJointId.Waist));
        relations.Add(new KeyValuePair <ZgJointId, ZgJointId>(ZgJointId.LeftKnee, ZgJointId.LeftHip));
        relations.Add(new KeyValuePair <ZgJointId, ZgJointId>(ZgJointId.RightKnee, ZgJointId.RightHip));
        relations.Add(new KeyValuePair <ZgJointId, ZgJointId>(ZgJointId.Neck, ZgJointId.Torso));



        relations.Add(new KeyValuePair <ZgJointId, ZgJointId>(ZgJointId.LeftHand, ZgJointId.LeftElbow));
        relations.Add(new KeyValuePair <ZgJointId, ZgJointId>(ZgJointId.RightHand, ZgJointId.RightElbow));
        relations.Add(new KeyValuePair <ZgJointId, ZgJointId>(ZgJointId.LeftAnkle, ZgJointId.LeftKnee));
        relations.Add(new KeyValuePair <ZgJointId, ZgJointId>(ZgJointId.RightAnkle, ZgJointId.RightKnee));
        relations.Add(new KeyValuePair <ZgJointId, ZgJointId>(ZgJointId.Head, ZgJointId.Neck));


        foreach (KeyValuePair <ZgJointId, ZgJointId> e in relations)
        {
            jointObject[e.Key].transform.parent = jointObject[e.Value].transform;


            try{
                jointObject[e.Key].transform.position =
                    jointObject[e.Value].transform.position
                    + get_offset_of_plane(jointObject[e.Value].transform)
                    + get_connection_point_list(e.Key, e.Value, aSizes.mMountingPositions[get_joint_alpha_index(e.Value)])
                    + (useHeadOrder ?
                       get_headfirst_Z_offset(e.Key) - get_headfirst_Z_offset(e.Value) :
                       get_Z_offset(e.Key) - get_Z_offset(e.Value));
                //jointObject[e.Key].GetComponentInChildren<Renderer>().material.renderQueue = (int)(get_Z_offset(e.Key).z*(10));
            }
            catch
            {
                //this should only happen for missing hand dots right now
                //put the hand on the elbow
                jointObject[e.Key].transform.position = jointObject[e.Value].transform.position;
            }
        }

        yield return(null);

        List <KeyValuePair <GameObject, float> > rotateMe = new List <KeyValuePair <GameObject, float> >();

        rotateMe.Add(new KeyValuePair <GameObject, float>(leftUpperArm, -90));
        rotateMe.Add(new KeyValuePair <GameObject, float>(rightUpperArm, -90));

        rotateMe.Add(new KeyValuePair <GameObject, float>(leftUpperLeg, -90));
        rotateMe.Add(new KeyValuePair <GameObject, float>(rightUpperLeg, -90));
        rotateMe.Add(new KeyValuePair <GameObject, float>(torso, 90));
        rotateMe.Add(new KeyValuePair <GameObject, float>(waist, -90));
        rotateMe.Add(new KeyValuePair <GameObject, float>(neck, 90));

        rotateMe.Add(new KeyValuePair <GameObject, float>(leftLowerLeg, -90));
        rotateMe.Add(new KeyValuePair <GameObject, float>(rightLowerLeg, -90));
        rotateMe.Add(new KeyValuePair <GameObject, float>(leftLowerArm, -90));
        rotateMe.Add(new KeyValuePair <GameObject, float>(rightLowerArm, -90));

        foreach (KeyValuePair <GameObject, float> e in rotateMe)
        {
            GameObject tempParent = new GameObject("genTempParent");
            tempParent.transform.position = e.Key.transform.position;
            List <Transform> children = new List <Transform>();
            for (int i = 0; i < e.Key.transform.childCount; i++)
            {
                if (e.Key.transform.GetChild(i).parent == e.Key.transform)
                {
                    children.Add(e.Key.transform.GetChild(i));
                }
            }
            foreach (Transform f in children)
            {
                f.parent = tempParent.transform;
            }
            tempParent.transform.rotation = Quaternion.AngleAxis(e.Value, Vector3.forward) * tempParent.transform.rotation;
            foreach (Transform f in children)
            {
                f.parent = e.Key.transform;
            }
            GameObject.Destroy(tempParent);
        }

        yield return(this);
    }