Exemple #1
0
    public void ApplyParts()
    {
        Transform t          = GetComponent <Transform>();
        int       siblingIdx = t.GetSiblingIndex();

        int partIdx    = 0;
        int layerOrder = (t.parent.childCount - siblingIdx) * _parts.Count;

        foreach (var p in _parts)
        {
            SpriteRenderer renderer = p.GetSpriteRenderer();
            if (p.type != PartType.None)
            {
                switch (p.type)
                {
                case PartType.Body:
                    renderer.color        = skinColor;
                    renderer.sortingOrder = layerOrder;
                    break;

                case PartType.Cloth:
                    renderer.color        = clothColor;
                    renderer.sortingOrder = layerOrder + 1;
                    break;

                case PartType.Head:
                    renderer.color        = skinColor;
                    renderer.sortingOrder = layerOrder + 2;
                    break;

                case PartType.Nose:
                    renderer.color        = skinColor;
                    renderer.sortingOrder = layerOrder + 4;
                    break;

                case PartType.Hair:
                case PartType.Beard:
                    renderer.color        = hairColor;
                    renderer.sortingOrder = layerOrder + 5;
                    break;

                case PartType.Eyes:
                    renderer.sortingOrder = layerOrder + 6;
                    break;

                case PartType.MouthNormal:
                    renderer.color        = skinColor;
                    mouth                 = p;
                    renderer.sortingOrder = layerOrder + 3;
                    break;
                }
            }
            else
            {
                p.GetSpriteRenderer().color = skinColor;
                renderer.sortingOrder = layerOrder + 6 + partIdx++;
            }
        }
    }
Exemple #2
0
    public Sprite GetRandomSprite(BodyPartRandomizer part, Gender gender)
    {
        if (part.type == PartType.Cloth && part.relative != null)
        {
            Dictionary <PartType, List <Sprite> > refDico = GetAppropriateDictionary(gender);
            List <Sprite> refList = refDico[part.type];

            string relativeName = part.relative.GetSpriteRenderer().sprite.name;
            char   last         = relativeName[relativeName.Length - 1];

            char target = '0';
            switch (last)
            {
            case '1':
                target = '1';
                break;

            case '0':
                target = '2';
                break;

            case '2':
                target = '3';
                break;
            }

            refList.Shuffle();
            foreach (var s in refList)
            {
                if (s.name[s.name.Length - 3] == target)
                {
                    return(s);
                }
            }

            return(null);
        }
        else
        {
            return(GetRandomSprite(part.type, gender));
        }
    }
Exemple #3
0
    public void RandomizeParts()
    {
        Transform t          = GetComponent <Transform>();
        int       siblingIdx = t.GetSiblingIndex();

        skinColor  = NPCManager.Instance.GetRandomSkinColor();
        hairColor  = NPCManager.Instance.GetRandomHairColor();
        clothColor = NPCManager.Instance.GetRandomClothColor();

        int partIdx    = 0;
        int layerOrder = (t.parent.childCount - siblingIdx) * _parts.Count;

        foreach (var p in _parts)
        {
            SpriteRenderer renderer = p.GetSpriteRenderer();
            if (p.type != PartType.None)
            {
                renderer.sprite = NPCManager.Instance.GetRandomSprite(p, gender);

                switch (p.type)
                {
                case PartType.Body:
                    renderer.color        = skinColor;
                    renderer.sortingOrder = layerOrder;
                    break;

                case PartType.Cloth:
                    renderer.color        = clothColor;
                    renderer.sortingOrder = layerOrder + 1;
                    break;

                case PartType.Head:
                    renderer.color        = skinColor;
                    renderer.sortingOrder = layerOrder + 2;
                    break;

                case PartType.Nose:
                    renderer.color        = skinColor;
                    renderer.sortingOrder = layerOrder + 4;
                    break;

                case PartType.Hair:
                case PartType.Beard:
                    renderer.color        = hairColor;
                    renderer.sortingOrder = layerOrder + 7;
                    break;

                case PartType.Eyes:
                    renderer.sortingOrder = layerOrder + 5;
                    break;

                case PartType.MouthNormal:
                    renderer.color        = skinColor;
                    mouth                 = p;
                    renderer.sortingOrder = layerOrder + 3;
                    break;
                }
            }
            else
            {
                renderer.color = skinColor;
                if (p.name.Contains("ClosedEyes"))
                {
                    closedEyes = p;
                    closedEyes.gameObject.SetActive(false);
                    renderer.sortingOrder = layerOrder + 6;
                }
                else // bras
                {
                    renderer.sortingOrder = layerOrder + 6 + partIdx++;
                }
            }
        }
        // Debug.Log("... " + t.parent.Find("Killer").gameObject.GetComponent<CharacterRandomizer>().StringifyCharacter());
        if (CompareCharacter(t.parent.Find("Killer").gameObject.GetComponent <CharacterRandomizer>()))
        {
            RandomizeParts();
        }
    }