Beispiel #1
0
        public static void AddButton(DebugButtonPanel btnPanel, string btnLabel, Action onClickFunction, out GameObject debugBtnObj)
        {
            debugBtnObj = null;
            if (LC_Utils.IsBuildForProduction())
            {
                return;
            }

            Vector3 btnPos = btnPanel.transform.position;

            btnPos += btnPanel.transform.up * (btnPanel.ButtonQuantity * LC_Utils.GetDefaultButtonSize().y);

            if (btnPanel.ButtonQuantity != 0)
            {
                btnPos += btnPanel.transform.up * btnPanel.ButtonQuantity * LC_Utils.GetDefaultButtonPanelOffset();
            }

            GameObject newBtn = LC_Debug.CreateDebugButton(btnLabel, btnPos, onClickFunction, false);

            newBtn.transform.rotation = btnPanel.transform.rotation;
            newBtn.transform.parent   = btnPanel.transform;

            btnPanel.ButtonQuantity++;
            debugBtnObj = newBtn;
        }
 private void OnMouseUp()
 {
     backgroundSprite.color = backgroundColor;
     if (OnClickAction != null)
     {
         OnClickAction();
     }
     else
     {
         LC_Debug.TextPopup("This button is not assigned a function", transform.position + transform.right * (LC_Utils.GetDefaultButtonSize().x / 2 + LC_Utils.GetDefaultButtonPanelOffset()));
     }
 }
            public static GameObject CreateDebugButton(Transform parent, string btnLabel, Vector3 position, Action onClickFunction, bool rotateToCamera = true)
            {
                GameObject  btnObj            = new GameObject("DebugButton_" + btnLabel);
                DebugButton btnDebugComponent = btnObj.AddComponent <DebugButton>();
                BoxCollider btnCollider       = btnObj.AddComponent <BoxCollider>();

                btnObj.layer = LC_Utils.GetSettings().ButtonsLayerMask;

                if (rotateToCamera)
                {
                    btnObj.AddComponent <LookToCamera>().RotateY = true;
                }
                if (parent != null)
                {
                    btnObj.transform.parent = parent;
                }

                if (onClickFunction != null)
                {
                    btnDebugComponent.OnClickAction = onClickFunction;
                }

                btnCollider.isTrigger = true;
                btnCollider.size      = LC_Utils.GetDefaultButtonSize();

                btnObj.transform.position = position;

                TextMesh buttonLabel =
                    CreateWorldText(
                        text: btnLabel,
                        parent: btnObj.transform,
                        localPosition: Vector3.zero,
                        color: Color.black,
                        textAlignment: TextAlignment.Center,
                        textAnchor: TextAnchor.MiddleCenter,
                        fontSize: LC_Utils.GetDefaultFontSize()
                        );

                GameObject buttonBackground =
                    CreateWorldSprite(
                        parent: btnObj.transform,
                        name: "DebugButton_Background",
                        sprite: LC_Utils.GetDefaultSpriteSquare(),
                        position: Vector3.zero,
                        localScale: LC_Utils.GetDefaultButtonSize(),
                        color: LC_Utils.GetDefaultButtonColor()
                        );

                CreateWorldSprite(
                    parent: btnObj.transform,
                    name: "DebugButton_BackgroundBorder",
                    sprite: LC_Utils.GetDefaultSpriteSquare(),
                    position: Vector3.zero + btnObj.transform.forward * 0.01f,
                    localScale: LC_Utils.GetDefaultButtonSize() + new Vector3(.05f, .05f, .05f),
                    color: Color.gray
                    );

                btnDebugComponent.buttonLabel            = buttonLabel;
                btnDebugComponent.backgroundSprite       = buttonBackground.GetComponent <SpriteRenderer>();
                btnDebugComponent.backgroundColor        = LC_Utils.GetDefaultButtonColor();
                btnDebugComponent.backgroundOnClickColor = LC_Utils.GetDefaultButtonColorOnClick();
                btnDebugComponent.backgroundOnOverColor  = LC_Utils.GetDefaultButtonColorOnOver();

                btnDebugComponent.SetButtonLabelText(btnLabel);

                LC_Debug.RuntimeDebugObjectsManager.debugObjects.Add(btnObj);

                return(btnObj);
            }
    private void Start()
    {
        GameObject btnPanel = LC_Debug.CreateButtonPanel(Vector3.up);

        DebugButtonPanel.AddButton(btnPanel.GetComponent <DebugButtonPanel>(), "Test 1", () => LC_Debug.TextPopup("Test1", Vector3.up));
        DebugButtonPanel.AddButton(btnPanel.GetComponent <DebugButtonPanel>(), "Test 2", () => LC_Debug.TextPopup("Test2", Vector3.up));
        DebugButtonPanel.AddButton(btnPanel.GetComponent <DebugButtonPanel>(), "Test 3", () => LC_Debug.TextPopup("Test3", Vector3.up), out GameObject debugBtn);

        if (debugBtn != null)
        {
            debugBtn.GetComponent <DebugButton>().OnClickAction = () => { LC_Debug.TextPopup("Action replace test", debugBtn.transform.position + debugBtn.transform.right * (LC_Utils.GetDefaultButtonSize().x / 2 + LC_Utils.GetDefaultButtonPanelOffset())); }
        }
        ;

        CameraSwitcher.SetupReturnAction(() => Debug.Log("Returning to original camera"));


        LC_Utils.CreateKeyCodeAction(KeyCode.F1,
                                     () => {
            if (LC_Utils.IsBuildForProduction())
            {
                return;
            }
            LC_Debug.UseFreeLookCamera();
        });

        LC_Utils.CreateKeyCodeAction(KeyCode.F2,
                                     () => {
            if (LC_Utils.IsBuildForProduction())
            {
                return;
            }
            LC_Debug.UseFreeLookCamera();
        });


        LC_Utils.CreateKeyCodeAction(KeyCode.E,
                                     () => {
            if (LC_Utils.IsBuildForProduction())
            {
                return;
            }
            LC_Debug.RuntimeDebugObjectsManager.DisableDebugObjects();
        });

        LC_Utils.CreateKeyCodeAction(KeyCode.R,
                                     () => {
            if (LC_Utils.IsBuildForProduction())
            {
                return;
            }
            LC_Debug.RuntimeDebugObjectsManager.EnableDebugObjects();
        });

        LC_Utils.CreateKeyCodeAction(KeyCode.Backspace,
                                     () => {
            if (LC_Utils.IsBuildForProduction())
            {
                return;
            }
            CameraSwitcher.ReturnToOriginalCamera();
        });
    }
}