예제 #1
0
        public async Task <JsonResult> Save(UMAModel uma)
        {
            var u = new UMA
            {
                ValidityDate = uma.InitialDate,
                Value        = uma.Value,
                ID           = Guid.NewGuid(),
                Active       = true,
                Timestamp    = DateTime.UtcNow,
                Description  = "Some Fee",
                CreationDate = DateTime.Now,
                Name         = "Nominas fee",
                StatusID     = 1,
                user         = SessionModel.IdentityID,
                company      = SessionModel.CompanyID,
                InstanceID   = SessionModel.InstanceID,
            };

            if (!uma.ID.HasValue)
            {
                u.ID = Guid.NewGuid();
                await client.CreateAsync(new List <UMA>() { u }, SessionModel.CompanyID);
            }
            else
            {
                u.ID = uma.ID.Value;
                await client.UpdateAsync(new List <UMA>() { u }, SessionModel.CompanyID);
            }

            return(Json(u.ID));
        }
예제 #2
0
		public void SlotAtlasEvent(UMA.UMAData umaData, UMA.SlotData slotData, Material material, Rect atlasRect)
		{
			var overlay = slotData.GetOverlay(0);
			if (overlay != null)
			{
				material.color = overlay.colorData.color;
			}
		}
예제 #3
0
	public void CharacterUpdated(UMA.UMAData umaData)
	{
		var sb = new StringBuilder();
		sb.AppendFormat("Vertices {0} Bones {1}\n", umaData.myRenderer.sharedMesh.vertexCount, umaData.myRenderer.bones.Length);
		
		foreach (var mat in umaData.myRenderer.sharedMaterials)
		{
			sb.AppendFormat("{0} {1}x{2}\n", mat.name, mat.mainTexture.width, mat.mainTexture.height);
		}
		GetComponent<UnityEngine.UI.Text>().text = sb.ToString();
	}
예제 #4
0
		public void OnCharacterUpdate(UMA.UMAData data)
		{
			foreach (var componentName in removeComponentNames)
			{
				var component = data.animator.GetComponent(componentName);
				Destroy(component);
			}
			foreach (var componentName in disableComponentNames)
			{
				var behavior = (data.animator.GetComponent(componentName) as Behaviour);
				if (behavior != null) behavior.enabled = false;
			}
		}
예제 #5
0
	void umaData_OnCharacterUpdated(UMA.UMAData obj)
	{
		var bc = obj.myRenderer.GetComponent<BoxCollider>();
		if (bc != null)
		{
			var mesh = new Mesh();
			obj.myRenderer.BakeMesh(mesh);
			mesh.RecalculateBounds();
			bc.center = mesh.bounds.center;
			bc.size = mesh.bounds.size;
			var posi = obj.myRenderer.transform.parent.localPosition;
			//posi.y = -mesh.bounds.min.y;
			obj.myRenderer.transform.parent.localPosition = posi;
		}
	}
예제 #6
0
	/// <summary>
	/// Load data into the specified UMA recipe.
	/// </summary>
	/// <param name="umaRecipe">UMA recipe.</param>
	/// <param name="context">Context.</param>
	public override void Load(UMA.UMAData.UMARecipe umaRecipe, UMAContext context)
	{
		var packedRecipe = PackedLoad(context);
		switch (packedRecipe.version)
		{
			case 2:
				UnpackRecipeVersion2(umaRecipe, packedRecipe, context);
				break;

			case 1:
			default:
				if (UnpackRecipeVersion1 (umaRecipe, packedRecipe, context)) 
				{
					umaRecipe.MergeMatchingOverlays ();
				}
				break;
		}
	}
예제 #7
0
    protected override UMACrowdRandomSet.CrowdRaceData SetGeneratedUMARace(UMA.UMAData.UMARecipe umaRecipe)
    {
        if (this.bodyTypeCycler != null)
        {
            RACBodyType bodyTypeOfCrowd = this.bodyTypeCycler.GetCurrentlySelectedBodyType();

            if (bodyTypeOfCrowd.isFemale)
                umaRecipe.SetRace(raceLibrary.GetRace("RACHumanFemale"));
            else
                umaRecipe.SetRace(raceLibrary.GetRace("HumanMale"));

            this.customization.InstanciateNewSliders(bodyTypeOfCrowd.ControlList);

            return null;
        }
        else
        {
            return base.SetGeneratedUMARace(umaRecipe);
        }
    }
예제 #8
0
 /// <summary>
 /// Save data from the specified UMA recipe.
 /// </summary>
 /// <param name="umaRecipe">UMA recipe.</param>
 /// <param name="context">Context.</param>
 public override void Save(UMA.UMAData.UMARecipe umaRecipe, UMAContext context)
 {
     umaRecipe.MergeMatchingOverlays();
     var packedRecipe = PackRecipeV2(umaRecipe);
     PackedSave(packedRecipe, context);
 }
예제 #9
0
    public static void UnpackRecipeVersion2(UMA.UMAData.UMARecipe umaRecipe, UMAPackRecipe umaPackRecipe, UMAContext context)
    {
        umaRecipe.slotDataList = new SlotData[umaPackRecipe.slotsV2.Length];
        umaRecipe.additionalSlotCount = 0;
        umaRecipe.SetRace(context.GetRace(umaPackRecipe.race));

        umaRecipe.ClearDna();
        for (int dna = 0; dna < umaPackRecipe.packedDna.Count; dna++)
        {
            Type dnaType = UMADna.GetType(umaPackRecipe.packedDna[dna].dnaType);
            umaRecipe.AddDna(UMADna.LoadInstance(dnaType, umaPackRecipe.packedDna[dna].packedDna));
        }

        OverlayColorData[] colorData;
        if ((umaPackRecipe.fColors != null) && (umaPackRecipe.fColors.Length > 0))
        {
            colorData = new OverlayColorData[umaPackRecipe.fColors.Length];
            for (int i = 0; i < colorData.Length; i++)
            {
                colorData[i] = new OverlayColorData();
                umaPackRecipe.fColors[i].SetOverlayColorData(colorData[i]);
            }
        }
        else if ((umaPackRecipe.colors != null) && (umaPackRecipe.colors.Length > 0))
        {
            colorData = new OverlayColorData[umaPackRecipe.colors.Length];
            for (int i = 0; i < colorData.Length; i++)
            {
                colorData[i] = new OverlayColorData();
                umaPackRecipe.colors[i].SetOverlayColorData(colorData[i]);
            }
        }
        else {
            colorData = new OverlayColorData[0];
        }

        umaRecipe.sharedColors = new OverlayColorData[umaPackRecipe.sharedColorCount];
        for (int i = 0; i < umaRecipe.sharedColors.Length; i++)
        {
            umaRecipe.sharedColors[i] = colorData[i];
        }

        for (int i = 0; i < umaPackRecipe.slotsV2.Length; i++)
        {
            PackedSlotDataV2 packedSlot = umaPackRecipe.slotsV2[i];
            if (packedSlot != null && packedSlot.id != null)
            {
                var tempSlotData = context.InstantiateSlot(packedSlot.id);
                tempSlotData.overlayScale = packedSlot.scale * 0.01f;
                umaRecipe.slotDataList[i] = tempSlotData;

                if (packedSlot.copyIdx == -1)
                {
                    for (int i2 = 0; i2 < packedSlot.overlays.Length; i2++)
                    {
                        PackedOverlayDataV2 packedOverlay = packedSlot.overlays[i2];
                        OverlayData overlayData = context.InstantiateOverlay(packedOverlay.id);
                        overlayData.rect = new Rect(packedOverlay.rect[0],
                                                    packedOverlay.rect[1],
                                                    packedOverlay.rect[2],
                                                    packedOverlay.rect[3]);
                        if (packedOverlay.colorIdx < umaPackRecipe.sharedColorCount)
                        {
                            overlayData.colorData = umaRecipe.sharedColors[packedOverlay.colorIdx];
                        }
                        else
                        {
                            overlayData.colorData = colorData[packedOverlay.colorIdx];
                        }
                        overlayData.EnsureChannels(overlayData.asset.material.channels.Length);
                        tempSlotData.AddOverlay(overlayData);
                    }
                }
                else
                {
                    tempSlotData.SetOverlayList(umaRecipe.slotDataList[packedSlot.copyIdx].GetOverlayList());
                }
            }
        }
    }
예제 #10
0
    public static bool UnpackRecipeVersion1(UMA.UMAData.UMARecipe umaRecipe, UMAPackRecipe umaPackRecipe, UMAContext context)
    {
        if (umaPackRecipe.packedSlotDataList == null)
            return false;

        umaRecipe.slotDataList = new SlotData[umaPackRecipe.packedSlotDataList.Length];
        umaRecipe.additionalSlotCount = 0;
        umaRecipe.SetRace(context.GetRace(umaPackRecipe.race));

        umaRecipe.ClearDna();
        for (int dna = 0; dna < umaPackRecipe.packedDna.Count; dna++)
        {
            Type dnaType = UMADna.GetType(umaPackRecipe.packedDna[dna].dnaType);
            umaRecipe.AddDna(UMADna.LoadInstance(dnaType, umaPackRecipe.packedDna[dna].packedDna));
        }

        for (int i = 0; i < umaPackRecipe.packedSlotDataList.Length; i++)
        {
            if (umaPackRecipe.packedSlotDataList[i] != null && umaPackRecipe.packedSlotDataList[i].slotID != null)
            {
                var tempSlotData = context.InstantiateSlot(umaPackRecipe.packedSlotDataList[i].slotID);
                tempSlotData.overlayScale = umaPackRecipe.packedSlotDataList[i].overlayScale * 0.01f;
                umaRecipe.slotDataList[i] = tempSlotData;

                if (umaPackRecipe.packedSlotDataList[i].copyOverlayIndex == -1)
                {

                    for (int overlay = 0; overlay < umaPackRecipe.packedSlotDataList[i].OverlayDataList.Length; overlay++)
                    {
                        Color tempColor;
                        Rect tempRect;

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

                        if (umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].rectList != null)
                        {
                            Rect originalRect = context.InstantiateOverlay(umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].overlayID).rect;
                            tempRect = new Rect(umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].rectList[0], umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].rectList[1], umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].rectList[2], umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].rectList[3]);

                            Vector2 aspectRatio = new Vector2(tempRect.width/originalRect.width,tempRect.height/originalRect.height);

                            tempRect = new Rect(tempRect.x/aspectRatio.x,tempRect.y/aspectRatio.y,tempRect.width/aspectRatio.x,tempRect.height/aspectRatio.y);

                        }
                        else
                        {
                            tempRect = new Rect(0, 0, 0, 0);
                        }

                        tempSlotData.AddOverlay(context.InstantiateOverlay(umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].overlayID));
                        tempSlotData.GetOverlay(tempSlotData.OverlayCount - 1).colorData.color = tempColor;
                        tempSlotData.GetOverlay(tempSlotData.OverlayCount - 1).rect = tempRect;

                        if (umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].channelMaskList != null)
                        {
                            for (int channelAdjust = 0; channelAdjust < umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].channelMaskList.Length; channelAdjust++)
                            {
                                packedOverlayData tempData = umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay];
                                tempSlotData.GetOverlay(tempSlotData.OverlayCount - 1).SetColor(channelAdjust, new Color32((byte)tempData.channelMaskList[channelAdjust][0],
                                                                                                                           (byte)tempData.channelMaskList[channelAdjust][1],
                                                                                                                           (byte)tempData.channelMaskList[channelAdjust][2],
                                                                                                                           (byte)tempData.channelMaskList[channelAdjust][3]));
                            }
                        }

                        if (umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].channelAdditiveMaskList != null)
                        {
                            for (int channelAdjust = 0; channelAdjust < umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay].channelAdditiveMaskList.Length; channelAdjust++)
                            {
                                packedOverlayData tempData = umaPackRecipe.packedSlotDataList[i].OverlayDataList[overlay];
                                tempSlotData.GetOverlay(tempSlotData.OverlayCount - 1).SetAdditive(channelAdjust, new Color32((byte)tempData.channelAdditiveMaskList[channelAdjust][0],
                                                                                                                              (byte)tempData.channelAdditiveMaskList[channelAdjust][1],
                                                                                                                              (byte)tempData.channelAdditiveMaskList[channelAdjust][2],
                                                                                                                              (byte)tempData.channelAdditiveMaskList[channelAdjust][3]));
                            }
                        }

                    }
                }
                else
                {
                    tempSlotData.SetOverlayList(umaRecipe.slotDataList[umaPackRecipe.packedSlotDataList[i].copyOverlayIndex].GetOverlayList());
                }
            }
        }
        return true;
    }
예제 #11
0
    /*
    public static UMAPackRecipe PackRecipeV1(UMA.UMAData.UMARecipe umaRecipe)
    {
        UMAPackRecipe umaPackRecipe = new UMAPackRecipe();

        //var umaPackRecipe = new Packed
        int slotCount = umaRecipe.slotDataList.Length - umaRecipe.AdditionalSlots;
        umaPackRecipe.packedSlotDataList = new packedSlotData[slotCount];
        umaPackRecipe.race = umaRecipe.raceData.raceName;

        foreach (var dna in umaRecipe.GetAllDna())
        {
            UMAPackedDna packedDna = new UMAPackedDna();
            packedDna.dnaType = dna.GetType().Name;
            packedDna.packedDna = UMA.UMADna.SaveInstance(dna);
            umaPackRecipe.packedDna.Add(packedDna);
        }

        for (int i = 0; i < slotCount; i++)
        {
            if (umaRecipe.slotDataList[i] != null)
            {
                packedSlotData tempPackedSlotData = new packedSlotData();
                umaPackRecipe.packedSlotDataList[i] = tempPackedSlotData;

                tempPackedSlotData.slotID = umaRecipe.slotDataList[i].asset.slotName;
                tempPackedSlotData.overlayScale = Mathf.FloorToInt(umaRecipe.slotDataList[i].overlayScale * 100);

                bool copiedOverlays = false;
                for (int i2 = 0; i2 < i; i2++)
                {
                    if (umaRecipe.slotDataList[i2] != null && umaPackRecipe.packedSlotDataList[i2] != null)
                    {
                        if (umaRecipe.slotDataList[i].GetOverlayList() == umaRecipe.slotDataList[i2].GetOverlayList())
                        {
                            tempPackedSlotData.copyOverlayIndex = i2;
                            copiedOverlays = true;
                            break;
                        }
                    }
                }
                if( copiedOverlays ) continue;

                tempPackedSlotData.OverlayDataList = new packedOverlayData[umaRecipe.slotDataList[i].OverlayCount];

                for (int overlayID = 0; overlayID < tempPackedSlotData.OverlayDataList.Length; overlayID++)
                {
                    tempPackedSlotData.OverlayDataList[overlayID] = new packedOverlayData();
                    tempPackedSlotData.OverlayDataList[overlayID].overlayID = umaRecipe.slotDataList[i].GetOverlay(overlayID).asset.overlayName;
                    OverlayColorData colorData = umaRecipe.slotDataList[i].GetOverlay(overlayID).colorData;
                    if (colorData.color != Color.white)
                    {
                        Color32 color = umaRecipe.slotDataList[i].GetOverlay(overlayID).colorData.color;
                        tempPackedSlotData.OverlayDataList[overlayID].colorList = new int[4];
                        tempPackedSlotData.OverlayDataList[overlayID].colorList[0] = color.r;
                        tempPackedSlotData.OverlayDataList[overlayID].colorList[1] = color.g;
                        tempPackedSlotData.OverlayDataList[overlayID].colorList[2] = color.b;
                        tempPackedSlotData.OverlayDataList[overlayID].colorList[3] = color.a;
                    }

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

                    if (colorData.channelMask != null && colorData.channelMask.Length > 0)
                    {
                        tempPackedSlotData.OverlayDataList[overlayID].channelMaskList = new int[colorData.channelMask.Length][];

                        for (int channelAdjust = 0; channelAdjust < colorData.channelMask.Length; channelAdjust++)
                        {
                            tempPackedSlotData.OverlayDataList[overlayID].channelMaskList[channelAdjust] = new int[4];
                            tempPackedSlotData.OverlayDataList[overlayID].channelMaskList[channelAdjust][0] = colorData.channelMask[channelAdjust].r;
                            tempPackedSlotData.OverlayDataList[overlayID].channelMaskList[channelAdjust][1] = colorData.channelMask[channelAdjust].g;
                            tempPackedSlotData.OverlayDataList[overlayID].channelMaskList[channelAdjust][2] = colorData.channelMask[channelAdjust].b;
                            tempPackedSlotData.OverlayDataList[overlayID].channelMaskList[channelAdjust][3] = colorData.channelMask[channelAdjust].a;
                        }

                    }
                    if (colorData.channelAdditiveMask != null)
                    {
                        tempPackedSlotData.OverlayDataList[overlayID].channelAdditiveMaskList = new int[colorData.channelAdditiveMask.Length][];
                        for (int channelAdjust = 0; channelAdjust < colorData.channelAdditiveMask.Length; channelAdjust++)
                        {
                            tempPackedSlotData.OverlayDataList[overlayID].channelAdditiveMaskList[channelAdjust] = new int[4];
                            tempPackedSlotData.OverlayDataList[overlayID].channelAdditiveMaskList[channelAdjust][0] = colorData.channelAdditiveMask[channelAdjust].r;
                            tempPackedSlotData.OverlayDataList[overlayID].channelAdditiveMaskList[channelAdjust][1] = colorData.channelAdditiveMask[channelAdjust].g;
                            tempPackedSlotData.OverlayDataList[overlayID].channelAdditiveMaskList[channelAdjust][2] = colorData.channelAdditiveMask[channelAdjust].b;
                            tempPackedSlotData.OverlayDataList[overlayID].channelAdditiveMaskList[channelAdjust][3] = colorData.channelAdditiveMask[channelAdjust].a;
                        }

                    }
                }
            }
        }
        return umaPackRecipe;
    }
    */
    public static UMAPackRecipe PackRecipeV2(UMA.UMAData.UMARecipe umaRecipe)
    {
        UMAPackRecipe umaPackRecipe = new UMAPackRecipe();
        umaPackRecipe.version = 2;

        int slotCount = umaRecipe.slotDataList.Length - umaRecipe.additionalSlotCount;
        umaPackRecipe.slotsV2 = new PackedSlotDataV2[slotCount];
        if (umaRecipe.raceData != null)
        {
            umaPackRecipe.race = umaRecipe.raceData.raceName;
        }

        foreach (var dna in umaRecipe.GetAllDna())
        {
            UMAPackedDna packedDna = new UMAPackedDna();
            packedDna.dnaType = dna.GetType().Name;
            packedDna.packedDna = UMA.UMADna.SaveInstance(dna);
            umaPackRecipe.packedDna.Add(packedDna);
        }

        umaPackRecipe.sharedColorCount = 0;
        if (umaRecipe.sharedColors != null)
            umaPackRecipe.sharedColorCount = umaRecipe.sharedColors.Length;
        List<OverlayColorData> colorEntries = new List<OverlayColorData>(umaPackRecipe.sharedColorCount);
        List<PackedOverlayColorDataV3> packedColorEntries = new List<PackedOverlayColorDataV3>(umaPackRecipe.sharedColorCount);
        for (int i = 0; i < umaPackRecipe.sharedColorCount; i++)
        {
            colorEntries.Add(umaRecipe.sharedColors[i]);
            packedColorEntries.Add(new PackedOverlayColorDataV3(umaRecipe.sharedColors[i]));
        }

        for (int i = 0; i < slotCount; i++)
        {
            if (umaRecipe.slotDataList[i] != null)
            {
                PackedSlotDataV2 tempPackedSlotData = new PackedSlotDataV2();
                umaPackRecipe.slotsV2[i] = tempPackedSlotData;

                tempPackedSlotData.id = umaRecipe.slotDataList[i].asset.slotName;
                tempPackedSlotData.scale = Mathf.FloorToInt(umaRecipe.slotDataList[i].overlayScale * 100);

                bool copiedOverlays = false;
                for (int i2 = 0; i2 < i; i2++)
                {
                    if (umaRecipe.slotDataList[i2] != null && umaPackRecipe.slotsV2[i2] != null)
                    {
                        if (umaRecipe.slotDataList[i].GetOverlayList() == umaRecipe.slotDataList[i2].GetOverlayList())
                        {
                            tempPackedSlotData.copyIdx = i2;
                            copiedOverlays = true;
                            break;
                        }
                    }
                }
                if( copiedOverlays ) continue;

                tempPackedSlotData.overlays = new PackedOverlayDataV2[umaRecipe.slotDataList[i].OverlayCount];

                for (int overlayIdx = 0; overlayIdx < tempPackedSlotData.overlays.Length; overlayIdx++)
                {
                    PackedOverlayDataV2 tempPackedOverlay = new PackedOverlayDataV2();

                    OverlayData overlayData = umaRecipe.slotDataList[i].GetOverlay(overlayIdx);
                    tempPackedOverlay.id = overlayData.asset.overlayName;
                    tempPackedOverlay.rect = new int[4];
                    tempPackedOverlay.rect[0] = Mathf.FloorToInt(overlayData.rect.x);
                    tempPackedOverlay.rect[1] = Mathf.FloorToInt(overlayData.rect.y);
                    tempPackedOverlay.rect[2] = Mathf.FloorToInt(overlayData.rect.width);
                    tempPackedOverlay.rect[3] = Mathf.FloorToInt(overlayData.rect.height);

                    OverlayColorData colorData = overlayData.colorData;
                    int colorIndex = colorEntries.IndexOf(colorData);
                    if (colorIndex < 0)
                    {
                        PackedOverlayColorDataV3 newColorEntry = new PackedOverlayColorDataV3(colorData);
                        packedColorEntries.Add(newColorEntry);
                        colorIndex = colorEntries.Count;
                        colorEntries.Add(colorData);
                    }
                    tempPackedOverlay.colorIdx = colorIndex;

                    tempPackedSlotData.overlays[overlayIdx] = tempPackedOverlay;
                }
            }
        }

        umaPackRecipe.fColors = packedColorEntries.ToArray();
        return umaPackRecipe;
    }
예제 #12
0
	public static void Apply(UMA.UMAData umaData, CrowdRaceData race, Color skinColor, Color HairColor, HashSet<string> Keywords, SlotLibraryBase slotLibrary, OverlayLibraryBase overlayLibrary)
	{
		var slotParts = new HashSet<string>();
		umaData.umaRecipe.slotDataList = new SlotData[race.slotElements.Length];
		for (int i = 0; i < race.slotElements.Length; i++)
		{
			var currentElement = race.slotElements[i];
			if (!string.IsNullOrEmpty(currentElement.requirement) && !slotParts.Contains(currentElement.requirement)) continue;
			if (!string.IsNullOrEmpty(currentElement.condition))
			{
				if (currentElement.condition.StartsWith("!"))
				{
					if (Keywords.Contains(currentElement.condition.Substring(1))) continue;
				}
				else
				{
					if (!Keywords.Contains(currentElement.condition)) continue;
				}
			}
			if (currentElement.possibleSlots.Length == 0) continue;
			int randomResult = Random.Range(0, currentElement.possibleSlots.Length);
			var slot = currentElement.possibleSlots[randomResult];
			if (string.IsNullOrEmpty(slot.slotID)) continue;
			slotParts.Add(slot.slotID);
			SlotData slotData;
			if (slot.useSharedOverlayList && slot.overlayListSource >= 0 && slot.overlayListSource < i)
			{
				slotData = slotLibrary.InstantiateSlot(slot.slotID, umaData.umaRecipe.slotDataList[slot.overlayListSource].GetOverlayList());
			}
			else
			{
				if (slot.useSharedOverlayList)
				{
					Debug.LogError("UMA Crowd: Invalid overlayListSource for " + slot.slotID);
				}
				slotData = slotLibrary.InstantiateSlot(slot.slotID);
			}
			umaData.umaRecipe.slotDataList[i] = slotData;
			for (int overlayIdx = 0; overlayIdx < slot.overlayElements.Length; overlayIdx++)
			{
				var currentOverlayElement = slot.overlayElements[overlayIdx];
				randomResult = Random.Range(0, currentOverlayElement.possibleOverlays.Length);
				var overlay = currentOverlayElement.possibleOverlays[randomResult];
				if (string.IsNullOrEmpty(overlay.overlayID)) continue;
				overlay.UpdateVersion();
				slotParts.Add(overlay.overlayID);
				Color overlayColor;
				switch (overlay.overlayType)
				{
					case UMACrowdRandomSet.OverlayType.Color:
						overlayColor = overlay.minRGB;
						break;
					case UMACrowdRandomSet.OverlayType.Texture:
						overlayColor = Color.white;
						break;
					case UMACrowdRandomSet.OverlayType.Hair:
						overlayColor = HairColor * overlay.hairColorMultiplier;
						break;
					case UMACrowdRandomSet.OverlayType.Skin:
						overlayColor = skinColor + new Color(Random.Range(overlay.minRGB.r, overlay.maxRGB.r), Random.Range(overlay.minRGB.g, overlay.maxRGB.g), Random.Range(overlay.minRGB.b, overlay.maxRGB.b), 1);
						break;
					case UMACrowdRandomSet.OverlayType.Random:
						overlayColor = new Color(Random.Range(overlay.minRGB.r, overlay.maxRGB.r), Random.Range(overlay.minRGB.g, overlay.maxRGB.g), Random.Range(overlay.minRGB.b, overlay.maxRGB.b), Random.Range(overlay.minRGB.a, overlay.maxRGB.a));
						break;
					default:
						Debug.LogError("Unknown RandomSet overlayType: "+((int)overlay.overlayType));
						overlayColor = overlay.minRGB;
						break;
				}
				var overlayData = overlayLibrary.InstantiateOverlay(overlay.overlayID, overlayColor);
				slotData.AddOverlay(overlayData);
				if (overlay.colorChannelUse != ChannelUse.None)
				{
					overlayColor.a *= overlay.minRGB.a;
					if (overlay.colorChannelUse == ChannelUse.InverseColor)
					{
						Vector3 color = new Vector3(overlayColor.r, overlayColor.g, overlayColor.b);
						var len = color.magnitude;
						if (len < 1f) len = 1f;
						color = new Vector3(1.001f, 1.001f, 1.001f) - color;
						color = color.normalized* len;
						overlayColor = new Color(color.x, color.y, color.z, overlayColor.a);
					}
					overlayData.SetColor(overlay.colorChannel, overlayColor);
				}
			}
			if (umaData.umaRecipe.slotDataList[i].GetOverlayList().Count == 0)
			{
				Debug.LogError("Slot without overlay: " + umaData.umaRecipe.slotDataList[i].slotName + " at index " + i + " of race: " + race.raceID);
			}
		}
	}
예제 #13
0
	public void SlotAtlasEvent(UMA.UMAData umaData, UMA.SlotData slotData, Material material, Rect atlasRect)
	{
		Debug.Log(umaData.name + " got slot " + slotData.asset.slotName);
	}
 public override void Save(UMA.UMAData.UMARecipe umaRecipe, UMAContext context)
 {
     var packedRecipe = PackRecipe(umaRecipe);
     PackedSave(packedRecipe, context);
 }
    public static UMAPackRecipe PackRecipe(UMA.UMAData.UMARecipe umaRecipe)
    {
        UMAPackRecipe umaPackRecipe = new UMAPackRecipe();

        //var umaPackRecipe = new Packed
        umaPackRecipe.packedSlotDataList = new packedSlotData[umaRecipe.slotDataList.Length];
        umaPackRecipe.race = umaRecipe.raceData.raceName;

        umaPackRecipe.packedDna.Clear();

        foreach (var dna in umaRecipe.umaDna.Values)
        {
            UMAPackedDna packedDna = new UMAPackedDna();
            packedDna.dnaType = dna.GetType().Name;
            packedDna.packedDna = UMA.UMADna.SaveInstance(dna);
            umaPackRecipe.packedDna.Add(packedDna);
        }

        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.slotID = umaRecipe.slotDataList[i].slotName;
                    tempPackedSlotData.overlayScale = Mathf.FloorToInt(umaRecipe.slotDataList[i].overlayScale * 100);
                    tempPackedSlotData.OverlayDataList = new packedOverlayData[umaRecipe.slotDataList[i].OverlayCount];

                    for (int overlayID = 0; overlayID < tempPackedSlotData.OverlayDataList.Length; overlayID++)
                    {
                        tempPackedSlotData.OverlayDataList[overlayID] = new packedOverlayData();
                        tempPackedSlotData.OverlayDataList[overlayID].overlayID = umaRecipe.slotDataList[i].GetOverlay(overlayID).overlayName;

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

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

                        if (umaRecipe.slotDataList[i].GetOverlay(overlayID).channelMask != null)
                        {
                            tempPackedSlotData.OverlayDataList[overlayID].channelMaskList = new int[umaRecipe.slotDataList[i].GetOverlay(overlayID).channelMask.Length][];

                            for (int channelAdjust = 0; channelAdjust < umaRecipe.slotDataList[i].GetOverlay(overlayID).channelMask.Length; channelAdjust++)
                            {
                                tempPackedSlotData.OverlayDataList[overlayID].channelMaskList[channelAdjust] = new int[4];
                                tempPackedSlotData.OverlayDataList[overlayID].channelMaskList[channelAdjust][0] = umaRecipe.slotDataList[i].GetOverlay(overlayID).channelMask[channelAdjust].r;
                                tempPackedSlotData.OverlayDataList[overlayID].channelMaskList[channelAdjust][1] = umaRecipe.slotDataList[i].GetOverlay(overlayID).channelMask[channelAdjust].g;
                                tempPackedSlotData.OverlayDataList[overlayID].channelMaskList[channelAdjust][2] = umaRecipe.slotDataList[i].GetOverlay(overlayID).channelMask[channelAdjust].b;
                                tempPackedSlotData.OverlayDataList[overlayID].channelMaskList[channelAdjust][3] = umaRecipe.slotDataList[i].GetOverlay(overlayID).channelMask[channelAdjust].a;
                            }

                        }
                        if (umaRecipe.slotDataList[i].GetOverlay(overlayID).channelAdditiveMask != null)
                        {
                            tempPackedSlotData.OverlayDataList[overlayID].channelAdditiveMaskList = new int[umaRecipe.slotDataList[i].GetOverlay(overlayID).channelAdditiveMask.Length][];
                            for (int channelAdjust = 0; channelAdjust < umaRecipe.slotDataList[i].GetOverlay(overlayID).channelAdditiveMask.Length; channelAdjust++)
                            {
                                tempPackedSlotData.OverlayDataList[overlayID].channelAdditiveMaskList[channelAdjust] = new int[4];
                                tempPackedSlotData.OverlayDataList[overlayID].channelAdditiveMaskList[channelAdjust][0] = umaRecipe.slotDataList[i].GetOverlay(overlayID).channelAdditiveMask[channelAdjust].r;
                                tempPackedSlotData.OverlayDataList[overlayID].channelAdditiveMaskList[channelAdjust][1] = umaRecipe.slotDataList[i].GetOverlay(overlayID).channelAdditiveMask[channelAdjust].g;
                                tempPackedSlotData.OverlayDataList[overlayID].channelAdditiveMaskList[channelAdjust][2] = umaRecipe.slotDataList[i].GetOverlay(overlayID).channelAdditiveMask[channelAdjust].b;
                                tempPackedSlotData.OverlayDataList[overlayID].channelAdditiveMaskList[channelAdjust][3] = umaRecipe.slotDataList[i].GetOverlay(overlayID).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].GetOverlayList() == umaRecipe.slotDataList[i2].GetOverlayList())
                                {
                                    tempPackedSlotData = new packedSlotData();
                                    tempPackedSlotData.slotID = umaRecipe.slotDataList[i2].slotName;
                                    tempPackedSlotData.copyOverlayIndex = i;
                                    //umaPackRecipe.packedSlotDataList[i2] = tempPackedSlotData;
                                }
                            }
                        }
                    }
                }
            }
        }
        return umaPackRecipe;
    }
예제 #16
0
 public abstract void Load(UMA.UMAData umaData, UMAContext context);
예제 #17
0
 public abstract void Save(UMA.UMAData umaData, UMAContext context);
예제 #18
0
	public void CreatedEvent(UMA.UMAData data)
	{
		Debug.Log(data.name + " Created", data.gameObject);
	}
예제 #19
0
	public abstract void Save(UMA.UMAData.UMARecipe umaRecipe, UMAContext context);
	public static void Apply(UMA.UMAData umaData, CrowdRaceData race, Color skinColor, Color HairColor, HashSet<string> Keywords, SlotLibraryBase slotLibrary, OverlayLibraryBase overlayLibrary)
	{
		var slotParts = new HashSet<string>();
		umaData.umaRecipe.slotDataList = new SlotData[race.slotElements.Length];
		for (int i = 0; i < race.slotElements.Length; i++)
		{
			var currentElement = race.slotElements[i];
			if (!string.IsNullOrEmpty(currentElement.requirement) && !slotParts.Contains(currentElement.requirement)) continue;
			if (!string.IsNullOrEmpty(currentElement.condition))
			{
				if (currentElement.condition.StartsWith("!"))
				{
					if (Keywords.Contains(currentElement.condition.Substring(1))) continue;
				}
				else
				{
					if (!Keywords.Contains(currentElement.condition)) continue;
				}
			}
			if (currentElement.possibleSlots.Length == 0) continue;
			int randomResult = Random.Range(0, currentElement.possibleSlots.Length);
			var slot = currentElement.possibleSlots[randomResult];
			if (string.IsNullOrEmpty(slot.slotID)) continue;
			slotParts.Add(slot.slotID);
			SlotData slotData;
			if (slot.useSharedOverlayList && slot.overlayListSource >= 0 && slot.overlayListSource < i)
			{
				slotData = slotLibrary.InstantiateSlot(slot.slotID, umaData.umaRecipe.slotDataList[slot.overlayListSource].GetOverlayList());
			}
			else
			{
				if (slot.useSharedOverlayList)
				{
					Debug.LogError("UMA Crowd: Invalid overlayListSource for " + slot.slotID);
				}
				slotData = slotLibrary.InstantiateSlot(slot.slotID);
			}
			umaData.umaRecipe.slotDataList[i] = slotData;
			for (int overlayIdx = 0; overlayIdx < slot.overlayElements.Length; overlayIdx++)
			{
				var currentOverlayElement = slot.overlayElements[overlayIdx];
				randomResult = Random.Range(0, currentOverlayElement.possibleOverlays.Length);
				var overlay = currentOverlayElement.possibleOverlays[randomResult];
				if (string.IsNullOrEmpty(overlay.overlayID)) continue;
				slotParts.Add(overlay.overlayID);
				Color overlayColor;
				if (overlay.useSkinColor)
				{
					overlayColor = skinColor + new Color(Random.Range(overlay.minRGB.r, overlay.maxRGB.r), Random.Range(overlay.minRGB.g, overlay.maxRGB.g), Random.Range(overlay.minRGB.b, overlay.maxRGB.b), 1);
				}
				else if (overlay.useHairColor)
				{
					overlayColor = HairColor * overlay.hairColorMultiplier;
				}
				else
				{
					overlayColor = new Color(Random.Range(overlay.minRGB.r, overlay.maxRGB.r), Random.Range(overlay.minRGB.g, overlay.maxRGB.g), Random.Range(overlay.minRGB.b, overlay.maxRGB.b), 1);
				}
				slotData.AddOverlay(overlayLibrary.InstantiateOverlay(overlay.overlayID, overlayColor));
			}
			if (umaData.umaRecipe.slotDataList[i].GetOverlayList().Count == 0)
			{
				Debug.LogError("Slot without overlay: " + umaData.umaRecipe.slotDataList[i].slotName + " at index " + i + " of race: " + race.raceID);
			}
		}
	}
 public override void Load(UMA.UMAData.UMARecipe umaRecipe, UMAContext context)
 {
     var packedRecipe = PackedLoad(context);
     UnpackRecipe(umaRecipe, packedRecipe, context);
 }
예제 #22
0
	public void DestroyedEvent(UMA.UMAData data)
	{
		Debug.Log(data.name + " Destoyed", data.gameObject);
	}