private void OnClickDeleteCube(string nameText)
 {
     CubePersistance.DeleteCube(nameText);
     ActionKeyPersistance.Delete(nameText);
     this.procUI.drawActionButtonMapping.Refresh();
     this.Refresh();
 }
    protected override GameObject[] GenerateUI(out Vector2 offsets)
    {
        string[] textNames = CubePersistance.GetAllSavedCubes().Select(z => z.Name).ToArray();

        for (int i = 0; i < textNames.Length; i++)
        {
            string nameText = textNames[i];

            float mainX = tl.x;
            float mainY = tl.y - i * (this.procUI.buttonPixelsY + this.procUI.yOffset);

            if (i == 0)
            {
                Debug.Log($"{mainX} {mainY}");
            }

            float delX = tl.x + this.procUI.buttonPixelsX + this.procUI.xOffset;
            float delY = tl.y - i * (this.procUI.buttonPixelsY + this.procUI.yOffset);

            GameObject main   = this.generator.DrawButton(nameText, new Vector2(mainX, mainY));
            GameObject delete = this.generator.DrawButton("X", new Vector2(delX, delY), new Vector2(30, 30), Color.red);

            main.GetComponent <Button>().onClick.AddListener(() => this.OnClickLoadCube(nameText));
            delete.GetComponent <Button>().onClick.AddListener(() => this.OnClickDeleteCube(nameText));

            this.Elements.Add(main);
            this.Elements.Add(delete);
        }

        offsets = new Vector2(this.procUI.buttonPixelsX + this.procUI.xOffset * 2 + 30, 0);

        return(this.Elements.ToArray());
    }
    private void OnClickSave(TMP_InputField nameInput)
    {
        string nameText = nameInput.text;

        string[] existingNames = CubePersistance.GetAllSavedCubes().Select(z => z.Name).ToArray();

        if (string.IsNullOrWhiteSpace(nameText) || nameText.Length < 5 || existingNames.Contains(nameText))
        {
            Debug.Log("Invalid Name!");
            return;
        }

        Debug.Log("VALID Name!");

        this.procUI.tracker.Persist(nameText);

        this.procUI.drawSavedCubesRow.Refresh();
    }
    private void ActionButtonOnClick(int id)
    {
        ActionButton btnInfo = this.buttons.Single(x => x.ID == id);

        if (btnInfo.CubeName != null)
        {
            Debug.Log($"WORKS=> {btnInfo.CubeName}");

            GameObject player = ReferenceBuffer.Instance.PlayerObject;

            Vector3?droneMarker = null;
            if (ReferenceBuffer.Instance.DroneIntersection != null)
            {
                droneMarker = ReferenceBuffer.Instance.DroneIntersection.GetIntersectionPosition;
            }

            ReferenceBuffer.Instance.worldSpaceUI.connTracker.RunCube(btnInfo.CubeName, new Variable[]
            {
                new Variable
                {
                    Name  = ResultCanvas.PlayerForwardVarName,
                    Value = ReferenceBuffer.Instance.PlayerObject.transform.forward,
                },
                new Variable
                {
                    Name  = ResultCanvas.PlayerPositionVarName,
                    Value = ReferenceBuffer.Instance.PlayerObject.transform.position,
                },

                new Variable
                {
                    Name  = ResultCanvas.PlayerMarkerVarName,
                    Value = ReferenceBuffer.Instance.PlayerIntersection.GetIntersectionPosition,
                },
                new Variable
                {
                    Name  = ResultCanvas.DroneMarkerVarName,
                    Value = droneMarker,
                },
            });

            return;
        }

        CubeInfo[] infos = CubePersistance.GetAllSavedCubes();

        if (infos.Length == 0)
        {
            Debug.Log("There are no saved QUBES!!!");
            return;
        }

        string lastName = infos.Last().Name;

        var persistedKeys = ActionKeyPersistance.GetKeyCubeMapping();

        if (persistedKeys.Select(x => x.CubeName).Contains(lastName))
        {
            Debug.Log("That spell name already keyd!");
            return;
        }

        ActionKeyPersistance.Persist(new ActionKeyPersistance.ActionKeyPersistanceData
        {
            CubeName = lastName,
            KeyId    = id,
        });

        btnInfo.Button.transform.Find("Text").GetComponent <Text>().text = lastName;
    }
 public ConnectionsTracker(WorldSpaceUI UI)
 {
     this.persistance = new CubePersistance(UI);
 }