Ejemplo n.º 1
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;
            }
        }
Ejemplo n.º 2
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();
            }
        }
Ejemplo n.º 3
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;
            }
        }
Ejemplo n.º 4
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);
            }
        }