private void StartPick(int i)
        {
            if (onDeactivateGizmos != null)
            {
                onDeactivateGizmos.Invoke();
            }
            pickingVertexIndex = i;
            pickingVertex      = true;
            for (int j = 0; j < vertexInfos.Length; j++)
            {
                vertexInfos[j].coordsBforeEdit = vertexInfos[j].currentCoords;
                if (j != i)
                {
                    vertexInfos[j].DisableUIElements();
                }
            }

            if (!vertexPicker)
            {
                vertexPicker = Instantiate(vertexPickerPrefab).GetComponentInChildren <CapsuleRay>();
                vertexPicker.SetCamera(CVSPUIManager.GetEditorCamera());
            }
            vertexPicker.SetActive(true);
            vertexInfos[i].oldCoords = vertexInfos[i].currentCoords;
            selectedHighlight.SetActive(true);
            Vector3 pos = selectedHighlight.transform.position;

            StopAllCoroutines();
            StartCoroutine(CVSPUIUtils.UIMovementCoroutine(selectedHighlight, 0.15f, new Vector3(pos.x, vertexInfos[i].parentObject.position.y, pos.z)));
        }
Exemplo n.º 2
0
        public void OnEditName(string s)
        {
            if (ignoreEditOnce)
            {
                ignoreEditOnce = false;
                return;
            }

            btnSave.interactable      = input.text.Length == 0 || (input.text.Length > 0 && input.text.IndexOfAny(Path.GetInvalidFileNameChars()) < 0);
            input.textComponent.color = btnSave.interactable ? valid : invalid;
            bWrnInvalidName           = !btnSave.interactable;
            DirectoryInfo d = new DirectoryInfo(CVSPPresetManager.Directory);

            FileSystemInfo[] fileSystemInfo = d.GetFileSystemInfos();
            if (d.Exists &&
                fileSystemInfo
                .FirstOrDefault(q => q is FileInfo && Path.GetFileNameWithoutExtension(q.Name) == input.text && q.Extension == ".xml")
                != null)
            {
                bWrnFileExists = true;
            }
            else
            {
                bWrnFileExists = false;
            }
            if (wrnFileExists == null)
            {
                wrnFileExists  = CVSPUIManager.Localize("#LOC_CVSP_WrnFileExists");
                wrnInvalidName = CVSPUIManager.Localize("#LOC_CVSP_WrnInvalidName");
            }
        }
        void Start()
        {
            if (thicknessInput != null)
            {
                thicknessInput.text = "0.01";
                //StartCoroutine(AddListenerCoroutine());
                FindVertexInfos();
                foreach (var item in vertexInfos)
                {
                    AddListener(item);
                }
                btnCancleDeletion.onClick.AddListener(OnCancleDeletion);
                btnClose.onClick.AddListener(OnClose);
                btnConfirm.onClick.AddListener(OnConfirm);
                thicknessInput.onEndEdit.AddListener(OnValidateThicknessInput);
                if (PickTip.Length == 0)
                {
                    PickTip = CVSPUIManager.Localize("#LOC_CVSP_PickingVertexTip");
                    IdleTip = CVSPUIManager.Localize("#LOC_CVSP_CreatePanelIdleTip");
                }
                gameObject.SetActive(false);

                vertexMarkers = new ScreenMarker[4];
                for (int i = 0; i < vertexMarkers.Length; vertexMarkers[i].id = i++)
                {
                    ;
                }
            }
        }
 private void StartSearch(char c)
 {
     title.text    = CVSPUIManager.Localize("#LOC_CVSP_SEARCH_FOR") + ' ';
     searchString += c;
     title.text   += searchString;
     searchEnabled = true;
     OpenDirectory(searchString + "*");
 }
 private void AddSearchChar(char c)
 {
     searchString += c;
     if (searchString.Length > 16)
     {
         searchString = searchString.Substring(0, 16);
     }
     title.text = CVSPUIManager.Localize("#LOC_CVSP_SEARCH_FOR") + ' ' + searchString;
     OpenDirectory(searchString + "*");
 }
 private void UpdatePreview()
 {
     currentFilePath = currentPath + Path.DirectorySeparatorChar + selectedFileName.text;
     if (File.Exists(currentFilePath))
     {
         var t2d = CVSPUIManager.LoadTextureFromFile(currentFilePath, selectingNormalMap && convertToNormal);
         if (t2d)
         {
             iPreview.texture = t2d;
             iPreviewBG.gameObject.SetActive(true);
             fileInfo.text = $"{selectedFileName.text}:  {t2d.width}*{t2d.height}  {t2d.format}\r\n{currentFilePath.Substring(currentFilePath.LastIndexOf("GameData"))}";
         }
     }
 }
        private bool OpenDirectory(string searchS = "*")
        {
            DirectoryInfo d = new DirectoryInfo(currentPath);

            if (d.Exists)
            {
                Clear();
                if (currentPath.Length > TxeturePath.Length)
                {
                    //子文件夹
                    btnBack.gameObject.SetActive(true);
                }
                else
                {
                    btnBack.gameObject.SetActive(false);
                }
                var f = d.GetFileSystemInfos(searchS);
                foreach (var info in f)
                {
                    if (info is DirectoryInfo)
                    {
                        var g = Instantiate(folderItemPrefab);
                        g.SetActive(true);
                        g.GetComponentInChildren <Text>().text = info.Name;
                        g.transform.SetParent(fileList.transform, false);
                    }
                }
                foreach (var info in f)
                {
                    if (info is FileInfo)
                    {
                        if (IsTexture(info.Name))
                        {
                            var g = Instantiate(fileItemPrefab);
                            g.SetActive(true);
                            g.GetComponentInChildren <Text>().text = info.Name;
                            g.transform.SetParent(fileList.transform, false);
                        }
                    }
                }
                return(true);
            }
            else
            {
                errorMsg = CVSPUIManager.Localize("#LOC_CVSP_TEXTURE_DIRECTORY_NOT_FOUND");
            }
            return(false);
        }
 public void OpenDialog(string path, string title, bool asNormal)
 {
     readme.enabled     = asNormal;
     selectingNormalMap = asNormal;
     chkBoxConvertNormal.gameObject.SetActive(selectingNormalMap);
     currentPath   = path;
     searchEnabled = false;
     if (OpenDirectory())
     {
         searchString    = string.Empty;
         titleString     = CVSPUIManager.Localize("#LOC_CVSP_SELECT") + ' ' + title;
         this.title.text = titleString;
         CVSPUIManager.Instance.Close();
     }
     gameObject.SetActive(true);
 }
 void Start()
 {
     link   = CVSPUIManager.Localize(link);
     unlink = CVSPUIManager.Localize(unlink);
     if (name.EndsWith("0"))
     {
         toggle0 = this;
         toggle.SetIsOnWithoutNotify(default0);
         text.text = default0 ? unlink : link;
     }
     else
     {
         toggle1 = this;
         toggle.SetIsOnWithoutNotify(default1);
         text.text = default1 ? unlink : link;
     }
 }
        private void OnDeleteClick()
        {
            var selected = EventSystem.current.currentSelectedGameObject;

            if (selected && selected.TryGetComponent(out Button _))
            {
                string btnName = selected.name;
                if (int.TryParse(btnName.Substring(btnName.Length - 1), out int i))
                {
                    if (deletedIndex != -1)
                    {
                        CVSPUIManager.PostMessage("#LOC_CVSP_WRN_AtLeastThreeVertices");
                        vertexInfos[deletedIndex].EnableUIElements();
                    }
                    deletedIndex = i;
                    vertexInfos[i].DisableUIElements();
                    Vector3 pos = deletedHighlight.transform.position;
                    deletedHighlight.transform.position = new Vector3(pos.x, vertexInfos[i].parentObject.position.y, pos.z);
                    deletedHighlight.SetActive(true);
                }
            }
        }
Exemplo n.º 11
0
 internal void SetActive(bool b)
 {
     mouseRay.SetActive(b);
     vertexMarker.enabled = b;
     SetCamera(CVSPUIManager.GetEditorCamera());
 }
 void Update()
 {
     if (Input.anyKey)
     {
         if (Input.anyKeyDown)
         {
             if (Input.GetKeyDown(KeyCode.F5))
             {
                 EndSearch();
                 OpenDirectory();
             }
             if (!searchEnabled)
             {
                 foreach (char c in Input.inputString)
                 {
                     if (c != '\b')
                     {
                         if (c != '\n' && c != '\r') // enter/return/backspace
                         {
                             StartSearch(c);
                             break;
                         }
                     }
                     else
                     {
                         OnBackClick();
                     }
                 }
             }
             else
             {
                 foreach (char c in Input.inputString)
                 {
                     if (c == '\b') // has backspace/delete been pressed?
                     {
                         if (searchString.Length != 0)
                         {
                             searchString = searchString.Substring(0, searchString.Length - 1);
                             title.text   = CVSPUIManager.Localize("#LOC_CVSP_SEARCH_FOR") + ' ' + searchString;
                             if (searchString.Length == 0)
                             {
                                 EndSearch();
                             }
                         }
                     }
                     else if ((c == '\n') || (c == '\r')) // enter/return
                     {
                         EndSearch();
                     }
                     else
                     {
                         AddSearchChar(c);
                     }
                 }
             }
         }
         if (Time.unscaledTime - lastScrollTime > 0.1f)
         {
             if ((Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.UpArrow)) && fileList.transform.childCount > 2)
             {
                 Transform listTransform = fileList.transform;
                 bool      moveUp        = Input.GetKey(KeyCode.UpArrow);
                 index = Mathf.Clamp(index, 2, listTransform.childCount - 1);
                 GameObject curr = EventSystem.current.currentSelectedGameObject;
                 if (!selectedFileName || !curr /*|| !selectedFileName.transform.IsChildOf(curr.transform)*/)
                 {
                     if (moveUp)
                     {
                         index = listTransform.childCount - 1;
                     }
                     else
                     {
                         index = 2;
                     }
                 }
                 else
                 {
                     if (moveUp)
                     {
                         index = index > 2 ? index - 1 : 2;
                     }
                     else
                     {
                         index = index == listTransform.childCount - 1 ? index : index + 1;
                     }
                 }
                 selectedFileName = listTransform.GetChild(index).GetComponentInChildren <Text>();
                 Button button = selectedFileName.GetComponentInParent <Button>();
                 button.Select();
                 if (!movingSelectedToVisible)
                 {
                     StartCoroutine(BringSelectedToVisible());
                 }
             }
             lastScrollTime = Time.unscaledTime;
         }
         else if ((Input.GetKeyUp(KeyCode.DownArrow) || Input.GetKeyUp(KeyCode.UpArrow)) && selectedFileName)
         {
             Button button = selectedFileName.GetComponentInParent <Button>();
             button.Select();
             button.onClick.Invoke();
         }
     }
 }
        private void OnConfirm()
        {
            if (pickingVertex)
            {
                FinishPick();
            }
            else
            {
                int     deletedIndexTemp = deletedIndex;
                Vector3 v0, v1, v2, v3 = Vector3.zero;
                //Main axis (part local Y axis)
                Vector3    mainAxis;
                Vector3    position;
                Vector3    zAxis;
                Quaternion orientation;
                float      height0, height1;
                float      length;
                float      tilt0;
                float      tilt1;
                Vector3    normal;
                if (!float.TryParse(thicknessInput.text, out float thickness))
                {
                    thickness = 0;
                }
                float width = thickness;

                #region Check if there are vertices at the same position
                bool hasOverlap = false;
                for (int i = 0; i < vertexInfos.Length; i++)
                {
                    if (i != deletedIndexTemp)
                    {
                        var v = vertexInfos[i].currentCoords;
                        for (int j = i + 1; j < vertexInfos.Length - i; j++)
                        {
                            if (j != deletedIndexTemp && vertexInfos[j].currentCoords == v)
                            {
                                if (!hasOverlap)
                                {
                                    deletedIndexTemp = j;
                                    hasOverlap       = true;
                                }
                                else
                                {
                                    CVSPUIManager.PostMessage("#LOC_CVSP_WRN_AtLeastThreeVertices");
                                    return;
                                }
                            }
                        }
                    }
                }
                #endregion

                Vector3 v01, v32;
                #region Re-organize vertices order to make sure thickness is applied on correct side

                #region Calculate normal
                if (deletedIndexTemp < 0)
                {
                    v0  = vertexInfos[0].currentCoords;
                    v1  = vertexInfos[1].currentCoords;
                    v2  = vertexInfos[2].currentCoords;
                    v3  = vertexInfos[3].currentCoords;
                    v01 = v1 - v0;
                    v32 = v2 - v3;
                    var norm012 = Vector3.Cross(v01, v2 - v1);
                    var norm230 = Vector3.Cross(-v32, v0 - v3);

                    #region Fix abnormal normals
                    if (Vector3.Dot(norm012, norm230) < 0)
                    {
                        var temp = v3;
                        v3      = v2;
                        v2      = temp;
                        v32     = v2 - v3;
                        norm230 = Vector3.Cross(-v32, v0 - v3);
                    }
                    #endregion

                    normal = (norm012 + norm230) / 2;
                }
                else
                {
                    int i = 0;
                    if (i == deletedIndexTemp)
                    {
                        i++;
                    }
                    v0 = vertexInfos[i++].currentCoords;
                    if (i == deletedIndexTemp)
                    {
                        i++;
                    }
                    v1 = vertexInfos[i++].currentCoords;
                    if (i == deletedIndexTemp)
                    {
                        i++;
                    }
                    v2     = vertexInfos[i].currentCoords;
                    v01    = v1 - v0;
                    normal = Vector3.Cross(v01, v2 - v1);
                }
                #endregion

                #region Flip
                if (Vector3.Dot(CapsuleRay.editorCamera.transform.forward, normal) > 0)
                {
                    normal = -normal;
                    var temp = v1;
                    v1 = v0;
                    v0 = temp;
                    if (deletedIndexTemp < 0)
                    {
                        temp = v3;
                        v3   = v2;
                        v2   = temp;
                    }
                }
                #endregion
                #endregion

                var   offsetDistance = thickness / 2;
                float twist          = 0;

                if (deletedIndexTemp < 0)
                {
                    v01 = v1 - v0;
                    v32 = v2 - v3;

                    #region Apply thickness (by offseting vertices)
                    var     norm012   = Vector3.Cross(v01, v2 - v1).normalized;
                    var     norm230   = Vector3.Cross(-v32, v0 - v3).normalized;
                    Vector3 offset012 = -norm012 * offsetDistance;
                    v0 += offset012;
                    v1 += offset012;
                    Vector3 offset230 = -norm230 * offsetDistance;
                    v2 += offset230;
                    v3 += offset230;
                    v01 = v1 - v0;
                    v32 = v2 - v3;
                    #endregion

                    var mid01 = (v0 + v1) / 2;
                    var mid32 = (v2 + v3) / 2;
                    mainAxis = mid32 - mid01;
                    position = (mid01 + mid32) / 2;
                    Vector3 v01prj = v01 - Vector3.Project(v01, mainAxis);
                    Vector3 v32prj = v32 - Vector3.Project(v32, mainAxis);
                    zAxis = v01prj;

                    #region Clamp twist to +/-45 deg
                    twist = -Vector3.SignedAngle(v01prj, v32prj, mainAxis);
                    if (Mathf.Abs(twist) > 45f)
                    {
                        var limit = Mathf.Sign(twist) * 45f;
                        CVSPUIManager.PostMessage($"#LOC_CVSP_Twist {twist.ToString("#0.#")} #LOC_CVSP_OutOfLimit +/-45");
                        var correction = limit - twist;
                        twist = limit;
                        //减去偏移,以免它造成旋转后位置不正确
                        Quaternion q = Quaternion.AngleAxis(correction, mainAxis);
                        v2       -= offset230;
                        v3       -= offset230;
                        v2        = q * v2;
                        v3        = q * v3;
                        offset230 = q * offset230;
                        v2       += offset230;
                        v3       += offset230;
                        vertexInfos[2].SetCoordinates(v2);
                        vertexInfos[3].SetCoordinates(v3);
                        vertexInfos[2].UpdateInputField();
                        vertexInfos[3].UpdateInputField();
                    }
                    #endregion

                    #region Calculate shape
                    tilt0   = Vector3.SignedAngle(v01, mainAxis, Vector3.Cross(v01, mainAxis)) + -90f;
                    tilt1   = Vector3.SignedAngle(v32, mainAxis, Vector3.Cross(v32, mainAxis)) + -90f;
                    height0 = v01.magnitude;
                    height1 = v32.magnitude;
                    #endregion
                }
                else
                {
                    v01 = v1 - v0;

                    #region Apply thickness (by offseting vertices)
                    var norm012 = Vector3.Cross(v01, v2 - v1).normalized;
                    v0 -= norm012 * offsetDistance;
                    v1 -= norm012 * offsetDistance;
                    v2 -= norm012 * offsetDistance;
                    #endregion

                    var mid01 = (v0 + v1) / 2;
                    mainAxis = v2 - mid01;
                    Vector3 v01prj = v01 - Vector3.Project(v01, mainAxis);
                    zAxis = v01prj;

                    #region Calculate shape
                    position = (mid01 + v2) / 2;
                    height0  = v01.magnitude;
                    height1  = 0;
                    tilt0    = Vector3.SignedAngle(v01, mainAxis, Vector3.Cross(v01, mainAxis)) + -90f;
                    tilt1    = 0;
                    #endregion
                }

                length      = mainAxis.magnitude;
                orientation = Quaternion.LookRotation(-zAxis, -mainAxis);
                if (Mathf.Abs(tilt0) > 45f)
                {
                    CVSPUIManager.PostMessage($"#LOC_CVSP_Tilt {tilt0.ToString("#0.#")} #LOC_CVSP_OutOfLimit #LOC_CVSP_NeedHelp");
                }
                if (Mathf.Abs(tilt1) > 45f)
                {
                    CVSPUIManager.PostMessage($"#LOC_CVSP_Tilt {tilt1.ToString("#0.#")} #LOC_CVSP_OutOfLimit #LOC_CVSP_NeedHelp");
                }
                if (height0 > 20f)
                {
                    CVSPUIManager.PostMessage($"#LOC_CVSP_Height 0 {height0.ToString("#0.#")} #LOC_CVSP_OutOfLimit #LOC_CVSP_NeedHelp");
                }
                if (height1 > 20f)
                {
                    CVSPUIManager.PostMessage($"#LOC_CVSP_Height 1 {height1.ToString("#0.#")} #LOC_CVSP_OutOfLimit #LOC_CVSP_NeedHelp");
                }
                if (length > 20f)
                {
                    CVSPUIManager.PostMessage($"#LOC_CVSP_Length {length.ToString("#0.#")} #LOC_CVSP_OutOfLimit #LOC_CVSP_NeedHelp");
                }

                #region Send Parameters to create part
                CVSPPartInfo info = new CVSPPartInfo()
                {
                    height0     = height0,
                    height1     = height1,
                    width       = width,
                    length      = length,
                    position    = position,
                    orientation = orientation,
                    twist       = twist,
                    tilt0       = tilt0,
                    tilt1       = tilt1
                };
                CVSPUIManager.CreateCVSPPart(info);
                #endregion
            }
        }