Beispiel #1
0
    public static System.String SaveInstance(DKUMADna instance)
    {
        System.Type dnaType = instance.GetType();
        if (dnaType == typeof(DKUMADnaHumanoid))
        {
            return(DKUMADnaHumanoid.SaveInstance(instance as DKUMADnaHumanoid));
        }

        return(null);
    }
Beispiel #2
0
    public void LoadFromWin()
    {
        DKUMASaveTool umaSaveTool = (DKUMASaveTool)target;
        GameObject    gameObject  = (GameObject)umaSaveTool.gameObject;
        DKUMAData     umaData     = gameObject.GetComponent("DKUMAData") as DKUMAData;

        umaData.Loading = true;

        if (umaData)
        {
            var path = EditorUtility.OpenFilePanel("Load serialized Avatar", "", "txt");
            if (path.Length != 0)
            {
                DKUMAData.UMARecipe     umaRecipe     = new DKUMAData.UMARecipe();
                DKUMAData.UMAPackRecipe umaPackRecipe = new DKUMAData.UMAPackRecipe();

                streamedUMA   = System.IO.File.ReadAllText(path);
                umaPackRecipe = JsonMapper.ToObject <DKUMAData.UMAPackRecipe>(streamedUMA);
                foreach (DKRaceData _Race in umaData.raceLibrary.raceElementList)
                {
                    if (_Race.raceName == umaPackRecipe.race)
                    {
                        umaRecipe.raceData = _Race;
                    }
                }

                // New
                Transform tempUMA = (Instantiate(umaRecipe.raceData.racePrefab, umaData.transform.position, umaData.transform.rotation) as GameObject).transform;
                Debug.Log("Creating ... " + tempUMA);
                DKUMAData newUMA = tempUMA.gameObject.GetComponentInChildren <DKUMAData>();
                newUMA.umaRecipe   = umaRecipe;
                newUMA.streamedUMA = streamedUMA;
                DKUMADnaHumanoid            _UMADnaHumanoid = new DKUMADnaHumanoid();
                Dictionary <Type, DKUMADna> umaDna          = new Dictionary <Type, DKUMADna>();

                newUMA.umaPackRecipe = umaPackRecipe;

                // DNA
                // load DK_UMAdnaHumanoid
                newUMA.umaRecipe.umaDna.Clear();
                for (int dna = 0; dna < newUMA.umaPackRecipe.packedDna.Count; dna++)
                {
                    Type dnaType = DKUMADna.GetType(newUMA.umaPackRecipe.packedDna[dna].dnaType);
                    newUMA.umaRecipe.umaDna.Add(dnaType, DKUMADna.LoadInstance(dnaType, umaPackRecipe.packedDna[dna].packedDna));
                    umaDna = newUMA.umaRecipe.umaDna;
                }

                // Modifyers
                for (int i = 0; i < umaRecipe.raceData.DNAConverterDataList.Count; i++)
                {
                    // create new DK DNA
                    DKRaceData.DNAConverterData _newDNA = new DKRaceData.DNAConverterData();

                    // add to DK_UMAdnaHumanoid
                    DKUMADna temp = null;
                    if (umaDna.TryGetValue(_UMADnaHumanoid.GetType(), out temp))
                    {
                        Debug.Log("success : " + umaDna[_UMADnaHumanoid.GetType()].Values.GetValue(i).ToString());

                        // there it is, apply the value to the modifyer
                        DNAValue = float.Parse(umaDna[_UMADnaHumanoid.GetType()].Values.GetValue(i).ToString());
                    }

                    _newDNA.Name  = umaRecipe.raceData.DNAConverterDataList[i].Name;
                    _newDNA.Value = DNAValue;
                    _newDNA.Part  = umaRecipe.raceData.DNAConverterDataList[i].Part;
                    _newDNA.Part2 = umaRecipe.raceData.DNAConverterDataList[i].Part2;
                    newUMA.DNAList2.Add(_newDNA);
                }
                newUMA.LoadFromMemoryStream();
                newUMA.Awaking();
                newUMA.atlasResolutionScale = umaData.atlasResolutionScale;
                newUMA.Dirty(true, true, true);
                newUMA.transform.parent.gameObject.name = avatarName.stringValue;
                newUMA.transform.parent = umaData.transform.parent;

                serializedObject.ApplyModifiedProperties();

                // Finshing by destroying the previous model
                                #if UNITY_EDITOR
                DestroyImmediate(umaData.transform.gameObject);
                                #endif
                if (Application.isPlaying)
                {
                    Destroy(umaData.transform.gameObject);
                }
            }
        }
    }
Beispiel #3
0
    public void LoadFromString(DKUMAData _DKUMAData, string IncStreamedUMA)
    {
//		Debug.Log ("LoadFromString Start ");
        //	streamedUMA = IncStreamedUMA;

        DKUMAData umaData = _DKUMAData;

        umaData.Loading = true;

        if (umaData)
        {
            DKUMAData.UMARecipe     umaRecipe     = new DKUMAData.UMARecipe();
            DKUMAData.UMAPackRecipe umaPackRecipe = new DKUMAData.UMAPackRecipe();
            DK_UMACrowd             _DK_UMACrowd  = GameObject.Find("DKUMACrowd").GetComponent <DK_UMACrowd>();

            umaPackRecipe = JsonMapper.ToObject <DKUMAData.UMAPackRecipe>(IncStreamedUMA);
            foreach (DKRaceData _Race in _DK_UMACrowd.raceLibrary.raceElementList)
            {
                if (_Race.raceName == umaPackRecipe.race)
                {
                    umaRecipe.raceData = _Race;
                    //		Debug.Log ("Race Loaded "+umaPackRecipe.race);
                }
            }

            // New
            DKUMADnaHumanoid            _UMADnaHumanoid = new DKUMADnaHumanoid();
            Dictionary <Type, DKUMADna> umaDna          = new Dictionary <Type, DKUMADna>();

            // DNA
            // load DK_UMAdnaHumanoid
            for (int dna = 0; dna < umaPackRecipe.packedDna.Count; dna++)
            {
                Type dnaType = DKUMADna.GetType(umaPackRecipe.packedDna[dna].dnaType);
                if (dna != 0 && dnaType != null)
                {
                    umaRecipe.umaDna.Add(dnaType, DKUMADna.LoadInstance(dnaType, umaPackRecipe.packedDna[dna].packedDna));
                }
                umaDna = umaRecipe.umaDna;
            }

            Transform tempUMA = (Instantiate(umaRecipe.raceData.racePrefab, umaData.transform.position, umaData.transform.rotation) as GameObject).transform;
            DKUMAData newUMA  = tempUMA.gameObject.GetComponentInChildren <DKUMAData>();
            newUMA.umaRecipe     = umaRecipe;
            newUMA.umaPackRecipe = umaPackRecipe;
            newUMA.streamedUMA   = IncStreamedUMA;

            // Modifyers
            for (int i = 0; i < umaRecipe.raceData.DNAConverterDataList.Count; i++)
            {
                // create new DK DNA
                DKRaceData.DNAConverterData _newDNA = new DKRaceData.DNAConverterData();

                // add to DK_UMAdnaHumanoid
                DKUMADna temp = null;
                if (umaDna.TryGetValue(_UMADnaHumanoid.GetType(), out temp))
                {
                    // there it is, apply the value to the modifyer
                    DNAValue = float.Parse(umaDna[_UMADnaHumanoid.GetType()].Values.GetValue(i).ToString());
                    if (DNAValue == 0)
                    {
                        DNAValue = 0.5f;
                    }
                }

                _newDNA.Name  = umaRecipe.raceData.DNAConverterDataList[i].Name;
                _newDNA.Value = DNAValue;
                _newDNA.Part  = umaRecipe.raceData.DNAConverterDataList[i].Part;
                _newDNA.Part2 = umaRecipe.raceData.DNAConverterDataList[i].Part2;
                newUMA.DNAList2.Add(_newDNA);
            }
            newUMA.LoadFromMemoryStream();
            newUMA.Dirty(true, true, true);
            Transform Parent = umaData.transform.parent;
            newUMA.transform.parent = Parent;
            Transform ZeroPoint = _DK_UMACrowd.zeroPoint;
            if (ZeroPoint != null)
            {
                //	tempUMA.transform.position = _DK_UMACrowd.zeroPoint.transform.position;
                Parent.transform.position = _DK_UMACrowd.zeroPoint.transform.position;
            }
            else
            {
                ZeroPoint = GameObject.Find("ZeroPoint").transform;
                //	tempUMA.transform.position = ZeroPoint.transform.position;
                Parent.transform.position = ZeroPoint.transform.position;
            }
            //	tempUMA.transform.position = Parent.position;
            //	Parent.name = Selection.activeGameObject.GetComponentInParent(UMA.UMAData).transform.parent.name;
            NewAvatarGo = Parent.gameObject;


            // Finishing by destroying the previous model
                        #if UNITY_EDITOR
            //	DestroyImmediate(umaData.transform.parent.gameObject);
            DestroyImmediate(umaData.transform.gameObject);
                        #endif
            //	if (  Application.isPlaying && umaData ) Destroy(umaData.transform.parent.gameObject);
            if (Application.isPlaying && umaData)
            {
                Destroy(umaData.transform.gameObject);
            }
        }
    }
Beispiel #4
0
    public virtual void UnpackRecipe()
    {
        //	Debug.Log ("UnpackRecipe");
        DetectAll();

        if (umaPackRecipe == null)
        {
            Debug.LogError("PackRecipe is null");
        }
        else
        {
            umaRecipe.slotDataList = new DKSlotData[umaPackRecipe.packedSlotDataList.Length];
        }
        raceLibrary.Awake();
        slotLibrary.Awake();
        overlayLibrary.Awake();
        DKumaGenerator.Awake();

        // Race
        try{
            umaRecipe.SetRace(raceLibrary.GetRace(umaPackRecipe.race));
        }catch (NullReferenceException) { Debug.LogError("Element Pack Recipe to survey : No race found"); }
        //	Debug.Log("Packed race found");

        // DNA
        umaRecipe.umaDna.Clear();
        for (int dna = 0; dna < umaPackRecipe.packedDna.Count; dna++)
        {
            //	Debug.Log ( "DNAList :"+ umaPackRecipe.packedDna.Count.ToString());
            Type dnaType = DKUMADna.GetType(umaPackRecipe.packedDna[dna].dnaType);
            try{
                umaRecipe.umaDna.Add(dnaType, DKUMADna.LoadInstance(dnaType, umaPackRecipe.packedDna[dna].packedDna));
                //	Debug.Log("DNA count :"+umaRecipe.umaDna.Count+" ("+dnaType.ToString()+")" );
                //	Debug.Log("Packed DNA :"+umaPackRecipe.packedDna[dna].packedDna );
            }
            catch (ArgumentNullException) {
                Debug.Log("DNA Error: Skipping DNA element (ArgumentNullException: Argument cannot be null. Parameter name: key)");
            }
        }

        // Slot
        for (int i = 0; i < umaPackRecipe.packedSlotDataList.Length; i++)
        {
            if (umaPackRecipe.packedSlotDataList[i] != null && umaPackRecipe.packedSlotDataList[i].sID != null)
            {
                DKSlotData tempSlotData = DKSlotData.CreateInstance <DKSlotData>();
                tempSlotData = slotLibrary.InstantiateSlot(umaPackRecipe.packedSlotDataList[i].sID);
                tempSlotData.overlayScale = umaPackRecipe.packedSlotDataList[i].oS * 0.01f;
                umaRecipe.slotDataList[i] = tempSlotData;

                if (umaPackRecipe.packedSlotDataList[i].cOI == -1)
                {
                    for (int overlay = 0; overlay < umaPackRecipe.packedSlotDataList[i].ODL.Length; overlay++)
                    {
                        Color tempColor;
                        Rect  tempRect;

                        if (umaPackRecipe.packedSlotDataList[i].ODL[overlay].cL != null)
                        {
                            tempColor = new Color(umaPackRecipe.packedSlotDataList[i].ODL[overlay].cL[0] / 255.0f, umaPackRecipe.packedSlotDataList[i].ODL[overlay].cL[1] / 255.0f, umaPackRecipe.packedSlotDataList[i].ODL[overlay].cL[2] / 255.0f, umaPackRecipe.packedSlotDataList[i].ODL[overlay].cL[3] / 255.0f);
                        }
                        else
                        {
                            tempColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
                        }

                        if (umaPackRecipe.packedSlotDataList[i].ODL[overlay].rL != null)
                        {
                            tempRect = new Rect(umaPackRecipe.packedSlotDataList[i].ODL[overlay].rL[0], umaPackRecipe.packedSlotDataList[i].ODL[overlay].rL[1], umaPackRecipe.packedSlotDataList[i].ODL[overlay].rL[2], umaPackRecipe.packedSlotDataList[i].ODL[overlay].rL[3]);
                        }
                        else
                        {
                            tempRect = new Rect(0, 0, 0, 0);
                        }
                        bool AlreadyIn;
                        AlreadyIn = false;

                        for (int i1 = 0; i1 < tempSlotData.overlayList.Count; i1++)
                        {
                            if (tempSlotData.overlayList[i1].overlayName == umaPackRecipe.packedSlotDataList[i].ODL[overlay].oID)
                            {
                                AlreadyIn = true;
                                iTmp      = i1;
                                //	tempSlotData.overlayList.Remove(tempSlotData.overlayList[i1]);
                            }
                        }
                        tempSlotData.overlayList.Add(overlayLibrary.InstantiateOverlay(umaPackRecipe.packedSlotDataList[i].ODL[overlay].oID));
                        tempSlotData.overlayList[tempSlotData.overlayList.Count - 1].color = tempColor;
                        tempSlotData.overlayList[tempSlotData.overlayList.Count - 1].rect  = tempRect;
                        if (AlreadyIn == true)
                        {
                            tempSlotData.overlayList.Remove(tempSlotData.overlayList[iTmp]);
                            AlreadyIn = false;
                        }
                        if (umaPackRecipe.packedSlotDataList[i].ODL[overlay].cML != null)
                        {
                            for (int channelAdjust = 0; channelAdjust < umaPackRecipe.packedSlotDataList[i].ODL[overlay].cML.Length; channelAdjust++)
                            {
                                packedOverlayData tempData = umaPackRecipe.packedSlotDataList[i].ODL[overlay];
                                tempSlotData.overlayList[tempSlotData.overlayList.Count - 1].SetColor(channelAdjust, new Color32((byte)tempData.cML[channelAdjust][0],
                                                                                                                                 (byte)tempData.cML[channelAdjust][1],
                                                                                                                                 (byte)tempData.cML[channelAdjust][2],
                                                                                                                                 (byte)tempData.cML[channelAdjust][3]));
                            }
                        }

                        if (umaPackRecipe.packedSlotDataList[i].ODL[overlay].cAML != null)
                        {
                            for (int channelAdjust = 0; channelAdjust < umaPackRecipe.packedSlotDataList[i].ODL[overlay].cAML.Length; channelAdjust++)
                            {
                                packedOverlayData tempData = umaPackRecipe.packedSlotDataList[i].ODL[overlay];
                                tempSlotData.overlayList[tempSlotData.overlayList.Count - 1].SetAdditive(channelAdjust, new Color32((byte)tempData.cAML[channelAdjust][0],
                                                                                                                                    (byte)tempData.cAML[channelAdjust][1],
                                                                                                                                    (byte)tempData.cAML[channelAdjust][2],
                                                                                                                                    (byte)tempData.cAML[channelAdjust][3]));
                            }
                        }
                    }
                }
                else
                {
                    tempSlotData.overlayList = umaRecipe.slotDataList[umaPackRecipe.packedSlotDataList[i].cOI].overlayList;
                }
            }
        }
        //	Debug.Log("Packed slots list :"+umaPackRecipe.packedSlotDataList.Length.ToString() );
        if (gameObject.GetComponent <DK_RPG_UMA>() == null)
        {
            isShapeDirty   = true;
            isTextureDirty = true;
            isMeshDirty    = true;
            Dirty();
        }
    }
Beispiel #5
0
    public virtual void PackRecipe()
    {
        umaPackRecipe.packedSlotDataList = new packedSlotData[umaRecipe.slotDataList.Length];
        umaPackRecipe.race = umaRecipe.raceData.raceName;
        //	Debug.Log ( " Autosaving 5 (Race) : "+umaPackRecipe.race );
        // DNA
        umaPackRecipe.packedDna.Clear();
        foreach (var dna in umaRecipe.umaDna.Values)
        {
            //	Debug.Log ( " Autosaving 6 "+dna.Names[1].ToString()+" / "/*+dna.Values[0].ToString()*/);
            // UMA
            UMAPackedDna packedDna = new UMAPackedDna();
            packedDna.dnaType = dna.GetType().Name;

            packedDna.packedDna = DKUMADna.SaveInstance(dna);

            umaPackRecipe.packedDna.Add(packedDna);
        }


        // DK UMA

/*		DK_UMAPackedDna DK_packedDna = new DK_UMAPackedDna();
 *              DK_packedDna.dnaType = "Modifyers";
 *              DK_packedDna.tmpDNAList = DNAList2;
 *              //	DK_packedDna.packedDna = UMADna.SaveInstance(dna);
 *              umaPackRecipe.DKpackedDna = DK_packedDna;
 *              //	Debug.Log ( DK_packedDna.dnaType );
 *
 *              foreach (var dna in DNAList2) {
 *                      string _value = dna.Value.ToString ("f3");
 *                      dna.Value = float.Parse (_value);
 *              }
 */
        // Slots
        for (int i = 0; i < umaRecipe.slotDataList.Length; i++)
        {
            if (umaRecipe.slotDataList[i] != null)
            {
                if (umaRecipe.slotDataList[i].listID != -1 && umaPackRecipe.packedSlotDataList[i] == null)
                {
                    packedSlotData tempPackedSlotData;

                    tempPackedSlotData = new packedSlotData();

                    tempPackedSlotData.sID = umaRecipe.slotDataList[i].slotName;
                    tempPackedSlotData.oS  = Mathf.FloorToInt(umaRecipe.slotDataList[i].overlayScale * 100);
                    tempPackedSlotData.ODL = new DKUMAData.packedOverlayData[umaRecipe.slotDataList[i].overlayList.Count];

                    for (int oID = 0; oID < tempPackedSlotData.ODL.Length; oID++)
                    {
                        tempPackedSlotData.ODL[oID]     = new packedOverlayData();
                        tempPackedSlotData.ODL[oID].oID = umaRecipe.slotDataList[i].overlayList[oID].overlayName;

                        if (umaRecipe.slotDataList[i].overlayList[oID].color != new Color(1.0f, 1.0f, 1.0f, 1.0f))
                        {
                            //Color32 instead of Color?
                            tempPackedSlotData.ODL[oID].cL    = new int[4];
                            tempPackedSlotData.ODL[oID].cL[0] = Mathf.FloorToInt(umaRecipe.slotDataList[i].overlayList[oID].color.r * 255.0f);
                            tempPackedSlotData.ODL[oID].cL[1] = Mathf.FloorToInt(umaRecipe.slotDataList[i].overlayList[oID].color.g * 255.0f);
                            tempPackedSlotData.ODL[oID].cL[2] = Mathf.FloorToInt(umaRecipe.slotDataList[i].overlayList[oID].color.b * 255.0f);
                            tempPackedSlotData.ODL[oID].cL[3] = Mathf.FloorToInt(umaRecipe.slotDataList[i].overlayList[oID].color.a * 255.0f);
                        }

                        if (umaRecipe.slotDataList[i].overlayList[oID].rect != new Rect(0, 0, 0, 0))
                        {
                            //Might need float in next version
                            tempPackedSlotData.ODL[oID].rL    = new int[4];
                            tempPackedSlotData.ODL[oID].rL[0] = (int)umaRecipe.slotDataList[i].overlayList[oID].rect.x;
                            tempPackedSlotData.ODL[oID].rL[1] = (int)umaRecipe.slotDataList[i].overlayList[oID].rect.y;
                            tempPackedSlotData.ODL[oID].rL[2] = (int)umaRecipe.slotDataList[i].overlayList[oID].rect.width;
                            tempPackedSlotData.ODL[oID].rL[3] = (int)umaRecipe.slotDataList[i].overlayList[oID].rect.height;
                        }

                        if (umaRecipe.slotDataList[i].overlayList[oID].channelMask != null)
                        {
                            tempPackedSlotData.ODL[oID].cML = new int[umaRecipe.slotDataList[i].overlayList[oID].channelMask.Length][];

                            for (int channelAdjust = 0; channelAdjust < umaRecipe.slotDataList[i].overlayList[oID].channelMask.Length; channelAdjust++)
                            {
                                tempPackedSlotData.ODL[oID].cML[channelAdjust]    = new int[4];
                                tempPackedSlotData.ODL[oID].cML[channelAdjust][0] = umaRecipe.slotDataList[i].overlayList[oID].channelMask[channelAdjust].r;
                                tempPackedSlotData.ODL[oID].cML[channelAdjust][1] = umaRecipe.slotDataList[i].overlayList[oID].channelMask[channelAdjust].g;
                                tempPackedSlotData.ODL[oID].cML[channelAdjust][2] = umaRecipe.slotDataList[i].overlayList[oID].channelMask[channelAdjust].b;
                                tempPackedSlotData.ODL[oID].cML[channelAdjust][3] = umaRecipe.slotDataList[i].overlayList[oID].channelMask[channelAdjust].a;
                            }
                        }
                        if (umaRecipe.slotDataList[i].overlayList[oID].channelAdditiveMask != null)
                        {
                            tempPackedSlotData.ODL[oID].cAML = new int[umaRecipe.slotDataList[i].overlayList[oID].channelAdditiveMask.Length][];
                            for (int channelAdjust = 0; channelAdjust < umaRecipe.slotDataList[i].overlayList[oID].channelAdditiveMask.Length; channelAdjust++)
                            {
                                tempPackedSlotData.ODL[oID].cAML[channelAdjust]    = new int[4];
                                tempPackedSlotData.ODL[oID].cAML[channelAdjust][0] = umaRecipe.slotDataList[i].overlayList[oID].channelAdditiveMask[channelAdjust].r;
                                tempPackedSlotData.ODL[oID].cAML[channelAdjust][1] = umaRecipe.slotDataList[i].overlayList[oID].channelAdditiveMask[channelAdjust].g;
                                tempPackedSlotData.ODL[oID].cAML[channelAdjust][2] = umaRecipe.slotDataList[i].overlayList[oID].channelAdditiveMask[channelAdjust].b;
                                tempPackedSlotData.ODL[oID].cAML[channelAdjust][3] = umaRecipe.slotDataList[i].overlayList[oID].channelAdditiveMask[channelAdjust].a;
                            }
                        }
                    }

                    umaPackRecipe.packedSlotDataList[i] = tempPackedSlotData;

                    //Shared overlays wont generate duplicated data
                    for (int i2 = i + 1; i2 < umaRecipe.slotDataList.Length; i2++)
                    {
                        if (umaRecipe.slotDataList[i2] != null)
                        {
                            if (umaPackRecipe.packedSlotDataList[i2] == null)
                            {
                                if (umaRecipe.slotDataList[i].overlayList == umaRecipe.slotDataList[i2].overlayList)
                                {
                                    tempPackedSlotData     = new packedSlotData();
                                    tempPackedSlotData.sID = umaRecipe.slotDataList[i2].slotName;
                                    tempPackedSlotData.cOI = i;
                                    //umaPackRecipe.packedSlotDataList[i2] = tempPackedSlotData;
                                }
                            }
                        }
                    }
                }
            }
        }
    }