using System; using System.Collections.Generic; using System.Linq; using Goap.Core; using Phantom.XRMOD.UnityFusion.Runtime; using UnityEngine; using UnityFusion.CLR.TypeSystem; namespace Goap.Runtime { public class ClassResolver { public List Load(IEnumerable list) where TType : class, IHasConfig where TConfig : IClassConfig { TType action; if (list == null) return new List(); return list.Where(x => !string.IsNullOrEmpty(x?.ClassType) && x.ClassType != "UNDEFINED").Select(x => { if (x is CLRType || CodesHook.GetAppDomain == null) { action = Activator.CreateInstance(Type.GetType(x.ClassType)) as TType; } else { try { action = CodesHook.GetAppDomain.Instantiate(x.ClassType).CLRInstance as TType; } catch (Exception tmp_Exception) { Debug.LogError($"Error:{x.ClassType}\n{tmp_Exception}"); throw; } } action?.SetConfig(x); return action; }).ToList(); } public TType Load(string type) where TType : class { if (string.IsNullOrEmpty(type)) return null; return Activator.CreateInstance(Type.GetType(type)) as TType; } public HashSet LoadTypes(IEnumerable list) { var types = list.Select(Type.GetType); var classes = types.Select(Activator.CreateInstance); return classes.Cast().ToHashSet(); } } }