Пример #1
0
        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();
        }
Пример #2
0
        private void RebuildContractDisplay()
        {
            var settings = target as BGSDKSettings;

            contracts.Clear();

            foreach (var contract in settings.contracts)
            {
                try
                {
                    var contractRoot = contractMarkup.CloneTree();
                    contracts.Add(contractRoot);
                    var label          = contractRoot.Q <Label>("label");
                    var content        = contractRoot.Q <VisualElement>("content");
                    var addToken       = contractRoot.Q <UnityEditor.UIElements.ToolbarButton>("addToken");
                    var contractRemove = contractRoot.Q <UnityEditor.UIElements.ToolbarButton>("removeContract");
                    label.text        = contract.SystemName;
                    addToken.clicked += () =>
                    {
                        BGSDK.Engine.Token nToken = CreateInstance <Engine.Token>();
                        nToken.name              = contract.data.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);
                        string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path + "/" + nToken.name + ".asset");
                        AssetDatabase.CreateAsset(nToken, assetPathAndName);
                        AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(BGSDKSettings.current));
                        AssetDatabase.SaveAssets();
                        AssetDatabase.Refresh();

                        RebuildContractDisplay();
                        EditorUtility.SetDirty(target);
                    };
                    contractRemove.clicked += () =>
                    {
                        foreach (var token in contract.tokens)
                        {
                            AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(token));
                        }

                        settings.contracts.Remove(contract);
                        AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(contract));

                        RebuildContractDisplay();
                        EditorUtility.SetDirty(target);
                    };


                    foreach (var token in contract.tokens)
                    {
                        var tokenRoot = tokenMarkup.CloneTree();
                        content.Add(tokenRoot);
                        var tokenLabel  = tokenRoot.Q <Label>("label");
                        var tokenRemove = tokenRoot.Q <UnityEditor.UIElements.ToolbarButton>("removeToken");
                        tokenRemove.clicked += () =>
                        {
                            contract.tokens.Remove(token);
                            AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(token));
                            RebuildContractDisplay();
                            EditorUtility.SetDirty(target);
                        };
                        tokenLabel.text = token.SystemName;
                    }
                }
                catch (Exception ex)
                {
                    Debug.LogException(ex);
                }
            }
        }
Пример #3
0
        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);
            }
        }