示例#1
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);
                }
            }
        }
    }
示例#2
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);
            }
        }
    }