Пример #1
0
        /// <summary>
        ///     Apply this config's values to a GameObject's ItemDrop.
        /// </summary>
        /// <param name="prefab"></param>
        public void Apply(GameObject prefab)
        {
            var itemDrop = prefab.GetComponent <ItemDrop>();

            if (itemDrop == null)
            {
                Logger.LogError($"GameObject has no ItemDrop attached");
                return;
            }

            var shared = itemDrop.m_itemData.m_shared;

            if (shared == null)
            {
                Logger.LogError($"ItemDrop has no SharedData component");
                return;
            }

            // Set the Item to the prefab name
            Item = prefab.name;

            // Set the name and description if provided
            if (!string.IsNullOrEmpty(Name))
            {
                shared.m_name = Name;
            }
            if (!string.IsNullOrEmpty(Description))
            {
                shared.m_description = Description;
            }

            // If there is still no m_name, add a token from the prefabs name
            if (string.IsNullOrEmpty(shared.m_name))
            {
                shared.m_name = $"${prefab.name}";
            }

            // Add a piece table if provided
            if (!string.IsNullOrEmpty(PieceTable))
            {
                shared.m_buildPieces = Mock <PieceTable> .Create(PieceTable);
            }

            // Set icons if provided
            if (Icons != null && Icons.Length > 0)
            {
                itemDrop.m_itemData.m_shared.m_icons = Icons;

                // Set variants if a StyleTex is provided
                if (StyleTex != null)
                {
                    ExtEquipment.Enable();
                    foreach (var rend in ShaderHelper.GetRenderers(prefab))
                    {
                        foreach (var mat in rend.materials)
                        {
                            if (mat.shader != Shader.Find("Custom/Creature"))
                            {
                                mat.shader = Shader.Find("Custom/Creature");
                            }

                            if (mat.HasProperty("_StyleTex"))
                            {
                                itemDrop.m_itemData.m_shared.m_variants = Icons.Length;
                                rend.gameObject.GetOrAddComponent <ItemStyle>();
                                mat.EnableKeyword("_USESTYLES_ON");
                                mat.SetFloat("_Style", 0f);
                                mat.SetFloat("_UseStyles", 1f);
                                mat.SetTexture("_StyleTex", StyleTex);
                            }
                        }
                    }
                }
            }
        }