Esempio n. 1
0
    public void UpdateUnit(UnitDefinition unit)
    {
        bool needsRegen = false;

        if ((MatPairStruct)this.unit.race != unit.race)
        {
            race       = CreatureRaws.Instance[unit.race.mat_type];
            caste      = race.caste[unit.race.mat_index];
            needsRegen = true;
        }
        if (oldWounds != null || unit.wounds != null)
        {
            if (oldWounds == null && unit.wounds != null)
            {
                needsRegen = true;
            }
            else if (oldWounds != null && unit.wounds == null)
            {
                needsRegen = true;
            }
            else if (oldWounds.Count != unit.wounds.Count)
            {
                needsRegen = true;
            }
            else
            {
                for (int i = 0; i < unit.wounds.Count; i++)
                {
                    if (oldWounds[i].severed_part != unit.wounds[i].severed_part)
                    {
                        needsRegen = true;
                        break;
                    }
                    if (oldWounds[i].parts.Count != unit.wounds[i].parts.Count)
                    {
                        needsRegen = true;
                        break;
                    }
                }
            }
        }
        oldWounds = unit.wounds;
        this.unit = unit;
        if (needsRegen || oldChibiSize != GameSettings.Instance.units.chibiness || oldScaleUnits != GameSettings.Instance.units.scaleUnits)
        {
            oldScaleUnits = GameSettings.Instance.units.scaleUnits;
            oldChibiSize  = GameSettings.Instance.units.chibiness;
            MakeBody();
        }

        if (((UnitFlags1)unit.flags1 & UnitFlags1.on_ground) == UnitFlags1.on_ground)
        {
            if (!onGround)
            {
                rootPart.transform.localRotation = Quaternion.Euler(90, 0, 0);
                rootPart.transform.localPosition = new Vector3(0, bounds.max.z, 0);
                onGround = true;
            }
        }
        else
        {
            if (onGround)
            {
                rootPart.transform.localRotation = Quaternion.identity;
                rootPart.transform.localPosition = new Vector3(0, -bounds.min.y, 0);
                onGround = false;
            }
        }
        if (unit.facing != null && GameMap.DFtoUnityDirection(unit.facing).sqrMagnitude > 0 && unit.rider_id < 0)
        {
            transform.rotation = Quaternion.LookRotation(GameMap.DFtoUnityDirection(unit.facing));
        }
        else if (unit.rider_id >= 0)
        {
            transform.rotation = Quaternion.identity;
        }

        if (InventoryChanged(unit.inventory))
        {
            foreach (var part in spawnedParts)
            {
                part.Value.inventory.Clear();
            }
            //Here we add pants first before shirts because otherwise the layering looks bad.
            foreach (var item in unit.inventory)
            {
                if (!ClothingTexture.GetTexture(item.item.type).isDress)
                {
                    AddInventoryItem(item);
                }
            }
            foreach (var item in unit.inventory)
            {
                if (ClothingTexture.GetTexture(item.item.type).isDress)
                {
                    AddInventoryItem(item);
                }
            }
            foreach (var part in spawnedParts)
            {
                part.Value.UpdateItems(unit);
            }
        }
    }
Esempio n. 2
0
	/// <summary>
	/// Recreates this object with new values.
	/// </summary>
	/// <returns>The new object.</returns>
	public Character Recreate()
	{
		ClearCustomizationEvents();

		name = string.Empty;
		gender = Gender.Male;
		height = 0.5f;
		athletic = 0;
		heavy = 0;
		light = 0;
		skinColor = new Color(0.745f, 0.569f, 0.412f);
		primarySkinDetail = null;
		secondarySkinDetail = null;
		hair = null;
		eyebrows = null;
		eyes = null;
		facialHair = null;

		underclothing = null;
		torso = null;
		hands = null;
		legs = null;
		feet = null;
		return this;
	}
Esempio n. 3
0
 internal void ApplyEquipment(List <BodyPart.Equip> inventory, RemoteFortressReader.UnitDefinition unit)
 {
     //first of all disable any layers that are not used anymore, but not need to remove them entirely.
     for (int i = inventory.Count; i < instantiatedClothingLayers.Count; i++)
     {
         instantiatedClothingLayers[i].gameObject.SetActive(false);
     }
     for (int i = 0; i < inventory.Count; i++)
     {
         var item = inventory[i];
         //If it's not a worn clothing item, hide the respective layers.
         if (item.item.mode == RemoteFortressReader.InventoryMode.Worn)
         {
             if (instantiatedClothingLayers.Count > i && instantiatedClothingLayers[i] != null)
             {
                 instantiatedClothingLayers[i].gameObject.SetActive(false);
             }
         }
         if (specialEquipment.ContainsKey(item.item.item.type))
         {
             var model = specialEquipment[item.item.item.type];
             model.gameObject.SetActive(true);
             model.UpdateMaterial(item.item.item, unit);
         }
         else if (item.item.mode == RemoteFortressReader.InventoryMode.Worn)
         {
             var clothingTexture = ClothingTexture.GetTexture(item.item.item.type);
             if (clothingTexture == null || clothingTexture.baseMat == null)
             {
                 Debug.Log("Could not load texture for " + ItemRaws.Instance[item.item.item.type].id);
                 continue;
             }
             GenericClothingLayer clothing;
             if (clothingTexture.isDress)
             {
                 clothing = dressClothing;
             }
             else
             {
                 clothing = pantClothing;
             }
             if (clothing == null)
             {
                 continue;
             }
             if (i >= instantiatedClothingLayers.Count)
             {
                 instantiatedClothingLayers.AddRange(Enumerable.Repeat <ItemModel>(null, i - instantiatedClothingLayers.Count + 1));
             }
             if (instantiatedClothingLayers[i] == null)
             {
                 GameObject newLayer = new GameObject();
                 newLayer.transform.parent        = transform;
                 newLayer.transform.localPosition = clothing.pos;
                 newLayer.transform.localRotation = clothing.rotation;
                 newLayer.transform.localScale    = clothing.scale;
                 var mf = newLayer.AddComponent <MeshFilter>();
                 mf.sharedMesh = clothing.mesh;
                 var mr  = newLayer.AddComponent <MeshRenderer>();
                 var mat = clothingTexture.GetMaterial(i);
                 mr.sharedMaterial = mat;
                 var im = newLayer.AddComponent <ItemModel>();
                 instantiatedClothingLayers[i] = im;
             }
             if (instantiatedClothingLayers[i] == null)
             {
                 continue;
             }
             instantiatedClothingLayers[i].gameObject.SetActive(true);
             instantiatedClothingLayers[i].UpdateMaterial(item.item.item, unit);
             if (Application.isEditor)
             {
                 instantiatedClothingLayers[i].name = item.itemDef.id;
             }
         }
     }
 }
Esempio n. 4
0
	public static void Deserialize(byte[] serialized, out ClothingTexture clothing)
	{
		Item item;
		Deserialize(serialized, out item);
		clothing = (ClothingTexture)item;
	}
Esempio n. 5
0
	public static byte[] Serialize(ClothingTexture clothing)
	{
		return Serialize((Item)clothing);
	}
Esempio n. 6
0
	private void OnUnderclothingChange(ClothingTexture value)
	{
		try
		{
			if (value == null)
			{
				bodyObject.material.SetTexture("_UnderclothingTex", Utility.Load<Texture2D>("Art/General/Textures/Clear"));
			}
			else
			{
				if (value.Textures[0].Texture == 0)
				{
					bodyObject.material.SetTexture("_UnderclothingTex", Utility.Load<Texture2D>("Art/General/Textures/Clear"));
				}
				else if (value.Textures[0].Texture == 1)
				{
					bodyObject.material.SetTexture("_UnderclothingTex", Utility.Load<Texture2D>("Art/General/Textures/White"));
				}
				else
				{
					bodyObject.material.SetTexture("_UnderclothingTex", Utility.Load<Texture2D>("Art/Character/" + Character.Gender.ToString() + "/Underclothing/Overlays/" + value.Textures[0].Texture));
				}
				bodyObject.material.SetColor("_UnderclothingColor", value.Textures[0].Color);
			}
		}
		finally
		{
			Resources.UnloadUnusedAssets();
		}
	}
Esempio n. 7
0
	private void OnEyesChange(ClothingTexture value)
	{
		try
		{
			if (value == null)
			{
				bodyObject.material.SetTexture("_EyeTex", Utility.Load<Texture2D>("Art/Character/" + Character.Gender.ToString() + "/Eyes/Overlays (1)/2"));
				bodyObject.material.SetTexture("_IrisTex", Utility.Load<Texture2D>("Art/Character/" + Character.Gender.ToString() + "/Eyes/Overlays (2)/2"));
				bodyObject.material.SetColor("_IrisColor1", defaultEyeColor);
				bodyObject.material.SetColor("_IrisColor2", defaultEyeColor);
			}
			else
			{
				if (value.Textures[0].Texture == 0)
				{
					bodyObject.material.SetTexture("_EyeTex", Utility.Load<Texture2D>("Art/General/Textures/Clear"));
				}
				else if (value.Textures[0].Texture == 1)
				{
					bodyObject.material.SetTexture("_EyeTex", Utility.Load<Texture2D>("Art/General/Textures/White"));
				}
				else
				{
					bodyObject.material.SetTexture("_EyeTex", Utility.Load<Texture2D>("Art/Character/" + Character.Gender.ToString() + "/Eyes/Overlays (1)/" + value.Textures[0].Texture));
				}
				bodyObject.material.SetColor("_EyeColor", value.Textures[0].Color);

				if (value.Textures[1].Texture == 0)
				{
					bodyObject.material.SetTexture("_IrisTex", Utility.Load<Texture2D>("Art/General/Textures/Clear"));
				}
				else if (value.Textures[1].Texture == 1)
				{
					bodyObject.material.SetTexture("_IrisTex", Utility.Load<Texture2D>("Art/General/Textures/White"));
				}
				else
				{
					bodyObject.material.SetTexture("_IrisTex", Utility.Load<Texture2D>("Art/Character/" + Character.Gender.ToString() + "/Eyes/Overlays (2)/" + value.Textures[1].Texture));
				}
				bodyObject.material.SetColor("_IrisColor1", value.Textures[1].Color);
				bodyObject.material.SetColor("_IrisColor2", value.Textures[2].Color);
			}
		}
		finally
		{
			Resources.UnloadUnusedAssets();
		}
	}
Esempio n. 8
0
	private void OnSecondarySkinDetailChange(ClothingTexture value)
	{
		try
		{
			if (value == null)
			{
				if (Character.PrimarySkinDetail == null)
				{
					bodyObject.material.shader = Utility.FindShader("PP/Character (Detail x0)");
				}
				else
				{
					bodyObject.material.shader = Utility.FindShader("PP/Character (Detail x1)");
					bodyObject.material.SetTexture("_PrimarySkinDetailTex", Utility.Load<Texture2D>("Art/Character/" + Character.Gender.ToString() + "/Skin Detail/Overlays/" + Character.PrimarySkinDetail.Textures[0].Texture));
				}
			}
			else
			{
				if (Character.PrimarySkinDetail == null)
				{
					bodyObject.material.shader = Utility.FindShader("PP/Character (Detail x1)");
					bodyObject.material.SetTexture("_PrimarySkinDetailTex", Utility.Load<Texture2D>("Art/Character/" + Character.Gender.ToString() + "/Skin Detail/Overlays/" + value.Textures[0].Texture));
				}
				else
				{
					bodyObject.material.shader = Utility.FindShader("PP/Character (Detail x2)");
					bodyObject.material.SetTexture("_PrimarySkinDetailTex", Utility.Load<Texture2D>("Art/Character/" + Character.Gender.ToString() + "/Skin Detail/Overlays/" + Character.PrimarySkinDetail.Textures[0].Texture));
					bodyObject.material.SetTexture("_SecondarySkinDetailTex", Utility.Load<Texture2D>("Art/Character/" + Character.Gender.ToString() + "/Skin Detail/Overlays/" + value.Textures[0].Texture));
				}
			}
		}
		finally
		{
			Resources.UnloadUnusedAssets();
		}
	}