Пример #1
0
        public void MoveItem(int direction)
        {
            // Checking selected item
            if (lbCameras.SelectedItem == null || lbCameras.SelectedIndex < 0)
            {
                return; // No selected item - nothing to do
            }
            // Calculate new index using move direction
            int newIndex = lbCameras.SelectedIndex + direction;

            // Checking bounds of the range
            if (newIndex < 0 || newIndex >= lbCameras.Items.Count)
            {
                return; // Index out of range - nothing to do
            }
            UnifyCamera selected = lbCameras.SelectedItem as UnifyCamera;

            inputData.Cameras.RemoveAt(lbCameras.SelectedIndex);
            inputData.Cameras.Insert(newIndex, selected);

            ((ListBox)lbCameras).DataSource    = null;
            ((ListBox)lbCameras).DataSource    = this.inputData.Cameras;
            ((ListBox)lbCameras).DisplayMember = "Name";

            // Restore selection
            lbCameras.SetSelected(newIndex, true);
        }
Пример #2
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();
        }
Пример #3
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);
        }
Пример #4
0
        private void GetCameras()
        {
            // get all named view objects
            NamedViewTable     allCameras = doc.NamedViews;
            List <UnifyCamera> camList    = new List <UnifyCamera>();

            foreach (ViewInfo vi in allCameras)
            {
                UnifyCamera cam = new UnifyCamera();
                cam.ObjType        = "ViewCamera";
                cam.Guid           = vi.Viewport.Id;
                cam.CameraLocation = vi.Viewport.CameraLocation.ToString();
                cam.CameraTarget   = vi.Viewport.FrustumCenterPoint(2).ToString();
                cam.Name           = vi.Name;

                camList.Add(cam);
            }

            this.Cameras = camList;
        }
Пример #5
0
    private static void ProcessCharacter()
    {
        List <UnifyCamera> allCameras = deserialized["Cameras"].Cast <UnifyCamera>().ToList();

        // get origin camera
        UnifyCamera originCam = allCameras.Where(x => x.IsPlayerOriginCamera).FirstOrDefault();

        // get fps controller
        var character = GameObject.FindGameObjectWithTag("Player");

        if (character != null)
        {
            character.transform.position = Utilities.TranslateFromRhinoCS(originCam.CameraLocation);

            // set camera direction
            GameObject tempObj = new GameObject("Temp");
            tempObj.transform.position = Utilities.TranslateFromRhinoCS(originCam.CameraTarget);
            character.transform.LookAt(tempObj.transform.position);
            DestroyImmediate(tempObj);

            // print debug message
            Debug.Log("Character was processed.");
        }
    }
Пример #6
0
 private void cbCameras_SelectedIndexChanged(object sender, System.EventArgs e)
 {
     UnifyCamera selected = cbCameras.SelectedValue as UnifyCamera;
 }
Пример #7
0
        private void LoadPresets()
        {
            FormPresets presets = null;

            try
            {
                string json = File.ReadAllText(this.SelectedProject);
                presets = JsonConvert.DeserializeObject <FormPresets>(json);
            }
            catch { }

            if (presets != null)
            {
                if (presets.AssetsLocation != null)
                {
                    // set project path and input data
                    tbFolderPath.Text = presets.AssetsLocation;
                    this.inputData.UnityProjectPath = presets.AssetsLocation;
                }

                if (presets.OriginCamera != null)
                {
                    // set selected origin camera
                    int index = cbCameras.FindStringExact(presets.OriginCamera);
                    if (index != -1)
                    {
                        cbCameras.SelectedIndex = index;
                    }
                }

                if (presets.JumpCameras != null)
                {
                    // set jump cameras
                    // modify source list order
                    for (int i = 0; i < lbCameras.Items.Count; i++)
                    {
                        UnifyCamera cam = lbCameras.Items[i] as UnifyCamera;
                        if (presets.JumpCameras.ContainsKey(cam.Name))
                        {
                            this.inputData.Cameras.Remove(cam);
                            this.inputData.Cameras.Insert(presets.JumpCameras[cam.Name].Index, cam);
                        }
                    }

                    // re-set the list box bounding to re-set the order.
                    ((ListBox)lbCameras).DataSource    = null;
                    ((ListBox)lbCameras).DataSource    = this.inputData.Cameras;
                    ((ListBox)lbCameras).DisplayMember = "Name";

                    // set check boxes
                    foreach (KeyValuePair <string, ValuePair> item in presets.JumpCameras)
                    {
                        int index1 = lbCameras.FindStringExact(item.Key);
                        if (index1 != -1)
                        {
                            lbCameras.SetItemCheckState(index1, item.Value.Checked == true ? CheckState.Checked : CheckState.Unchecked);
                        }
                    }
                }

                if (presets.MeshColliders != null)
                {
                    // set nesh colliders
                    foreach (KeyValuePair <string, bool> item in presets.MeshColliders)
                    {
                        int index2 = lbAllLayers.FindStringExact(item.Key);
                        int index3 = lbSelectedLayers.FindStringExact(item.Key);
                        if (index2 != -1 && item.Value == true)
                        {
                            lbSelectedLayers.Items.Add(lbAllLayers.Items[index2]);
                            lbAllLayers.Items.RemoveAt(index2);
                        }
                        if (index3 != -1 && item.Value == false)
                        {
                            lbAllLayers.Items.Add(lbSelectedLayers.Items[index3]);
                            lbSelectedLayers.Items.RemoveAt(index3);
                        }
                    }
                }

                this.checkedNodes = new List <UnifyLayer>();
                if (presets.DesignOptions != null)
                {
                    // set Design Options
                    TreeNode nd = null;
                    IEnumerable <TreeNode> treeViewFlat = treeView1.FlattenTree();
                    foreach (KeyValuePair <string, bool> item in presets.DesignOptions)
                    {
                        nd = treeViewFlat.Where(x => ((UnifyLayer)x.Tag).Name == item.Key).FirstOrDefault();
                        if (nd != null)
                        {
                            nd.Checked = item.Value;

                            // if node is checked also add it to checked node list
                            if (item.Value)
                            {
                                this.checkedNodes.Add((UnifyLayer)nd.Tag);
                            }
                        }
                    }
                }
            }
        }