Exemplo n.º 1
0
 private void ChangeMode(eVeinModificationMode newmode)
 {
     modMode      = newmode;
     ShowModeMenu = false;
     dialog       = null;
     UIRealtimeTip.Popup("Vein Gardener Mode Changed to: " + modMode);
 }
Exemplo n.º 2
0
        private void HandleClick()
        {
            Vector3 worldPos;
            // RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTrans, Input.mousePosition, uicam, out var localPoint);
            Ray ray = GameCamera.main.ScreenPointToRay(Input.mousePosition);

            if (Input.GetMouseButtonDown(0))
            {
                // Debug.Log("Clicking screen pos: " + Input.mousePosition.ToString() + " Ray: " + ray.ToString());

                PlanetData localPlanet = GameMain.localPlanet;
                if (localPlanet == null)
                {
                    return;
                }

                if (Physics.Raycast(ray, out var hitInfo, 1000f, 15873, QueryTriggerInteraction.Ignore))
                {
                    worldPos = hitInfo.point;
                    // Debug.Log("Clicked on world pos: " + worldPos.ToString());

                    Gardener.VeinGroup.GetClosestIndex(ray, localPlanet, out int closestVeinGroupIndex, out int closestVeinIndex, out float closestVeinDistance, out float closestVeinDistance2D);

                    switch (modMode)
                    {
                    case eVeinModificationMode.AddVein:
                        if (closestVeinGroupIndex < 0)
                        {
                            var veinGroup = Gardener.VeinGroup.New(EVeinType.Iron, worldPos.normalized);
                            closestVeinGroupIndex = localPlanet.AddVeinGroupData(veinGroup);
                            Debug.Log("Adding new veinGroup: " + veinGroup.type.ToString() + " index: " + closestVeinGroupIndex + " Pos: " + veinGroup.pos * localPlanet.radius);
                        }
                        Gardener.Vein.Add(localPlanet, worldPos, closestVeinGroupIndex);
                        break;

                    case eVeinModificationMode.ModifyVeinGroup:
                        if (closestVeinGroupIndex >= 0)
                        {
                            PlanetData.VeinGroup veinGroup = localPlanet.veinGroups[closestVeinGroupIndex];
                            Debug.Log("Clicked on veinGroup: " + veinGroup.ToString() + " index: " + closestVeinGroupIndex + " Type: " + veinGroup.type);
                            Debug.Log("VeinGroup: " + veinGroup.pos.ToString() + " index: " + (veinGroup.pos * (localPlanet.realRadius + 2.5f)));

                            dialog = new UIVeinGroupDialog()
                            {
                                localPlanet    = localPlanet,
                                veinGroupIndex = closestVeinGroupIndex,
                                Show           = true
                            };
                        }
                        else
                        {
                            dialog = null;
                        }
                        break;

                    case eVeinModificationMode.RemoveVein:
                        if (closestVeinGroupIndex >= 0 && closestVeinIndex >= 0 && closestVeinDistance2D < 1)
                        {
                            Debug.Log("Removing vein: " + closestVeinIndex + " in group: " + closestVeinGroupIndex);
                            Gardener.Vein.Remove(localPlanet, closestVeinIndex, closestVeinGroupIndex);
                            Gardener.VeinGroup.UpdatePosFromChildren(closestVeinGroupIndex);
                        }
                        break;

                    case eVeinModificationMode.Deactivated:
                    default:
                        break;
                    }
                }
            }
        }