Example #1
0
        private WorldBound Vector2WorldBound(Vector3 center, Vector3 extents)
        {
            WorldBound worldBound = new WorldBound();

            worldBound.centerX  = center.x;
            worldBound.centerY  = center.y;
            worldBound.centerZ  = center.z;
            worldBound.extentsX = extents.x;
            worldBound.extentsY = extents.y;
            worldBound.extentsZ = extents.z;
            worldBound.existed  = true;
            return(worldBound);
        }
Example #2
0
        public WorldBound GetWorldBound(GameObject gameobject)
        {
            Vector3    center  = new Vector3();
            Vector3    extents = new Vector3();
            WorldBound worldBound;
            Renderer   render = gameobject.GetComponent <Renderer>();

            if (render != null)
            {
                center     = render.bounds.center;
                extents    = render.bounds.extents;
                worldBound = Vector2WorldBound(center, extents);
                return(worldBound);
            }

            MeshFilter meshFilter = gameobject.GetComponent <MeshFilter>();

            if (meshFilter != null && meshFilter.sharedMesh != null)
            {
                //Logger.d("By MeshFilter");
                Mesh mesh = meshFilter.sharedMesh;
                center     = mesh.bounds.center;
                extents    = mesh.bounds.extents;
                worldBound = Vector2WorldBound(center, extents);
                return(worldBound);
            }

            Collider collider = gameobject.GetComponent <Collider>();

            if (gameobject.activeInHierarchy && collider != null && collider.enabled)
            {
                center     = collider.bounds.center;
                extents    = collider.bounds.extents;
                worldBound = Vector2WorldBound(center, extents);
                return(worldBound);
            }
            worldBound         = new WorldBound();
            worldBound.existed = false;
            return(worldBound);
        }
Example #3
0
        protected void handleGetWorldBound(Command command)
        {
            Logger.d("handleGetWorldBound");

            List <int>        instances   = JsonParser.Deserialization <List <int> >(command);
            List <WorldBound> worldBounds = new List <WorldBound>();

            for (int i = 0; i < instances.Count; ++i)
            {
                int        instance   = instances[i];
                GameObject obj        = GameObjectManager.INSTANCE.FindGameObjectGlobal(instance);
                WorldBound worldBound = null;
                try
                {
                    if (obj != null)
                    {
                        worldBound = uiHelper.GetWorldBound(obj);
                    }
                    else
                    {
                        worldBound         = new WorldBound();
                        worldBound.existed = false;
                    }
                }
                catch (System.Exception ex)
                {
                    Logger.w(ex.Message + " " + ex.StackTrace);
                    worldBound         = new WorldBound();
                    worldBound.existed = false;
                }
                worldBound.id = instance;
                worldBounds.Add(worldBound);
            }

            command.sendObj = worldBounds;
            CommandDispatcher.SendCommand(command);
        }