BetterAnimalsTab.Widgets_PetFollow.Initialize C# (CSharp) Méthode

Initialize() private static méthode

private static Initialize ( ) : void
Résultat void
        private static void Initialize()
        {
            _available = LoadedModManager.RunningMods.Any( mod => mod.Name == PF_MOD_NAME );
            _initialized = true;

            if ( _available )
            {
                try
                {
                    // get the assembly
                    var PF_assembly = LoadedModManager
                                        .RunningMods.First( mod => mod.Name == PF_MOD_NAME )
                                        .assemblies.loadedAssemblies.First();

                    if (PF_assembly == null )
                        throw new Exception( "PetFollow assembly not found." );

                    // get the Utils type
                    var PF_UtilsType = PF_assembly.GetType( PF_TYPE_UTILS );
                    if (PF_UtilsType == null )
                        throw new Exception( "PetFollow utilities type not found.");

                    // get the various fields and methods we need.
                    // methods: get drafted following
                    _hasDraftedDesignationMethodInfo = PF_UtilsType.GetMethod( PF_METHOD_GET_FOLLOW_DRAFTED,
                                                                               BINDINGDLAGS_ALL );
                    if ( _hasDraftedDesignationMethodInfo == null )
                        throw new Exception( "PetFollow method not found: " + PF_METHOD_GET_FOLLOW_DRAFTED );

                    // methods: get hunter following
                    _hasHuntDesignationMethodInfo = PF_UtilsType.GetMethod( PF_METHOD_GET_FOLLOW_HUNTED,
                                                                               BINDINGDLAGS_ALL );
                    if ( _hasHuntDesignationMethodInfo == null )
                        throw new Exception( "PetFollow method not found: " + PF_METHOD_GET_FOLLOW_HUNTED );

                    // methods: set following
                    _setDesignationMethodInfo = PF_UtilsType.GetMethod( PF_METHOD_SET_FOLLOW, BINDINGDLAGS_ALL );
                    if ( _setDesignationMethodInfo == null )
                        throw new Exception( "PetFollow method not found: " + PF_METHOD_SET_FOLLOW );

                    // methods: things is 'followable' (i.e. has master, obedience, player faction)
                    _thingIsFollowableMethodInfo = PF_UtilsType.GetMethod( PF_METHOD_THING_FOLLOWABLE, BINDINGDLAGS_ALL );
                    if ( _thingIsFollowableMethodInfo == null )
                        throw new Exception( "PetFollow method not found: " + PF_METHOD_THING_FOLLOWABLE );

                    // fields: hunter follow designation name
                    _designationNameFollowHunter =
                        PF_UtilsType.GetField( PF_FIELD_DEFNAME_FOLLOW_HUNTER, BINDINGDLAGS_ALL )?.GetValue( null ) as string;
                    if ( _designationNameFollowHunter.NullOrEmpty() )
                        throw new Exception( "PetFollow field not found: " + PF_FIELD_DEFNAME_FOLLOW_HUNTER );

                    // fields: drafted follow designation name
                    _designationNameFollowDrafted =
                        PF_UtilsType.GetField( PF_FIELD_DEFNAME_FOLLOW_DRAFTED, BINDINGDLAGS_ALL )?.GetValue( null ) as string;
                    if ( _designationNameFollowDrafted.NullOrEmpty() )
                        throw new Exception( "PetFollow field not found: " + PF_FIELD_DEFNAME_FOLLOW_DRAFTED );

                    // icons: hunter
                    FollowHuntIcon = ContentFinder<Texture2D>.Get( "HuntFollow" );
                    if ( FollowHuntIcon == null )
                        throw new Exception( "PetFollow icon not found: HuntFollow" );

                    // icons: drafted
                    FollowDraftIcon = ContentFinder<Texture2D>.Get( "DraftFollow" );
                    if ( FollowDraftIcon == null )
                        throw new Exception( "PetFollow icon not found: DraftFollow" );

                    Log.Message( "Animal Tab :: PetFollow functionality integrated" );
                }
                catch
                {
                    _anyError = true;
                    Log.Error( "Animal Tab :: Error in PetFollow integration - functionality disabled" );
                    throw;
                }
            }
        }