Ejemplo n.º 1
0
    public static GameObject GetHair(GameObject reference, string name, Material material, Color color)
    {
        List <GameObject> list;
        bool       flag = ClothFactory.clothCache.TryGetValue(name, out list);
        GameObject result;

        if (flag)
        {
            for (int i = 0; i < list.Count; i++)
            {
                GameObject gameObject = list[i];
                bool       flag2      = gameObject == null;
                if (flag2)
                {
                    Debug.Log("Hair is null");
                    list.RemoveAt(i);
                    i = Mathf.Max(i - 1, 0);
                }
                else
                {
                    ParentFollow component = gameObject.GetComponent <ParentFollow>();
                    bool         flag3     = !component.isActiveInScene;
                    if (flag3)
                    {
                        component.isActiveInScene                 = true;
                        gameObject.renderer.material              = material;
                        gameObject.renderer.material.color        = color;
                        gameObject.GetComponent <Cloth>().enabled = true;
                        gameObject.GetComponent <SkinnedMeshRenderer>().enabled = true;
                        gameObject.GetComponent <ParentFollow>().SetParent(reference.transform);
                        ClothFactory.ReapplyClothBones(reference, gameObject);
                        return(gameObject);
                    }
                }
            }
            GameObject gameObject2 = ClothFactory.GenerateCloth(reference, name);
            gameObject2.renderer.material       = material;
            gameObject2.renderer.material.color = color;
            gameObject2.AddComponent <ParentFollow>().SetParent(reference.transform);
            list.Add(gameObject2);
            ClothFactory.clothCache[name] = list;
            result = gameObject2;
        }
        else
        {
            GameObject gameObject2 = ClothFactory.GenerateCloth(reference, name);
            gameObject2.renderer.material       = material;
            gameObject2.renderer.material.color = color;
            gameObject2.AddComponent <ParentFollow>().SetParent(reference.transform);
            list = new List <GameObject>
            {
                gameObject2
            };
            ClothFactory.clothCache.Add(name, list);
            result = gameObject2;
        }
        return(result);
    }