Exemplo n.º 1
0
        /// <summary>
        /// Updates an existing surface object.
        /// </summary>
        /// <param name="gameObject">Game object reference to the surfaceObject.</param>
        /// <param name="meshID">User specified ID for the mesh.</param>
        /// <returns>True if successful</returns>
        protected void UpdateSurfaceObject(GameObject gameObject, int meshID)
        {
            // If it's in the list, update it
            for (int i = 0; i < SurfaceObjects.Count; ++i)
            {
                if (SurfaceObjects[i].Object == gameObject)
                {
                    SurfaceObject thisSurfaceObject = SurfaceObjects[i];
                    thisSurfaceObject.ID = meshID;
                    thisSurfaceObject.UpdateID++;
                    SurfaceObjects[i] = thisSurfaceObject;
                    return;
                }
            }

            // Not in the list, add it
            SurfaceObject surfaceObject = new SurfaceObject();

            surfaceObject.ID       = meshID;
            surfaceObject.UpdateID = 0;

            surfaceObject.Object   = gameObject;
            surfaceObject.Filter   = surfaceObject.Object.GetComponent <MeshFilter>();
            surfaceObject.Renderer = surfaceObject.Object.GetComponent <MeshRenderer>();

            SurfaceObjects.Add(surfaceObject);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Cleans up references to objects that we have created.
 /// </summary>
 protected void Cleanup()
 {
     for (int index = 0; index < SurfaceObjects.Count; index++)
     {
         Destroy(SurfaceObjects[index].Object);
     }
     SurfaceObjects.Clear();
 }
Exemplo n.º 3
0
 /// <summary>
 /// Removes and optionally destroys the specified surfaceObject that we've created
 /// </summary>
 /// <param name="surface">The surface game object</param>
 /// <param name="removeAndDestroy">If true, the surface will be removed and destroyed. If false, it will only be removed.</param>
 protected void RemoveSurfaceObject(GameObject surface, bool removeAndDestroy = true)
 {
     // Remove it from our list
     for (int index = 0; index < SurfaceObjects.Count; index++)
     {
         if (SurfaceObjects[index].Object == surface)
         {
             if (removeAndDestroy)
             {
                 Destroy(SurfaceObjects[index].Object);
             }
             SurfaceObjects.RemoveAt(index);
             break;
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a new surface game object.
        /// </summary>
        /// <param name="mesh">The mesh to attach. Can be null.</param>
        /// <param name="objectName">What to name this object.</param>
        /// <param name="parentObject">What to parent this object to.</param>
        /// <param name="meshID">Optional user specified ID for the mesh.</param>
        /// <returns>The newly created game object.</returns>
        protected GameObject AddSurfaceObject(Mesh mesh, string objectName, Transform parentObject, int meshID = 0)
        {
            SurfaceObject surfaceObject = new SurfaceObject();

            surfaceObject.ID       = meshID;
            surfaceObject.UpdateID = 0;

            surfaceObject.Object = new GameObject(objectName, componentsRequiredForSurfaceMesh);
            surfaceObject.Object.transform.SetParent(parentObject);
            surfaceObject.Object.layer = SpatialMappingManager.Instance.PhysicsLayer;

            surfaceObject.Filter            = surfaceObject.Object.GetComponent <MeshFilter>();
            surfaceObject.Filter.sharedMesh = mesh;

            surfaceObject.Renderer = surfaceObject.Object.GetComponent <MeshRenderer>();
            surfaceObject.Renderer.sharedMaterial = RenderMaterial;

            SurfaceObjects.Add(surfaceObject);

            return(surfaceObject.Object);
        }
Exemplo n.º 5
0
    /// <summary>
    /// Event raised by the planet when a new surface is generated.
    /// If enabled, adds SurfaceObjects component to the Surface and populates it with objects
    /// </summary>
    public void OnSurfaceGenerated(Surface s)
    {
        if (automaticPerVertexPlacement)
        {
            if (s.lodLevel == lodLevel)
            {
                SurfaceObjects so = s.gameObject.AddComponent <SurfaceObjects>();

                so.minHeight         = minHeight;
                so.maxHeight         = maxHeight;
                so.minPolarity       = minPolarity;
                so.maxPolarity       = maxPolarity;
                so.objectChance      = objectChance;
                so.scale             = scale;
                so.rotation          = rotation;
                so.scaleVariation    = scaleVariation;
                so.rotationVariation = rotationVariation;

                so.Populate(s, objectToPlace);
                surfaceObjects.Add(so);
            }
        }
    }