Пример #1
0
        private void btnExport_Click(object sender, System.EventArgs e)
        {
            // in case that user used copy/paste to add new asset path
            // check if stored asset path is different than current one and update
            if (tbFolderPath.Text != this.inputData.UnityProjectPath)
            {
                this.inputData.UnityProjectPath = tbFolderPath.Text;
            }
            // deploy assets to specified Unity location
            if (this.inputData.UnityProjectPath != null)
            {
                Utility.CopyDir(this.inputData.PluginFolderPath + @"\Assets", this.inputData.UnityProjectPath);
            }

            // set origin camera property
            // jump cameras are data bound so property should be set already for those
            if (cbCameras.SelectedValue != null)
            {
                UnifyCamera camera = cbCameras.SelectedValue as UnifyCamera;
                camera.IsPlayerOriginCamera = true;
            }

            if (lbCameras.Items.Count > 0)
            {
                foreach (var item in lbCameras.CheckedItems)
                {
                    UnifyCamera cam = item as UnifyCamera;
                    cam.IsPlayerJumpCamera = true;
                }
            }

            // set MeshCollider property for Layers
            foreach (object o in lbSelectedLayers.Items)
            {
                UnifyLayer layer = o as UnifyLayer;
                layer.MeshCollider = true;
            }
            foreach (object o in lbAllLayers.Items)
            {
                UnifyLayer layer = o as UnifyLayer;
                layer.MeshCollider = false;
            }

            // set layers singled out for design options
            this.inputData.DesignOptions = this.checkedNodes;

            this.inputData.ProcessExports();

            // save form presets
            SavePresets();

            // close form
            this.Close();
        }
Пример #2
0
        private void SavePresets()
        {
            FormPresets presets = new FormPresets();

            // save assets location
            presets.AssetsLocation = tbFolderPath.Text;

            // save origin camera selection
            presets.OriginCamera = ((UnifyCamera)cbCameras.SelectedValue).Name;

            // save jump cameras
            Dictionary <string, ValuePair> jumpCameras = new Dictionary <string, ValuePair>();

            for (int i = 0; i < lbCameras.Items.Count; i++)
            {
                UnifyCamera camera = lbCameras.Items[i] as UnifyCamera;
                if (lbCameras.GetItemChecked(i))
                {
                    jumpCameras.Add(camera.Name, new ValuePair(true, i));
                }
                else
                {
                    jumpCameras.Add(camera.Name, new ValuePair(false, i));
                }
            }
            presets.JumpCameras = jumpCameras;

            // save mesh colliders
            Dictionary <string, bool> meshColliders = new Dictionary <string, bool>();

            for (int i = 0; i < lbAllLayers.Items.Count; i++)
            {
                UnifyLayer layer = lbAllLayers.Items[i] as UnifyLayer;
                meshColliders.Add(layer.Name, false);
            }
            for (int i = 0; i < lbSelectedLayers.Items.Count; i++)
            {
                UnifyLayer layer = lbSelectedLayers.Items[i] as UnifyLayer;
                meshColliders.Add(layer.Name, true);
            }
            presets.MeshColliders = meshColliders;

            // save design options
            this.designOptions = new Dictionary <string, bool>();
            SerializeTreeView(treeView1);
            presets.DesignOptions = this.designOptions;

            // write to project file
            string json = JsonConvert.SerializeObject(presets, Formatting.Indented);

            File.WriteAllText(this.SelectedProject, json);
        }
Пример #3
0
        private void CheckAllChildNodes(TreeNode treeNode, bool nodeChecked, string parentName)
        {
            foreach (TreeNode node in treeNode.Nodes)
            {
                node.Checked = nodeChecked;
                UnifyLayer layer = (UnifyLayer)node.Tag;

                if (nodeChecked)
                {
                    layer.DesignOptionName = parentName;
                    checkedNodes.Add(layer);
                }
                else
                {
                    layer.DesignOptionName = "";
                    checkedNodes.Remove(layer);
                }
                if (node.Nodes.Count > 0)
                {
                    this.CheckAllChildNodes(node, nodeChecked, parentName);
                }
            }
        }
Пример #4
0
        private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
        {
            // check all child nodes as well
            if (e.Action != TreeViewAction.Unknown)
            {
                UnifyLayer node = (UnifyLayer)e.Node.Tag;

                if (e.Node.Nodes.Count > 0)
                {
                    this.CheckAllChildNodes(e.Node, e.Node.Checked, node.Name);
                }
                if (e.Node.Checked)
                {
                    node.DesignOptionName = node.Name;
                    this.checkedNodes.Add(node);
                }
                else
                {
                    node.DesignOptionName = "";
                    this.checkedNodes.Remove(node);
                }
            }
        }
Пример #5
0
        private void GetMaterialsAndLayers()
        {
            List <UnifyMaterial> matList     = new List <UnifyMaterial>();
            List <UnifyLayer>    unifyLayers = new List <UnifyLayer>();

            this.NestingLevel = 0;

            // get all materials by layers
            foreach (Layer layer in doc.Layers)
            {
                // process Layer info
                UnifyLayer ul = new UnifyLayer();
                ul.ObjType      = "Layer";
                ul.Guid         = layer.Id;
                ul.Name         = layer.FullPath.Replace(":", "_");
                ul.MeshCollider = false;
                ul.Parent       = layer.ParentLayerId;
                ul.Level        = layer.FullPath.Split(new string[] { "::" }, StringSplitOptions.None).Count();
                ul.ShortName    = layer.Name;

                if (ul.Level > this.NestingLevel)
                {
                    this.NestingLevel = ul.Level;
                }
                unifyLayers.Add(ul);

                // process material info
                int           renderMatIndex = layer.RenderMaterialIndex;
                Material      rhinoMat       = doc.Materials[renderMatIndex];
                UnifyMaterial mat            = new UnifyMaterial();

                mat.ObjType         = "MaterialObject";
                mat.Guid            = rhinoMat.Id;
                mat.Name            = rhinoMat.Name;
                mat.Diffuse         = Utility.ColorToString(rhinoMat.DiffuseColor);
                mat.SpecularColor   = Utility.ColorToString(rhinoMat.SpecularColor);
                mat.EmissionColor   = Utility.ColorToString(rhinoMat.EmissionColor);
                mat.ReflectionColor = Utility.ColorToString(rhinoMat.ReflectionColor);
                mat.Metallic        = rhinoMat.Shine;

                if (rhinoMat.GetBitmapTexture() != null)
                {
                    mat.DiffuseTexture = rhinoMat.GetBitmapTexture().FileName;
                }
                if (rhinoMat.GetTransparencyTexture() != null)
                {
                    mat.TransparencyTexture = rhinoMat.GetTransparencyTexture().FileName;
                }
                if (rhinoMat.GetEnvironmentTexture() != null)
                {
                    mat.EnvironmentTexture = rhinoMat.GetEnvironmentTexture().FileName;
                }
                if (rhinoMat.GetBumpTexture() != null)
                {
                    mat.BumpTexture = rhinoMat.GetBumpTexture().FileName;
                }

                mat.Transparency = rhinoMat.Transparency;
                mat.UniqueName   = layer.FullPath.Replace("::", "__");

                matList.Add(mat);
            }

            this.Materials = matList;
            this.Layers    = unifyLayers;
        }