Пример #1
0
        private void showTorusEditor()
        {
            innerRadius = EditorGUILayout.FloatField("Inner radius", innerRadius);
            outerRadius = EditorGUILayout.FloatField("Outer radius", outerRadius);
            nbSides     = EditorGUILayout.IntField("Sides", nbSides);
            nbRadSeg    = EditorGUILayout.IntField("Segments", nbRadSeg);

            if (GUILayout.Button("Update"))
            {
                Vector3    oldPos = editingObject.transform.position;
                Quaternion oldRot = editingObject.transform.rotation;
                DestroyImmediate(editingObject);
                editingObject = ShapeFactory.createTorus(outerRadius, innerRadius, nbRadSeg, nbSides);
                editingObject.transform.position = oldPos;
                editingObject.transform.rotation = oldRot;
            }
        }
Пример #2
0
        private void showCylinderEditor()
        {
            innerRadius = EditorGUILayout.FloatField("Inner radius", innerRadius);
            outerRadius = EditorGUILayout.FloatField("Outer radius", outerRadius);

            height  = EditorGUILayout.FloatField("Height", height);
            nbSides = EditorGUILayout.IntField("Sides", nbSides);

            if (GUILayout.Button("Update"))
            {
                Vector3    oldPos = editingObject.transform.position;
                Quaternion oldRot = editingObject.transform.rotation;
                DestroyImmediate(editingObject);
                editingObject = ShapeFactory.createTube(height, nbSides, outerRadius, innerRadius, outerRadius, innerRadius);
                editingObject.transform.position = oldPos;
                editingObject.transform.rotation = oldRot;
            }
        }
Пример #3
0
        private IEnumerator placeOnAxis(GameObject parent)
        {
            if (Selection.transforms.Length == 1 || prefabs.Count > 0)
            {
                List <GameObject> objects = new List <GameObject>();

                int xdir = 1;
                int ydir = 1;
                int zdir = 1;

                if (x_dir == 0)
                {
                    xdir = -1;
                }
                if (y_dir == 0)
                {
                    ydir = -1;
                }
                if (z_dir == 0)
                {
                    zdir = -1;
                }

                var xsize = distance;
                var ysize = distance;
                var zsize = distance;

                Vector3 current = Vector3.zero;

                for (var x = 0; x < (int)x_count; x++)
                {
                    for (var y = 0; y < (int)y_count; y++)
                    {
                        for (var z = 0; z < (int)z_count; z++)
                        {
                            SceneView.RepaintAll();

                            if (pickRandom)
                            {
                                int index = Random.Range(0, prefabs.Count);
                                original = prefabs[index];

                                toolbox = EditorWindow.GetWindow <Toolbox>();
                                if (toolbox != null)
                                {
                                    current = Toolbox.gizmoPosition;
                                }
                                else
                                {
                                    current = original.transform.position;
                                }
                            }
                            else
                            {
                                current = Selection.transforms[0].position;
                            }


                            float probability = Random.Range(0, 1f);

                            if (randomizePlacement && probability < targetProbability)
                            {
                                continue;
                            }

                            float randomDistX = distance;
                            float randomDistY = distance;
                            float randomDistZ = distance;

                            if (randomizePlacement)
                            {
                                randomDistX = Random.Range(0, randomDistance);
                                randomDistY = Random.Range(0, randomDistance);
                                randomDistZ = Random.Range(0, randomDistance);
                            }

                            float   _y     = current.y;
                            Vector3 normal = Vector3.zero;

                            if (useRay)
                            {
                                _y = getCurrentHeight((current.x - x * xdir * xsize) + randomDistX, (current.z - z * zdir * zsize) + randomDistZ, out normal);
                            }
                            else
                            {
                                _y = (current.y - y * ydir * ysize) + randomDistY;
                            }

                            Vector3 targetPos =
                                new Vector3(
                                    (current.x - x * xdir * xsize) + randomDistX,
                                    _y,
                                    (current.z - z * zdir * zsize) + randomDistZ);

                            float dist     = (spherePosition - targetPos).magnitude;
                            bool  inSphere = dist < sphereRadius;

                            if (!occupiedPlace(targetPos, parent.transform))
                            {
                                if (keepInSphere && !inSphere)
                                {
                                    continue;
                                }

                                if (limitHeight && targetPos.y > maxHeight)
                                {
                                    continue;
                                }

                                GameObject g = null;
                                g = Instantiate(original);

                                if (randomizePlacement)
                                {
                                    float scale = Random.Range(_minSize, _maxSize);
                                    g.transform.localScale = new Vector3(scale, scale, scale);
                                }

                                if (randomizeRotation)
                                {
                                    g.transform.Rotate(new Vector3(0, Random.Range(0, 90f), 0));
                                }
                                if (normalForRotation)
                                {
                                    g.transform.rotation = Quaternion.FromToRotation(g.transform.up, normal) * g.transform.rotation;
                                }

                                Undo.RegisterCreatedObjectUndo(g, g.name);
                                g.transform.position = targetPos;

                                objects.Add(g);

                                if (groupObjects && !combineObjects)
                                {
                                    g.transform.SetParent(parent.transform);
                                }

                                yield return(new WaitForSeconds(0.01f));
                            }
                        }
                    }
                }
                if (!groupObjects && combineObjects)
                {
                    ShapeFactory.combineObjects(objects.ToArray());

                    foreach (GameObject g in objects)
                    {
                        DestroyImmediate(g);
                    }

                    DestroyImmediate(parent);
                }
            }

            yield return(null);
        }
Пример #4
0
        static void Callback(System.Object obj)
        {
            SceneView sceneView = SceneView.lastActiveSceneView;

            if (obj.ToString().Equals("front"))
            {
                sceneView.rotation = new Quaternion(0, 0, 0, 1);
            }
            else if (obj.ToString().Equals("top"))
            {
                sceneView.rotation = new Quaternion(1, 0, 0, 1);
            }
            else if (obj.ToString().Equals("left"))
            {
                sceneView.rotation = new Quaternion(0, 1, 0, 1);
            }
            else if (obj.ToString().Equals("ortho"))
            {
                toggleOrtho(sceneView);
            }

            /*
             * else if (obj.ToString().Equals("toolbox")) {
             *
             *  toolbox = ScriptableObject.CreateInstance<Toolbox>();
             *  toolbox.titleContent = new GUIContent("Toolbox", toolboxIcon);
             *  toolbox.ShowUtility();
             *  // window.Show();
             * }
             */
            else if (obj.ToString().Equals("moveToCursor"))
            {
                toolbox = EditorWindow.GetWindow <Toolbox>();
                if (toolbox != null)
                {
                    sceneView.LookAt(Toolbox.gizmoPosition);
                }
            }
            else if (obj.ToString().Equals("snapSelectionToCursor"))
            {
                if (Selection.activeGameObject != null)
                {
                    Selection.activeGameObject.transform.position = Toolbox.gizmoPosition;
                }
            }
            else if (obj.ToString().Equals("snapCursorToSelection"))
            {
                if (Selection.activeGameObject != null)
                {
                    Toolbox.gizmoPosition = Selection.activeGameObject.transform.position;
                }
            }

            else if (obj.ToString().Equals("snapCursorToGrid"))
            {
                int gridSize = EditorPrefs.GetInt("Toolkit_GridSize", 1);

                Vector3 pos = Toolbox.gizmoPosition;

                pos.x = EditorHelper.snap((int)pos.x, gridSize);
                pos.z = EditorHelper.snap((int)pos.z, gridSize);

                Toolbox.gizmoPosition = pos;
            }
            else if (obj.ToString().Equals("mergeObjects"))
            {
                if (Selection.gameObjects.Length > 0)
                {
                    ShapeFactory.combineObjects(Selection.gameObjects);
                }
            }
            else if (obj.ToString().Equals("drawMode"))
            {
                wireframe = !wireframe;

                if (wireframe)
                {
                    SceneView.lastActiveSceneView.renderMode = DrawCameraMode.Wireframe;
                }
                else
                {
                    SceneView.lastActiveSceneView.renderMode = DrawCameraMode.Textured;
                }

                sceneView.Repaint();
            }
        }
Пример #5
0
        static void createToolbar()
        {
            SceneView sceneView = SceneView.lastActiveSceneView;

            Handles.BeginGUI();
            GUILayout.BeginVertical();



            if (GUILayout.Button(contents[0], GUILayout.Width(32), GUILayout.Height(32)))
            {
                sceneView.LookAt(gizmoPosition);
            }

            else if (GUILayout.Button(contents[1], GUILayout.Width(32), GUILayout.Height(32)))
            {
                if (Selection.activeGameObject != null)
                {
                    Selection.activeGameObject.transform.position = gizmoPosition;
                }
            }

            else if (GUILayout.Button(contents[2], GUILayout.Width(32), GUILayout.Height(32)))
            {
                if (Selection.activeGameObject != null)
                {
                    gizmoPosition = Selection.activeGameObject.transform.position;
                }
            }

            else if (GUILayout.Button(contents[3], GUILayout.Width(32), GUILayout.Height(32)))
            {
                int gridSize = EditorPrefs.GetInt("Toolkit_GridSize", 1);

                Vector3 pos = gizmoPosition;

                pos.x = EditorHelper.snap((int)pos.x, gridSize);
                pos.z = EditorHelper.snap((int)pos.z, gridSize);

                gizmoPosition = pos;
            }

            else if (GUILayout.Button(contents[4], GUILayout.Width(32), GUILayout.Height(32)))
            {
                if (Selection.gameObjects.Length > 0)
                {
                    ShapeFactory.combineObjects(Selection.gameObjects);
                }
            }

            else if (GUILayout.Button(contents[5], GUILayout.Width(32), GUILayout.Height(32)))
            {
                Selection.activeGameObject.SetActive(true);
            }

            else if (GUILayout.Button(contents[6], GUILayout.Width(32), GUILayout.Height(32)))
            {
                Selection.activeGameObject.SetActive(false);
            }

            else if (GUILayout.Button(contents[7], GUILayout.Width(32), GUILayout.Height(32)))
            {
                if (objectCloner == null)
                {
                    objectCloner = ScriptableObject.CreateInstance <ObjectCloner>();
                }
                objectCloner.Show();
            }


            else if (GUILayout.Button(contents[8], GUILayout.Width(32), GUILayout.Height(32)))
            {
                if (selector == null)
                {
                    selector = ScriptableObject.CreateInstance <FilterSelector>();
                }
                selector.Show();
            }

            else if (GUILayout.Button(contents[9], GUILayout.Width(32), GUILayout.Height(32)))
            {
                if (colorSelector == null)
                {
                    colorSelector = ScriptableObject.CreateInstance <ColorSelector>();
                }
                colorSelector.Show();
            }


            else if (GUILayout.Button(contents[10], GUILayout.Width(32), GUILayout.Height(32)))
            {
                if (waypointGenerator == null)
                {
                    waypointGenerator = ScriptableObject.CreateInstance <WaypointGenerator>();
                }
                waypointGenerator.Show();
            }

            GUILayout.EndVertical();
            Handles.EndGUI();
        }