public static void GetModifierChanges(int modifierTier, ref OverrideData __result)
        {
            try
            {
                if (BannerlordCheatsSettings.Instance?.CraftedWeaponHandlingBonus > 0)
                {
                    __result.Handling += BannerlordCheatsSettings.Instance.CraftedWeaponHandlingBonus;
                }

                if (BannerlordCheatsSettings.Instance?.CraftedWeaponSwingDamageBonus > 0)
                {
                    __result.SwingDamageOverriden += BannerlordCheatsSettings.Instance.CraftedWeaponSwingDamageBonus;
                }

                if (BannerlordCheatsSettings.Instance?.CraftedWeaponSwingSpeedBonus > 0)
                {
                    __result.SwingSpeedOverriden += BannerlordCheatsSettings.Instance.CraftedWeaponSwingSpeedBonus;
                }

                if (BannerlordCheatsSettings.Instance?.CraftedWeaponThrustDamageBonus > 0)
                {
                    __result.ThrustDamageOverriden += BannerlordCheatsSettings.Instance.CraftedWeaponThrustDamageBonus;
                }

                if (BannerlordCheatsSettings.Instance?.CraftedWeaponThrustSpeedBonus > 0)
                {
                    __result.ThrustSpeedOverriden += BannerlordCheatsSettings.Instance.CraftedWeaponThrustSpeedBonus;
                }
            }
            catch (Exception e)
            {
                SubModule.LogError(e, typeof(CraftedWeaponModifierBonus));
            }
        }
Esempio n. 2
0
 public static void GetModifierChanges(int modifierTier, ref OverrideData __result)
 {
     __result.Handling              += BannerlordCheatsSettings.Instance.CraftedWeaponHandlingBonus;
     __result.SwingDamageOverriden  += BannerlordCheatsSettings.Instance.CraftedWeaponSwingDamageBonus;
     __result.SwingSpeedOverriden   += BannerlordCheatsSettings.Instance.CraftedWeaponSwingSpeedBonus;
     __result.ThrustDamageOverriden += BannerlordCheatsSettings.Instance.CraftedWeaponThrustDamageBonus;
     __result.ThrustSpeedOverriden  += BannerlordCheatsSettings.Instance.CraftedWeaponThrustSpeedBonus;
 }
Esempio n. 3
0
 public static void PrintProperties(PropertyInfo[] properties, OverrideData instance)
 {
     foreach (var prop in properties)
     {
         OLogger.Log("\t" +
                     prop.Name + "\t" +
                     prop.GetValue(instance));
     }
 }
    public Type GetTypeFromAttrs(OverrideData overrideData)
    {
        Type overrideType    = null;
        bool componentExists = false;

        foreach (var t in TypeManager.GetAllTypes())
        {
            if (t.Type != null)
            {
                //TODO(andrew.theisen): this grabs the first IComponentData that matches these attributes but multiple matches can exist such as URPMaterialPropertyBaseColor
                //                and HDRPMaterialPropertyBaseColor. It actually shouldn't matter which one is used can they can work either shader.
                foreach (var attr in t.Type.GetCustomAttributes(typeof(MaterialPropertyAttribute), false))
                {
                    if (TypeManager.IsSharedComponentType(t.TypeIndex))
                    {
                        continue;
                    }

                    var propAttr = (MaterialPropertyAttribute)attr;
                    MaterialPropertyFormat propFormat = 0;
                    //TODO(andrew.theisen): So this won't use exisiting IComponentDatas always. for example:
                    //                HDRPMaterialPropertyEmissiveColor is Float3, but the ShaderPropertyType
                    //                is Color but without alpha. can fix this when we can get the DOTS
                    //                type or byte size of the property
                    if (overrideData.type == ShaderPropertyType.Vector || overrideData.type == ShaderPropertyType.Color)
                    {
                        propFormat = MaterialPropertyFormat.Float4;
                    }
                    else if (overrideData.type == ShaderPropertyType.Float || overrideData.type == ShaderPropertyType.Range)
                    {
                        propFormat = MaterialPropertyFormat.Float;
                    }
                    else
                    {
                        break;
                    }

                    if (propAttr.Name == overrideData.name && propAttr.Format == propFormat)
                    {
                        overrideType    = t.Type;
                        componentExists = true;
                        break;
                    }
                }
            }
            if (componentExists)
            {
                break;
            }
        }
        return(overrideType);
    }
Esempio n. 5
0
        public void OverrideDataConstructorTest()
        {
            OverrideData target = new OverrideData();

            Assert.AreEqual(typeof(OverrideData), target.GetType());
        }
Esempio n. 6
0
    public void GenerateScriptString()
    {
        string preamble =
            @"using System;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Rendering;
using UnityEngine;
";

        for (int i = 0; i < overrideList.Count; i++)
        {
            OverrideData overrideData = overrideList[i];

            bool componentExists = false;
            foreach (var t in TypeManager.GetAllTypes())
            {
                if (t.Type != null)
                {
                    if (t.Type.ToString() == overrideData.name.Replace("_", "") + "Vector4Override")
                    {
                        componentExists = true;
                        break;
                    }
                }
            }

            if (componentExists)
            {
                continue;
            }

            string generatedStruct = "";

            string @fieldName = overrideData.name.Replace("_", "");
            string @typeName  = "";

            if (overrideData.type == ShaderPropertyType.Color ||
                overrideData.type == ShaderPropertyType.Vector)
            {
                @typeName       = "Vector4";
                generatedStruct =
                    $@"
[Serializable]
[MaterialProperty(""{@overrideData.name}"", MaterialPropertyFormat.Float4)]
struct {@fieldName}{@typeName}Override : IComponentData, IConvertVector
{{
    public float4 Value;

    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem, Vector4 value)
    {{
        Value = new float4(value.x, value.y, value.z, value.w);
        dstManager.AddComponentData(entity, this);
    }}
}}
";
            }
            else if (overrideData.type == ShaderPropertyType.Float)
            {
                @typeName       = "Float";
                generatedStruct =
                    $@"
[Serializable]
[MaterialProperty(""{@overrideData.name}"", MaterialPropertyFormat.Float)]
struct {@fieldName}{@typeName}Override : IComponentData, IConvertFloat
{{
    public float Value;

    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem, float value)
    {{
        Value = value;
        dstManager.AddComponentData(entity, this);
    }}
}}
";
            }

            if (generatedStruct != "")
            {
                //TODO(atheisen): way to guarantee compile happens promptly on file creation to not confuse user?
                //TODO(atheisen): writeall text 260 char limit for filepath
                string scriptPath = Path.Combine(Path.GetDirectoryName(overrideData.materialName),
                                                 $@"{@fieldName}{@typeName}OverrideGenerated.cs");
                File.WriteAllText(scriptPath, preamble + generatedStruct);
            }
        }
    }