static public int ctor_s(IntPtr l)
 {
     try {
         UnityEngine.RectInt o;
         o = new UnityEngine.RectInt();
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int ctor__Vector2Int__Vector2Int_s(IntPtr l)
 {
     try {
         UnityEngine.RectInt    o;
         UnityEngine.Vector2Int a1;
         checkValueType(l, 1, out a1);
         UnityEngine.Vector2Int a2;
         checkValueType(l, 2, out a2);
         o = new UnityEngine.RectInt(a1, a2);
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int constructor(IntPtr l)
 {
     try {
         int argc = LuaDLL.lua_gettop(l);
         UnityEngine.RectInt o;
         if (argc == 5)
         {
             System.Int32 a1;
             checkType(l, 2, out a1);
             System.Int32 a2;
             checkType(l, 3, out a2);
             System.Int32 a3;
             checkType(l, 4, out a3);
             System.Int32 a4;
             checkType(l, 5, out a4);
             o = new UnityEngine.RectInt(a1, a2, a3, a4);
             pushValue(l, true);
             pushValue(l, o);
             return(2);
         }
         else if (argc == 3)
         {
             UnityEngine.Vector2Int a1;
             checkValueType(l, 2, out a1);
             UnityEngine.Vector2Int a2;
             checkValueType(l, 3, out a2);
             o = new UnityEngine.RectInt(a1, a2);
             pushValue(l, true);
             pushValue(l, o);
             return(2);
         }
         else if (argc == 0)
         {
             o = new UnityEngine.RectInt();
             pushValue(l, true);
             pushObject(l, o);
             return(2);
         }
         return(error(l, "New object failed."));
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int ctor__Int32__Int32__Int32__Int32_s(IntPtr l)
 {
     try {
         UnityEngine.RectInt o;
         System.Int32        a1;
         checkType(l, 1, out a1);
         System.Int32 a2;
         checkType(l, 2, out a2);
         System.Int32 a3;
         checkType(l, 3, out a3);
         System.Int32 a4;
         checkType(l, 4, out a4);
         o = new UnityEngine.RectInt(a1, a2, a3, a4);
         pushValue(l, true);
         pushValue(l, o);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Exemple #5
0
 /// <summary>
 /// Get the objects in this tree that intersect with the specified rectangle.
 /// </summary>
 /// <param name="rect">The rectangle to find objects in.</param>
 /// <param name="results">A reference to a list that will be populated with the results.</param>
 public void getObjects(Rectangle rect, ref List <T> results)
 {
     _quadTreeRoot.getObjects(rect, ref results);
 }
Exemple #6
0
 /// <summary>
 /// Get the objects in this tree that intersect with the specified rectangle.
 /// </summary>
 /// <param name="rect">The rectangle to find objects in.</param>
 public List <T> getObjects(Rectangle rect)
 {
     return(_quadTreeRoot.getObjects(rect));
 }
Exemple #7
0
 /// <summary>
 /// Creates a QuadTree for the specified area.
 /// </summary>
 /// <param name="rect">The area this QuadTree object will encompass.</param>
 public QuadTree(Rectangle rect)
 {
     _quadTreeRoot = new QuadTreeNode <T>(rect);
 }
 static public int constructor(IntPtr l)
 {
     try {
                     #if DEBUG
         var    method     = System.Reflection.MethodBase.GetCurrentMethod();
         string methodName = GetMethodName(method);
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.BeginSample(methodName);
                     #else
         Profiler.BeginSample(methodName);
                     #endif
                     #endif
         int argc = LuaDLL.lua_gettop(l);
         UnityEngine.RectInt o;
         if (argc == 5)
         {
             System.Int32 a1;
             checkType(l, 2, out a1);
             System.Int32 a2;
             checkType(l, 3, out a2);
             System.Int32 a3;
             checkType(l, 4, out a3);
             System.Int32 a4;
             checkType(l, 5, out a4);
             o = new UnityEngine.RectInt(a1, a2, a3, a4);
             pushValue(l, true);
             pushValue(l, o);
             return(2);
         }
         else if (argc == 3)
         {
             UnityEngine.Vector2Int a1;
             checkValueType(l, 2, out a1);
             UnityEngine.Vector2Int a2;
             checkValueType(l, 3, out a2);
             o = new UnityEngine.RectInt(a1, a2);
             pushValue(l, true);
             pushValue(l, o);
             return(2);
         }
         else if (argc == 0)
         {
             o = new UnityEngine.RectInt();
             pushValue(l, true);
             pushObject(l, o);
             return(2);
         }
         return(error(l, "New object failed."));
     }
     catch (Exception e) {
         return(error(l, e));
     }
             #if DEBUG
     finally {
                     #if UNITY_5_5_OR_NEWER
         UnityEngine.Profiling.Profiler.EndSample();
                     #else
         Profiler.EndSample();
                     #endif
     }
             #endif
 }
Exemple #9
0
 private extern void Internal_CopyActiveRenderTextureToHoles(RectInt rect, int destX, int destY, bool allowDelayedCPUSync);
Exemple #10
0
 private extern void Internal_CopyActiveRenderTextureToHeightmap(RectInt rect, int destX, int destY, TerrainHeightmapSyncControl syncControl);
Exemple #11
0
        public void CopyActiveRenderTextureToTexture(string textureName, int textureIndex, RectInt sourceRect, Vector2Int dest, bool allowDelayedCPUSync)
        {
            if (String.IsNullOrEmpty(textureName))
            {
                throw new ArgumentNullException("textureName");
            }

            var source = RenderTexture.active;

            if (source == null)
            {
                throw new InvalidOperationException("Active RenderTexture is null.");
            }

            int textureWidth  = 0;
            int textureHeight = 0;

            if (textureName == HolesTextureName)
            {
                if (textureIndex != 0)
                {
                    throw new ArgumentOutOfRangeException("textureIndex");
                }
                else if (source == holesTexture)
                {
                    throw new ArgumentException("source", "Active RenderTexture cannot be holesTexture.");
                }
                textureWidth = textureHeight = holesResolution;
            }
            else if (textureName == AlphamapTextureName)
            {
                if (textureIndex < 0 || textureIndex >= alphamapTextureCount)
                {
                    throw new ArgumentOutOfRangeException("textureIndex");
                }
                textureWidth = textureHeight = alphamapResolution;
            }
            else
            {
                // TODO: Support generic terrain textures.
                throw new ArgumentException($"Unrecognized terrain texture name: \"{textureName}\"");
            }

            if (sourceRect.x < 0 || sourceRect.y < 0 || sourceRect.xMax > source.width || sourceRect.yMax > source.height)
            {
                throw new ArgumentOutOfRangeException("sourceRect");
            }
            else if (dest.x < 0 || dest.x + sourceRect.width > textureWidth)
            {
                throw new ArgumentOutOfRangeException("dest.x");
            }
            else if (dest.y < 0 || dest.y + sourceRect.height > textureHeight)
            {
                throw new ArgumentOutOfRangeException("dest.y");
            }

            if (textureName == HolesTextureName)
            {
                Internal_CopyActiveRenderTextureToHoles(sourceRect, dest.x, dest.y, allowDelayedCPUSync);
                return;
            }

            var dstTexture = GetAlphamapTexture(textureIndex);

            // Delay synching back (using ReadPixels) if CopyTexture can be used.
            // TODO: Checking the format compatibility is difficult as it varies by platforms. For instance copying between ARGB32 RT and RGBA32 Tex seems to be fine on all tested platforms...
            allowDelayedCPUSync = allowDelayedCPUSync && SupportsCopyTextureBetweenRTAndTexture;
            if (allowDelayedCPUSync)
            {
                if (dstTexture.mipmapCount > 1)
                {
                    // Composes mip0 in a RT with full mipchain.
                    var tmp = RenderTexture.GetTemporary(new RenderTextureDescriptor(dstTexture.width, dstTexture.height, source.format)
                    {
                        sRGB             = false,
                        useMipMap        = true,
                        autoGenerateMips = false
                    });
                    if (!tmp.IsCreated())
                    {
                        tmp.Create();
                    }

                    Graphics.CopyTexture(dstTexture, 0, 0, tmp, 0, 0);
                    Graphics.CopyTexture(source, 0, 0, sourceRect.x, sourceRect.y, sourceRect.width, sourceRect.height, tmp, 0, 0, dest.x, dest.y);

                    // Generate the mips on the GPU
                    tmp.GenerateMips();

                    // Copy the full mipchain back to the alphamap texture
                    Graphics.CopyTexture(tmp, dstTexture);

                    RenderTexture.ReleaseTemporary(tmp);
                }
                else
                {
                    Graphics.CopyTexture(source, 0, 0, sourceRect.x, sourceRect.y, sourceRect.width, sourceRect.height, dstTexture, 0, 0, dest.x, dest.y);
                }

                // TODO: Support generic terrain textures.
                Internal_MarkAlphamapDirtyRegion(textureIndex, dest.x, dest.y, sourceRect.width, sourceRect.height);
            }
            else
            {
                if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Metal || !SystemInfo.graphicsUVStartsAtTop)
                {
                    dstTexture.ReadPixels(new Rect(sourceRect.x, sourceRect.y, sourceRect.width, sourceRect.height), dest.x, dest.y);
                }
                else
                {
                    dstTexture.ReadPixels(new Rect(sourceRect.x, source.height - sourceRect.yMax, sourceRect.width, sourceRect.height), dest.x, dest.y);
                }
                dstTexture.Apply(true);

                // TODO: Check if the texture is previously marked dirty?
                // TODO: Support generic terrain textures.
                Internal_ClearAlphamapDirtyRegion(textureIndex);
            }

            Experimental.TerrainAPI.TerrainCallbacks.InvokeTextureChangedCallback(this, textureName, new RectInt(dest.x, dest.y, sourceRect.width, sourceRect.height), !allowDelayedCPUSync);
        }
Exemple #12
0
 public void ClampToBounds(RectInt bounds)
 {
     this.position = new Vector2Int(Math.Max(Math.Min(bounds.xMax, this.position.x), bounds.xMin), Math.Max(Math.Min(bounds.yMax, this.position.y), bounds.yMin));
     this.size     = new Vector2Int(Math.Min(bounds.xMax - this.position.x, this.size.x), Math.Min(bounds.yMax - this.position.y, this.size.y));
 }
 internal static void InvokeTextureChangedCallback(TerrainData terrainData, string textureName, RectInt texelRegion, bool synched)
 {
     if (textureChanged != null)
     {
         foreach (var user in terrainData.users)
         {
             textureChanged.Invoke(user, textureName, texelRegion, synched);
         }
     }
 }