public void SetSkinColor(SkinPart skinPart, uint skinType, Color?color1, Color?color2) { if (skinPart == SkinPart.Head && color1 == null) { return; } if (skinPart != SkinPart.Head && color1 == null && color2 == null) { return; } GameObject[] partObjs = skinPart == SkinPart.Body ? bodies : (skinPart == SkinPart.Head ? heads : pants); GameObject skinTypeObj = partObjs[skinType]; SkinnedMeshRenderer meshRenderer = skinTypeObj.GetComponent <SkinnedMeshRenderer>(); if (meshRenderer == null) { return; } if (skinPart == SkinPart.Head) { meshRenderer.material.SetColor("Color_01", color1.Value); } else { meshRenderer.material.SetColor("Color_02", color1.Value); meshRenderer.material.SetColor("Color_03", color2.Value); } }
public SkinPartParams this[SkinPart part] { get { switch (part) { case SkinPart.Body: return(Body); case SkinPart.Marking: return(Marking); case SkinPart.Decoration: return(Decoration); case SkinPart.Hands: return(Hands); case SkinPart.Feet: return(Feet); case SkinPart.Eyes: return(Eyes); default: throw new ArgumentOutOfRangeException(nameof(part), part, null); } } }
public void SetSkinPart(SkinPart skinPart, uint skinType) { GameObject[] partObjs = skinPart == SkinPart.Body ? bodies : (skinPart == SkinPart.Head ? heads : pants); for (int i = 0; i < partObjs.Length; i++) { partObjs[i].SetActive(i == skinType); } }
public SkinPartParams this[SkinPart part] { set { var index = 0; switch (part) { case SkinPart.Body: IntSkinPartName1 = value.Name.StrToInts(6); break; case SkinPart.Marking: IntSkinPartName2 = value.Name.StrToInts(6); break; case SkinPart.Decoration: IntSkinPartName3 = value.Name.StrToInts(6); break; case SkinPart.Hands: IntSkinPartName4 = value.Name.StrToInts(6); break; case SkinPart.Feet: IntSkinPartName5 = value.Name.StrToInts(6); break; case SkinPart.Eyes: IntSkinPartName6 = value.Name.StrToInts(6); break; default: throw new ArgumentOutOfRangeException(nameof(part), part, null); } SkinPartUseCustomColors[(int)part] = value.UseCustomColor ? 1 : 0; SkinPartColors[(int)part] = value.Color; } }
/// <summary> /// Saves the current skin as a list /// </summary> private void GetDefSkin() { //Init defSkin = gameObject.AddComponent <Skin>(); //Set name defSkin.skinName = (string.IsNullOrEmpty(defatulSkinName)) ? defatulSkinName : "_default"; //Create parts list defSkin.skinParts = new List <SkinPart>(); //Get all instances of Sprite Mesh // -- NOTE : This can be changed so that it goes to a public variable, in case only certain body parts want to be stored SpriteMeshInstance[] instances = GetComponentsInChildren <SpriteMeshInstance>(); foreach (var instance in instances) { SkinPart newpart = new SkinPart(); newpart.bodyPart = instance; newpart.spriteMesh = instance.spriteMesh; defSkin.skinParts.Add(newpart); } //Add the default skin to the list skins.Add(defSkin); }
public void SetSkinPart(SkinPart skinPart, uint skinType, Color?color1 = null, Color?color2 = null) { character.SetSkinPart(skinPart, skinType); character.SetSkinColor(skinPart, skinType, color1, color2); }
private SpriteMeshInstance GetEquipmentMesh(SkinPart part) { return(this.bodyParts.GetValueOrDefault(part, null)); }
private void SetSprites(Character c, Texture2D skin, Texture2D outline, int characterOrderIndex) { // Grab all the sprites out of this texture Sprite[] skinSprites = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(skin)).OfType <Sprite>().ToArray(); Sprite[] outlineSprites = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(outline)).OfType <Sprite>().ToArray(); Dictionary <int, CharacterSprite> spritesAtFrame = new Dictionary <int, CharacterSprite>(); for (int i = 0; i < skinSprites.Length; i++) { Sprite s = skinSprites[i]; int textureWidth = s.texture.width; int textureHeight = s.texture.height; // In case we are using a texture atlas, find the real original texture size if (s.rect != s.textureRect) { if (getWidthAndHeightDelegate == null) { var method = typeof(TextureImporter).GetMethod("GetWidthAndHeight", BindingFlags.NonPublic | BindingFlags.Instance); getWidthAndHeightDelegate = Delegate.CreateDelegate(typeof(GetWidthAndHeight), null, method) as GetWidthAndHeight; } string path = AssetDatabase.GetAssetPath(s); var importer = AssetImporter.GetAtPath(path) as TextureImporter; if (importer != null) { getWidthAndHeightDelegate(importer, ref textureWidth, ref textureHeight); } } // Set the sprite information int x = (int)(s.rect.x / s.rect.height); int y = (int)((textureHeight - (s.rect.y + s.rect.height)) / s.rect.width); int index = (int)(y * (textureWidth / s.rect.width)) + x; spritesAtFrame[index] = new CharacterSprite { Skin = s, Outline = outlineSprites[i] }; } bool hasWeapon = false; bool hasShield = false; // Loop through all the transforms so we don't miss a disabled sprite renderer component Transform[] objects = c.GetComponentsInChildren <Transform>(/*includeInactive=*/ true); for (int i = 0; i < objects.Length; i++) { GameObject go = objects[i].gameObject; // Determine the sprite type based on the name bool isSkin = true; string partName = go.name; if (go.name.Contains("Sprite")) { isSkin = !go.name.EndsWith("Sprite-Outline"); if (isSkin) { partName = go.name.Replace("Sprite", ""); } else { partName = go.name.Replace("Sprite-Outline", ""); } } else if (go.name.EndsWith("Mask")) { partName = go.name; isSkin = true; } else { continue; } // Update the sprite with the correct one from the skin texture if (skinParts.ContainsKey(partName)) { SkinPart part = skinParts[partName]; Renderer r = go.GetComponent <Renderer>(); int index = part.TextureIndex; if (spritesAtFrame.ContainsKey(index)) { // Set the correct sprite Sprite sprite = (isSkin ? spritesAtFrame[index].Skin : spritesAtFrame[index].Outline); SpriteRenderer sr = go.GetComponent <SpriteRenderer>(); if (sr == null) { SpriteMask sm = go.GetComponent <SpriteMask>(); sm.sprite = sprite; r.enabled = false; } else { sr.sprite = sprite; r.enabled = true; } // Hide the special sprites that get turned on only in animations if (go.name.Contains("Back") || go.name.Contains("Dead") || go.name.Contains("FX")) { r.gameObject.SetActive(false); } // Update the outline sprite order if (!isSkin) { r.sortingOrder = -100; } } else { // Hide this renderer SpriteRenderer sr = go.GetComponent <SpriteRenderer>(); if (sr == null) { SpriteMask sm = go.GetComponent <SpriteMask>(); sm.sprite = null; } else { sr.sprite = null; } r.enabled = false; } // Create the weapon collider shape if we find one if (partName == "HeldItemMainCollider" && isSkin) { SpriteRenderer sr = go.GetComponent <SpriteRenderer>(); if (sr.sprite != null) { hasWeapon = true; } PolygonCollider2D pc = go.GetComponent <PolygonCollider2D>(); if (pc != null) { if (sr.sprite != null) { // Creating a new component will auto set the collider to the shape of the sprite PolygonCollider2D newShape = sr.gameObject.AddComponent <PolygonCollider2D>(); // Copy the points to the original collider so we don't make a new component and mess up prefab hierarchy pc.SetPath(0, newShape.points); pc.enabled = true; pc.isTrigger = true; sr.enabled = false; c.WeaponObject = pc; DestroyImmediate(newShape); } else { pc.enabled = false; } } } } } // Change the character if we don't find a weapon sprite if (!hasWeapon) { c.EquippedWeaponType = Character.WeaponType.None; c.ThrowMainProjectile = null; } // Update based on the shield c.IsBlockEnabled = hasShield; // Set the tag c.gameObject.tag = "Player"; }
public SkinPartInfo(SkinPart part, string mesh) { Part = part; Mesh = mesh; }