The Prysm integration in Unity3D supports multiple systems with custom settings.
The Prysm CohtmlUISystem
component controls some of the behavior of all cohtml.Net.View objects assigned to it.
When creating a scene, Prysm will spawn a default CohtmlUISystem
and every View will be connected to it, unless otherwise specified.
You want to customize the system-related behavior of your Views
, you can create your custom CohtmlUISystem
objects and and attach any number of Views
to them.
The cohtml.Net.SystemSettings you can customize are:
Below you can see how a system with a custom Resource Handler
would look like in the Unity3D Editor.
To set up a system with a custom Resource handler see the example below. You can assign custom Localization manager and TextTransformation manager in the same way.
The general steps needed are:
GameObject
and assign your custom Resource handler to it.GameObject
and assign your System settings component to it.Views
before the View.Start()
method is called. They cannot be changed afterwards.You can do that via the Unity3D editor or via script.
CohtmlSystemSettings
component to the scene.CustomResourceHandler.cs
.MonoBehaviour
script that creates your CustomResourceHandler
object and attaches it to the ResourceHandler property of the system settings. public class CustomSettingsAssigner : MonoBehaviour{public void AssignResourceHandler(){CohtmlSystemSettings settings = GetComponent<CohtmlSystemSettings>();settings.ResourceHandler = new CustomResourceHandler();}}
CustomSettingsAssigner.cs
script to the CohtmlSystemSettings GameObject
.AssignResourceHandler()
method to the first event called On Resource Handler Assign. CohtmlUISystem
and assign the CohtmlSystemSettings
into its properties.MonoBehaviour
script that overrides the UnityEngine.Awake()
method. Use it to create a CohtmlSystemSettings
component, add your custom Resource Handler to it, then spawn your custom CohtmlUISystem
using the CreateNativeUISystem(settings)
method. public class CustomSettingsAssigner : MonoBehaviour{public void Awake(){CohtmlSystemSettings settings = gameObject.AddComponent<CohtmlSystemSettings>();settings.ResourceHandler = new CustomResourceHandler();CohtmlUISystem system = gameObject.AddComponent<CohtmlUISystem>();system.CreateNativeUISystem(settings);// NOTE: You can start assigning Views to the CohtmlUISystem here// i.e. MyView.CohtmlUISystem = system;}}
CohtmlUISystem
by changing the View.CohtmlUISystem
property.The default behaviors you can override in the SystemSettings
from cohtml.Net.SystemSettings are:
The resource handler provides your resources (e.g images, scripts, fonts etc.) to the cohtml.Net.View components.
By default it will load these resources from the UIResources
folder or fetch them from web.
The UI resources folder in the project is the place from where Prysm loads your pages. When a CohtmlView loads any URL it would try to replace the coui://[host] part of the URL with a specified location, until it finds the resource.
By default the only location searched this way will be Assets/StreamingAssets/Cohtml/UIResources. Prysm uses the StreamingAssets folder because it is a special Unity3D location for content that is intended to be included in the built project and can be accessed on all platforms.
For example, when loading the URL coui://UIResources/MyFirstUI/my-page.html
, Prysm will search for that file in Assets/StreamingAssets/Cohtml/UIResources/MyFirstUI/my-page.html
The general steps needed are:
ResourceLocationsAssigner.cs
, with a method called AssignResourceLocations()
. This method will assign the ResourceHandler's HostLocationsMap property which holds a Dictionary of hosts to Locations map. Host is the key. Value is the locations. public class ResourceLocationsAssigner : MonoBehaviour{public void AssignResourceLocations(){CohtmlSystemSettings systemSettings = GetComponent<CohtmlSystemSettings>();// Create Default or Custom Resource Handler.systemSettings.ResourceHandler = new DefaultResourceHandler();systemSettings.HostLocationsMap = new Dictionary<string, List<string>>{// Example how to use Default host and locations. That initialization is not mandatory.{DefaultResourceHandler.DefaultHostLocations.Key,DefaultResourceHandler.DefaultHostLocations.Value},{"persistent", new List<string> {Application.persistentDataPath}},// Example how to use your custom hosts with collection of locations.{"mylocation", new List<string>{Application.streamingAssetsPath + "/DownloadedPatch",Application.streamingAssetsPath + "/MyLocation"}}};}}
CohtmlUISystem
component to the created GameObject.CohtmlSystemSettings
to the created GameObject.ResourceLocationsAssigner.cs
to the created GameObject.The Localization manager is used to dynamically translate your User Interface. There is no default Localization manager implementation.
Prysm supports the text-transform
CSS property that allows automatic uppercase/lowercase/capitalize transformations of text. There is no default TextTransformation manager implementation, so you need to implement your own.
You can use the Debugger settings to enable or disable the DevTools Inspector and change its port and enable or disable the Devtools inspector
in a built game.
DefaultUISystem
DevTools Inspector settings you can access it through the Library Configuration window from Context Menu -> Prysm -> Configure LibraryIt is not necessary to create a CohtmlSystemSetting
s component for every System
you have on the scene. Prysm will assign a default settings component for every system component. Do it only when you want to add a custom implementation.
It is not necessary to create CohtmlUISystem
components for every cohtml.Net.View instance. You can have multiple Views using your custom system at the same time.
Having multiple instances of cohtml.Net.UISystem and CohtmlSystemSettings on the same GameObject
is not allowed.