Beispiel #1
0
        private void AddFile(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            string            objectTypeName = Regex.Replace(Path.GetFileNameWithoutExtension(path), "([A-ZА-Я])", " $1");
            string            fileName       = ObjectBuildHelper.ConvertToNiceName(objectTypeName).Trim();
            CreateObjectModel model          = new CreateObjectModel()
            {
                Path       = path,
                ObjectName = fileName
                             .Replace(" ", "")
                             .Replace("(", "")
                             .Replace(")", "")
                             .Replace("-", ""),
                LocalizedName   = fileName,
                LocalizedNameRU = fileName,
                IsGrabbable     = true,
                IsPhysicsOn     = true
            };

            _modelsList.Add(model);
        }
Beispiel #2
0
        private void Initialize(string path, bool isFolder)
        {
            if (_modelsList != null)
            {
                _modelsList.Clear();
                _modelsList = null;
            }

            _existingObjectNames = ObjectBuildHelper.GetExistingObjectsNames();

            _modelsList = new List <CreateObjectModel>();

            if (isFolder)
            {
                _selectedFolder = path + Path.AltDirectorySeparatorChar;
                AddFolder(path);
            }
            else
            {
                _selectedFolder = path.Substring(0, path.IndexOf(Path.GetFileName(path), StringComparison.Ordinal));
                AddFile(path);
            }

            if (_modelsList.Count == 0)
            {
                _window.Close();
                EditorUtility.DisplayDialog("No models to import", $"No models to import", "Ok");
                return;
            }

            _window.Show();

            CleanUp();
        }
Beispiel #3
0
        static void Init()
        {
            var window = GetWindow <CreateObjectWindow>(true, "Create object", true);

            window.minSize = MinWindowSize;
            window.maxSize = MaxWindowSize;
            window.Show();

            _existingObjectNames = ObjectBuildHelper.GetExistingObjectsNames();

            if (Selection.activeGameObject != null)
            {
                _gameObject = Selection.activeGameObject;

                string objectTypeName = Regex.Replace(_gameObject.name, "([A-ZА-Я])", " $1");
                objectTypeName   = ObjectBuildHelper.ConvertToNiceName(objectTypeName).Trim();
                _objectClassName = objectTypeName
                                   .Replace(" ", "")
                                   .Replace("(", "")
                                   .Replace(")", "")
                                   .Replace("-", "");

                _localizedName   = objectTypeName;
                _localizedNameRU = objectTypeName;
            }

            AuthorSettings.Initialize();
            _authorName  = AuthorSettings.Name;
            _authorEmail = AuthorSettings.Email;
            _authorUrl   = AuthorSettings.Url;

            _scrollPosition = Vector2.zero;
        }
Beispiel #4
0
        private void DrawObjectTypeNameField()
        {
            _objectClassName = EditorGUILayout.TextField("Object Class Name", _objectClassName);

            _objectTypeNameIsValid = false;
            if (string.IsNullOrEmpty(_objectClassName))
            {
                EditorGUILayout.HelpBox($"Object Class Name can't be empty", MessageType.Error);
            }
            else if (!ObjectBuildHelper.IsValidTypeName(_objectClassName))
            {
                EditorGUILayout.HelpBox($"Object Class Name contains unavailable symbols", MessageType.Error);
            }
            else if (_existingObjectNames.Any(x => string.Equals(x, _objectClassName, StringComparison.OrdinalIgnoreCase)))
            {
                EditorGUILayout.HelpBox($"An object with the same Object Class Name already exists.", MessageType.Error);
            }
            else
            {
                _objectTypeNameIsValid = true;
            }
        }
Beispiel #5
0
        private void AddFolder(string path)
        {
            DirectoryInfo dirInfo = new DirectoryInfo(path);

            FileInfo[] files = dirInfo.GetFiles();

            foreach (FileInfo file in files)
            {
                string ext = file.Extension.Replace(".", "");
                if (!AvailableFileFormats.Any(x => string.Equals(x, ext, StringComparison.OrdinalIgnoreCase)))
                {
                    continue;
                }

                string            objectTypeName = Regex.Replace(file.Name, "([A-ZА-Я])", " $1");
                string            fileName       = ObjectBuildHelper.ConvertToNiceName(Path.GetFileNameWithoutExtension(objectTypeName)).Trim();
                CreateObjectModel model          = new CreateObjectModel()
                {
                    Path       = file.FullName,
                    ObjectName = fileName
                                 .Replace(" ", "")
                                 .Replace("(", "")
                                 .Replace(")", "")
                                 .Replace("-", ""),
                    LocalizedName   = fileName,
                    LocalizedNameRU = fileName,
                    IsGrabbable     = true,
                    IsPhysicsOn     = true
                };

                //Will prevent .meta files from getting into the import window
                if (!Regex.IsMatch(file.FullName, @".+\.meta$"))
                {
                    _modelsList.Add(model);
                }
            }
        }
Beispiel #6
0
        private void CreateAll()
        {
            _gltfQueue = new List <CreateObjectModel>();

            foreach (CreateObjectModel fileModel in _modelsList)
            {
                if (!ObjectBuildHelper.IsValidTypeName(fileModel.ObjectName))
                {
                    Debug.Log("Can't create object with class name " + fileModel.ObjectName + ": not a valid type name");

                    continue;
                }

                _currentStep = "Importing model from " + fileModel.Path + "...";

                fileModel.Guid            = Guid.NewGuid().ToString();
                fileModel.LocalizedName   = ObjectBuildHelper.EscapeString(fileModel.LocalizedName);
                fileModel.LocalizedNameRU = ObjectBuildHelper.EscapeString(fileModel.LocalizedNameRU);
                fileModel.ObjectFolder    = "Assets/Objects/" + fileModel.ObjectName;
                fileModel.ModelFolder     = fileModel.ObjectFolder + "/Model";
                fileModel.ModelImportPath = fileModel.ModelFolder + "/" + Path.GetFileName(fileModel.Path);
                fileModel.PrefabPath      = fileModel.ObjectFolder + "/" + fileModel.ObjectName + ".prefab";

                if (Directory.Exists(fileModel.ObjectFolder))
                {
                    EditorUtility.DisplayDialog(fileModel.ObjectName + " already exists!",
                                                "Object with this name already exists", "OK");
                    fileModel.Skip = true;
                }
                else
                {
                    Debug.Log("Create folder " + fileModel.ObjectFolder);
                    Directory.CreateDirectory(fileModel.ObjectFolder);
                    Directory.CreateDirectory(fileModel.ObjectFolder + "/Model");

                    CreateTags(fileModel);

                    string extension = Path.GetExtension(fileModel.Path);

                    if (extension == null)
                    {
                        fileModel.Skip = true;

                        EditorUtility.DisplayDialog(fileModel.ObjectName + " can't be imported",
                                                    "Unsupported file format", "OK");

                        continue;
                    }

                    if (extension.Contains("zip"))
                    {
                        fileModel.ModelImportPath = fileModel.ModelFolder +
                                                    "/" +
                                                    Path.GetFileNameWithoutExtension(fileModel.Path) +
                                                    ".prefab";
                        ImportGLTFQueue(fileModel);
                    }
                    else
                    {
                        ImportUsualAsset(fileModel);
                    }
                }
            }

            if (_gltfQueue.Count == 0)
            {
                CreateCode();
            }
        }
Beispiel #7
0
        private void DrawListItem(CreateObjectModel fileModel)
        {
            var nameLabelWidth = GUILayout.Width(LangLabelWidth);
            var nameFieldWidth = GUILayout.Width(ObjectNameFieldWidth);

            GUILayout.BeginHorizontal();

            var subPath = Path.GetFileName(fileModel.Path);

            GUILayout.Label(subPath, EditorStyles.label, GUILayout.Width(PathFieldWidth));
            fileModel.ObjectName = EditorGUILayout.TextField(fileModel.ObjectName, nameFieldWidth);

            EditorGUILayout.BeginVertical(GUILayout.Width(ObjectNameFieldWidth + LangLabelWidth + GUISpaceSize));

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("EN", nameLabelWidth);
            fileModel.LocalizedName = EditorGUILayout.TextField(fileModel.LocalizedName, nameFieldWidth);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("RU", nameLabelWidth);
            fileModel.LocalizedNameRU = EditorGUILayout.TextField(fileModel.LocalizedNameRU, nameFieldWidth);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();

            fileModel.IsGrabbable =
                EditorGUILayout.Toggle(fileModel.IsGrabbable, GUILayout.Width(GrabCheckboxWidth));

            fileModel.IsPhysicsOn =
                EditorGUILayout.Toggle(fileModel.IsPhysicsOn, GUILayout.Width(PhysicsCheckboxWidth));

            fileModel.BiggestSideSize =
                EditorGUILayout.FloatField(fileModel.BiggestSideSize, GUILayout.Width(SizeFieldWidth));
            fileModel.Mass = EditorGUILayout.FloatField(fileModel.Mass, GUILayout.Width(MassFieldWidth));

            var tagsStyle = new GUIStyle(EditorStyles.textField)
            {
                wordWrap = true,
            };
            var tagsLayout = new[]
            {
                GUILayout.Width(TagsFieldWidth),
                GUILayout.MaxHeight(30),
                GUILayout.ExpandHeight(false),
            };

            fileModel.Tags = EditorGUILayout.TextArea(fileModel.Tags, tagsStyle, tagsLayout);
            GUILayout.EndHorizontal();

            GUILayout.Label("", GUILayout.Height(5));

            bool objectTypeNameIsValid = false;

            if (string.IsNullOrEmpty(fileModel.ObjectName))
            {
                EditorGUILayout.HelpBox($"Object Class Name can't be empty", MessageType.Error);
            }
            else if (!ObjectBuildHelper.IsValidTypeName(fileModel.ObjectName))
            {
                EditorGUILayout.HelpBox($"Object Class Name contains unavailable symbols", MessageType.Error);
            }
            else if (_existingObjectNames.Any(x => string.Equals(x, fileModel.ObjectName, StringComparison.OrdinalIgnoreCase)))
            {
                EditorGUILayout.HelpBox($"An object with the same Object Class Name already exists.", MessageType.Error);
            }
            else
            {
                objectTypeNameIsValid = true;
            }

            if (!objectTypeNameIsValid)
            {
                _allObjectTypeNamesIsValid = false;
            }
        }
Beispiel #8
0
        private void Create()
        {
            if (_gameObject == null)
            {
                EditorUtility.DisplayDialog("Error!", "GameObject can't be null.", "OK");

                return;
            }

            if (!ObjectBuildHelper.IsValidTypeName(_objectClassName, true))
            {
                return;
            }

            _localizedName   = ObjectBuildHelper.EscapeString(_localizedName);
            _localizedNameRU = ObjectBuildHelper.EscapeString(_localizedNameRU);

            CreateObjectModel model = new CreateObjectModel()
            {
                Guid            = Guid.NewGuid().ToString(),
                ObjectName      = _objectClassName.Replace(" ", ""),
                LocalizedName   = _localizedName,
                LocalizedNameRU = _localizedNameRU,
                MobileReady     = _mobileReady
            };

            model.ObjectFolder = "Assets/Objects/" + model.ObjectName;
            model.PrefabPath   = model.ObjectFolder + "/" + model.ObjectName + ".prefab";

            if (Directory.Exists(model.ObjectFolder))
            {
                EditorUtility.DisplayDialog(model.ObjectName + " already exists!",
                                            "Object with this name already exists!", "OK");
            }
            else
            {
                Debug.Log("Create folder " + model.ObjectFolder);
                Directory.CreateDirectory(model.ObjectFolder);

                Debug.Log("Create prefab " + _gameObject.name);

                CreatePrefab(_gameObject, model.PrefabPath, model.Guid,
                             _objectClassName, null, null,
                             false);
                CreateTags(model);

                model.ClassName = CreateCode(model);

                _modelsList = new List <CreateObjectModel>();
                _modelsList.Add(model);

                CreateObjectTempModel temp = new CreateObjectTempModel()
                {
                    Objects = _modelsList, BuildNow = false
                };

                string jsonModels = JsonConvert.SerializeObject(temp, Formatting.None,
                                                                new JsonSerializerSettings {
                    NullValueHandling = NullValueHandling.Ignore
                });
                File.WriteAllText(CreateObjectTempModel.TempFilePath, jsonModels);
                AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
            }
        }