Exemple #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;
        }
            public static Text DrawTextUIWithAnchoredPos(string textString, Transform parent, Vector2 anchoredPosition, int fontSize, Font font)
            {
                GameObject textGo = new GameObject("Text", typeof(RectTransform), typeof(Text));

                textGo.transform.SetParent(parent, false);
                Transform textGoTrans = textGo.transform;

                textGoTrans.SetParent(parent, false);
                textGoTrans.localPosition = Vector3.zero;
                textGoTrans.localScale    = Vector3.one;

                RectTransform textGoRectTransform = textGo.GetComponent <RectTransform>();

                textGoRectTransform.sizeDelta        = new Vector2(0, 0);
                textGoRectTransform.anchoredPosition = anchoredPosition;

                Text text = textGo.GetComponent <Text>();

                text.text               = textString;
                text.verticalOverflow   = VerticalWrapMode.Overflow;
                text.horizontalOverflow = HorizontalWrapMode.Overflow;
                text.alignment          = TextAnchor.MiddleLeft;
                if (font == null)
                {
                    font = LC_Utils.GetDefaultFont();
                }
                text.font     = font;
                text.fontSize = fontSize;

                return(text);
            }
 public static GameObject CreateButtonPanel(Transform parent, Vector3 position)
 {
     if (LC_Utils.IsBuildForProduction())
     {
         return(LC_Utils.GetDeafultEmptyObject()); // Do nothing
     }
     return(LC_GraphicsDebugUtils.CreateButtonPanel(parent, position));
 }
 public static GameObject CreateDebugButton(Transform parent, string btnLabel, Vector3 position, Action onClickFunction, bool rotateToCamera = true)
 {
     if (LC_Utils.IsBuildForProduction())
     {
         return(LC_Utils.GetDeafultEmptyObject()); // Do nothing
     }
     return(LC_GraphicsDebugUtils.CreateDebugButton(parent, btnLabel, position, onClickFunction, rotateToCamera));
 }
 public static GameObject CreateWorldText(Transform parent, string text, Vector3 localPosition, int fontSize, Color color, TextAnchor textAnchor, TextAlignment textAlignment, int sortingOrder)
 {
     if (LC_Utils.IsBuildForProduction())
     {
         return(LC_Utils.GetDeafultEmptyObject()); // Do nothing
     }
     return(LC_GraphicsDebugUtils.CreateWorldText(parent, text, localPosition, fontSize, color, textAnchor, textAlignment, sortingOrder).gameObject);
 }
        // Creates a Text pop up at the world position
        public static void TextPopup(string text, Vector3 position)
        {
            if (LC_Utils.IsBuildForProduction())
            {
                return;
            }

            LC_GraphicsDebugUtils.CreateWorldTextPopup(text, position);
        }
        // World text pop up at mouse position
        public static void WorldTextPopupMouse(string text)
        {
            if (LC_Utils.IsBuildForProduction())
            {
                return;
            }

            LC_GraphicsDebugUtils.CreateWorldTextPopup(text, Utils.LC_Utils.GetMouseWorldPosition());
        }
 public static GameObject CreateWorldText(string text, Transform parent = null, Vector3 localPosition = default(Vector3), int fontSize = 40, Color?color = null, TextAnchor textAnchor = TextAnchor.UpperLeft, TextAlignment textAlignment = TextAlignment.Left, int sortingOrder = LC_Utils.sortingOrderDefault)
 {
     if (LC_Utils.IsBuildForProduction())
     {
         return(LC_Utils.GetDeafultEmptyObject()); // Do nothing
     }
     if (color == null)
     {
         color = Color.white;
     }
     return(LC_GraphicsDebugUtils.CreateWorldText(parent, text, localPosition, fontSize, color, textAnchor, textAlignment, sortingOrder).gameObject);
 }
        public Vector3 GetMouseWorldSnappedPosition()
        {
            Vector3 mousePosition = LC_Utils.GetMouseWorldPosition_Ray();

            grid.GetXZ(mousePosition, out int x, out int z);

            if (placedObjectTypeSO != null)
            {
                Vector2Int rotationOffset            = placedObjectTypeSO.GetRotationOffset(dir);
                Vector3    placedObjectWorldPosition = grid.GetWorldPosition(x, z) + new Vector3(rotationOffset.x, 0, rotationOffset.y) * grid.GetCellSize();
                return(placedObjectWorldPosition);
            }
            else
            {
                return(mousePosition);
            }
        }
Exemple #10
0
        void Update()
        {
            Vector3 position = LC_Utils.GetMouseWorldPosition();

            if (Input.GetMouseButtonDown(0))
            {
                //grid.SetValue(LC_Utils.GetMouseWorldPosition(), true);
            }
            if (Input.GetMouseButtonDown(1))
            {
                // Debug.Log(grid.GetValue(LC_Utils.GetMouseWorldPosition()));
            }

            if (Input.GetKeyDown(KeyCode.A))
            {
                gridXZ.GetGridObject(position).AddLetter("A");
            }
            if (Input.GetKeyDown(KeyCode.B))
            {
                gridXZ.GetGridObject(position).AddLetter("B");
            }
            if (Input.GetKeyDown(KeyCode.C))
            {
                gridXZ.GetGridObject(position).AddLetter("C");
            }

            if (Input.GetKeyDown(KeyCode.Alpha1))
            {
                gridXZ.GetGridObject(position).AddNumber("1");
            }
            if (Input.GetKeyDown(KeyCode.Alpha2))
            {
                gridXZ.GetGridObject(position).AddNumber("2");
            }
            if (Input.GetKeyDown(KeyCode.Alpha3))
            {
                gridXZ.GetGridObject(position).AddNumber("3");
            }
        }
Exemple #11
0
 // Start is called before the first frame update
 void Start()
 {
     CameraSwitcher.SetupCurrentCamera(LC_Utils.GetCurrentCamera());
     FunctionUpdater.Create(LC_Debug.RuntimeDebugObjectsManager.HandleDebugObjectsFarFromCamera);
 }
        void Update()
        {
            if (Input.GetMouseButtonDown(0) && placedObjectTypeSO != null)
            {
                Vector3 mousePosition = LC_Utils.GetMouseWorldPosition_Ray();
                grid.GetXZ(mousePosition, out int x, out int z);

                Vector2Int placedObjectOrigin = new Vector2Int(x, z);
                placedObjectOrigin = grid.ValidateGridPosition(placedObjectOrigin);
                List <Vector2Int> gridPositionList = placedObjectTypeSO.GetGridPositionsList(new Vector2Int(x, z), dir);

                // Test
                bool canBuild = true;
                foreach (Vector2Int gridPosition in gridPositionList)
                {
                    Debug.Log("Search: " + gridPosition.x + "; " + gridPosition.y);
                    if (!grid.GetGridObject(gridPosition.x, gridPosition.y).CanBuild())
                    {
                        Debug.Log("Cannot here!!");
                        // Cannot build here
                        canBuild = false;
                        break;
                    }
                }

                //GridObject gridObject = grid.GetGridObject(x, z);
                if (canBuild)
                {
                    Vector2Int rotationOffset            = placedObjectTypeSO.GetRotationOffset(dir);
                    Vector3    placedObjectWorldPosition = grid.GetWorldPosition(x, z) + new Vector3(rotationOffset.x, 0, rotationOffset.y) * grid.GetCellSize();

                    PlacedObject placedObject = PlacedObject.Create(placedObjectWorldPosition, new Vector2Int(x, z), dir, placedObjectTypeSO);

                    foreach (Vector2Int gridPosition in gridPositionList)
                    {
                        Debug.Log("Placed = x: " + gridPosition.x + "; " + gridPosition.y);
                        grid.GetGridObject(gridPosition.x, gridPosition.y).SetPlacedObject(placedObject);
                    }

                    OnObjectPlaced?.Invoke(this, EventArgs.Empty);
                }
                else
                {
                    LC_Debug.CreateWorldTextPopup("Cannot build here!!", LC_Utils.GetMouseWorldPosition_Ray(), new Vector3(0, 1f));
                }
            }

            if (Input.GetMouseButtonDown(1))
            {
                GridObject gridObject = grid.GetGridObject(LC_Utils.GetMouseWorldPosition_Ray());
                if (gridObject != null)
                {
                    PlacedObject placedObject = gridObject.GetPlacedObject();

                    if (placedObject != null)
                    {
                        placedObject.DestroySelf();
                        List <Vector2Int> gridPositionList = placedObject.GetGridPositionsList();

                        foreach (Vector2Int gridPosition in gridPositionList)
                        {
                            grid.GetGridObject(gridPosition.x, gridPosition.y).ClearPlacedObject();
                        }
                    }
                }
            }

            if (Input.GetKeyDown(KeyCode.R))
            {
                dir = PlacedObjectTypeSO.GetNextDir(dir);
            }

            if (Input.GetKeyDown(KeyCode.Alpha1))
            {
                placedObjectTypeSO = placedObjectTypeSOList[0]; RefreshSelectedObjectType();
            }
            if (Input.GetKeyDown(KeyCode.Alpha2))
            {
                placedObjectTypeSO = placedObjectTypeSOList[1]; RefreshSelectedObjectType();
            }
            if (Input.GetKeyDown(KeyCode.Alpha3))
            {
                placedObjectTypeSO = placedObjectTypeSOList[2]; RefreshSelectedObjectType();
            }

/*            if (Input.GetKeyDown(KeyCode.Alpha4)) { placedObjectTypeSO = placedObjectTypeSOList[3]; RefreshSelectedObjectType(); }
 *          if (Input.GetKeyDown(KeyCode.Alpha5)) { placedObjectTypeSO = placedObjectTypeSOList[4]; RefreshSelectedObjectType(); }*/
        }
            /*
             *
             * public static void CreateUITextPopup(string textString, Vector3 position)
             * {
             *  CreateUITextPopup(textString, position, position + new Vector3(0, 20), Color.white);
             * }
             *
             * public static void CreateUITextPopup(string textString, Vector3 position, Vector3 finalPopupPosition, Color color, int fontSize = 40, float popupTime = 1f)
             * {
             *  Text text = DrawTextUI(textString, position, fontSize, GetDefaultFont());
             *  Transform transform = text.transform;
             *  Vector3 moveAmount = (finalPopupPosition - position) / popupTime;
             *
             *  FunctionUpdater.Create(delegate () {
             *      transform.position += moveAmount * Time.deltaTime;
             *      popupTime -= Time.deltaTime;
             *      if (popupTime <= 0f)
             *
             *      {
             *          UnityEngine.Object.Destroy(transform.gameObject);
             *          return true;
             *      }
             *      else
             *      {
             *          return false;
             *      }
             *  }, "UITextPopup"); ;
             * }
             *
             */

            public static Text DrawTextUIAnchoredPos(string textString, Vector2 anchoredPosition, int fontSize, Font font)
            {
                return(DrawTextUIWithAnchoredPos(textString, LC_Utils.GetCanvasTransform(), anchoredPosition, fontSize, font));
            }
            // Create Text Updater in UI
            public static FunctionUpdater CreateUITextUpdater(Func <string> GetTextFunc, Vector2 anchoredPosition)
            {
                Text text = DrawTextUIAnchoredPos(GetTextFunc(), anchoredPosition, 20, LC_Utils.GetDefaultFont());

                return(FunctionUpdater.Create(() => {
                    text.text = GetTextFunc();
                    return false;
                }, "UITextUpdater"));
            }
            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);
            }
 public static void HandleDebugObjectsFarFromCamera()
 {
     foreach (GameObject debugObj in debugObjects)
     {
         if (Vector3.Distance(debugObj.transform.position, CameraSwitcher.CurrentCamera.transform.position) > LC_Utils.GetSettings().DebugObjectsDrawDistance)
         {
             debugObj.SetActive(false);
         }
         else
         {
             if (!hidingObjects)
             {
                 debugObj.SetActive(true);
             }
         }
     }
 }
 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()));
     }
 }
    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();
        });
    }
}