private void DrawContractListArea() { EditorGUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.Width(250), GUILayout.ExpandHeight(true)); if (BGSDKSettings.current != null) { if (BGSDKSettings.current.contracts == null) { BGSDKSettings.current.contracts = new List <BGSDK.Engine.Contract>(); } EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); var color = GUI.contentColor; EditorGUILayout.LabelField("Contracts", EditorStyles.whiteLabel, GUILayout.Width(200)); GUI.contentColor = new Color(0.25f, 0.75f, 0.25f, 1); if (GUILayout.Button(CreateContractIcon, EditorStyles.toolbarButton, GUILayout.Width(25))) { GUI.FocusControl(null); BGSDK.Engine.Contract nContract = new BGSDK.Engine.Contract(); nContract.name = "New Contract"; nContract.SystemName = "New Contract"; nContract.updatedFromServer = false; nContract.tokens = new List <BGSDK.Engine.Token>(); BGSDKSettings.current.contracts.Add(nContract); EditorUtility.SetDirty(BGSDKSettings.current); AssetDatabase.AddObjectToAsset(nContract, BGSDKSettings.current); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(nContract)); activeContract = nContract; activeToken = null; } GUI.contentColor = color; EditorGUILayout.EndHorizontal();; if (BGSDKSettings.current.contracts.Count > 0) { if (activeContract == null) { activeContract = BGSDKSettings.current.contracts[0]; } scrollPos_ContractArea = EditorGUILayout.BeginScrollView(scrollPos_ContractArea); foreach (var con in BGSDKSettings.current.contracts) { DrawContractEntryDesigner(con); } EditorGUILayout.EndScrollView(); BGSDKSettings.current.contracts.RemoveAll(p => p == null); } } else { tab = 0; } EditorGUILayout.EndVertical(); }
public override VisualElement CreateInspectorGUI() { var settings = target as BGSDKSettings; path = AssetDatabase.GetAssetPath(settings); if (path == "") { path = "Assets"; } else if (Path.GetExtension(path) != "") { path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), ""); } var root = inspectorMarkup.CloneTree(); tglApplication = root.Q <UnityEditor.UIElements.ToolbarToggle>("tglApplication"); tglApi = root.Q <UnityEditor.UIElements.ToolbarToggle>("tglApi"); tglModel = root.Q <UnityEditor.UIElements.ToolbarToggle>("tglModel"); var addContract = root.Q <UnityEditor.UIElements.ToolbarButton>("addContract"); addContract.clicked += () => { BGSDK.Engine.Contract nContract = CreateInstance <Engine.Contract>(); nContract.name = "New Contract"; nContract.data.name = "New Contract"; nContract.updatedFromServer = false; if (settings.contracts == null) { settings.contracts = new List <BGSDK.Engine.Contract>(); } nContract.tokens = new List <Token>(); string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path + "/" + nContract.name + ".asset"); AssetDatabase.CreateAsset(nContract, assetPathAndName); settings.contracts.Add(nContract); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(BGSDKSettings.current)); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); RebuildContractDisplay(); }; var syncData = root.Q <UnityEditor.UIElements.ToolbarButton>("syncButton"); syncData.clicked += () => { BGSDKSettings.current = settings; var syncProc = BGSDK.Editor.EditorUtilities.SyncSettings(RebuildContractDisplay); StartCoroutine(syncProc); }; contracts = root.Q <VisualElement>("content"); appPage = root.Q <VisualElement>("appPage"); apiPage = root.Q <VisualElement>("apiPage"); modelPage = root.Q <VisualElement>("modelPage"); RebuildContractDisplay(); tglApplication.value = app; tglApi.value = api; tglModel.value = model; appPage.style.display = app ? DisplayStyle.Flex : DisplayStyle.None; apiPage.style.display = api ? DisplayStyle.Flex : DisplayStyle.None; modelPage.style.display = model ? DisplayStyle.Flex : DisplayStyle.None; tglApplication.RegisterValueChangedCallback(HandleToggleApplicationChange); tglApi.RegisterValueChangedCallback(HandleToggleApiChange); tglModel.RegisterValueChangedCallback(HandleToggleModelChange); return(root); }
private void DrawContractEntryDesigner(BGSDK.Engine.Contract contract) { if (contract == null) { return; } bool hasRemoved = false; EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); EditorGUILayout.LabelField(new GUIContent(ContractIcon), GUILayout.Width(20)); if (GUILayout.Toggle(activeContract == contract && activeToken == null, contract.SystemName, EditorStyles.toolbarButton)) { if (activeContract != contract || activeToken != null) { GUI.FocusControl(null); } activeContract = contract; activeToken = null; } var color = GUI.contentColor; GUI.contentColor = new Color(0.25f, 0.75f, 0.25f, 1); if (GUILayout.Button(CreateTokenIcon, EditorStyles.toolbarButton, GUILayout.Width(25))) { GUI.FocusControl(null); BGSDK.Engine.Token nToken = new BGSDK.Engine.Token(); nToken.name = contract.name + " : New Token"; nToken.SystemName = "New Token"; nToken.UpdatedFromServer = false; nToken.contract = contract; if (contract.tokens == null) { contract.tokens = new List <BGSDK.Engine.Token>(); } contract.tokens.Add(nToken); AssetDatabase.AddObjectToAsset(nToken, contract); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(BGSDKSettings.current)); activeToken = nToken; } GUI.contentColor = new Color(1, 0.50f, 0.50f, 1); if (GUILayout.Button(RemoveContractIcon, EditorStyles.toolbarButton, GUILayout.Width(25))) { GUI.FocusControl(null); if (EditorUtility.DisplayDialog("Delete Contract", "Are you sure you want to delete [" + contract.name + "] and all of its tokens.\n\nNote this will not remove a deployed contract from the backend service it only removes the contract from the configuraiton in your applicaiton.", "Delete", "Cancel")) { if (contract.tokens != null) { foreach (var token in contract.tokens) { DestroyImmediate(token, true); hasRemoved = true; } } DestroyImmediate(contract, true); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(BGSDKSettings.current)); } } GUI.contentColor = color; EditorGUILayout.EndHorizontal(); if (hasRemoved) { return; } if (contract.tokens == null) { contract.tokens = new List <BGSDK.Engine.Token>(); } contract.tokens.Sort((a, b) => { return(a.SystemName.CompareTo(b.SystemName)); }); foreach (var token in contract.tokens) { EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); EditorGUILayout.LabelField("", GUILayout.Width(20)); EditorGUILayout.LabelField(new GUIContent(TokenIcon), GUILayout.Width(20)); if (GUILayout.Toggle(activeContract == contract && activeToken == token, token.SystemName, EditorStyles.toolbarButton)) { if (activeToken != token) { GUI.FocusControl(null); } activeContract = token.contract; activeToken = token; } GUI.contentColor = new Color(1, 0.5f, 0.5f, 1); if (GUILayout.Button(RemoveTokenIcon, EditorStyles.toolbarButton, GUILayout.Width(25))) { GUI.FocusControl(null); if (EditorUtility.DisplayDialog("Delete Token", "Are you sure you want to delete [" + contract.name + "].\n\nNote this will not remove a deployed token from the backend service it only removes the token from the configuraiton in your applicaiton.", "Delete", "Cancel")) { DestroyImmediate(token, true); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(BGSDKSettings.current)); hasRemoved = true; } } GUI.contentColor = color; EditorGUILayout.EndHorizontal(); } if (hasRemoved) { contract.tokens.RemoveAll(p => p == null); } }