Exemplo n.º 1
0
    // export
    private void Export()
    {
        Instance  = this;
        _canceled = false;

        try {
            // load config json
            GLexConfig.Load();

            // create exporter and setup paths
            Type     exporterType = Type.GetType((string)GLexConfig.ExporterType, true);
            Exporter exporter     = Activator.CreateInstance(exporterType) as Exporter;

            exporter.SetupPaths(_exportDirectory);

            // recurse scene graph
            mData = new GLexData();

            if (!GLexConfig.ExportSceneGameObject)
            {
                mData.Scene   = new GLexScene(mData);
                mData.Project = new GooProject(mData, PlayerSettings.productName);
            }

            for (int i = 0; i < _toExport.Count; ++i)
            {
                if (!RecurseSceneGraph(_toExport[i].transform, null))
                {
                    return;
                }
            }

            EditorUtility.DisplayProgressBar("Preparing for export", string.Empty, 0);
            mData.PrepareForExport();

            // export
            if (exporter.Export(mData))
            {
                if (!exporter.WithoutErrors)
                {
                    Debug.LogError("One or more errors occurred during export: " + exporter.Error);
                }
                else
                {
                    EditorUtility.ClearProgressBar();
                    EditorUtility.DisplayDialog("Export successful!", "Exported to " + GLexConfig.BasePath, "ok");
                    Debug.Log("Exported to " + GLexConfig.BasePath);
                }
            }
            else
            {
                Debug.LogError("User cancelled export");
            }
        }
        finally {
            EditorUtility.ClearProgressBar();
        }
    }
    public void SaveBinaryData()
    {
        var outPath = Path.Combine(GLexConfig.GetPathFor("image"), BinaryId);

        if (!File.Exists(outPath))
        {
            // Because the filename is a hash of its contents, we know we don't need to actually write out the file if it already exists
            File.WriteAllBytes(outPath, _dataBytes);
        }
    }
Exemplo n.º 3
0
    // texture access methods

    private bool HasTextureOn(string uniform)
    {
        if (mMaterial.HasProperty(GLexConfig.GetTextureUniformFor(uniform)))
        {
            return(mMaterial.GetTexture(GLexConfig.GetTextureUniformFor(uniform)) != null);
        }
        else
        {
            return(false);
        }
    }
Exemplo n.º 4
0
 private Texture2D GetTextureOn(string uniform)
 {
     if (HasTextureOn(uniform))
     {
         return(mMaterial.GetTexture(GLexConfig.GetTextureUniformFor(uniform)) as Texture2D);
     }
     else
     {
         Debug.LogError("GLexMaterial.GetTextureOn: " + uniform + " doesn't exist");
         return(null);
     }
 }
Exemplo n.º 5
0
    public StringTemplate LoadTemplate(string name)
    {
        if (_templateGroup == null)
        {
            _templateGroup = new StringTemplateGroup("MG", GLexConfig.TemplatePath, typeof(DefaultTemplateLexer));
            _templateGroup.RegisterAttributeRenderer(typeof(bool), TemplateRenderers.BoolRenderer.Instance);
            _templateGroup.RegisterAttributeRenderer(typeof(Color), TemplateRenderers.ColorRenderer.Instance);
            _templateGroup.RegisterAttributeRenderer(typeof(DateTime), TemplateRenderers.DateTimeRenderer.Instance);
            _templateGroup.RegisterAttributeRenderer(typeof(Vector3), TemplateRenderers.VectorRenderer.Instance);
            _templateGroup.RegisterAttributeRenderer(typeof(Vector2), TemplateRenderers.VectorRenderer.Instance);
            _templateGroup.RegisterAttributeRenderer(typeof(Matrix4x4), TemplateRenderers.MatrixRenderer.Instance);
        }

        Debug.Log(name);
        return(_templateGroup.GetInstanceOf(GLexConfig.GetTemplate(name)));
    }
Exemplo n.º 6
0
    private bool RecurseSceneGraph(Transform transform, Transform parent)
    {
        if (_canceled)
        {
            return(false);
        }

        if (EditorUtility.DisplayCancelableProgressBar("Collecting Objects", transform.name, 0))
        {
            Debug.LogError("User cancelled export");
            _canceled = true;
            return(false);
        }

        bool active = GLexConfig.GetOption(GLexConfig.RECURSEINACTIVESCHILDREN) ? transform.gameObject.activeSelf : transform.gameObject.activeInHierarchy;

        if (!GLexConfig.ExportLeafWithOnlyTransform &&
            transform.GetComponents <Component>().Length == 1 &&
            transform.childCount == 0)
        {
            active = false;
        }

        if (transform.GetComponent <GLexGameObjectSettings>() != null &&
            transform.GetComponent <GLexGameObjectSettings>().export == false)
        {
            active = false;
        }

        if (active)
        {
            GLexGameObject gameObject = new GLexGameObject(transform.gameObject, mData);
            mData.AddGameObject(gameObject);

            foreach (KeyValuePair <string, string> componentAndConverters in GLexConfig.Converters)
            {
                var unityComponent = transform.GetComponent(componentAndConverters.Key);

                if (unityComponent != null)
                {
                    Type          coConverterType = Type.GetType(componentAndConverters.Value, true);
                    GLexComponent component       = Activator.CreateInstance(coConverterType) as GLexComponent;

                    component.AssociateWithGameObject(transform.gameObject);
                    component.AssociateWithComponent(unityComponent);

                    mData.AddComponent(component);
                    gameObject.AddComponent(component);
                }
            }
        }

        // traverse children
        if (active || GLexConfig.GetOption(GLexConfig.RECURSEINACTIVESCHILDREN))
        {
            for (int c = 0; c < transform.childCount; c++)
            {
                RecurseSceneGraph(transform.GetChild(c), transform);
            }
        }

        return(true);
    }
Exemplo n.º 7
0
    public void PrepareForExport()
    {
        if (GLexConfig.GetOption(GLexConfig.SETUNIQUENAMES))
        {
            Dictionary <string, int> uniqueNames = new Dictionary <string, int>();

            foreach (GLexGameObject gameObject in mGLexGameObjects)
            {
                if (gameObject.Settings == null)
                {
                    _addedSettingsTo.Add(gameObject);
                    gameObject.AddSettings();
                }
                else
                {
                    gameObject.ResetSettingsExportName();
                }
            }

            foreach (GLexGameObject gameObject in mGLexGameObjects)
            {
                if (uniqueNames.ContainsKey(gameObject.Settings.UniqueName))
                {
                    gameObject.Settings.UniqueName = gameObject.Settings.UniqueName + (++uniqueNames[gameObject.Settings.UniqueName]).ToString();
                }
                else
                {
                    uniqueNames.Add(gameObject.Settings.UniqueName, 0);
                }
            }
        }

        // Keep preparing objects while new ones are being added
        int prevGameObjectCount = 0, prevComponentCount = 0;

        while (prevGameObjectCount < mGLexGameObjects.Count || prevComponentCount < mGLexComponents.Count)
        {
            int goStart = prevGameObjectCount;
            int gcStart = prevComponentCount;
            prevGameObjectCount = mGLexGameObjects.Count;
            prevComponentCount  = mGLexComponents.Count;

            for (int i = goStart; i < prevGameObjectCount; ++i)
            {
                mGLexGameObjects[i].PrepareForExport();
            }
            for (int i = gcStart; i < prevComponentCount; ++i)
            {
                mGLexComponents[i].PrepareForExport();
            }
        }

        // find top objects
        foreach (GLexGameObject gameObject in mGLexGameObjects)
        {
            if (!gameObject.HasParent)
            {
                mGLexTopGameObjects.Add(gameObject);
            }
        }

        GLexMaterial.PrepareForExport();
        GLexMesh.PrepareForExport();
        GLexTexture.PrepareForExport();
        GLexShader.PrepareForExport();
        GLexSkinnedMeshRenderer.StaticPrepareForExport();
        GLexBone.PrepareForExport();
        // GLexAnimation		   .PrepareForExport();
        // GLexAnimationClip      .PrepareForExport();

        mGLexGameObjectsAsArray    = mGLexGameObjects.ToArray();
        mGLexTopGameObjectsAsArray = mGLexTopGameObjects.ToArray();
        mGLexComponentsAsArray     = mGLexComponents.ToArray();

        mScene.PrepareForExport();
    }
Exemplo n.º 8
0
 public void SaveBinaryData()
 {
     File.WriteAllBytes(Path.Combine(GLexConfig.GetPathFor("sound"), BinaryId), _dataBytes);
 }