### Install Loxodon Framework via OpenUPM CLI Source: https://github.com/vovgou/loxodon-framework/blob/master/Installation.md This snippet demonstrates how to install the openupm-cli globally using npm, navigate to your Unity project's root directory, and then add the com.vovgou.loxodon-framework package using the openupm command. This method requires Node.js and npm. ```bash npm install -g openupm-cli cd F:/workspace/New Unity Project openupm add com.vovgou.loxodon-framework ``` -------------------------------- ### Perform Data Binding Setup in Loxodon Framework Lua (Start) Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.XLua/Assets/Samples/Loxodon Framework XLua/2.0.0/Examples/Resources/DatabindingExample.lua.txt The `start` method of `DatabindingExample` illustrates the process of setting up data bindings. It initializes instances of `Account` and `DatabindingViewModel`, assigns the view model to the `BindingContext`, and then uses `CreateBindingSet` to establish various one-way and two-way bindings between UI elements (e.g., `username`, `password`, `email` inputs) and view model properties. It also includes an example of expression-based binding for formatting the `birthday`. ```Lua function M:start() local account = Account({ id = 1, username = "test", password = "test", email = "yangpc.china@gmail.com", birthday = os.time({year =2000, month = 03, day =03, hour =00, min =00, sec = 00}), address = "beijing", remember = true }) self.viewModel = DatabindingViewModel({ account = account, username = "", email = "", remember = true, errors = ObservableDictionary() }) self:BindingContext().DataContext = self.viewModel local bindingSet = self:CreateBindingSet(); bindingSet:Bind(self.username):For("text"):To("account.username"):OneWay() bindingSet:Bind(self.password):For("text"):To("account.password"):OneWay() bindingSet:Bind(self.email):For("text"):To("account.email"):OneWay() bindingSet:Bind(self.remember):For("text"):To("account.remember"):OneWay() bindingSet:Bind(self.birthday):For("text"):ToExpression(function(vm) return os.date("%Y-%m-%d",vm.account.birthday) end ,"account.birthday"):OneWay() bindingSet:Bind(self.address):For("text"):To("account.address"):OneWay() bindingSet:Bind(self.errorMessage):For("text"):To("errors['errorMessage']"):OneWay() bindingSet:Bind(self.usernameInput):For("text","onEndEdit"):To("username"):TwoWay() end ``` -------------------------------- ### Initialize Async/Await Example Class and Dependencies in Lua Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.XLua/Assets/Samples/Loxodon Framework XLua/2.0.0/Examples/Resources/AsyncAndAwaitExample.lua.txt This snippet demonstrates the initial setup for an asynchronous example class in Lua. It includes the necessary `require` statements for core framework modules like `System`, `AsyncTask`, and Unity's `Resources` and `GameObject`, followed by the class definition itself, preparing the environment for async/await operations. ```Lua require("framework.System") local AsyncTask = require("framework.AsyncTask") local Resources = CS.UnityEngine.Resources local GameObject = CS.UnityEngine.GameObject local M=class("AsyncAndAwaitExample",target) ``` -------------------------------- ### Install Loxodon Framework TextUGUI via OpenUPM Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.TextUGUI/README.md Instructions for installing the Loxodon Framework TextUGUI package using OpenUPM. This method requires Node.js and openupm-cli, which should be installed first if not already present. The commands install the CLI globally and then add the package to your Unity project. ```Shell # Install openupm-cli,please ignore if it is already installed. npm install -g openupm-cli #Go to the root directory of your project cd F:/workspace/New Unity Project #Install loxodon-framework-textugui openupm add com.vovgou.loxodon-framework-textugui ``` -------------------------------- ### Initialize Loxodon Framework Services in Lua (Awake) Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.XLua/Assets/Samples/Loxodon Framework XLua/2.0.0/Examples/Resources/DatabindingExample.lua.txt This `awake` method, part of the `DatabindingExample` class, demonstrates the initialization of core Loxodon Framework services. It retrieves the application context and container, sets up localization with `DefaultDataProvider` and `XmlDocumentParser`, and starts the `LuaBindingServiceBundle` for data binding. ```Lua function M:awake() local context = Context.GetApplicationContext() local container = context:GetContainer() local cultureInfo = Locale.GetCultureInfo() local localization = Localization.Current localization.CultureInfo = cultureInfo localization:AddDataProvider(DefaultDataProvider("LuaLocalizations", XmlDocumentParser())) local bundle = LuaBindingServiceBundle(container) bundle:Start(); end ``` -------------------------------- ### Install Loxodon Framework Connection via OpenUPM Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.Connection/Assets/LoxodonFramework/Connection/Documentation~/README.md Instructions to install the Loxodon Framework Connection using OpenUPM, which requires Node.js and npm. First, install openupm-cli globally, then navigate to the Unity project root and add the package. ```Shell # Install openupm-cli,please ignore if it is already installed. npm install -g openupm-cli #Go to the root directory of your project cd F:/workspace/New Unity Project #Install loxodon-framework-connection openupm add com.vovgou.loxodon-framework-connection ``` -------------------------------- ### Configure Loxodon Framework Dependency in Unity manifest.json Source: https://github.com/vovgou/loxodon-framework/blob/master/Installation.md This JSON snippet illustrates how to manually add the com.vovgou.loxodon-framework package as a dependency and configure the package.openupm.com scoped registry within your Unity project's Packages/manifest.json file. This approach bypasses the need for Node.js and openupm-cli. ```json { "dependencies": { ... "com.unity.modules.xr": "1.0.0", "com.vovgou.loxodon-framework": "2.6.3" }, "scopedRegistries": [ { "name": "package.openupm.com", "url": "https://package.openupm.com", "scopes": [ "com.vovgou" ] } ] } ``` -------------------------------- ### Initialize Loxodon Framework Application and Display Startup Window in Lua Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.XLua/Assets/Samples/Loxodon Framework XLua/2.0.0/Examples/Resources/Launcher.lua.txt This Lua code snippet illustrates the core steps for starting an application with the Loxodon Framework. It shows how to obtain and utilize the application context for registering global services (e.g., AccountService), retrieve a view locator, create a window container, and load a specific UI window (Startup). The example also demonstrates how to manage the window's lifecycle, including creation, display, and listening for transition events like state changes and completion. ```Lua require("framework.System") local WindowContainer = CS.Loxodon.Framework.Views.WindowContainer local Context = CS.Loxodon.Framework.Contexts.Context local AccountService = require("Services.AccountService") -- --模块 --@module Launcher local M=class("Launcher",target) function M:start() -- 获得应用上下文,一个游戏建议创建应用上下文和玩家上下文。 -- 全局的服务都放入应用上下文中,如账号服务,网络组件,配置服务等基础组件和服务 -- 只与某个玩家相关的如背包服务、装备服务、角色服务都放入玩家上下文,当登出游戏可以统一释放 local context = Context.GetApplicationContext() --注册一个账号服务 context:GetContainer():Register("accountService",AccountService()) -- 从应用上下文获得一个视图定位器 local locator = context:GetService("IUIViewLocator") -- 创建一个名为MAIN的窗口容器 local winContainer = WindowContainer.Create("MAIN") -- 通过视图定位器,加载一个启动窗口视图 local window = locator:LoadWindow(winContainer, "LuaUI/Startup/Startup") window:Create() --创建窗口 local transition = window:Show() --显示窗口,返回一个transition对象,窗口显示一般会有窗口动画,所以是一个持续过程的操作 transition:OnStateChanged(function(w,state) print("Window:"..w.Name.." State:"..state:ToString()) end) --监听显示窗口过程的窗口状态 transition:OnFinish(function() print("OnFinished") end) --监听窗口显示完成事件 print("lua start...") end return M ``` -------------------------------- ### Install Loxodon Framework TextMeshPro via OpenUPM CLI Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.TextMeshPro/README.md Provides command-line instructions for installing the Loxodon Framework TextMeshPro plugin using OpenUPM. This method automatically manages dependencies and requires Node.js npm and openupm-cli to be installed. ```Shell # Install openupm-cli,please ignore if it is already installed. npm install -g openupm-cli #Go to the root directory of your project cd F:/workspace/New Unity Project #Install loxodon-framework-textmeshpro openupm add com.vovgou.loxodon-framework-textmeshpro ``` -------------------------------- ### Install Loxodon Framework ILRuntime via OpenUPM CLI Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.ILRuntime/README.md Commands to install the openupm-cli globally using npm, navigate to the Unity project's root directory, and then add the Loxodon Framework ILRuntime package using the openupm command-line interface. This method requires Node.js and npm to be installed. ```Shell # Install openupm-cli,please ignore if it is already installed. npm install -g openupm-cli #Go to the root directory of your project cd F:/workspace/New Unity Project #Install loxodon-framework-ilruntime openupm add com.vovgou.loxodon-framework-ilruntime ``` -------------------------------- ### Install Loxodon Framework TextFormatting via OpenUPM CLI Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.TextFormatting/README.md Instructions to install the Loxodon Framework TextFormatting plugin using the OpenUPM command-line interface. This method automatically manages dependencies and requires Node.js and openupm-cli to be installed globally. ```Shell npm install -g openupm-cli cd F:/workspace/New Unity Project openupm add com.vovgou.loxodon-framework-textformatting ``` -------------------------------- ### Install Loxodon Framework Addressable via OpenUPM Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.Addressable/Assets/LoxodonFramework/Addressable/Documentation~/README.md Instructions to install the Loxodon Framework Addressable plugin using OpenUPM, which automatically manages dependencies. This method requires Node.js and openupm-cli to be installed first. ```Shell npm install -g openupm-cli cd F:/workspace/New Unity Project openupm add com.vovgou.loxodon-framework-addressable ``` -------------------------------- ### Install Loxodon Framework NLog via OpenUPM CLI Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.NLog/README.md Commands to install openupm-cli globally and then add the loxodon-framework-nlog package to a Unity project using OpenUPM. This method requires Node.js and npm to be installed first. ```bash npm install -g openupm-cli cd F:/workspace/New Unity Project openupm add com.vovgou.loxodon-framework-nlog ``` -------------------------------- ### Loxodon Framework UI Data Binding Setup Source: https://github.com/vovgou/loxodon-framework/blob/master/docs/LoxodonFramework.md This C# snippet illustrates the process of setting up data binding in the Loxodon Framework. It involves creating an initial Account object, instantiating a DatabindingViewModel, obtaining the binding context, and then defining numerous one-way and two-way bindings between UI elements (e.g., text fields, toggles, buttons) and properties within the view model. It also demonstrates binding to expressions and localized strings. ```C# ID = 1, Username = "test", Password = "test", Email = "yangpc.china@gmail.com", Birthday = new DateTime(2000, 3, 3) }; account.Address.Value = "beijing"; //创建数据绑定视图 DatabindingViewModel databindingViewModel = new DatabindingViewModel() { Account = account }; //获得数据绑定上下文 IBindingContext bindingContext = this.BindingContext(); //将视图模型赋值到DataContext bindingContext.DataContext = databindingViewModel; //绑定UI控件到视图模型 BindingSet bindingSet; bindingSet = this.CreateBindingSet(); //绑定左侧视图到账号子视图模型 bindingSet.Bind(this.username).For(v => v.text).To(vm => vm.Account.Username).OneWay(); bindingSet.Bind(this.password).For(v => v.text).To(vm => vm.Account.Password).OneWay(); bindingSet.Bind(this.email).For(v => v.text).To(vm => vm.Account.Email).OneWay(); bindingSet.Bind(this.remember).For(v => v.text).To(vm => vm.Remember).OneWay(); bindingSet.Bind(this.birthday).For(v => v.text).ToExpression(vm => string.Format("{0} ({1})", vm.Account.Birthday.ToString("yyyy-MM-dd"), (DateTime.Now.Year - vm.Account.Birthday.Year))).OneWay(); bindingSet.Bind(this.address).For(v => v.text).To(vm => vm.Account.Address).OneWay(); //绑定右侧表单到视图模型 bindingSet.Bind(this.errorMessage).For(v => v.text).To(vm => vm.Errors["errorMessage"]).OneWay(); bindingSet.Bind(this.usernameEdit).For(v => v.text, v => v.onEndEdit).To(vm => vm.Username).TwoWay(); bindingSet.Bind(this.usernameEdit).For(v => v.onValueChanged).To(vm => vm.OnUsernameValueChanged); bindingSet.Bind(this.emailEdit).For(v => v.text, v => v.onEndEdit).To(vm => vm.Email).TwoWay(); bindingSet.Bind(this.emailEdit).For(v => v.onValueChanged).To(vm => vm.OnEmailValueChanged); bindingSet.Bind(this.rememberEdit).For(v => v.isOn, v => v.onValueChanged).To(vm => vm.Remember).TwoWay(); bindingSet.Bind(this.submit).For(v => v.onClick).To(vm => vm.OnSubmit); bindingSet.Build(); //绑定标题,标题通过本地化文件配置 BindingSet staticBindingSet = this.CreateBindingSet(); staticBindingSet.Bind(this.title).For(v => v.text).To(() => Res.databinding_tutorials_title).OneTime(); staticBindingSet.Build(); } ``` -------------------------------- ### Quick Start: Implementing a Data-Bound ListView in Unity Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.OSA/README.md This C# example demonstrates how to integrate Loxodon Framework OSA with Unity's UI to create a data-bound ListView. It includes a ViewModel (`ListViewExampleViewModel`) for managing `ObservableList` data and a MonoBehaviour (`ListViewExample`) for setting up the binding between UI elements (Buttons, ListViewBindingAdapter) and the ViewModel's commands and properties. The example showcases adding, changing, moving, and resetting items in the list. ```C# public class ListViewExampleViewModel : ViewModelBase { private int id = 0; private ObservableList items; public ObservableList Items { get { return this.items; } set { this.Set(ref items, value); } } public ListViewExampleViewModel() { this.CreateItems(3); } public void AddItem() { items.Add(CreateItem()); } public void ChangeItem() { if (items != null && items.Count > 0) { var model = items[0]; model.Color = DemosUtil.GetRandomColor(); } } public void MoveItem() { if (items != null && items.Count > 1) { items.Move(0, items.Count - 1); } } public void ResetItem() { items.Clear(); } private void CreateItems(int count) { this.items = new ObservableList(); for (int i = 0; i < count; i++) items.Add(CreateItem()); } private ItemViewModel CreateItem() { return new ItemViewModel(this.items) { Title = "Item #" + (id++), }; } } public class ListViewExample : MonoBehaviour { public Button addButton; public Button changeButton; public Button moveButton; public Button resetButton; public ListViewBindingAdapter listView; protected void Awake() { ApplicationContext context = Context.GetApplicationContext(); BindingServiceBundle bindingService = new BindingServiceBundle(context.GetContainer()); bindingService.Start(); } private void Start() { var bindingSet = this.CreateBindingSet(); bindingSet.Bind(addButton).For(v => v.onClick).To(vm => vm.AddItem); bindingSet.Bind(changeButton).For(v => v.onClick).To(vm => vm.ChangeItem); bindingSet.Bind(moveButton).For(v => v.onClick).To(vm => vm.MoveItem); bindingSet.Bind(resetButton).For(v => v.onClick).To(vm => vm.ResetItem); bindingSet.Bind(listView).For(v => v.Items).To(vm => vm.Items); bindingSet.Build(); this.SetDataContext(new ListViewExampleViewModel()); } } ``` -------------------------------- ### Install openupm-cli globally using npm Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.Connection/README.md This command installs the openupm-cli globally using npm. It is a prerequisite for installing Loxodon Framework Connection via OpenUPM. ```shell npm install -g openupm-cli ``` -------------------------------- ### Install Loxodon Framework Fody via OpenUPM CLI Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.Fody/Packages/com.vovgou.loxodon-framework-fody/Documentation~/README.md This snippet provides the shell commands to install the Loxodon Framework Fody plugin and its associated Fody add-ins (PropertyChanged, ToString, BindingProxy) using the OpenUPM command-line interface. Ensure Node.js and openupm-cli are installed before running these commands. ```Shell # Install openupm-cli,please ignore if it is already installed. npm install -g openupm-cli #Go to the root directory of your project cd F:/workspace/New Unity Project #Install loxodon-framework-fody-propertychanged openupm add com.vovgou.loxodon-framework-fody-propertychanged #Install loxodon-framework-fody-tostring openupm add com.vovgou.loxodon-framework-fody-tostring #Install loxodon-framework-fody-bindingproxy openupm add com.vovgou.loxodon-framework-fody-bindingproxy ``` -------------------------------- ### Install Loxodon Framework Connection via OpenUPM Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.Connection/README.md This command adds the Loxodon Framework Connection package to your Unity project using the openupm-cli. This is the recommended installation method. ```shell openupm add com.vovgou.loxodon-framework-connection ``` -------------------------------- ### Install Loxodon Framework Fody via OpenUPM CLI Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.Fody/README.md This snippet provides the command-line instructions to install the Loxodon Framework Fody plugins using OpenUPM CLI. It includes commands to install 'openupm-cli' globally and then add specific Loxodon Fody packages to a Unity project. This method is recommended as OpenUPM automatically manages dependencies. ```Shell # Install openupm-cli,please ignore if it is already installed. npm install -g openupm-cli #Go to the root directory of your project cd F:/workspace/New Unity Project #Install loxodon-framework-fody-propertychanged openupm add com.vovgou.loxodon-framework-fody-propertychanged #Install loxodon-framework-fody-tostring openupm add com.vovgou.loxodon-framework-fody-tostring #Install loxodon-framework-fody-bindingproxy openupm add com.vovgou.loxodon-framework-fody-bindingproxy ``` -------------------------------- ### Local Application Configuration Settings Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework/Assets/LoxodonFramework/Samples~/Tutorials/Resources/application.windowseditor.properties.txt This snippet demonstrates how to define local application configuration parameters, including a username and password. These settings are typically used for development or testing environments and are often stored in a properties-like file. ```Configuration #application config #local application.local.username = loxodon.framework.editor application.local.password = loxodon.framework.editor ``` -------------------------------- ### Configuring Loxodon Preferences with Custom Serializer and Encryptor Source: https://github.com/vovgou/loxodon-framework/blob/master/docs/LoxodonFramework.md This snippet demonstrates how to configure the Loxodon `Preferences` system with a custom serializer and encryptor. It shows the setup of a `DefaultEncryptor` with a specific key and IV, and how to register a custom `ITypeEncoder` (like `ColorTypeEncoder`) with the serializer before registering the `BinaryFilePreferencesFactory`. ```C# //默认使用AES128_CBC_PKCS7加密,当然你也可以自己实现IEncryptor接口,定义自己的加密算法。 byte[] iv = Encoding.ASCII.GetBytes("5CyM5tcL3yDFiWlN"); byte[] key = Encoding.ASCII.GetBytes("W8fnmqMynlTJXPM1"); IEncryptor encryptor = new DefaultEncryptor(key, iv); //序列化和反序列化类 ISerializer serializer = new DefaultSerializer(); //添加自定义的类型编码器 serializer.AddTypeEncoder(new ColorTypeEncoder()); //注册Preferences工厂 BinaryFilePreferencesFactory factory = new BinaryFilePreferencesFactory(serializer, encryptor); Preferences.Register(factory); ``` -------------------------------- ### Install Loxodon Framework Connection via Git URL Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.Connection/README.md This URL can be used in Unity's Package Manager (Unity 2019.3.4f1 or higher) to install the Loxodon Framework Connection directly from the GitHub repository. ```Git URL https://github.com/vovgou/loxodon-framework.git?path=Loxodon.Framework.Connection/Assets/LoxodonFramework/Connection ``` -------------------------------- ### Install Loxodon Framework Connection via manifest.json Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.Connection/Assets/LoxodonFramework/Connection/Documentation~/README.md Configuration for `Packages/manifest.json` to include the Loxodon Framework Connection package. This method adds a scoped registry for `package.openupm.com` and declares the package as a dependency, bypassing the need for Node.js or openm-cli. ```JSON { "dependencies": { ... "com.unity.modules.xr": "1.0.0", "com.vovgou.loxodon-framework-connection": "2.0.0" }, "scopedRegistries": [ { "name": "package.openupm.com", "url": "https://package.openupm.com", "scopes": [ "com.vovgou", "com.openupm" ] } ] } ``` -------------------------------- ### Creating and Opening a Window within a Specific Container (C#) Source: https://github.com/vovgou/loxodon-framework/blob/master/docs/LoxodonFramework.md This C# example illustrates how to instantiate a `WindowContainer` and then load and display a new window within that specific container. This pattern is crucial for managing windows hierarchically and organizing UI flows in complex applications. ```C# WindowContainer winContainer = WindowContainer.Create("MAIN"); IUIViewLocator locator = context.GetService(); //在MAIN容器中打开一个窗口 StartupWindow window = locator.LoadWindow(winContainer, "UI/Startup/Startup"); ITransition transition = window.Show() ``` -------------------------------- ### Install Loxodon Framework TextUGUI via manifest.json Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.TextUGUI/README.md This method allows installation of the Loxodon Framework TextUGUI by directly modifying the project's Packages/manifest.json file. It involves adding the package as a dependency and configuring the OpenUPM scoped registry, eliminating the need for Node.js or openupm-cli. ```JSON { "dependencies": { ... "com.vovgou.loxodon-framework-textugui": "2.6.5" }, "scopedRegistries": [ { "name": "package.openupm.com", "url": "https://package.openupm.com", "scopes": [ "com.vovgou", "com.openupm" ] } ] } ``` -------------------------------- ### XML Configuration Example for Localized UI Dimensions Source: https://github.com/vovgou/loxodon-framework/blob/master/docs/LoxodonFramework.md This XML snippet provides an example of how localization data for UI dimensions can be structured. It defines a vector2-array named 'button.position' for offsetMin and offsetMax values, and a rect named 'button.position2' for anchoredPosition and sizeDelta, demonstrating how different UI properties can be localized. ```XML (100,50) (-100,-50) (100,100,200,60) ``` -------------------------------- ### Install Loxodon Framework Addressable via OpenUPM CLI Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.Addressable/README.md Commands to install openupm-cli globally and then add the Loxodon Framework Addressable package to a Unity project using openupm. This method automatically manages dependencies and requires Node.js. ```Shell npm install -g openupm-cli cd F:/workspace/New Unity Project openupm add com.vovgou.loxodon-framework-addressable ``` -------------------------------- ### Install Loxodon Framework Addressable via manifest.json Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.Addressable/Assets/LoxodonFramework/Addressable/Documentation~/README.md Configuration for installing the Loxodon Framework Addressable plugin by modifying the project's Packages/manifest.json file. This method does not require Node.js or openupm-cli. ```JSON { "dependencies": { ... "com.unity.modules.xr": "1.0.0", "com.vovgou.loxodon-framework-addressable": "2.0.1" }, "scopedRegistries": [ { "name": "package.openupm.com", "url": "https://package.openupm.com", "scopes": [ "com.vovgou", "com.openupm" ] } ] } ``` -------------------------------- ### Initialize AccountService Class in Lua Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.XLua/Assets/Samples/Loxodon Framework XLua/2.0.0/Examples/LuaScripts/Services/AccountService.lua.txt This snippet defines the `AccountService` class, inheriting from `ObservableObject`, and its constructor. The constructor initializes an in-memory table to store `Account` objects, pre-populating it with a 'test' account. This serves as a basic example for account management within the Loxodon Framework. ```Lua require("framework.System") local ObservableObject = require("framework.ObservableObject") local AsyncTask = require("framework.AsyncTask") local Account = class("Account",ObservableObject) local M=class("AccountService") function M:ctor() self.accounts = {} local account = Account({username="test",password="test"}) self.accounts[account.username] = account end ``` -------------------------------- ### Install OpenUPM CLI globally Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.Log4Net/README.md This command installs the `openupm-cli` tool globally using npm. It is a prerequisite for managing Unity packages via OpenUPM, allowing for automated dependency management. ```shell npm install -g openupm-cli ``` -------------------------------- ### Install Loxodon Framework TextMeshPro by Modifying manifest.json Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.TextMeshPro/README.md Details how to install the Loxodon Framework TextMeshPro plugin by manually editing the `Packages/manifest.json` file. This approach adds the package as a dependency and configures the OpenUPM scoped registry, bypassing the need for Node.js or openupm-cli. ```JSON { "dependencies": { ... "com.vovgou.loxodon-framework-textmeshpro": "2.6.5" }, "scopedRegistries": [ { "name": "package.openupm.com", "url": "https://package.openupm.com", "scopes": [ "com.vovgou", "com.openupm" ] } ] } ``` -------------------------------- ### C# AlertDialog Control Usage Example Source: https://github.com/vovgou/loxodon-framework/blob/master/docs/LoxodonFramework.md This example demonstrates how to use the `AlertDialog` control in C#. It shows how to modify the default view path for the dialog and how to display a message dialog with a custom title, message, buttons, and a callback to handle the user's selection result. ```C# //对话框视图默认目录路径是UI/AlertDialog,可以通过如下方式修改视图路径 AlertDialog.ViewName = "Your view directory/AlertDialog"; //C#,打开一个对话框窗口 AlertDialog.ShowMessage("This is a dialog test.", "Interation Example", "Yes", null, "No", true, result => { Debug.LogFormat("Result:{0}",result); }); ``` -------------------------------- ### Install Loxodon Framework Addressable via Unity manifest.json Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.Addressable/README.md Configuration for the `Packages/manifest.json` file to add the Loxodon Framework Addressable package and the OpenUPM scoped registry. This method does not require Node.js or openupm-cli. ```JSON { "dependencies": { ... "com.unity.modules.xr": "1.0.0", "com.vovgou.loxodon-framework-addressable": "2.0.1" }, "scopedRegistries": [ { "name": "package.openupm.com", "url": "https://package.openupm.com", "scopes": [ "com.vovgou", "com.openupm" ] } ] } ``` -------------------------------- ### Implementing a Message System in Unity with Loxodon Messenger Source: https://github.com/vovgou/loxodon-framework/blob/master/docs/LoxodonFramework.md This example illustrates the Loxodon Messenger system for inter-module communication. It demonstrates how to obtain the default Messenger, subscribe to messages by type, publish messages, and subscribe/publish messages on specific channels. It also shows how to properly dispose of subscriptions to prevent memory leaks. ```C# public class MessengerExample : MonoBehaviour { private IDisposable subscription; private IDisposable chatroomSubscription; private void Start() { //获得默认的Messenger Messenger messenger = Messenger.Default; //订阅一个消息,确保subscription是成员变量,否则subscription被GC回收时会自动退订消息 subscription = messenger.Subscribe((PropertyChangedMessage message) => { Debug.LogFormat("Received Message:{0}", message); }); //发布一个属性名改变的消息 messenger.Publish(new PropertyChangedMessage("clark", "tom", "Name")); //订阅聊天频道"chatroom1"的消息 chatroomSubscription = messenger.Subscribe("chatroom1", (string message) => { Debug.LogFormat("Received Message:{0}", message); }); //向聊天频道"chatroom1"发布一条消息 messenger.Publish("chatroom1", "hello!"); } private void OnDestroy() { if (this.subscription != null) { //退订消息 this.subscription.Dispose(); this.subscription = null; } if (this.chatroomSubscription != null) { //退订消息 this.chatroomSubscription.Dispose(); this.chatroomSubscription = null; } } } ``` -------------------------------- ### Configure Loxodon Framework NLog via manifest.json Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.NLog/README.md JSON configuration for the 'Packages/manifest.json' file to add the 'com.vovgou.loxodon-framework-nlog' dependency and the OpenUPM scoped registry. This installation method does not require Node.js or openm-cli. ```json { "dependencies": { ... "com.unity.modules.xr": "1.0.0", "com.vovgou.loxodon-framework-nlog": "2.6.1" }, "scopedRegistries": [ { "name": "package.openupm.com", "url": "https://package.openupm.com", "scopes": [ "com.vovgou", "com.openupm" ] } ] } ``` -------------------------------- ### Add Loxodon Framework Log4Net package via OpenUPM Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.Log4Net/README.md This command uses the `openupm-cli` to add the `com.vovgou.loxodon-framework-log4net` package to your Unity project. OpenUPM automatically handles its dependencies, simplifying the installation process. ```shell openupm add com.vovgou.loxodon-framework-log4net ``` -------------------------------- ### Install Loxodon Framework Fody via Unity manifest.json Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.Fody/README.md This snippet shows how to manually install Loxodon Framework Fody plugins by directly modifying the 'Packages/manifest.json' file in a Unity project. It involves adding the OpenUPM registry configuration and specifying the Loxodon Fody packages as dependencies. This method does not require Node.js or 'openupm-cli'. ```JSON { "dependencies": { "com.vovgou.loxodon-framework-fody": "2.6.0", "com.vovgou.loxodon-framework-fody-propertychanged": "2.6.0", "com.vovgou.loxodon-framework-fody-tostring": "2.6.0", "com.vovgou.loxodon-framework-fody-bindingproxy": "2.6.0" }, "scopedRegistries": [ { "name": "package.openupm.com", "url": "https://package.openupm.com", "scopes": [ "com.vovgou", "com.openupm" ] } ] } ``` -------------------------------- ### Creating and Binding a Custom Window in Loxodon Framework Source: https://github.com/vovgou/loxodon-framework/blob/master/docs/LoxodonFramework.md This snippet demonstrates how to create a custom window and bind its UI elements to a ViewModel using the Loxodon Framework's data binding capabilities. It includes examples for both C# and Lua, showcasing how to establish two-way and one-way bindings for properties and events. ```C# public class ExampleWindow : Window { public Text progressBarText; public Slider progressBarSlider; public Text tipText; public Button button; protected override void OnCreate(IBundle bundle) { BindingSet bindingSet; bindingSet = this.CreateBindingSet(new ExampleViewModel()); bindingSet.Bind(this.progressBarSlider).For("value", "onValueChanged").To("ProgressBar.Progress").TwoWay(); bindingSet.Bind(this.progressBarSlider.gameObject).For(v => v.activeSelf) .To(vm => vm.ProgressBar.Enable).OneWay(); bindingSet.Bind(this.progressBarText).For(v => v.text) .ToExpression( vm => string.Format("{0}%", Mathf.FloorToInt(vm.ProgressBar.Progress * 100f))) .OneWay(); bindingSet.Bind(this.tipText).For(v => v.text).To(vm => vm.ProgressBar.Tip).OneWay(); bindingSet.Bind(this.button).For(v => v.onClick).To(vm => vm.Click).OneWay(); binding,bound to the onClick event and interactable property. bindingSet.Build(); } protected override void OnDismiss() { } } ``` ```Lua require("framework.System") local ExampleViewModel = require("LuaUI.Startup.ExampleViewModel") --- --模块 --@module ExampleWindow local M=class("ExampleWindow",target) function M:onCreate(bundle) self.viewModel = ExampleViewModel() self:BindingContext().DataContext = self.viewModel local bindingSet = self:CreateBindingSet() bindingSet:Bind(self.progressBarSlider):For("value", "onValueChanged"):To("progressBar.progress"):TwoWay() bindingSet:Bind(self.progressBarSlider.gameObject):For("activeSelf"):To("progressBar.enable"):OneWay() bindingSet:Bind(self.progressBarText):For("text"):ToExpression( function(vm) return string.format("%0.2f%%",vm.progressBar.progress * 100) end, "progressBar.progress"):OneWay() bindingSet:Bind(self.tipText):For("text"):To("progressBar.tip"):OneWay() bindingSet:Bind(self.button):For("onClick"):To("command"):OneWay() bindingSet:Build() end return M ``` -------------------------------- ### Configure Unity Package Manager Dependencies for Loxodon Framework Data Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.Data/README.md To install the Loxodon Framework Data plugin and its optional components (LiteDB and Newtonsoft.Json support), add the OpenUPM registry and the plugin dependencies to your Unity project's `manifest.json` file. This allows Unity to automatically download and install the required packages. ```JSON { "dependencies": { ... "com.unity.modules.xr": "1.0.0", "com.vovgou.loxodon-framework-data": "2.4.9", "com.vovgou.loxodon-framework-data-litedb": "2.4.9", "com.vovgou.loxodon-framework-data-newtonsoft": "2.4.9" }, "scopedRegistries": [ { "name": "package.openupm.com", "url": "https://package.openupm.com", "scopes": [ "com.vovgou", "com.openupm" ] } ] } ``` -------------------------------- ### C# Example: Data Binding with TemplateTextMeshProUGUI and FormattableTextMeshProUGUI Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.TextMeshPro/README.md This C# code demonstrates how to implement data binding using `TemplateTextMeshProUGUI` and `FormattableTextMeshProUGUI` controls in the Loxodon Framework. It illustrates binding scalar parameters, array elements, and complex object properties (like `Hero.Health`) from a ViewModel to UI text. The example includes `ExampleViewModel` and `Hero` classes, showing how to set up observable properties for dynamic UI updates. ```C# public class FormattableTextMeshProUGUIExample : MonoBehaviour { public FormattableTextMeshProUGUI paramBinding1; public GenericParameters paramBinding2; public FormattableTextMeshProUGUI arrayBinding; public TemplateTextMeshProUGUI template; private ExampleViewModel viewModel; private void Start() { ApplicationContext context = Context.GetApplicationContext(); IServiceContainer container = context.GetContainer(); BindingServiceBundle bundle = new BindingServiceBundle(context.GetContainer()); bundle.Start(); BindingSet bindingSet = this.CreateBindingSet(); bindingSet.Bind(paramBinding1.AsParameters()).For(v => v.Parameter1).To(vm => vm.Time); bindingSet.Bind(paramBinding1.AsParameters()).For(v => v.Parameter2).To(vm => vm.FrameCount); //format:Example2,{0:yyyy-MM-dd HH:mm:ss}, FrameCount:{1} bindingSet.Bind(paramBinding2).For(v => v.Parameter1).To(vm => vm.Time); bindingSet.Bind(paramBinding2).For(v => v.Parameter2).To(vm => vm.FrameCount); //AsArray() bindingSet.Bind(arrayBinding.AsArray()).For(v => v[0]).To(vm => vm.Hero.MoveSpeed); bindingSet.Bind(arrayBinding.AsArray()).For(v => v[1]).To(vm => vm.Hero.AttackSpeed); bindingSet.Bind(template).For(v => v.Template).To(vm => vm.Template); bindingSet.Bind(template).For(v => v.Data).To(vm => vm); bindingSet.Build(); this.viewModel = new ExampleViewModel(); this.viewModel.Template = "Template,Frame:{FrameCount:D6},Health:{Hero.Health:D4} AttackDamage:{Hero.AttackDamage} Armor:{Hero.Armor}"; this.viewModel.Time = DateTime.Now; this.viewModel.TimeSpan = TimeSpan.FromSeconds(0); this.viewModel.Hero = new Hero(); this.SetDataContext(this.viewModel); } void Update() { viewModel.Time = DateTime.Now; viewModel.FrameCount = Time.frameCount; viewModel.Hero.Health = (Time.frameCount % 1000) / 10; } } public class ExampleViewModel : ObservableObject { private DateTime time; private TimeSpan timeSpan; private string template; private int frameCount; private Hero hero; public DateTime Time { get { return this.time; } set { this.Set(ref time, value); } } public TimeSpan TimeSpan { get { return this.timeSpan; } set { this.Set(ref timeSpan, value); } } public int FrameCount { get { return this.frameCount; } set { this.Set(ref frameCount, value); } } public string Template { get { return this.template; } set { this.Set(ref template, value); } } public Hero Hero { get { return this.hero; } set { this.Set(ref hero, value); } } } public class Hero : ObservableObject { private float attackSpeed = 95.5f; private float moveSpeed = 2.4f; private int health = 100; private int attackDamage = 20; private int armor = 30; public float AttackSpeed { get { return this.attackSpeed; } set { this.Set(ref attackSpeed, value); } } public float MoveSpeed { get { return this.moveSpeed; } set { this.Set(ref moveSpeed, value); } } public int Health { get { return this.health; } set { this.Set(ref health, value); } } public int AttackDamage { get { return this.attackDamage; } set { this.Set(ref attackDamage, value); } } public int Armor { ``` -------------------------------- ### Define Main Databinding ViewModel in Lua Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.XLua/Assets/Samples/Loxodon Framework XLua/2.0.0/Examples/Resources/DatabindingExample.lua.txt This snippet defines the `DatabindingViewModel` class, the primary view model for data binding examples. It extends `ObservableObject` and its constructor initializes properties such as an `Account` instance, `remember` flag, `username`, `email`, and an `ObservableDictionary` for storing validation errors. ```Lua local DatabindingViewModel = class("DatabindingViewModel",ObservableObject) function DatabindingViewModel:ctor(t) DatabindingViewModel.base(self).ctor(self,t) if not (t and type(t)=="table") then self.account = Account() self.remember = false self.username = "" self.email = "" self.errors = ObservableDictionary() end end ``` -------------------------------- ### Install Loxodon Framework TextFormatting via Unity manifest.json Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.TextFormatting/README.md Configuration snippet for directly adding the Loxodon Framework TextFormatting plugin to a Unity project by modifying the Packages/manifest.json file. This approach does not require Node.js or openupm-cli. ```JSON { "dependencies": { ... "com.vovgou.loxodon-framework-textformatting": "2.6.2" }, "scopedRegistries": [ { "name": "package.openupm.com", "url": "https://package.openupm.com", "scopes": [ "com.vovgou", "com.openupm" ] } ] } ``` -------------------------------- ### Registering WovenNodeProxyFactory for BindingProxy.Fody Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.Fody/README.md C# code demonstrating how to initialize the data binding service and register the `WovenNodeProxyFactory` with a specific priority after the `BindingServiceBundle` starts. ```C# ApplicationContext context = Context.GetApplicationContext(); IServiceContainer container = context.GetContainer(); /* Initialize the data binding service */ BindingServiceBundle bundle = new BindingServiceBundle(context.GetContainer()); bundle.Start(); INodeProxyFactoryRegister nodeFactoryRegister = container.Resolve(); nodeFactoryRegister.Register(new WovenNodeProxyFactory(),100);//Set the priority to 100 ``` -------------------------------- ### Initialize StartupViewModel and Setup Commands (Lua) Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.XLua/Assets/Samples/Loxodon Framework XLua/2.0.0/Examples/LuaScripts/Views/UI/Startup/StartupViewModel.lua.txt This constructor initializes the `StartupViewModel` by retrieving necessary services like `Localization`, `AccountService`, and `GlobalPreferences` from the application context. It sets up `AsyncInteractionRequest` for login and `InteractionRequest` for dismissal, and defines a `SimpleCommand` to handle the login flow, including displaying a `LoginViewModel` and loading the scene upon successful authentication. ```Lua function M:ctor() M.super.ctor(self) local context = Context.GetApplicationContext() self.localization = context:GetService("Localization") self.accountService = context:GetService("accountService") self.globalPreferences = context:GetGlobalPreferences() self.loginRequest = AsyncInteractionRequest(self) self.dismissRequest = InteractionRequest(self) self.progressBar = ProgressBar() self.command = SimpleCommand(async(function() self.command.Enabled = false local loginViewModel = LoginViewModel({accountService = self.accountService, localization = self.localization, globalPreferences = self.globalPreferences}) local notification = WindowNotification.CreateShowNotification(loginViewModel,false,true) await(self.loginRequest:Raise(notification)) self.command.Enabled = true if loginViewModel.account then self:loadScene() end --[[ self.loginRequest:Raise(loginViewModel, function(vm) self.command.Enabled = true if vm.account then self:loadScene() end end) --]] end),true) end ``` -------------------------------- ### Scheduling Timed Tasks with Loxodon IScheduledExecutor Source: https://github.com/vovgou/loxodon-framework/blob/master/docs/LoxodonFramework.md This example illustrates the use of Loxodon's `IScheduledExecutor` interface, specifically the `ThreadScheduledExecutor`, to schedule tasks. It shows how to create and start a scheduled executor, then schedule a task to run after an initial delay and repeat at a fixed rate. ```C# //创建并启动一个线程的定时任务执行器 var scheduled = new ThreadScheduledExecutor(); scheduled.Start(); //延时1000毫秒后执行,以固定频率,每隔2000毫秒,打印一句“This is a test.” IAsyncResult result = scheduled.ScheduleAtFixedRate(() => { Debug.Log("This is a test."); }, 1000, 2000); ``` -------------------------------- ### Basic Log4Net Usage Example in C# with Loxodon.Log Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.Log4Net/Assets/LoxodonFramework/Log4Net/Documentation~/README.md This C# class demonstrates how to obtain a logger instance from Loxodon.Log.LogManager and use it to write a debug message. It shows a simple logging operation within a MonoBehaviour's Start method. ```C# public class Log4NetExample : MonoBehaviour { private ILog log; void Start() { log = LogManager.GetLogger(typeof(Log4NetExample)); log.Debug("This is a debug test."); } } ``` -------------------------------- ### Accessing Dynamic Variables in C# Source: https://github.com/vovgou/loxodon-framework/blob/master/docs/LoxodonFramework.md This C# snippet shows how to retrieve values from a `VariableArray` (dynamic variable set) using the `Get` method. It demonstrates accessing basic types like `Color` and Unity UI components like `InputField`. ```C# //C#,访问变量 Color color = this.variables.Get("color"); InputField usernameInput = this.variables.Get("username"); InputField emailInput = this.variables.Get("email"); ``` -------------------------------- ### Initialize Log4Net Configuration and Loxodon.LogManager in C# Source: https://github.com/vovgou/loxodon-framework/blob/master/Loxodon.Framework.Log4Net/Assets/LoxodonFramework/Log4Net/Documentation~/README.md This C# class, inheriting from MonoBehaviour, initializes the Log4Net configuration by loading an XML file from Unity's Resources. It then registers a Log4NetFactory with Loxodon.Log.LogManager, ensuring proper logging setup on application start and graceful shutdown on destroy. ```C# public class Log4NetManager : MonoBehaviour { void Awake() { InitializeLog(); DontDestroyOnLoad(this.gameObject); } protected void InitializeLog() { /* Initialize the log4net */ string configFilename = "Log4NetConfig"; TextAsset configText = Resources.Load(configFilename); if (configText != null) { using (MemoryStream memStream = new MemoryStream(configText.bytes)) { log4net.Config.XmlConfigurator.Configure(memStream); } } /* Initialize the Loxodon.Log.LogManager */ LogManager.Registry(new Log4NetFactory()); } void OnDestroy() { log4net.LogManager.Shutdown(); } } ```