Exemple #1
0
 static public int Encapsulate(IntPtr l)
 {
     try{
         int argc = LuaDLL.lua_gettop(l);
         if (matchType(l, argc, 2, typeof(UnityEngine.Vector3)))
         {
             UnityEngine.Bounds  self = (UnityEngine.Bounds)checkSelf(l);
             UnityEngine.Vector3 a1;
             checkType(l, 2, out a1);
             self.Encapsulate(a1);
             setBack(l, self);
             return(0);
         }
         else if (matchType(l, argc, 2, typeof(UnityEngine.Bounds)))
         {
             UnityEngine.Bounds self = (UnityEngine.Bounds)checkSelf(l);
             UnityEngine.Bounds a1;
             checkType(l, 2, out a1);
             self.Encapsulate(a1);
             setBack(l, self);
             return(0);
         }
         LuaDLL.luaL_error(l, "No matched override function to call");
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Exemple #2
0
 public void Start()
 {
     Global = GameObject.FindGameObjectWithTag("GLOBALS").GetComponent<Globals>();
     ThisBounds = gameObject.GetComponent<Renderer>().bounds;
     Level = 1;
     InvokeRepeating("Mine", 3f, 3f);
 }
        public static Bounds GetPartColliderBoundsInBasis(this Part part, Matrix4x4 worldToBasisMatrix, int excessiveVerts = 2500)
        {
            Transform[] transforms = part.FindModelComponents<Transform>();
            Bounds bounds = new Bounds();
            for (int i = 0; i < transforms.Length; i++)
            {
                Transform t = transforms[i];

                MeshCollider mc = t.GetComponent<MeshCollider>();
                Mesh m;
                Matrix4x4 matrix = worldToBasisMatrix * t.localToWorldMatrix;

                if (mc == null)
                {
                    BoxCollider bc = t.GetComponent<BoxCollider>();
                    if (bc != null)
                    {
                        bounds.Encapsulate(matrix.MultiplyPoint3x4(bc.bounds.min));
                        bounds.Encapsulate(matrix.MultiplyPoint3x4(bc.bounds.max));
                    }
                    continue;
                }
                else
                    m = mc.sharedMesh;

                if (m == null)
                    continue;

                bounds.Encapsulate(matrix.MultiplyPoint3x4(m.bounds.min));
                bounds.Encapsulate(matrix.MultiplyPoint3x4(m.bounds.max));

            }
            return bounds;
        }
Exemple #4
0
    void OnDrawGizmosSelected()
    {
        // Draw World Space Origin
        Gizmos.DrawWireCube(Vector3.zero, new Vector3(100, 100, 100));
        switch (gizmosDrawType)
        {
        case GizmosDrawType.GizmosDrawTypeCameraInLeaf:
            // Draw the leaf which camera in side
            GizmosDrawCameraInsideLeaf(Camera.main);
            break;

        case GizmosDrawType.GizmosDrawTypeFrustumCulling:
            // Draw camera frustum culling process
            UnityEngine.Bounds[] bs = new UnityEngine.Bounds[lastVisibleLeafs.Count];
            for (int i = 0; i < bs.Length; i++)
            {
                BSPFileParser.BSPTreeLeaf leaf = _leafs[i];
                Bounds b = new Bounds();
                b.SetMinMax(new Vector3(leaf.mins[0], leaf.mins[1], leaf.mins[2]),
                            new Vector3(leaf.maxs[0], leaf.maxs[1], leaf.maxs[2]));
                b     = Right2Left(b);
                bs[i] = b;
            }
            GizmosDrawCameraFrustum(Camera.main, Color.green);
            GizmosDrawFrustumCulling(Camera.main, Color.yellow, bs);
            break;

        case GizmosDrawType.GizmosDrawTypeAllLeaves:
            GizmosDrawAllLeaves();
            break;
        }
    }
        public void onDrawGizmos( Vector3 basePosition )
        {
            Gizmos.color = new Color( 1f, 0f, 0.6f );

            var hasHorizontal = ( axis & CameraAxis.Horizontal ) == CameraAxis.Horizontal;
            var hasVertical = ( axis & CameraAxis.Vertical ) == CameraAxis.Vertical;
            var hasBothAxis = hasHorizontal && hasVertical;
            var bounds = new Bounds( basePosition, new Vector3( width, height ) );
            var lineWidth = Camera.main.orthographicSize;

            // expand our bounds to have larger lines if we only have a single axis
            if( hasVertical && !hasBothAxis )
            {
                bounds.Expand( new Vector3( lineWidth - bounds.size.x, 0f ) );
            }

            if( hasHorizontal && !hasBothAxis )
            {
                bounds.Expand( new Vector3( 0f, lineWidth - bounds.size.y ) );
            }

            if( hasVertical || hasBothAxis )
            {
                Gizmos.DrawLine( bounds.min, bounds.min + new Vector3( bounds.size.x, 0f ) );
                Gizmos.DrawLine( bounds.max, bounds.max - new Vector3( bounds.size.x, 0f ) );
            }

            if( hasHorizontal || hasBothAxis )
            {
                Gizmos.DrawLine( bounds.min, bounds.min + new Vector3( 0f, bounds.size.y ) );
                Gizmos.DrawLine( bounds.max, bounds.max - new Vector3( 0f, bounds.size.y ) );
            }
        }
 private void DoRenderPreview(bool shaded)
 {
     BillboardAsset target = this.target as BillboardAsset;
     Bounds bounds = new Bounds(new Vector3(0f, (this.m_Height.floatValue + this.m_Bottom.floatValue) * 0.5f, 0f), new Vector3(this.m_Width.floatValue, this.m_Height.floatValue, this.m_Width.floatValue));
     float magnitude = bounds.extents.magnitude;
     float num2 = 8f * magnitude;
     Quaternion quaternion = Quaternion.Euler(-this.m_PreviewDir.y, -this.m_PreviewDir.x, 0f);
     this.m_PreviewUtility.m_Camera.transform.rotation = quaternion;
     this.m_PreviewUtility.m_Camera.transform.position = (Vector3) (quaternion * (-Vector3.forward * num2));
     this.m_PreviewUtility.m_Camera.nearClipPlane = num2 - (magnitude * 1.1f);
     this.m_PreviewUtility.m_Camera.farClipPlane = num2 + (magnitude * 1.1f);
     this.m_PreviewUtility.m_Light[0].intensity = 1.4f;
     this.m_PreviewUtility.m_Light[0].transform.rotation = quaternion * Quaternion.Euler(40f, 40f, 0f);
     this.m_PreviewUtility.m_Light[1].intensity = 1.4f;
     Color ambient = new Color(0.1f, 0.1f, 0.1f, 0f);
     InternalEditorUtility.SetCustomLighting(this.m_PreviewUtility.m_Light, ambient);
     if (shaded)
     {
         target.MakeRenderMesh(this.m_ShadedMesh, 1f, 1f, 0f);
         target.MakeMaterialProperties(this.m_ShadedMaterialProperties, this.m_PreviewUtility.m_Camera);
         ModelInspector.RenderMeshPreviewSkipCameraAndLighting(this.m_ShadedMesh, bounds, this.m_PreviewUtility, target.material, null, this.m_ShadedMaterialProperties, new Vector2(0f, 0f), -1);
     }
     else
     {
         target.MakePreviewMesh(this.m_GeometryMesh);
         ModelInspector.RenderMeshPreviewSkipCameraAndLighting(this.m_GeometryMesh, bounds, this.m_PreviewUtility, this.m_GeometryMaterial, this.m_WireframeMaterial, null, new Vector2(0f, 0f), -1);
     }
     InternalEditorUtility.RemoveCustomLighting();
 }
Exemple #7
0
 public static float DistanceToBounds(Direction dir, Vector3 pos, Bounds liveable)
 {
     switch(dir)
     {
         case Direction.NORTH:
             return liveable.max.y - pos.y;
         case Direction.NORTHEAST:
             return Mathf.Min(liveable.max.y - pos.y, liveable.max.z - pos.z);
         case Direction.EAST:
             return liveable.max.z - pos.z;
         case Direction.SOUTHEAST:
             return Mathf.Min(pos.y - liveable.min.y, liveable.max.z - pos.z);
         case Direction.SOUTH:
             return pos.y - liveable.min.y;
         case Direction.SOUTHWEST:
             return Mathf.Min(pos.y - liveable.min.y, pos.z - liveable.min.z);
         case Direction.WEST:
             return pos.z - liveable.min.z;
         case Direction.NORTHWEST:
             return Mathf.Min(liveable.max.y - pos.y, pos.z - liveable.min.z);
         default:
         case Direction.CENTER:
             break;
     }
     return 99999f;
 }
Exemple #8
0
 public static void DoEditModeInspectorModeButton(SceneViewEditMode mode, string label, GUIContent icon, Bounds bounds, Editor caller)
 {
     if (!EditorUtility.IsPersistent(caller.target))
     {
         DetectMainToolChange();
         if (s_EditColliderButtonStyle == null)
         {
             s_EditColliderButtonStyle = new GUIStyle("Button");
             s_EditColliderButtonStyle.padding = new RectOffset(0, 0, 0, 0);
             s_EditColliderButtonStyle.margin = new RectOffset(0, 0, 0, 0);
         }
         Rect rect = EditorGUILayout.GetControlRect(true, 23f, new GUILayoutOption[0]);
         Rect position = new Rect(rect.xMin + EditorGUIUtility.labelWidth, rect.yMin, 33f, 23f);
         GUIContent content = new GUIContent(label);
         Vector2 vector = GUI.skin.label.CalcSize(content);
         Rect rect3 = new Rect(position.xMax + 5f, rect.yMin + ((rect.height - vector.y) * 0.5f), vector.x, rect.height);
         int instanceID = caller.GetInstanceID();
         bool flag = (editMode == mode) && (ownerID == instanceID);
         EditorGUI.BeginChangeCheck();
         bool flag2 = GUI.Toggle(position, flag, icon, s_EditColliderButtonStyle);
         GUI.Label(rect3, label);
         if (EditorGUI.EndChangeCheck())
         {
             ChangeEditMode(!flag2 ? SceneViewEditMode.None : mode, bounds, caller);
         }
     }
 }
        public Vector2 Move(float deltaX, float deltaY)
        {
            //Update bounds
            m_BoundsWithSkin = m_BoxCollider.bounds;
            m_BoundsWithSkin.Expand(-2.0f * m_SkinWidth);

            m_IsGrounded = false;
            m_IsGoingUpSlope = false;

            Vector2 deltaMovement = new Vector2(deltaX * Time.deltaTime, deltaY * Time.deltaTime);

            //Move horizontally
            HandleHorizontalMovement(ref deltaMovement);
            
            //Move vertically
            HandleVerticalMovement(ref deltaMovement);

            //Do the actual movement in world space
            transform.Translate(new Vector3(deltaMovement.x, deltaMovement.y, 0.0f), Space.World);

            //Return the current velocity
            Vector2 velocity = new Vector2(0.0f, 0.0f);

            if (Time.deltaTime > 0.0f)
                velocity = deltaMovement / Time.deltaTime;

            return velocity;
        }
Exemple #10
0
 public void Start()
 {
     Factories = new GameObject[10];
     Factories = Resources.LoadAll<GameObject>("Prefabs/Factories/Food");
     ThisBounds = gameObject.GetComponent<Renderer>().bounds;
     Global = GameObject.FindGameObjectWithTag("GLOBALS").GetComponent<Globals>();
 }
Exemple #11
0
        //-----------------------------------------------------
        //Renvoie la diagonale de la bounding box
        public static float GetBoundDiag(Bounds bbox)
        {
            Vector3 dim = bbox.size;
               // Calculer la taille idéale du champ de vision de la caméra (+projecteur) : la plus petite possible contenant l'objet

            float  bigDim = 0, bigDim2=0, bigI=0;
               for(int i=0; i<3; i++)      // Récupérer la dimension la plus grande
               {
                   if( (dim[i]>0 ? dim[i] : -dim[i]) > bigDim)
                   {
                       bigDim = (dim[i]>0 ? dim[i] : -dim[i]);
                       bigI = i;
                   }
               }
               for(int i=0; i<3; i++)      // Récupérer la 2e dimension la plus grande
               {
                   if( (dim[i]>0 ? dim[i] : -dim[i]) > bigDim2 && i!=bigI)
                       bigDim2 = (dim[i]>0 ? dim[i] : -dim[i]);
               }

            //       Debug.Log("IOSBigDim = "+bigDim+", BigDim2="+bigDim2);
               bigDim = bigDim/2;// * scl;
               bigDim2 = bigDim2/2;// * scl;

               return Mathf.Sqrt(bigDim*bigDim + bigDim2*bigDim2);
        }
        public Vector3 getDesiredPositionDelta( Bounds targetBounds, Vector3 basePosition, Vector3 targetAvgVelocity )
        {
            var desiredOffset = Vector3.zero;
            var hasHorizontal = ( axis & CameraAxis.Horizontal ) == CameraAxis.Horizontal;
            var hasVertical = ( axis & CameraAxis.Vertical ) == CameraAxis.Vertical;
            var bounds = new Bounds( basePosition, new Vector3( width, height, 5f ) );

            if( !bounds.Contains( targetBounds.max ) || !bounds.Contains( targetBounds.min ) )
            {
                // figure out the minimum distance we need to move to get the player back in our bounds
                // x-axis
                if( hasHorizontal && bounds.min.x > targetBounds.min.x )
                {
                    desiredOffset.x = targetBounds.min.x - bounds.min.x;
                }
                else if( hasHorizontal && bounds.max.x < targetBounds.max.x )
                {
                    desiredOffset.x = targetBounds.max.x - bounds.max.x;
                }

                // y-axis. disregard movement above the trap when in platform snap mode
                if( hasVertical && bounds.min.y > targetBounds.min.y )
                {
                    desiredOffset.y = targetBounds.min.y - bounds.min.y;
                }
                else if( /*!inPlatformSnapMode &&*/ hasVertical && bounds.max.y < targetBounds.max.y )
                {
                    desiredOffset.y = targetBounds.max.y - bounds.max.y;
                }
            }

            return desiredOffset;
        }
Exemple #13
0
        public Bounds GetBounds()
        {
            Bounds result = new Bounds();
            Vector3 min = Vector3.zero;
            Vector3 max = Vector3.zero;
            foreach (var child in this.GetComponentsInChildren<CaseManager>())
            {
                if (child.transform.position.x > max.x)
                {
                    max = new Vector3(child.transform.position.x, max.y, 0);
                }
                if (child.transform.position.x < min.x)
                {
                    min = new Vector3(child.transform.position.x, min.y, 0);
                }
                if (child.transform.position.y > max.y)
                {
                    max = new Vector3(max.x, child.transform.position.y, 0);
                }
                if (child.transform.position.y < min.y)
                {
                    min = new Vector3(min.x, child.transform.position.y, 0);
                }

            }
            result.SetMinMax(min, max);
            return result;
        }
		/** True if \a b1 and \a b2 intersects.
		 * \note This method ignores the Y axis
		 */
		private static bool Intersects (Bounds b1, Bounds b2)        {
			Vector3 min1 = b1.min;
			Vector3 max1 = b1.max;
			Vector3 min2 = b2.min;
			Vector3 max2 = b2.max;
			return min1.x <= max2.x && max1.x >= min2.x && min1.z <= max2.z && max1.z >= min2.z;
		}
Exemple #15
0
        public static UnityEngine.Bounds SharedVisualSpace(List <BoundingBox> bounds)
        {
            var center     = Vector3.zero;
            var totalCount = 0f;

            foreach (var bound in bounds)
            {
                foreach (Renderer child in bound.GetComponentsInChildren <Renderer>())
                {
                    if (child.GetComponent <BoundsHighlightSatellite>() == null)
                    {
                        center += child.bounds.center;
                        totalCount++;
                    }
                }
            }
            center /= Mathf.Max(totalCount, 1f);

            var extents = new UnityEngine.Bounds {
                center = center
            };

            foreach (var bound in bounds)
            {
                foreach (Renderer child in bound.GetComponentsInChildren <Renderer>())
                {
                    if (child.GetComponent <BoundsHighlightSatellite>() == null)
                    {
                        extents.Encapsulate(child.bounds);
                    }
                }
            }

            return(extents);
        }
Exemple #16
0
        private void Start()
		{
			_cameraTransform = transform;

            _mapRenderer = GameObject.Find("BaseMap").GetComponent<SpriteRenderer>();
            _bounds = _mapRenderer.sprite.bounds;
            _bounds.center = _mapRenderer.transform.position;

            _cameraTransform.position = new Vector3(_mapRenderer.transform.position.x, _mapRenderer.transform.position.y, -10);

			_basePosition = _cameraTransform.position;

			_offset = Vector3.zero;

            _camera = GetComponent<UnityEngine.Camera>();
            _windowaspect = (float)Screen.width / (float)Screen.height;
            _widthSize = _camera.orthographicSize * _windowaspect;
            SetBounds(_camera.orthographicSize);

            _camera.orthographicSize = _maxZoom;
            _zoom = _maxZoom;

            _pixelToUnitX = _widthSize * 2 / (float)Screen.width;
            _pixelToUnitY = _camera.orthographicSize * 2 / (float)Screen.height;


        }
Exemple #17
0
		/** Fills the buffer with all RecastMeshObjs which intersect the specified bounds */
		public static void GetAllInBounds (List<RecastMeshObj> buffer, Bounds bounds) {
			if (!Application.isPlaying){
				RecastMeshObj[] objs = FindObjectsOfType(typeof(RecastMeshObj)) as RecastMeshObj[];
				for (int i=0;i<objs.Length;i++) {
					objs[i].RecalculateBounds();
					if (objs[i].GetBounds ().Intersects (bounds)) {
						buffer.Add(objs[i]);
					}
				}
				return;
			} else if (Time.timeSinceLevelLoad == 0) {
				//Is is not guaranteed that all RecastMeshObj OnEnable functions have been called, so if it is the first frame since loading a new level
				//try to initialize all RecastMeshObj objects.
				RecastMeshObj[] objs = FindObjectsOfType(typeof(RecastMeshObj)) as RecastMeshObj[];
				for (int i=0;i<objs.Length;i++) objs[i].Register();
			}
			
			for (int q=0;q<dynamicMeshObjs.Count;q++) {
				if (dynamicMeshObjs[q].GetBounds ().Intersects (bounds)) {
					buffer.Add (dynamicMeshObjs[q]);
				}
			}
			
			Rect r = Rect.MinMaxRect (bounds.min.x, bounds.min.z, bounds.max.x, bounds.max.z);
			
			tree.QueryInBounds (r, buffer);
		}
Exemple #18
0
		public static void DrawBounds(Bounds bounds, Color color)
		{
			var size = bounds.size;

			var points = new Vector3[8];
			points[0] = bounds.center-bounds.extents;
			points[1] = points[0]+new Vector3(size.x, 0, 0);
			points[2] = points[0]+new Vector3(0, size.y, 0);
			points[3] = points[0]+new Vector3(0, 0, size.z);
			points[4] = bounds.center+bounds.extents;
			points[5] = points[4]-new Vector3(size.x, 0, 0);
			points[6] = points[4]-new Vector3(0, size.y, 0);
			points[7] = points[4]-new Vector3(0, 0, size.z);

			Debug.DrawLine(points[0], points[1], color);
			Debug.DrawLine(points[0], points[2], color);
			Debug.DrawLine(points[0], points[3], color);
			Debug.DrawLine(points[4], points[5], color);
			Debug.DrawLine(points[4], points[6], color);
			Debug.DrawLine(points[4], points[7], color);
			Debug.DrawLine(points[1], points[6], color);
			Debug.DrawLine(points[1], points[7], color);
			Debug.DrawLine(points[2], points[5], color);
			Debug.DrawLine(points[2], points[7], color);
			Debug.DrawLine(points[3], points[5], color);
			Debug.DrawLine(points[3], points[6], color);
		}
Exemple #19
0
        public List<DBVHNode> BoundsQuery(Bounds bounds)
        {
            List<DBVHNode> results = new List<DBVHNode>();

            if (nodes.Count > 0){

            Stack<DBVHNode> stack = new Stack<DBVHNode>();
            stack.Push(nodes[0]);
            while(stack.Count > 0)
            {

                DBVHNode node = stack.Pop();

                if (node.content != null){ //leaf node

                    if (bounds.Intersects(node.content.bounds))
                        results.Add(node);

                }else{

                    if (NodeExists(node.Left) && bounds.Intersects(nodes[node.Left].bounds))
                        stack.Push(nodes[node.Left]);

                    if (NodeExists(node.Right) && bounds.Intersects(nodes[node.Right].bounds))
                        stack.Push(nodes[node.Right]);

                }

            }
            }

            return results;
        }
            //from http://stackoverflow.com/a/17503268/931669
            public static bool existsBetween(Bounds box, Triangle3 triangle)
            {
                double triangleMin, triangleMax;
                double boxMin, boxMax;

                // Test the box normals (x-, y- and z-axes)
                var boxNormals = new Vector3[] {
                    new Vector3(1,0,0),
                    new Vector3(0,1,0),
                    new Vector3(0,0,1)
                };

                //Get the box vertices as array for project()
                var boxVertices = new Vector3[] {
                    box.center + new Vector3(box.extents.x, box.extents.y, box.extents.z),
                    box.center + new Vector3(box.extents.x, -box.extents.y, box.extents.z),
                    box.center + new Vector3(-box.extents.x, -box.extents.y, box.extents.z),
                    box.center + new Vector3(-box.extents.x, box.extents.y, box.extents.z),
                    box.center + new Vector3(box.extents.x, box.extents.y, -box.extents.z),
                    box.center + new Vector3(box.extents.x, -box.extents.y, -box.extents.z),
                    box.center + new Vector3(-box.extents.x, -box.extents.y, -box.extents.z),
                    box.center + new Vector3(-box.extents.x, box.extents.y, -box.extents.z),
                };


                for (int i = 0; i < 3; i++)
                {
                    project(triangle.ABC, boxNormals[i], out triangleMin, out triangleMax);
                    if (triangleMax < box.min[i] || triangleMin > box.max[i])
                        return false; // No intersection possible.
                }

                // Test the triangle normal
                double triangleOffset = Vector3.Dot(triangle.Normal, triangle.A);
                project(boxVertices, triangle.Normal, out boxMin, out boxMax);
                if (boxMax < triangleOffset || boxMin > triangleOffset)
                    return false; // No intersection possible.

                // Test the nine edge cross-products
                Vector3[] triangleEdges = new Vector3[] {
                    triangle.A - (triangle.B),
                    triangle.B - (triangle.C),
                    triangle.C - (triangle.A)
                };
                for (int i = 0; i < 3; i++)
                {
                    for (int j = 0; j < 3; j++)
                    {
                        // The box normals are the same as it's edge tangents
                        Vector3 axis = Vector3.Cross(triangleEdges[i], boxNormals[j]);
                        project(boxVertices, axis, out boxMin, out boxMax);
                        project(triangle.ABC, axis, out triangleMin, out triangleMax);
                        if (boxMax <= triangleMin || boxMin >= triangleMax)
                            return false; // No intersection possible
                    }
                }

                // No separating axis found.
                return true;
            }
Exemple #21
0
        // Compute bounding box
        //
        public Bounds GetBounds()
        {
            float xmin = Mathf.Infinity;
            float ymin = Mathf.Infinity;
            float xmax = -Mathf.Infinity;
            float ymax = -Mathf.Infinity;
            Point v;
            float vx, vy;

            for (int i = this.halfEdges.Count - 1; i >= 0; i--)
            {
                v = this.halfEdges[i].GetStartPoint();
                vx = v.x;
                vy = v.y;
                if (vx < xmin) { xmin = vx; }
                if (vy < ymin) { ymin = vy; }
                if (vx > xmax) { xmax = vx; }
                if (vy > ymax) { ymax = vy; }
                // we dont need to take into account end point,
                // since each end point matches a start point
            }

            // TODO: verify y
            Bounds bounds = new Bounds();
            bounds.SetMinMax(new Vector3(xmin, 0, xmax), new Vector3(ymin, 0, ymax));

            return bounds;
        }
Exemple #22
0
 static bool Bounds_op_Inequality__Bounds__Bounds(JSVCall vc, int argc)
 {
     UnityEngine.Bounds arg0 = (UnityEngine.Bounds)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
     UnityEngine.Bounds arg1 = (UnityEngine.Bounds)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
     JSApi.setBooleanS((int)JSApi.SetType.Rval, (System.Boolean)(arg0 != arg1));
     return(true);
 }
        /// <summary>
        /// Read the data using the reader.
        /// </summary>
        /// <param name="reader">Reader.</param>
        public override object Read(ISaveGameReader reader)
        {
            UnityEngine.Bounds bounds = new UnityEngine.Bounds();
            foreach (string property in reader.Properties)
            {
                switch (property)
                {
                case "center":
                    bounds.center = reader.ReadProperty <UnityEngine.Vector3> ();
                    break;

                case "size":
                    bounds.size = reader.ReadProperty <UnityEngine.Vector3> ();
                    break;

                case "extents":
                    bounds.extents = reader.ReadProperty <UnityEngine.Vector3> ();
                    break;

                case "min":
                    bounds.min = reader.ReadProperty <UnityEngine.Vector3> ();
                    break;

                case "max":
                    bounds.max = reader.ReadProperty <UnityEngine.Vector3> ();
                    break;
                }
            }
            return(bounds);
        }
Exemple #24
0
        private void PositionHighlight()
        {
            var center     = Vector3.zero;
            var totalCount = 0f;

            foreach (Renderer child in GetComponentsInChildren <Renderer>())
            {
                if (child.GetComponent <BoundsHighlightSatellite>() == null)
                {
                    center += child.bounds.center;
                    totalCount++;
                }
            }
            center /= Mathf.Max(totalCount, 1f);

            var extents = new UnityEngine.Bounds();

            extents.center = center;

            foreach (Renderer child in GetComponentsInChildren <Renderer>())
            {
                if (child.GetComponent <BoundsHighlightSatellite>() == null)
                {
                    extents.Encapsulate(child.bounds);
                }
            }


            HighlightBox.transform.rotation = Quaternion.identity;

            HighlightBox.transform.position = extents.center;
            HighlightBox.transform.SetWorldScale(extents.size + 2f * _HighlightPadding);
        }
Exemple #25
0
        public static Bounds GetBounds(GameObject gameObject)
        {
            //get gameObject object bounds
            var filter = gameObject.GetComponent<SkinnedMeshRenderer>() as Renderer;
            if (filter == null) filter = gameObject.GetComponent<MeshRenderer>();
            var bounds = new Bounds(gameObject.transform.position, new Vector3());
            if (filter == null)
            {
                var mf = gameObject.GetComponent<MeshFilter>();
                if (mf != null)
                {
                    bounds.size = mf.sharedMesh.bounds.size;
                }
                else
                {
                    if (gameObject.collider != null)
                    {
                        bounds.size = gameObject.collider.bounds.size;
                    }
                }
            }
            else
            {
                bounds.size = filter.bounds.size;
            }

            return bounds;
        }
        public void Start () {
            // Capture the bounds of the collider while it is closed
            bounds = GetComponent<Collider>().bounds;

            // Initially open the door
            SetState (open);
        }
Exemple #27
0
 public static RMC.Common.UnityEngineReplacement.Bounds Convert(UnityEngine.Bounds uBounds)
 {
     return(new RMC.Common.UnityEngineReplacement.Bounds(
                Convert(uBounds.center),
                Convert(uBounds.size)
                ));
 }
Exemple #28
0
 /**<summary> Get UnityEngine.Bounds from Parser.Bounds </summary>*/
 public UnityEngine.Bounds GetUnityBounds()
 {
     UnityEngine.Bounds bounds = new UnityEngine.Bounds();
     bounds.min = topLeft;
     bounds.max = bottomRight;
     return(bounds);
 }
Exemple #29
0
 static public int Expand(IntPtr l)
 {
     try{
         if (matchType(l, 2, typeof(float)))
         {
             UnityEngine.Bounds self = (UnityEngine.Bounds)checkSelf(l);
             System.Single      a1;
             checkType(l, 2, out a1);
             self.Expand(a1);
             setBack(l, self);
             return(0);
         }
         else if (matchType(l, 2, typeof(UnityEngine.Vector3)))
         {
             UnityEngine.Bounds  self = (UnityEngine.Bounds)checkSelf(l);
             UnityEngine.Vector3 a1;
             checkType(l, 2, out a1);
             self.Expand(a1);
             setBack(l, self);
             return(0);
         }
         LuaDLL.luaL_error(l, "No matched override function to call");
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
        /// <summary>
        /// Attaches this object to 'attachTarget' at 'point'
        /// </summary>
        /// <param name="point">Point to attach to.</param>
        /// <param name="attachTarget">Target object.</param>
        protected void AttachToTarget () {
            targetRenderer = attachTarget.GetComponent<Renderer>();
            targetBounds = targetRenderer.bounds;
            targetPosition = attachTarget.transform.position;

            float width = targetBounds.size.x;
            float height = targetBounds.size.y;
            float attachTargetX = targetPosition.x;
            float attachTargetY = targetPosition.y;
            //NOTE (aaron): Ideally this would be independent of anchor/pivot position, but I cannot find a way to abstract
            //the local relative position of this position within the object. Therefore, this currently only works for objects
            //with centered pivots.
            switch (attachPoint) {
                case AttachPoint.BottomLeft:
                    transform.position = new Vector3(attachTargetX - width / 2, attachTargetY - height / 2, 0);
                    break;
                case AttachPoint.BottomRight:
                    transform.position = new Vector3(attachTargetX + width / 2, attachTargetY - height / 2, 0);
                    break;
                case AttachPoint.TopLeft:
                    transform.position = new Vector3(attachTargetX - width / 2, attachTargetY + height / 2, 0);
                    break;
                case AttachPoint.TopRight:
                    transform.position = new Vector3(attachTargetX + width / 2, attachTargetY + height / 2, 0);
                    break;
                case AttachPoint.BottomCenter:
                    transform.position = new Vector3(attachTargetX, attachTargetY - height / 2, 0);
                    break;
                case AttachPoint.TopCenter:
                    transform.position = new Vector3(attachTargetX, attachTargetY + height / 2, 0);
                    break;
            }
        }
Exemple #31
0
 static public int IntersectRay(IntPtr l)
 {
     try{
         if (matchType(l, 2, typeof(UnityEngine.Ray)))
         {
             UnityEngine.Bounds self = (UnityEngine.Bounds)checkSelf(l);
             UnityEngine.Ray    a1;
             checkType(l, 2, out a1);
             System.Boolean ret = self.IntersectRay(a1);
             pushValue(l, ret);
             return(1);
         }
         else if (matchType(l, 2, typeof(UnityEngine.Ray), typeof(System.Single)))
         {
             UnityEngine.Bounds self = (UnityEngine.Bounds)checkSelf(l);
             UnityEngine.Ray    a1;
             checkType(l, 2, out a1);
             System.Single  a2;
             System.Boolean ret = self.IntersectRay(a1, out a2);
             pushValue(l, ret);
             pushValue(l, a2);
             return(2);
         }
         LuaDLL.luaL_error(l, "No matched override function to call");
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
Exemple #32
0
        //Battle Tile Array uses 32x32 px tiles.  Also includes tileSpriteLookup metadata object
        private void loadBattleTileArray(GameObject tileMapGameObject)
        {

            string strTileArray = "";

            Bounds mapBounds = tileMapGameObject.GetComponentInChildren<Renderer>().bounds;

            int tileWidth = (int)Math.Ceiling(mapBounds.size.x );
            int tileHeight = (int)Math.Ceiling(mapBounds.size.y );

            battleTileArray = new Tile[tileWidth, tileHeight];
            for (int y = 0; y < tileHeight; y++)
            {
                for (int x = 0; x < tileWidth; x++)
                {
                 
                    Vector3 center = new Vector3(x + Tile.TILE_SIZE, -y + Tile.TILE_SIZE,0);
                    Vector3 size = new Vector3(Tile.TILE_SIZE, Tile.TILE_SIZE);
                    Bounds tileBounds = new Bounds(center, size);
                    bool empty = !checkCollision(tileBounds);

                    battleTileArray[x, y] = new Tile(x, y, empty);

                    //Extra metadata on tile
                    battleTileArray[x, y].tileSpriteLookup = getTileSpriteLookup(tileBounds, x, y, empty);

                    strTileArray += empty ? "." : "#";
                }
                strTileArray += System.Environment.NewLine;
            }
            int i = 1;
        }
Exemple #33
0
        /// <summary>
        /// Gets the rendering bounds of the transform.
        /// </summary>
        /// <param name="transform">The game object to get the bounding box for.</param>
        /// <param name="pBound">The bounding box reference that will </param>
        /// <param name="encapsulate">Used to determine if the first bounding box to be 
        /// calculated should be encapsulated into the <see cref="pBound"/> argument.</param>
        /// <returns>Returns true if at least one bounding box was calculated.</returns>
        public static bool GetBoundWithChildren(Transform transform, ref Bounds pBound, ref bool encapsulate)
        {
            var didOne = false;

            // get 'this' bound
            if (transform.gameObject.renderer != null)
            {
                var bound = transform.gameObject.renderer.bounds;
                if (encapsulate)
                {
                    pBound.Encapsulate(bound.min);
                    pBound.Encapsulate(bound.max);
                }
                else
                {
                    pBound.min = bound.min; 
                    pBound.max = bound.max; 
                    encapsulate = true;
                }

                didOne = true;
            }

            // union with bound(s) of any/all children
            foreach (Transform child in transform)
            {
                if (GetBoundWithChildren(child, ref pBound, ref encapsulate))
                {
                    didOne = true;
                }
            }

            return didOne;
        }
        public static float MaxBoundsExtent(Transform obj, bool includeEffects)
        {
            // get the maximum bounds extent of object, including all child renderers,
            // but excluding particles and trails, for FOV zooming effect.

            var renderers = obj.GetComponentsInChildren<Renderer>();

            Bounds bounds = new Bounds();
            bool initBounds = false;
            foreach (Renderer r in renderers)
            {
                if (!((r is TrailRenderer) || (r is ParticleRenderer) || (r is ParticleSystemRenderer)))
                {
                    if (!initBounds)
                    {
                        initBounds = true;
                        bounds = r.bounds;
                    }
                    else
                    {
                        bounds.Encapsulate(r.bounds);
                    }
                }
            }
            float max = Mathf.Max(bounds.extents.x, bounds.extents.y, bounds.extents.z);
            return max;
        }
 static public int CalculateRelativeRectTransformBounds_s(IntPtr l)
 {
     try{
         if (matchType(l, 1, typeof(UnityEngine.Transform), typeof(UnityEngine.Transform)))
         {
             UnityEngine.Transform a1;
             checkType(l, 1, out a1);
             UnityEngine.Transform a2;
             checkType(l, 2, out a2);
             UnityEngine.Bounds ret = UnityEngine.RectTransformUtility.CalculateRelativeRectTransformBounds(a1, a2);
             pushValue(l, ret);
             return(1);
         }
         else if (matchType(l, 1, typeof(UnityEngine.Transform)))
         {
             UnityEngine.Transform a1;
             checkType(l, 1, out a1);
             UnityEngine.Bounds ret = UnityEngine.RectTransformUtility.CalculateRelativeRectTransformBounds(a1);
             pushValue(l, ret);
             return(1);
         }
         LuaDLL.luaL_error(l, "No matched override function to call");
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
        public override void OnEnter()
        {
            var bounds = new UnityEngine.Bounds(center.Value, size.Value);

            AstarPath.active.UpdateGraphs(bounds);
            Finish();
        }
        public void addPayload(Bounds box, Matrix4x4 boxTm)
        {
            Matrix4x4 m=w2l*boxTm;

            Vector3 p0=box.min, p1=box.max;
            var verts=new Vector3[8];
            for (int i=0; i<8; ++i)
              verts[i]=m.MultiplyPoint3x4(new Vector3(
            (i&1)!=0 ? p1.x : p0.x,
            (i&2)!=0 ? p1.y : p0.y,
            (i&4)!=0 ? p1.z : p0.z));

            addPayloadEdge(verts[0], verts[1]);
            addPayloadEdge(verts[2], verts[3]);
            addPayloadEdge(verts[4], verts[5]);
            addPayloadEdge(verts[6], verts[7]);

            addPayloadEdge(verts[0], verts[2]);
            addPayloadEdge(verts[1], verts[3]);
            addPayloadEdge(verts[4], verts[6]);
            addPayloadEdge(verts[5], verts[7]);

            addPayloadEdge(verts[0], verts[4]);
            addPayloadEdge(verts[1], verts[5]);
            addPayloadEdge(verts[2], verts[6]);
            addPayloadEdge(verts[3], verts[7]);
        }
Exemple #38
0
 public static void DrawBounds(Bounds bounds)
 {
     DrawLine(bounds.min, new Vector2(bounds.min.x, bounds.max.y));
     DrawLine(bounds.min, new Vector2(bounds.max.x, bounds.min.y));
     DrawLine(bounds.max, new Vector2(bounds.min.x, bounds.max.y));
     DrawLine(bounds.max, new Vector2(bounds.max.x, bounds.min.y));
 }
Exemple #39
0
        public static Bounds getChildBounds(this Transform t)
        {
            //To handle exeption when a object has no children and no sprite Renderer
            if (t.childCount == 0)
            {
                SpriteRenderer r = t.gameObject.GetComponent<SpriteRenderer>();

                if (r)
                    return r.bounds;
                else
                    return new Bounds();
            }

            Bounds bounds;
            // First find a center for your bounds.
            Vector3 center = Vector3.zero;
            foreach (Transform child in t.transform)
            {
                center += child.gameObject.GetComponent<SpriteRenderer>().bounds.center;
            }
            center /= t.transform.childCount; //center is average center of children

            //Now you have a center, calculate the bounds by creating a zero sized 'Bounds', 
            bounds = new Bounds(center, Vector3.zero);

            foreach (Transform child in t.transform)
            {
                bounds.Encapsulate(child.gameObject.GetComponent<SpriteRenderer>().bounds);
            }
            return bounds;
        }
Exemple #40
0
 public override object ReadJson( Type objectType, Dictionary<string,object> values)
 {
     Bounds b = new Bounds();
     b.center = new Vector3(	CastFloat(values["cx"]),CastFloat(values["cy"]),CastFloat(values["cz"]));
     b.extents = new Vector3(CastFloat(values["ex"]),CastFloat(values["ey"]),CastFloat(values["ez"]));
     return b;
 }
 public static Bounds CalculateRelativeRectTransformBounds(Transform root, Transform child)
 {
     RectTransform[] componentsInChildren = child.GetComponentsInChildren<RectTransform>(false);
     if (componentsInChildren.Length > 0)
     {
         Vector3 rhs = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
         Vector3 vector2 = new Vector3(float.MinValue, float.MinValue, float.MinValue);
         Matrix4x4 worldToLocalMatrix = root.worldToLocalMatrix;
         int index = 0;
         int length = componentsInChildren.Length;
         while (index < length)
         {
             componentsInChildren[index].GetWorldCorners(s_Corners);
             for (int i = 0; i < 4; i++)
             {
                 Vector3 lhs = worldToLocalMatrix.MultiplyPoint3x4(s_Corners[i]);
                 rhs = Vector3.Min(lhs, rhs);
                 vector2 = Vector3.Max(lhs, vector2);
             }
             index++;
         }
         Bounds bounds = new Bounds(rhs, Vector3.zero);
         bounds.Encapsulate(vector2);
         return bounds;
     }
     return new Bounds(Vector3.zero, Vector3.zero);
 }
 private static void DrawPoseError(Transform node, Bounds bounds)
 {
     if (Camera.current != null)
     {
         GUIStyle style = new GUIStyle(GUI.skin.label) {
             normal = { textColor = Color.red },
             wordWrap = false,
             alignment = TextAnchor.MiddleLeft
         };
         Vector3 position = node.position;
         Vector3 vector2 = node.position + ((Vector3) (Vector3.up * 0.2f));
         if (node.position.x <= node.root.position.x)
         {
             vector2.x = bounds.min.x;
         }
         else
         {
             vector2.x = bounds.max.x;
         }
         GUIContent content = new GUIContent(node.name);
         Rect rect = HandleUtility.WorldPointToSizedRect(vector2, content, style);
         rect.x += 2f;
         if (node.position.x > node.root.position.x)
         {
             rect.x -= rect.width;
         }
         Handles.BeginGUI();
         rect.y -= style.CalcSize(content).y / 4f;
         GUI.Label(rect, content, style);
         Handles.EndGUI();
         Handles.color = kErrorMessageColor;
         Handles.DrawLine(position, vector2);
     }
 }
        public ObjectInfoMetadata(GameObject go, int ownerID)
        {
            this.ObjectName = go.name;
            this.Position   = go.transform.position;
            this.Rotation   = go.transform.rotation;
            if (go.GetComponent <MeshFilter>() != null)
            {
                Mesh mesh = go.GetComponent <MeshFilter>().sharedMesh;
                if (mesh == null)
                {
                    mesh = go.GetComponent <MeshFilter>().mesh;
                }

                if (mesh != null)
                {
                    this.BoundingBox = mesh.bounds;
                }
            }
            else
            {
                this.BoundingBox = new Bounds();
            }

            this.OwnerID = (ownerID < 1) ? 0 : ownerID; // associate object with scene
        }
Exemple #44
0
 public void Reset()
 {
     bounds = kDefaultBounds;
     if (surfaceDefinition != null)
     {
         surfaceDefinition.Reset();
     }
 }
Exemple #45
0
    private Bounds getTileBounds(int x, int y)
    {
        Vector3 center = new UnityEngine.Vector3(x, y, 0);
        Vector3 size   = new UnityEngine.Vector3(Tile.TILE_SIZE, Tile.TILE_SIZE);
        Bounds  b      = new UnityEngine.Bounds(center, size);

        return(b);
    }
Exemple #46
0
 public Terrain(List <GameObject> terrainObjects)
 {
     foreach (GameObject obj2 in terrainObjects)
     {
         this.CollectMeshParts(obj2);
     }
     this.bounds = CalculateBounds(this.meshColliders);
 }
 /// <summary>
 /// Write the specified value using the writer.
 /// </summary>
 /// <param name="value">Value.</param>
 /// <param name="writer">Writer.</param>
 public override void Write(object value, ISaveGameWriter writer)
 {
     UnityEngine.Bounds bounds = (UnityEngine.Bounds)value;
     writer.WriteProperty("center", bounds.center);
     writer.WriteProperty("size", bounds.size);
     writer.WriteProperty("extents", bounds.extents);
     writer.WriteProperty("min", bounds.min);
     writer.WriteProperty("max", bounds.max);
 }
 static public void FastSetter(this UnityEngine.Animation o, string propertyName, UnityEngine.Bounds value)
 {
     switch (propertyName)
     {
     case "localBounds":
         o.localBounds = value; return;
     }
     LBoot.LogUtil.Error("UnityEngine.Animation no Setter Found : " + propertyName);
 }
Exemple #49
0
 static public int set_max(IntPtr l)
 {
     UnityEngine.Bounds  o = (UnityEngine.Bounds)checkSelf(l);
     UnityEngine.Vector3 v;
     checkType(l, 2, out v);
     o.max = v;
     setBack(l, o);
     return(0);
 }
    public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
    {
        UnityEngine.Bounds bounds = (UnityEngine.Bounds)value;
        JObject            jo     = new JObject();

        jo.Add("c", JToken.FromObject(new { x = bounds.center.x, y = bounds.center.y, z = bounds.center.z }));
        jo.Add("e", JToken.FromObject(new { x = bounds.extents.x, y = bounds.extents.y, z = bounds.extents.z }));
        serializer.Serialize(writer, jo);
    }
Exemple #51
0
 static public int constructor(IntPtr l)
 {
     UnityEngine.Bounds  o;
     UnityEngine.Vector3 a1;
     checkType(l, 2, out a1);
     UnityEngine.Vector3 a2;
     checkType(l, 3, out a2);
     o = new UnityEngine.Bounds(a1, a2);
     pushObject(l, o);
     return(1);
 }
Exemple #52
0
 private void CalculateBounds()
 {
     Bounds = new UnityEngine.Bounds(
         _camera.transform.position,
         new Vector3(
             _camera.orthographicSize * _camera.aspect * 2,
             _camera.orthographicSize * 2,
             0
             )
         );
 }
Exemple #53
0
    static bool Bounds_GetHashCode(JSVCall vc, int argc)
    {
        int len = argc;

        if (len == 0)
        {
            UnityEngine.Bounds argThis = (UnityEngine.Bounds)vc.csObj;                JSApi.setInt32((int)JSApi.SetType.Rval, (System.Int32)(argThis.GetHashCode()));
            JSMgr.changeJSObj(vc.jsObjID, argThis);
        }

        return(true);
    }
Exemple #54
0
    static bool Bounds_ToString(JSVCall vc, int argc)
    {
        int len = argc;

        if (len == 0)
        {
            UnityEngine.Bounds argThis = (UnityEngine.Bounds)vc.csObj;                JSApi.setStringS((int)JSApi.SetType.Rval, argThis.ToString());
            JSMgr.changeJSObj(vc.jsObjID, argThis);
        }

        return(true);
    }
 public BoundsVertices(UnityEngine.Bounds bounds)
 {
     BoundVertices    = new Vector3[8];
     BoundVertices[0] = bounds.min;
     BoundVertices[1] = bounds.max;
     BoundVertices[2] = new Vector3(BoundVertices[0].x, BoundVertices[0].y, BoundVertices[1].z);
     BoundVertices[3] = new Vector3(BoundVertices[0].x, BoundVertices[1].y, BoundVertices[0].z);
     BoundVertices[4] = new Vector3(BoundVertices[1].x, BoundVertices[0].y, BoundVertices[0].z);
     BoundVertices[5] = new Vector3(BoundVertices[0].x, BoundVertices[1].y, BoundVertices[1].z);
     BoundVertices[6] = new Vector3(BoundVertices[1].x, BoundVertices[0].y, BoundVertices[1].z);
     BoundVertices[7] = new Vector3(BoundVertices[1].x, BoundVertices[1].y, BoundVertices[0].z);
 }
Exemple #56
0
    static bool Bounds_Expand__Vector3(JSVCall vc, int argc)
    {
        int len = argc;

        if (len == 1)
        {
            UnityEngine.Vector3 arg0    = (UnityEngine.Vector3)JSApi.getVector3S((int)JSApi.GetType.Arg);
            UnityEngine.Bounds  argThis = (UnityEngine.Bounds)vc.csObj;        argThis.Expand(arg0);
            JSMgr.changeJSObj(vc.jsObjID, argThis);
        }

        return(true);
    }
Exemple #57
0
    static bool Bounds_Expand__Single(JSVCall vc, int argc)
    {
        int len = argc;

        if (len == 1)
        {
            System.Single      arg0    = (System.Single)JSApi.getSingle((int)JSApi.GetType.Arg);
            UnityEngine.Bounds argThis = (UnityEngine.Bounds)vc.csObj;        argThis.Expand(arg0);
            JSMgr.changeJSObj(vc.jsObjID, argThis);
        }

        return(true);
    }
Exemple #58
0
    static bool Bounds_Intersects__Bounds(JSVCall vc, int argc)
    {
        int len = argc;

        if (len == 1)
        {
            UnityEngine.Bounds arg0    = (UnityEngine.Bounds)JSMgr.datax.getObject((int)JSApi.GetType.Arg);
            UnityEngine.Bounds argThis = (UnityEngine.Bounds)vc.csObj;                JSApi.setBooleanS((int)JSApi.SetType.Rval, (System.Boolean)(argThis.Intersects(arg0)));
            JSMgr.changeJSObj(vc.jsObjID, argThis);
        }

        return(true);
    }
Exemple #59
0
    static bool Bounds_SqrDistance__Vector3(JSVCall vc, int argc)
    {
        int len = argc;

        if (len == 1)
        {
            UnityEngine.Vector3 arg0    = (UnityEngine.Vector3)JSApi.getVector3S((int)JSApi.GetType.Arg);
            UnityEngine.Bounds  argThis = (UnityEngine.Bounds)vc.csObj;                JSApi.setSingle((int)JSApi.SetType.Rval, (System.Single)(argThis.SqrDistance(arg0)));
            JSMgr.changeJSObj(vc.jsObjID, argThis);
        }

        return(true);
    }
Exemple #60
0
    static bool Bounds_ToString__String(JSVCall vc, int argc)
    {
        int len = argc;

        if (len == 1)
        {
            System.String      arg0    = (System.String)JSApi.getStringS((int)JSApi.GetType.Arg);
            UnityEngine.Bounds argThis = (UnityEngine.Bounds)vc.csObj;                JSApi.setStringS((int)JSApi.SetType.Rval, argThis.ToString(arg0));
            JSMgr.changeJSObj(vc.jsObjID, argThis);
        }

        return(true);
    }