public CharacterLoader()
 {
     Done   = false;
     Images = new CharacterData.CharacterDataImages();
     Sizes  = new CharacterData.CharacterDataSizes();
     Name   = "unset";
 }
Beispiel #2
0
    //TODO test me...
    //note this depends on previous computation of sizes from create_main_character
    static void create_mini_character(Object aMain, IEnumerable <Object> aObjects, CharacterData.CharacterDataSizes aSizes)
    {
        float scaleAmount = 0.1f;

        IEnumerable <Object> aImages = aObjects.Where(f => (sLimbs.Contains(strip_to_root(f)) && !is_B_image(f))).OrderBy(f => f.name);

        foreach (Object f in aImages)
        {
            Texture2D tex = f as Texture2D;
            set_texture_for_reading(tex);

            //we could also recompute the sizes...
            //aSizes.mLimbSizes.Add(new Vector2(((Texture2D)f).width, ((Texture2D)f).height));

            tex.Resize((int)(tex.width * scaleAmount), (int)(tex.height * scaleAmount));


            //actually, I will use a custom shader for this instead so this step is not necessary

            /*Color[] colors = tex.GetPixels();
             * for (int i = 0; i < colors.Length; i++)
             *  if (colors[i].a != 0)
             *      colors[i] = new Color(0.5f, 0.5f, 0.5f, colors[i].a);
             * tex.SetPixels(colors);*/

            //no need to dot his here since we know textures are small
            set_texture_for_render(tex);
        }

        for (int i = 0; i < aSizes.mMountingPositions.Count; i++)
        {
            for (int j = 0; j < aSizes.mMountingPositions[i].Count; j++)
            {
                aSizes.mMountingPositions[i][j] *= scaleAmount;
            }
        }

        //scale sizes from previously computed values
        for (int i = 0; i < aSizes.mLimbSizes.Count; i++)
        {
            aSizes.mLimbSizes[i] = aSizes.mLimbSizes[i] * scaleAmount;
        }

        //package
        TextAsset cdtxt = serialize_cd(aSizes);

        IEnumerable <Object> package = aObjects.Where(f => !is_B_image(f)).Where(f => aImages.Contains(f));
        List <Object>        assets  = new List <Object>();

        foreach (Object f in package)
        {
            assets.Add(f);
        }
        AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(cdtxt));
        cdtxt = (TextAsset)AssetDatabase.LoadAssetAtPath("Assets/CD.txt", typeof(TextAsset));
        assets.Add(cdtxt);
        //Debug.Log(cdtxt.text);
        BuildPipeline.BuildAssetBundle(aMain, assets.ToArray(), "Assets/Resources/" + aMain.name + "_mini.unity3d", BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets, EditorUserBuildSettings.activeBuildTarget);//, BuildOptions.UncompressedAssetBundle);//, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets);
    }
Beispiel #3
0
    public static TextAsset serialize_cd(CharacterData.CharacterDataSizes aData)
    {
        //package
        AssetDatabase.ImportAsset("Assets/CD.txt");
        TextAsset cdtxt = (TextAsset)AssetDatabase.LoadAssetAtPath("Assets/CD.txt", typeof(TextAsset));

        //Debug.Log (cdtxt.text);
        System.IO.Stream stream = System.IO.File.Open(AssetDatabase.GetAssetPath(cdtxt), System.IO.FileMode.Create);
        System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(CharacterData.CharacterDataSizes));
        xs.Serialize(stream, aData);
        //System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
        //bFormatter.Serialize(stream, aData);
        stream.Close();
        return(cdtxt);
    }
Beispiel #4
0
    static void ConvertTest()
    {
        IEnumerable <Object> folders = Selection.GetFiltered(typeof(Object), SelectionMode.TopLevel).Where(e => is_folder(e));
        Dictionary <Object, IEnumerable <Object> > fileMap = new Dictionary <Object, IEnumerable <Object> >();

        Debug.Log("trying to process " + folders.Count() + " folders");
        foreach (Object e in folders)
        {
            Object checkAgainst = e;
            fileMap[e] = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets).Where <Object>(delegate(Object f) { return(is_asset_in_directory(f, checkAgainst)); });
        }
        Dictionary <Object, IEnumerable <Object> > filteredMap = new Dictionary <Object, IEnumerable <Object> >();

        foreach (KeyValuePair <Object, IEnumerable <Object> > e in fileMap)
        {
            if (is_character(e.Value) || is_mini_character(e.Value))
            {
                filteredMap.Add(e.Key, e.Value);
            }
        }
        Debug.Log("Processing " + filteredMap.Count() + " characters.");
        foreach (KeyValuePair <Object, IEnumerable <Object> > e in filteredMap)
        {
            Debug.Log("processing " + e.Key);
            //Debug.Log(e.Key.name + " " +  AssetDatabase.GetAssetPath(e.Value.First()));
            try{
                CharacterData.CharacterDataSizes cd = create_main_character(e.Key, e.Value);
                //create_mini_character(e.Key, e.Value, cd);
            }
            catch (UnityException f)
            {
                Debug.Log("error processing character " + e.Key);
                throw f;
            }
            Debug.Log("sucssefully processed " + e.Key);
        }
    }
Beispiel #5
0
    static CharacterData.CharacterDataSizes create_main_character(Object aMain, IEnumerable <Object> aObjects)
    {
        string output = "";

        List <Object> valueList = aObjects.ToList();

        CharacterData.CharacterDataSizes cd = new CharacterData.CharacterDataSizes();
        cd.mName = aMain.name;

        //first process <limb>_B images
        IEnumerable <Object> bImages = valueList.Where(f => (sLimbs.Contains(strip_to_root(f)) && is_B_image(f))).OrderBy(f => strip_to_root(f));

        //int[] desiredSizes = new int[]{1,1,1,2,2,1,1,2,2,4,3};
        int[] desiredSizes = new int[] { 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 3 }; //this one has limb ends and head end
        int   counter      = 0;

        foreach (Object f in bImages)
        {
            //Debug.Log ("processing " + f.name);
            Texture2D limbProcessing = f as Texture2D;
            set_texture_for_reading(limbProcessing);
            cd.mMountingPositions.Add(get_limb_positions_in_order(limbProcessing));
            if (desiredSizes[counter] == 2)
            {
                foreach (var e in cd.mMountingPositions.Last())
                {
                    //Debug.Log(e);
                }
            }
            if (desiredSizes[counter] != cd.mMountingPositions.Last().Count)
            {
                Debug.Log("issue with " + f.name + " need " + desiredSizes[counter] + " found " + cd.mMountingPositions.Last().Count);
            }
            counter++;
        }

        //record <limb>_A  image sizes
        IEnumerable <Object> aImages = aObjects.Where(f => (sLimbs.Contains(strip_to_root(f)) && !is_B_image(f))).OrderBy(f => f.name);

        foreach (Object f in aImages)
        {
            Texture2D tex = f as Texture2D;
            set_texture_for_reading(tex);
            cd.mLimbSizes.Add(new Vector2(((Texture2D)f).width, ((Texture2D)f).height));
            set_texture_for_render(tex);
        }

        //parse POSITIONS.png
        try{
            Object    positionImage = valueList.Single(f => strip_to_root(f) == "POSITIONS");
            Texture2D bgProcessing  = positionImage as Texture2D;
            set_texture_for_reading(bgProcessing);
            try{ cd.mOffset = get_character_position(bgProcessing); }
            catch { Debug.Log("no character position found, this must be the sunset bundle"); }


            //EFFECTS
            TextAsset effects;
            try{ effects = valueList.Single(f => strip_to_root(f) == "EFFECTS") as TextAsset; }
            catch { effects = null; }

            //BACKGROUND STUFF
            var staticElts = valueList.Where(
                f => strip_to_root(f).StartsWith("FG") ||
                strip_to_root(f).StartsWith("BG") ||
                strip_to_root(f).StartsWith("CUTSCENE") ||
                strip_to_root(f).StartsWith("GIFT_") ||
                strip_to_root(f).StartsWith("SUNSET_") ||                               //special for sunset, we will read, font, sun, and score label from another bundle
                strip_to_root(f).StartsWith("START_")
                );
            foreach (var e in staticElts)
            {
                Debug.Log(e.name);
            }
            foreach (var img in staticElts)
            {
                CharacterData.ImageSizeOffsetAnimationData isoad = new CharacterData.ImageSizeOffsetAnimationData();
                if (effects != null)
                {
                    isoad.AnimationEffect = find_effect_string(effects, img.name);
                }
                isoad.Name = img.name;
                set_texture_for_reading((Texture2D)img);
                isoad.Size   = new Vector2(((Texture2D)img).width, ((Texture2D)img).height);
                isoad.Offset = find_position(bgProcessing, img.name);
                set_texture_for_render((Texture2D)img);
                cd.mStaticElements.Add(isoad);
            }



            //old background parsing
            IEnumerable <Object> bgImage = valueList.Where(f => strip_to_root(f) == "BACKGROUND");
            foreach (Object f in bgImage)
            {
                set_texture_for_reading((Texture2D)f);
                cd.mBackSize = (new Vector2(((Texture2D)f).width, ((Texture2D)f).height));
            }
            if (bgImage.Count() > 0)
            {
                set_texture_for_render((Texture2D)bgImage.First());
            }
        }catch (UnityException e)
        {
            Debug.Log("problem with POSITIONS, probably mini character " + e.StackTrace);
        }

        //package
        TextAsset            cdtxt   = serialize_cd(cd);
        IEnumerable <Object> package = aObjects.Where(f => !is_B_image(f)).Where(f => strip_to_root(f) != "POSITIONS");//.Where(f => strip_to_root(f) != "AUDIO");
        List <Object>        assets  = new List <Object>();

        foreach (Object f in package)
        {
            assets.Add(f);
        }
        AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(cdtxt));
        cdtxt = (TextAsset)AssetDatabase.LoadAssetAtPath("Assets/CD.txt", typeof(TextAsset));
        assets.Add(cdtxt);
        //Debug.Log(cdtxt.text);
#if UNITY_XBOXONE
        BuildPipeline.BuildAssetBundle(aMain, assets.ToArray(), "Assets/Resources/XB1" + aMain.name + ".unity3d", BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets, EditorUserBuildSettings.activeBuildTarget); //, BuildOptions.UncompressedAssetBundle);//, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets);
#else
        BuildPipeline.BuildAssetBundle(aMain, assets.ToArray(), "Assets/Resources/" + aMain.name + ".unity3d", BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets, EditorUserBuildSettings.activeBuildTarget);    //, BuildOptions.UncompressedAssetBundle);//, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets);
#endif
        //Debug.Log(output);
        return(cd);
    }
Beispiel #6
0
    //TODO DELETE
    //[MenuItem("Custom/Construct Graveyard Bundle")]
    static void Graveyard()
    {
        if (Selection.activeObject.name != "999")
        {
            Debug.Log("graveyard not selected");
            return;
        }
        List <Object> valueList = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets).ToList();

        CharacterData.CharacterDataSizes cd = new CharacterData.CharacterDataSizes();
        cd.mName = Selection.activeObject.name;


        //parse POSITIONS.png
        //TODO special colors here
        Object    positionImage = valueList.Single(f => strip_to_root(f) == "POSITIONS");
        Texture2D bgProcessing  = positionImage as Texture2D;

        set_texture_for_reading(bgProcessing);

        //new parsing
        TextAsset effects;

        try{ effects = valueList.Single(f => strip_to_root(f) == "EFFECTS") as TextAsset; }
        catch { effects = null; }
        var staticElts = valueList.Where(f => strip_to_root(f).StartsWith("FG") || strip_to_root(f).StartsWith("BG") || strip_to_root(f).StartsWith("CUTSCENE"));

        //foreach(var e in staticElts) Debug.Log (e.name);
        foreach (var img in staticElts)
        {
            CharacterData.ImageSizeOffsetAnimationData isoad = new CharacterData.ImageSizeOffsetAnimationData();
            if (effects != null)
            {
                isoad.AnimationEffect = find_effect_string(effects, img.name);
            }
            isoad.Name = img.name;
            set_texture_for_reading((Texture2D)img);
            isoad.Size   = new Vector2(((Texture2D)img).width, ((Texture2D)img).height);
            isoad.Offset = find_position(bgProcessing, img.name);
            set_texture_for_render((Texture2D)img);
            cd.mStaticElements.Add(isoad);
        }

        //old backgronud parsing
        IEnumerable <Object> bgImage = valueList.Where(f => strip_to_root(f) == "BACKGROUND");

        foreach (Object f in bgImage)
        {
            set_texture_for_reading((Texture2D)f);
            cd.mBackSize = (new Vector2(((Texture2D)f).width, ((Texture2D)f).height));
        }
        set_texture_for_render((Texture2D)bgImage.First());

        //set audio to 2D
        foreach (Object f in valueList.Where(g => strip_to_root(g) == "AUDIO"))
        {
            set_audio_for_2D((AudioClip)f);
        }

        //package
        TextAsset            cdtxt   = serialize_cd(cd);
        IEnumerable <Object> package = valueList.Where(f => !is_B_image(f)).Where(f => strip_to_root(f) != "POSITIONS");       //.Where(f => strip_to_root(f) != "AUDIO");
        List <Object>        assets  = new List <Object>();

        foreach (Object f in package)
        {
            assets.Add(f);
        }
        AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(cdtxt));
        cdtxt = (TextAsset)AssetDatabase.LoadAssetAtPath("Assets/CD.txt", typeof(TextAsset));
        assets.Add(cdtxt);
        BuildPipeline.BuildAssetBundle(Selection.activeObject, assets.ToArray(), "Assets/Resources/" + cd.mName + ".unity3d", BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets, EditorUserBuildSettings.activeBuildTarget);        //, BuildOptions.UncompressedAssetBundle);//, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets);
    }
    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);
    }