Exemple #1
0
        public static void BuildOnlyZip(VarwinObjectDescriptor varwinObj)
        {
            ObjectsBuilderWindow window =
                GetWindow <ObjectsBuilderWindow>(true, "Building VWO for " + varwinObj.Name, true);

            window.minSize = new Vector2(350, 110);
            window.Show();
            window.BuildOnlyZip(new ObjectBuildDescription(varwinObj));
        }
Exemple #2
0
        public static void BuildVarwinObject(VarwinObjectDescriptor varwinObj)
        {
            ObjectsBuilderWindow window =
                GetWindow <ObjectsBuilderWindow>(true, "Building object: " + varwinObj.Name, true);

            window.minSize = new Vector2(350, 110);
            window.Show();
            window.RunBuildVarwinObject(varwinObj);
        }
Exemple #3
0
        public ObjectBuildDescription(VarwinObjectDescriptor varwinObjectDescriptor)
        {
            ObjectName = varwinObjectDescriptor.Name;
            ObjectGuid = varwinObjectDescriptor.RootGuid;
            PrefabPath = varwinObjectDescriptor.Prefab;
            FolderPath = Path.GetDirectoryName(varwinObjectDescriptor.Prefab);

            ContainedObjectDescriptor =
                AssetDatabase.LoadAssetAtPath <GameObject>(varwinObjectDescriptor.Prefab).GetComponent <VarwinObjectDescriptor>() ??
                varwinObjectDescriptor;
            ConfigBlockly     = varwinObjectDescriptor.ConfigBlockly;
            ConfigAssetBundle = varwinObjectDescriptor.ConfigAssetBundle;
        }
        public static void RemoveWrapperIfNeeded(VarwinObjectDescriptor varwinObjectDescriptor)
        {
            string wrapperPath = GetWrapperPath(varwinObjectDescriptor);

            if (File.Exists(wrapperPath))
            {
                string oldWrapperCode = File.ReadAllText(wrapperPath);

                if (oldWrapperCode.Contains(WrapperAutogenerationMark))
                {
                    File.Delete(wrapperPath);
                }
            }
        }
    private void OnEnable()
    {
#if VRMAKER
        if (target == null)
        {
            return;
        }

        _varwinObjectDescriptor = (VarwinObjectDescriptor)target;

        if (_varwinObjectDescriptor != null)
        {
            _gameObject = _varwinObjectDescriptor.gameObject;
        }

        _nameProperty        = serializedObject.FindProperty("Name");
        _iconProperty        = serializedObject.FindProperty("Icon");
        _embeddedProperty    = serializedObject.FindProperty("Embedded");
        _mobileReadyProperty = serializedObject.FindProperty("MobileReady");

        _guidProperty              = serializedObject.FindProperty("Guid");
        _rootGuidProperty          = serializedObject.FindProperty("RootGuid");
        _configBlocklyProperty     = serializedObject.FindProperty("ConfigBlockly");
        _configAssetBundleProperty = serializedObject.FindProperty("ConfigAssetBundle");
        _prefabProperty            = serializedObject.FindProperty("Prefab");

        _authorNameProperty  = serializedObject.FindProperty("AuthorName");
        _authorEmailProperty = serializedObject.FindProperty("AuthorEmail");
        _authorUrlProperty   = serializedObject.FindProperty("AuthorUrl");

        _licenseCodeProperty    = serializedObject.FindProperty("LicenseCode");
        _licenseVersionProperty = serializedObject.FindProperty("LicenseVersion");

        _builtAtProperty = serializedObject.FindProperty("BuiltAt");

        _bakedObjectDirectory = Application.dataPath.Replace("Assets", "BakedObjects");
        _assetBundleDirectory = Application.dataPath.Replace("Assets", "AssetBundles");
        _objectName           = _nameProperty.stringValue;
        _bundleName           = $"{_objectName}_{_rootGuidProperty.stringValue.Replace("-", "")}";
        _prefabPath           = _prefabProperty.stringValue;
        string _prefabName = Path.GetFileNameWithoutExtension(Path.GetDirectoryName(_prefabPath));
        _iconPath = $"Assets/Objects/{_prefabName}/icon.png";
        _tagsPath = $"Assets/Objects/{_prefabName}/tags.txt";

        _dllFolder = $"{Application.dataPath.Replace("Assets", "Library")}/ScriptAssemblies";

        _zipFilePath = $"{_bakedObjectDirectory}/{_objectName}.vwo";
#endif
    }
    public void BuildVarwinObject(VarwinObjectDescriptor varwinObjectDescriptor)
    {
        varwinObjectDescriptor.PreBuild();

        CreateObjectUtils.ApplyPrefabInstanceChanges(varwinObjectDescriptor.gameObject);

        VarwinObjectDescriptor varwinPrefab = CreateObjectUtils.GetPrefab(varwinObjectDescriptor.gameObject).GetComponent <VarwinObjectDescriptor>();

        ObjectsBuilderWindow.BuildVarwinObject(varwinObjectDescriptor);
        ObjectsBuilderWindow window = GetWindow();

        if (window != null)
        {
            window.ObjectBuilt += OnObjectBuilt;
        }
    }
        public static void GenerateWrapper(VarwinObjectDescriptor varwinObjectDescriptor)
        {
            string wrapperPath = GetWrapperPath(varwinObjectDescriptor);

            //Check if this wrapper is autogenerated
            if (File.Exists(wrapperPath))
            {
                string oldWrapperCode = File.ReadAllText(wrapperPath);

                if (!oldWrapperCode.Contains(WrapperAutogenerationMark))
                {
                    Debug.LogWarning($"Wrapper {wrapperPath} is not autogenerated! It would not be overwrite.");
                    return;
                }
            }

            string   assemblyName = varwinObjectDescriptor.Name + "_" + varwinObjectDescriptor.RootGuid.Replace("-", "");
            Assembly assembly     = Assembly.Load(assemblyName);

            if (assembly == null)
            {
                string message = $"Can't generate wrapper: Assembly {assemblyName} has not found!";
                EditorUtility.DisplayDialog("Error!", message, "Ok");
                Debug.LogError(message);
                return;
            }

            string typeName       = "Varwin.Types." + assemblyName + "." + varwinObjectDescriptor.Name;
            Type   mainScriptType = assembly.GetType(typeName);

            if (mainScriptType == null)
            {
                mainScriptType = assembly.GetTypes().FirstOrDefault(x => x.IsSubclassOf(typeof(VarwinObject)));
            }

            if (mainScriptType == null)
            {
                string message = $"Can't generate wrapper: {typeName} in assembly {assemblyName} has not found!";
                EditorUtility.DisplayDialog("Error!", message, "Ok");
                Debug.LogError(message);
                return;
            }

            string wrapperText = GenerateWrapperText(mainScriptType, varwinObjectDescriptor.Name, varwinObjectDescriptor.RootGuid.Replace("-", ""));

            File.WriteAllText(wrapperPath, wrapperText);
        }
Exemple #8
0
        private void RunBuildObjects(CreateObjectModel[] objects)
        {
            try
            {
                _objectsToBuild      = new List <ObjectBuildDescription>();
                _state               = ObjectBuilderState.Preparing;
                _currentStatusString = "Preparing objects...";

                foreach (CreateObjectModel model in objects)
                {
                    GameObject prefab = AssetDatabase.LoadAssetAtPath <GameObject>(model.PrefabPath);

                    if (prefab != null)
                    {
                        VarwinObjectDescriptor objToBuild = prefab.GetComponent <VarwinObjectDescriptor>();

                        if (objToBuild != null)
                        {
                            PreBuild(prefab);

                            ObjectBuildDescription descr = new ObjectBuildDescription()
                            {
                                ObjectName = objToBuild.Name,
                                ObjectGuid = objToBuild.RootGuid,
                                PrefabPath = model.PrefabPath,
                                FolderPath = model.ObjectFolder,
                                ContainedObjectDescriptor = objToBuild
                            };

                            _objectsToBuild.Add(descr);
                        }
                    }
                }

                GenerateWrappers();
            }
            catch (Exception e)
            {
                EditorUtility.DisplayDialog("Error!", $"{e.Message}:\nProblem when build objects", "OK");
                Debug.LogException(e);
                Close();
            }
        }
Exemple #9
0
        private void RunBuildVarwinObject(VarwinObjectDescriptor varwinObjectDescriptor)
        {
            try
            {
                _objectsToBuild      = new List <ObjectBuildDescription>();
                _state               = ObjectBuilderState.Preparing;
                _currentStatusString = "Preparing objects...";

                _objectsToBuild.Add(new ObjectBuildDescription(varwinObjectDescriptor));

                GenerateWrappers();
            }
            catch (Exception e)
            {
                EditorUtility.DisplayDialog("Error!", $"{e.Message}:\nProblem when run build varwin object \"{varwinObjectDescriptor.Name}\"", "OK");
                Debug.LogException(e);
                Close();
            }
        }
Exemple #10
0
        private static bool Initialize(Wrapper wrapper, Type type, ObjectBuildDescription objectBuild)
        {
            if (string.IsNullOrWhiteSpace(type.FullName))
            {
                return(false);
            }

            _wrapperType = wrapper.GetType();
            Debug.Log($"<Color=Green><b>Wrapper {_wrapperType.Name} is loaded!</b></Color>");

            VarwinObjectDescriptor varwinObjectDescriptor = objectBuild.ContainedObjectDescriptor;

            Debug.Log($"Core version is {VarwinVersionInfo.VarwinVersion}");

            string builtAt = $"{DateTimeOffset.UtcNow:s}Z";

            if (DateTimeOffset.TryParse(varwinObjectDescriptor.BuiltAt, out DateTimeOffset builtAtDateTimeOffset))
            {
                builtAt = $"{builtAtDateTimeOffset.UtcDateTime:s}Z";
            }

            _config = new BlocklyConfig
            {
                Guid        = varwinObjectDescriptor.Guid,
                RootGuid    = varwinObjectDescriptor.RootGuid,
                Embedded    = varwinObjectDescriptor.Embedded,
                MobileReady = SdkSettings.MobileFeature.Enabled && varwinObjectDescriptor.MobileReady,
                Config      = new Config
                {
                    type   = $"{varwinObjectDescriptor.Name}_{varwinObjectDescriptor.RootGuid.Replace("-", "")}.{varwinObjectDescriptor.Name}Wrapper",
                    blocks = new List <Block>(),
                },
                Author = new JsonAuthor
                {
                    Name  = varwinObjectDescriptor.AuthorName,
                    Email = varwinObjectDescriptor.AuthorEmail,
                    Url   = varwinObjectDescriptor.AuthorUrl,
                },
                BuiltAt = $"{builtAt}",
                License = new JsonLicense
                {
                    Code    = varwinObjectDescriptor.LicenseCode,
                    Version = varwinObjectDescriptor.LicenseVersion,
                },
                SdkVersion = VarwinVersionInfo.VersionNumber
            };

            if (File.Exists(objectBuild.TagsPath))
            {
                var tags = File.ReadAllLines(objectBuild.TagsPath);
                _config.Tags = tags.ToList();
            }

            if (_config.Config.i18n == null)
            {
                _config.Config.i18n = new I18n();
            }
            var locales = type.GetCustomAttributes <LocaleAttribute>(true);

            foreach (var locale in locales)
            {
                if (locale.I18n != null)
                {
                    _config.Config.i18n = locale.I18n;
                    break;
                }
                else
                {
                    _config.Config.i18n.SetLocale(locale.Code, locale.Strings[0]);
                }
            }
            return(true);
        }
 private static string GetWrapperPath(VarwinObjectDescriptor varwinObjectDescriptor)
 {
     return(Path.GetDirectoryName(varwinObjectDescriptor.Prefab) + "\\" + varwinObjectDescriptor.Name + "Wrapper.cs");
 }
Exemple #12
0
        private void RunBuildAllObjects()
        {
            try
            {
                _objectsToBuild      = new List <ObjectBuildDescription>();
                _state               = ObjectBuilderState.Preparing;
                _currentStatusString = "Preparing objects...";

                var objectsPath = "Assets/Objects";
                if (!Directory.Exists(objectsPath))
                {
                    Directory.CreateDirectory(objectsPath);
                    try
                    {
                        Directory.CreateDirectory(objectsPath);
                    }
                    catch
                    {
                        Debug.LogError("Can't create directory \"" + objectsPath + "\"");
                        EditorUtility.DisplayDialog("Can't create directory",
                                                    "Can't create directory \"" + objectsPath + "\"",
                                                    "OK");
                        return;
                    }
                }

                foreach (string objectDir in Directory.EnumerateDirectories("Assets/Objects"))
                {
                    foreach (string objectPath in Directory.EnumerateFiles(objectDir, "*.prefab"))
                    {
                        GameObject prefab = AssetDatabase.LoadAssetAtPath <GameObject>(objectPath);

                        if (prefab != null)
                        {
                            VarwinObjectDescriptor objToBuild = prefab.GetComponent <VarwinObjectDescriptor>();

                            if (objToBuild != null)
                            {
                                PreBuild(prefab);

                                //Finally, it's our prefab to build
                                //Debug.Log("Building object " + objToBuild.Name);

                                ObjectBuildDescription descr = new ObjectBuildDescription()
                                {
                                    ObjectName = objToBuild.Name,
                                    ObjectGuid = objToBuild.RootGuid,
                                    PrefabPath = objectPath,
                                    FolderPath = objectDir,
                                    ContainedObjectDescriptor = objToBuild
                                };

                                _objectsToBuild.Add(descr);
                            }
                        }
                    }
                }

                GenerateWrappers();
            }
            catch (Exception e)
            {
                EditorUtility.DisplayDialog("Error!", $"{e.Message}:\nProblem when run build all objects", "OK");
                Debug.LogException(e);
                Close();
            }
        }