Пример #1
0
        public void Populate(Surface s, Transform objectTemplate)
        {
            surface = s;

            if (surfaceObjects != null)
            {
                DestroyExistingObjects();
            }

            surfaceObjects = new List <Transform>();

            GameObject objectsParent = new GameObject("Objects");

            objectsParent.transform.parent = this.transform;

            Vector3[] vertices = surface.mesh.vertices;
            Vector3[] normals  = surface.mesh.normals;
            Color[]   colors   = surface.mesh.colors;
            // colors contain planet data
            // r = height
            // g = polarity

            for (int i = 0; i < vertices.Length; i++)
            {
                if (colors[i].r >= minHeight && colors[i].r <= maxHeight && colors[i].g >= minPolarity && colors[i].g <= maxPolarity)
                {
                    if (Random.Range(0f, 1f) < objectChance)
                    {
                        Transform newObject = PlacementHelper.PlaceObject(objectTemplate, objectsParent.transform, vertices[i], normals[i], scale, rotation, scaleVariation, rotationVariation);
                        surfaceObjects.Add(newObject);
                    }
                }
            }
        }
Пример #2
0
        public void OnSceneGUI()
        {
            if (placeObjects)
            {
                HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));

                if (Event.current.type == EventType.MouseMove)
                {
                    Ray        ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                    RaycastHit hit;

                    if (Physics.Raycast(ray, out hit))
                    {
                        lastPoint  = hit.point;
                        lastNormal = hit.normal;

                        SceneView.RepaintAll();
                    }
                }

                if (Event.current.type == EventType.MouseDown)
                {
                    if (Event.current.button == 0)
                    {
                        Ray        ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                        RaycastHit hit = new RaycastHit();

                        if (Physics.Raycast(ray, out hit))
                        {
                            Surface s = hit.collider.gameObject.GetComponent <Surface>();
                            if (s != null)
                            {
                                placementHelper.PlaceObject(null, hit.point, hit.normal);
                            }
                        }

                        Event.current.Use();
                    }
                }

                Handles.DrawWireDisc(lastPoint, lastNormal, placementHelper.scale.magnitude);
            }
        }