示例#1
0
        static public string ExecuteScript(string filename)
        {
            string content = FileUtility.ReadStringFromFile(filename);

            if (string.IsNullOrEmpty(content))
            {
                Entry.LogError("Cannot find {0}, or it is empty!", filename);
                return(string.Empty);
            }
            return(ExecuteScript(content, Path.GetFileName(filename)));
        }
        static public void BindFromJson(string filename)
        {
            string jsonContent = FileUtility.ReadStringFromFile(filename);

            if (string.IsNullOrEmpty(jsonContent))
            {
                Entry.LogError("Try to bind dynamically but no content from json [{0}]!", filename);
                return;
            }

            BindingRecordConfig config = JsonUtility.FromJson <BindingRecordConfig>(jsonContent);

            if (config.assemblies?.Count > 0)
            {
#if UNITY_IOS
                Entry.LogError("Dynamic binding is not supported on iOS, since reflection is forbidden!");
#else
                foreach (BindingRecordConfigAssembly record in config.assemblies)
                {
#if !UNITY_IOS
                    Assembly assembly = Assembly.Load(record.name);
                    if (null == assembly)
                    {
                        Entry.LogError("Try to bind dynamically but load assembly [{0}] failed!", record.name);
                        continue;
                    }
#endif
                    foreach (string typename in record.types)
                    {
#if UNITY_IOS
                        Type type = sTypeTable?.GetType(typename);
#else
                        Type type = assembly.GetType(typename);
#endif
                        if (null == type)
                        {
                            Entry.LogError("Try to bind dynamically but load type [{0}] failed!", typename);
                            continue;
                        }
                        Bind(type);
                    }
                }
#endif
            }
        }