private void Start() { syncBehaviour = GetComponent <RemoteConfigSyncBehaviour>(); if (Points.Length == 0 || syncBehaviour == null) { gameObject.SetActive(false); return; } // Disable rendering until SyncComplete. renderer = GetComponent <Renderer>(); renderer.enabled = false; syncBehaviour.SyncComplete += Activate; }
/// <summary> /// Creates the UI elements and registers callbacks. /// </summary> public void OnEnable() { syncBehaviour = target as RemoteConfigSyncBehaviour; rootVisualElement = new VisualElement(); rootVisualElement.styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(stylePath)); // Show the Script field (not-editable) like standard inspectors do. var script = MonoScript.FromMonoBehaviour(syncBehaviour); var scriptField = new ObjectField("Script") { value = script }; scriptField.SetEnabled(false); rootVisualElement.Add(scriptField); // PrefixSource enum dropdown control. When PrefixSource changes, observe whether the // KeyPrefix field should be shown/hidden. var prefixSourceProp = serializedObject.FindProperty("PrefixSource"); prefixSourceField = new EnumField("Prefix Source", syncBehaviour.PrefixSource); prefixSourceField.BindProperty(prefixSourceProp); prefixSourceField.RegisterCallback <ChangeEvent <Enum> >(OnPrefixSourceChange); rootVisualElement.Add(prefixSourceField); // KeyPrefix control, only shown if syncBehaviour.PrefixSource == PrefixSource.Custom. var keyPrefixProperty = serializedObject.FindProperty("KeyPrefix"); keyPrefixField = new PropertyField(keyPrefixProperty); if (syncBehaviour.PrefixSource == PrefixSource.Custom) { rootVisualElement.Add(keyPrefixField); } // Sync All Fields control. var syncAllProp = serializedObject.FindProperty("SyncAllFields"); syncAllField = new PropertyField(syncAllProp); syncAllField.RegisterCallback <ChangeEvent <bool> >(OnSyncAllFieldsChange); rootVisualElement.Add(syncAllField); // Include sub-fields var includeSubProp = serializedObject.FindProperty("IncludeSubFields"); includeSubFieldsField = new PropertyField(includeSubProp); if (syncBehaviour.SyncAllFields) { rootVisualElement.Add(includeSubFieldsField); } var buttonContainer = new TemplateContainer(); // Use row class to place buttons side-by-side. buttonContainer.AddToClassList("row"); // Add a button that can invoke the SyncFields function on the object during gameplay. var syncButton = new Button(() => SyncFields()) { text = "Sync Fields" }; buttonContainer.Add(syncButton); // Add a button that prompts RemoteConfigSyncUIWindow to update sync targets. var updateButton = new Button(() => SyncWindow.RefreshSyncTargets()) { text = "Update targets" }; buttonContainer.Add(updateButton); // Add button to open the RemoteConfigSyncWindow. var rcWindowButton = new Button(() => SyncWindow.OpenWindow()) { text = "Open Sync Window" }; buttonContainer.Add(rcWindowButton); rootVisualElement.Add(buttonContainer); }