Exemplo n.º 1
0
/*	public void AutoLoadSelf (){
 *              DKUMASaveTool umaSaveTool = this;
 *              GameObject gameObject = (GameObject)umaSaveTool.gameObject;
 *              DKUMAData umaData = gameObject.GetComponent("DKUMAData") as DKUMAData;
 *              umaData.Loading = true;
 *
 *              DKUMAData.UMARecipe umaRecipe = new DKUMAData.UMARecipe();
 *              DKUMAData.UMAPackRecipe umaPackRecipe = new DKUMAData.UMAPackRecipe();
 *
 *      //	streamedUMA = System.IO.File.ReadAllText(path);
 *              streamedUMA = umaData.streamedUMA;
 *
 *              umaPackRecipe = JsonMapper.ToObject<DKUMAData.UMAPackRecipe>(streamedUMA);
 *
 *
 *      //	foreach ( DKRaceData _Race in umaData.raceLibrary.raceElementList ){
 *      //		if ( _Race.raceName == umaPackRecipe.race )
 *      //			umaRecipe.raceData =  _Race;
 *      //	}
 *
 *
 *              umaRecipe.raceData =  umaData.umaRecipe.raceData;
 *
 *              // 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 = umaData.transform.parent.name;
 *              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);
 *
 *      }
 */

    #region Old AutoLoadSelf ()
    public void AutoLoadSelf()
    {
        GameObject DKUMAGeneratorObj = GameObject.Find("DKUMAGenerator");

        if (DKUMAGeneratorObj != null)
        {
            _DKUMAGenerator = DKUMAGeneratorObj.GetComponent <DKUMAGenerator>();
        }

        DKUMAData umaData = gameObject.GetComponent("DKUMAData") as DKUMAData;

        if (umaData.transform.parent &&
            umaData.transform.parent.name.Contains("(Clone)") == false)
        {
            umaData.Loading = true;
            if (umaData)
            {
                umaData.LoadFromMemoryStream();

                for (int i = 0; i < _DKUMAGenerator.umaDirtyList.Count; i++)
                {
                    if (_DKUMAGenerator.umaDirtyList[i] == null)
                    {
                        _DKUMAGenerator.umaDirtyList.Remove(_DKUMAGenerator.umaDirtyList[i]);
                    }
                }

                _DKUMAGenerator.Awake();
                umaData.dirty = false;
                umaData.Dirty(true, true, true);

                umaData.myRenderer.enabled = false;

                //		Debug.Log ( "AutoLoadSelf");
            }
        }
    }
Exemplo n.º 2
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();
        }
    }