Пример #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);
        }
Пример #2
0
        private void ImportGLTFQueue(CreateObjectModel fileModel)
        {
            bool first = _gltfQueue.Count == 0;

            _gltfQueue.Add(fileModel);

            if (first)
            {
                ImportGLTF(_gltfQueue[0]);
            }
        }
Пример #3
0
 private void ImportUsualAsset(CreateObjectModel fileModel)
 {
     try
     {
         Debug.Log("Import model for " + fileModel.ObjectName);
         FileUtil.CopyFileOrDirectory(fileModel.Path, fileModel.ModelImportPath);
         AssetDatabase.ImportAsset(fileModel.ModelImportPath, ImportAssetOptions.ForceUpdate);
     }
     catch (Exception e)
     {
         EditorUtility.DisplayDialog("Error!", $"Problem when importing a model for \"{fileModel.ObjectName}\" ({fileModel.Path}): {e.Message}", "OK");
         Debug.LogException(e);
     }
 }
Пример #4
0
        public static string CreateCode(CreateObjectModel model)
        {
            string typeCs = File.ReadAllText(Application.dataPath + @"/Varwin/Core/Templates/ObjectType.txt");
            string asmdef = File.ReadAllText(Application.dataPath + @"/Varwin/Core/Templates/ObjectAsmdef.txt");

            string cleanGuid = model.Guid.Replace("-", "");

            typeCs = typeCs.Replace("{%Object%}", model.ObjectName)
                     .Replace("{%Object_Rus%}", model.LocalizedNameRU)
                     .Replace("{%Guid%}", cleanGuid)
                     .Replace("{%Object_En%}", model.LocalizedName);
            asmdef = asmdef.Replace("{%Object%}", model.ObjectName + "_" + cleanGuid);

            File.WriteAllText(model.ObjectFolder + "/" + model.ObjectName + ".cs", typeCs, Encoding.UTF8);
            File.WriteAllText(model.ObjectFolder + "/" + model.ObjectName + ".asmdef", asmdef, Encoding.UTF8);

            return(model.ObjectName + "_" + cleanGuid);
        }
Пример #5
0
        private void CreateTags(CreateObjectModel model)
        {
            if (model.Tags == null)
            {
                return;
            }

            if (model.Tags.Length == 0)
            {
                return;
            }
            var           tags    = model.Tags.Split(',');
            List <string> tagList = new List <string>();

            foreach (string tag in tags)
            {
                int i = 0;
                tagList.Add(tag[i] == ' ' ? tag.Remove(i, 1) : tag);
            }

            File.WriteAllLines(model.ObjectFolder + "/tags.txt", tagList);
        }
Пример #6
0
        private void ImportGLTF(CreateObjectModel fileModel)
        {
            try
            {
                if (_importer != null)
                {
                    _importer.cleanArtifacts();
                    _importer = null;
                }

                _importer = new SketchfabImporter(UpdateProgress, OnFinishImport);

                _importer.configure(GLTFUtils.getPathAbsoluteFromProject(fileModel.ModelFolder),
                                    Path.GetFileNameWithoutExtension(fileModel.Path), false);
                _importer.loadFromFile(fileModel.Path);
                fileModel.Extras = ParseAssetForLicense(_importer.GetGLTFInput());
            }
            catch (Exception e)
            {
                EditorUtility.DisplayDialog("Error!", $"Problem when importing a model for \"{fileModel.ObjectName}\" ({fileModel.Path}):\nNot valid model structure ({e.Message})", "OK");
                Debug.LogException(e);

                CleanUp();

                fileModel.Skip = true;

                if (_gltfQueue.Contains(fileModel))
                {
                    _gltfQueue.Remove(fileModel);
                }

                if (Directory.Exists("Assets/Objects/" + fileModel.ObjectName))
                {
                    Directory.Delete("Assets/Objects/" + fileModel.ObjectName, true);
                }
            }
        }
Пример #7
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);
                }
            }
        }
Пример #8
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;
            }
        }
Пример #9
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);
            }
        }