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); } } }
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); } } } }
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(); } }