using Godot; using System.Reflection; using System.Collections.Generic; namespace Rokojori { [Tool] [GlobalClass] public partial class SubMaterialTransfer:Resource { [Export] public string info; [ExportGroup("Shader Matching/Standard Shaders")] [Export] public bool canvasItem; [Export] public bool fog; [Export] public bool orm3D; [Export] public bool standard3D; [Export] public bool panoramaSky; [Export] public bool particleProcess; [Export] public bool physicalSky; [Export] public bool placeholder; [Export] public bool proceduralSky; [Export] public bool shader; [ExportGroup("Shader Matching/Custom Shaders")] [Export] public Shader[] shaders; public bool MatchesMaterial( Material m ) { if ( TypeTest( m, canvasItem ) ){ return true; } if ( TypeTest( m, fog ) ){ return true; } if ( TypeTest( m, orm3D ) ){ return true; } if ( TypeTest( m, standard3D ) ){ return true; } if ( TypeTest( m, panoramaSky ) ){ return true; } if ( TypeTest( m, particleProcess ) ){ return true; } if ( TypeTest( m, physicalSky ) ){ return true; } if ( TypeTest( m, placeholder ) ){ return true; } if ( TypeTest( m, proceduralSky ) ){ return true; } if ( TypeTest( m, shader ) ){ return true; } var shaderMaterial = m as ShaderMaterial; if ( shaderMaterial == null ) { return false; } for ( int i = 0; i < shaders.Length; i++ ) { if ( shaderMaterial.Shader == shaders[ i ] ) { return true; } } return false; } bool TypeTest( Material m, bool isType ) where T:class { if ( ! isType ) { return false; } return ( m as T ) != null; } [ExportGroup("Property Transfers")] [Export] public BoolPropertyTransfer[] bools; [Export] public ColorPropertyTransfer[] colors; [Export] public FloatPropertyTransfer[] floats; [Export] public IntPropertyTransfer[] ints; [Export] public Texture2DPropertyTransfer[] texture2D; [Export] public Vector2PropertyTransfer[] vector2; [Export] public Vector3PropertyTransfer[] vector3; [Export] public Vector4PropertyTransfer[] vector4; [Export] public CustomMaterialTransfer[] custom; public void Transfer( Material a, Material b ) { Arrays.ForEach( bools, p => p.Transfer( a, b ) ); Arrays.ForEach( colors, p => p.Transfer( a, b ) ); Arrays.ForEach( floats, p => p.Transfer( a, b ) ); Arrays.ForEach( ints, p => p.Transfer( a, b ) ); Arrays.ForEach( texture2D, p => p.Transfer( a, b ) ); Arrays.ForEach( vector2, p => p.Transfer( a, b ) ); Arrays.ForEach( vector3, p => p.Transfer( a, b ) ); Arrays.ForEach( vector4, p => p.Transfer( a, b ) ); } } }